mirror of
https://github.com/bbara04/Purefin.git
synced 2026-07-23 19:26:50 +00:00
feat: add ReadOnlySetting and corresponding UI component for displaying read-only settings
This commit is contained in:
@@ -41,6 +41,7 @@ import hu.bbara.purefin.core.feature.settings.SettingsViewModel
|
||||
import hu.bbara.purefin.core.settings.BooleanSetting
|
||||
import hu.bbara.purefin.core.settings.DropdownSetting
|
||||
import hu.bbara.purefin.core.settings.RangeSetting
|
||||
import hu.bbara.purefin.core.settings.ReadOnlySetting
|
||||
import hu.bbara.purefin.core.settings.SettingOption
|
||||
import hu.bbara.purefin.core.settings.StringSetting
|
||||
import hu.bbara.purefin.core.settings.VoidSetting
|
||||
@@ -149,6 +150,13 @@ private fun TvSettingOptionItem(
|
||||
}
|
||||
}
|
||||
|
||||
is ReadOnlySetting -> {
|
||||
TvReadOnlySettingItem(
|
||||
title = option.title,
|
||||
value = option.value
|
||||
)
|
||||
}
|
||||
|
||||
is VoidSetting -> {
|
||||
TvVoidSettingItem(
|
||||
title = option.title,
|
||||
@@ -200,6 +208,31 @@ private fun TvSettingsTopBar(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TvReadOnlySettingItem(
|
||||
title: String,
|
||||
value: String,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 28.dp, vertical = 16.dp)
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.bodyLarge
|
||||
)
|
||||
Text(
|
||||
text = value,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TvVoidSettingItem(
|
||||
title: String,
|
||||
|
||||
@@ -24,6 +24,7 @@ import hu.bbara.purefin.core.feature.settings.SettingsViewModel
|
||||
import hu.bbara.purefin.core.settings.BooleanSetting
|
||||
import hu.bbara.purefin.core.settings.DropdownSetting
|
||||
import hu.bbara.purefin.core.settings.RangeSetting
|
||||
import hu.bbara.purefin.core.settings.ReadOnlySetting
|
||||
import hu.bbara.purefin.core.settings.SettingOption
|
||||
import hu.bbara.purefin.core.settings.StringSetting
|
||||
import hu.bbara.purefin.core.settings.VoidSetting
|
||||
@@ -32,6 +33,7 @@ import hu.bbara.purefin.ui.screen.home.components.DefaultTopBarIconButton
|
||||
import hu.bbara.purefin.ui.screen.settings.components.BooleanSettingItem
|
||||
import hu.bbara.purefin.ui.screen.settings.components.DropdownSettingItem
|
||||
import hu.bbara.purefin.ui.screen.settings.components.RangeSettingItem
|
||||
import hu.bbara.purefin.ui.screen.settings.components.ReadOnlySettingItem
|
||||
import hu.bbara.purefin.ui.screen.settings.components.StringSettingItem
|
||||
import hu.bbara.purefin.ui.screen.settings.components.VoidSettingItem
|
||||
|
||||
@@ -138,6 +140,13 @@ private fun SettingOptionItem(
|
||||
}
|
||||
}
|
||||
|
||||
is ReadOnlySetting -> {
|
||||
ReadOnlySettingItem(
|
||||
title = option.title,
|
||||
value = option.value
|
||||
)
|
||||
}
|
||||
|
||||
is VoidSetting -> {
|
||||
VoidSettingItem(
|
||||
title = option.title,
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package hu.bbara.purefin.ui.screen.settings.components
|
||||
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
|
||||
@Composable
|
||||
fun ReadOnlySettingItem(
|
||||
title: String,
|
||||
value: String,
|
||||
modifier: Modifier = Modifier.Companion
|
||||
) {
|
||||
ListItem(
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.bodyLarge
|
||||
)
|
||||
},
|
||||
trailingContent = {
|
||||
Text(
|
||||
text = value,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
)
|
||||
},
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package hu.bbara.purefin.core.feature.update
|
||||
|
||||
import hu.bbara.purefin.core.settings.ReadOnlySetting
|
||||
import hu.bbara.purefin.core.settings.SettingGroup
|
||||
import hu.bbara.purefin.core.settings.SettingOption
|
||||
import hu.bbara.purefin.core.settings.SettingsGroupProvider
|
||||
import hu.bbara.purefin.core.settings.VoidSetting
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@@ -18,7 +20,8 @@ import javax.inject.Singleton
|
||||
@Singleton
|
||||
class AppUpdateController @Inject constructor(
|
||||
private val appUpdateRepository: AppUpdateRepository,
|
||||
private val appUpdateInstaller: AppUpdateInstaller
|
||||
private val appUpdateInstaller: AppUpdateInstaller,
|
||||
private val appVersionProvider: AppVersionProvider
|
||||
) : SettingsGroupProvider {
|
||||
private val _isCheckingForUpdates = MutableStateFlow(false)
|
||||
val isCheckingForUpdates: StateFlow<Boolean> = _isCheckingForUpdates.asStateFlow()
|
||||
@@ -34,16 +37,17 @@ class AppUpdateController @Inject constructor(
|
||||
|
||||
override val settingGroups: Flow<List<SettingGroup>> = availableUpdate
|
||||
.map { update ->
|
||||
if (update == null) {
|
||||
emptyList()
|
||||
} else {
|
||||
listOf(
|
||||
SettingGroup(
|
||||
title = "App",
|
||||
options = listOf(installUpdateSetting(update))
|
||||
)
|
||||
val options = listOfNotNull<SettingOption<*>>(
|
||||
buildNumberSetting(),
|
||||
update?.let { installUpdateSetting(it) }
|
||||
)
|
||||
|
||||
listOf(
|
||||
SettingGroup(
|
||||
title = "App",
|
||||
options = options
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun checkForUpdates(
|
||||
@@ -100,7 +104,14 @@ class AppUpdateController @Inject constructor(
|
||||
)
|
||||
}
|
||||
|
||||
private fun buildNumberSetting() = ReadOnlySetting(
|
||||
key = BUILD_NUMBER_KEY,
|
||||
title = "Build number",
|
||||
value = appVersionProvider.versionCode.toString()
|
||||
)
|
||||
|
||||
private companion object {
|
||||
const val BUILD_NUMBER_KEY = "build_number"
|
||||
const val INSTALL_APP_UPDATE_KEY = "install_app_update"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,14 @@ data class StringSetting(
|
||||
override val defaultValue: String
|
||||
) : SettingOption<String>
|
||||
|
||||
data class ReadOnlySetting(
|
||||
override val key: String,
|
||||
override val title: String,
|
||||
val value: String
|
||||
) : SettingOption<String> {
|
||||
override val defaultValue: String = value
|
||||
}
|
||||
|
||||
data class VoidSetting(
|
||||
override val key: String,
|
||||
override val title: String,
|
||||
|
||||
Reference in New Issue
Block a user