UI: support `NONE` Llama Tier in general settings
This commit is contained in:
parent
1f41ae2315
commit
e6413dd05d
|
|
@ -1,10 +1,7 @@
|
||||||
package com.example.llama.ui.components
|
package com.example.llama.ui.components
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.llama.cpp.ArmFeature
|
import android.llama.cpp.ArmFeature
|
||||||
import android.llama.cpp.ArmFeaturesMapper
|
import android.llama.cpp.ArmFeaturesMapper.DisplayItem
|
||||||
import android.llama.cpp.LLamaTier
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
|
@ -13,11 +10,8 @@ import androidx.compose.material3.SegmentedButton
|
||||||
import androidx.compose.material3.SegmentedButtonDefaults
|
import androidx.compose.material3.SegmentedButtonDefaults
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.core.net.toUri
|
|
||||||
import kotlin.math.sqrt
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -26,72 +20,41 @@ import kotlin.math.sqrt
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ArmFeaturesVisualizer(
|
fun ArmFeaturesVisualizer(
|
||||||
detectedTier: LLamaTier?,
|
supportedFeatures: List<DisplayItem>,
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
onFeatureClick: ((ArmFeature) -> Unit)? = null
|
onFeatureClick: ((ArmFeature) -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
val featuresData = remember(detectedTier) {
|
// Segmented Button Row for Features
|
||||||
ArmFeaturesMapper.getFeatureDisplayData(detectedTier)
|
MultiChoiceSegmentedButtonRow(
|
||||||
}
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = modifier.fillMaxWidth()
|
|
||||||
) {
|
) {
|
||||||
// Segmented Button Row for Features
|
supportedFeatures.forEachIndexed { index, item ->
|
||||||
MultiChoiceSegmentedButtonRow(
|
val weight = sqrt(item.feature.displayName.length.toFloat())
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
featuresData.forEachIndexed { index, item ->
|
|
||||||
val weight = sqrt(item.feature.displayName.length.toFloat())
|
|
||||||
|
|
||||||
SegmentedButton(
|
SegmentedButton(
|
||||||
modifier = Modifier.weight(weight),
|
modifier = Modifier.weight(weight),
|
||||||
shape = SegmentedButtonDefaults.itemShape(
|
shape = SegmentedButtonDefaults.itemShape(
|
||||||
index = index,
|
index = index,
|
||||||
count = featuresData.size
|
count = supportedFeatures.size
|
||||||
),
|
),
|
||||||
icon = {},
|
icon = {},
|
||||||
onCheckedChange = { onFeatureClick?.invoke(item.feature) },
|
onCheckedChange = { onFeatureClick?.invoke(item.feature) },
|
||||||
checked = item.isSupported,
|
checked = item.isSupported,
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = item.feature.displayName,
|
text = item.feature.displayName,
|
||||||
style = MaterialTheme.typography.labelSmall,
|
style = MaterialTheme.typography.labelSmall,
|
||||||
fontWeight = if (item.isSupported) {
|
fontWeight = if (item.isSupported) {
|
||||||
FontWeight.Medium
|
FontWeight.Medium
|
||||||
} else {
|
} else {
|
||||||
FontWeight.Light
|
FontWeight.Light
|
||||||
},
|
},
|
||||||
color = if (item.isSupported) {
|
color = if (item.isSupported) {
|
||||||
MaterialTheme.colorScheme.onSurface
|
MaterialTheme.colorScheme.onSurface
|
||||||
} else {
|
} else {
|
||||||
MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.7f)
|
MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.7f)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Alternative version with clickable features that open ARM documentation.
|
|
||||||
*/
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
|
||||||
fun ArmFeaturesVisualizerClickable(
|
|
||||||
detectedTier: LLamaTier?,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
ArmFeaturesVisualizer(
|
|
||||||
detectedTier = detectedTier,
|
|
||||||
modifier = modifier,
|
|
||||||
onFeatureClick = { feature ->
|
|
||||||
// Open ARM documentation in browser
|
|
||||||
val intent = Intent(Intent.ACTION_VIEW, feature.armDocUrl.toUri())
|
|
||||||
context.startActivity(intent)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package com.example.llama.ui.screens
|
package com.example.llama.ui.screens
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.llama.cpp.ArmFeaturesMapper
|
||||||
|
import android.llama.cpp.ArmFeaturesMapper.DisplayItem
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
|
@ -10,6 +13,7 @@ import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.SegmentedButton
|
import androidx.compose.material3.SegmentedButton
|
||||||
|
|
@ -20,12 +24,15 @@ import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.core.net.toUri
|
||||||
import com.example.llama.APP_NAME
|
import com.example.llama.APP_NAME
|
||||||
import com.example.llama.data.preferences.UserPreferences
|
import com.example.llama.data.preferences.UserPreferences
|
||||||
import com.example.llama.ui.components.ArmFeaturesVisualizerClickable
|
import com.example.llama.ui.components.ArmFeaturesVisualizer
|
||||||
import com.example.llama.viewmodel.SettingsViewModel
|
import com.example.llama.viewmodel.SettingsViewModel
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -41,6 +48,10 @@ fun SettingsGeneralScreen(
|
||||||
val themeMode by viewModel.themeMode.collectAsState()
|
val themeMode by viewModel.themeMode.collectAsState()
|
||||||
val detectedTier = viewModel.detectedTier
|
val detectedTier = viewModel.detectedTier
|
||||||
|
|
||||||
|
val supportedFeatures = remember(detectedTier) {
|
||||||
|
ArmFeaturesMapper.getFeatureDisplayData(detectedTier)
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
|
@ -128,9 +139,11 @@ fun SettingsGeneralScreen(
|
||||||
detectedTier?.let { tier ->
|
detectedTier?.let { tier ->
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
ArmFeaturesVisualizerClickable(detectedTier = detectedTier)
|
supportedFeatures?.let {
|
||||||
|
ArmFeaturesVisualizerClickable(supportedFeatures = supportedFeatures)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
}
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = "Optimization Tier: ${tier.name}",
|
text = "Optimization Tier: ${tier.name}",
|
||||||
|
|
@ -224,3 +237,23 @@ fun SettingsSwitch(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alternative version with clickable features that open ARM documentation.
|
||||||
|
*/
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun ArmFeaturesVisualizerClickable(
|
||||||
|
supportedFeatures: List<DisplayItem>,
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
ArmFeaturesVisualizer(
|
||||||
|
supportedFeatures = supportedFeatures,
|
||||||
|
onFeatureClick = { feature ->
|
||||||
|
// Open ARM documentation in browser
|
||||||
|
val intent = Intent(Intent.ACTION_VIEW, feature.armDocUrl.toUri())
|
||||||
|
context.startActivity(intent)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,13 +78,15 @@ object ArmFeaturesMapper {
|
||||||
/**
|
/**
|
||||||
* Gets the feature support data for UI display.
|
* Gets the feature support data for UI display.
|
||||||
*/
|
*/
|
||||||
fun getFeatureDisplayData(tier: LLamaTier?): List<DisplayItem> =
|
fun getFeatureDisplayData(tier: LLamaTier?): List<DisplayItem>? =
|
||||||
getSupportedFeatures(tier).let { flags ->
|
getSupportedFeatures(tier).let { optFlags ->
|
||||||
allFeatures.mapIndexed { index, feature ->
|
optFlags?.let { flags ->
|
||||||
DisplayItem(
|
allFeatures.mapIndexed { index, feature ->
|
||||||
feature = feature,
|
DisplayItem(
|
||||||
isSupported = flags?.getOrElse(index) { false } == true
|
feature = feature,
|
||||||
)
|
isSupported = flags.getOrElse(index) { false }
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue