UI: support `NONE` Llama Tier in general settings

This commit is contained in:
Han Yin 2025-07-03 13:44:25 -07:00
parent 1f41ae2315
commit e6413dd05d
3 changed files with 76 additions and 78 deletions

View File

@ -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,29 +20,21 @@ 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) {
ArmFeaturesMapper.getFeatureDisplayData(detectedTier)
}
Column(
modifier = modifier.fillMaxWidth()
) { ) {
// Segmented Button Row for Features // Segmented Button Row for Features
MultiChoiceSegmentedButtonRow( MultiChoiceSegmentedButtonRow(
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
featuresData.forEachIndexed { index, item -> supportedFeatures.forEachIndexed { index, item ->
val weight = sqrt(item.feature.displayName.length.toFloat()) 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) },
@ -72,26 +58,3 @@ fun ArmFeaturesVisualizer(
} }
} }
} }
}
/**
* 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)
}
)
}

View File

@ -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)
}
)
}

View File

@ -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 ->
optFlags?.let { flags ->
allFeatures.mapIndexed { index, feature -> allFeatures.mapIndexed { index, feature ->
DisplayItem( DisplayItem(
feature = feature, feature = feature,
isSupported = flags?.getOrElse(index) { false } == true isSupported = flags.getOrElse(index) { false }
) )
} }
} }
} }
}