mirror of
https://github.com/bbara04/Purefin.git
synced 2026-07-24 03:36:51 +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.BooleanSetting
|
||||||
import hu.bbara.purefin.core.settings.DropdownSetting
|
import hu.bbara.purefin.core.settings.DropdownSetting
|
||||||
import hu.bbara.purefin.core.settings.RangeSetting
|
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.SettingOption
|
||||||
import hu.bbara.purefin.core.settings.StringSetting
|
import hu.bbara.purefin.core.settings.StringSetting
|
||||||
import hu.bbara.purefin.core.settings.VoidSetting
|
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 -> {
|
is VoidSetting -> {
|
||||||
TvVoidSettingItem(
|
TvVoidSettingItem(
|
||||||
title = option.title,
|
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
|
@Composable
|
||||||
private fun TvVoidSettingItem(
|
private fun TvVoidSettingItem(
|
||||||
title: String,
|
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.BooleanSetting
|
||||||
import hu.bbara.purefin.core.settings.DropdownSetting
|
import hu.bbara.purefin.core.settings.DropdownSetting
|
||||||
import hu.bbara.purefin.core.settings.RangeSetting
|
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.SettingOption
|
||||||
import hu.bbara.purefin.core.settings.StringSetting
|
import hu.bbara.purefin.core.settings.StringSetting
|
||||||
import hu.bbara.purefin.core.settings.VoidSetting
|
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.BooleanSettingItem
|
||||||
import hu.bbara.purefin.ui.screen.settings.components.DropdownSettingItem
|
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.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.StringSettingItem
|
||||||
import hu.bbara.purefin.ui.screen.settings.components.VoidSettingItem
|
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 -> {
|
is VoidSetting -> {
|
||||||
VoidSettingItem(
|
VoidSettingItem(
|
||||||
title = option.title,
|
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
|
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.SettingGroup
|
||||||
|
import hu.bbara.purefin.core.settings.SettingOption
|
||||||
import hu.bbara.purefin.core.settings.SettingsGroupProvider
|
import hu.bbara.purefin.core.settings.SettingsGroupProvider
|
||||||
import hu.bbara.purefin.core.settings.VoidSetting
|
import hu.bbara.purefin.core.settings.VoidSetting
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
@@ -18,7 +20,8 @@ import javax.inject.Singleton
|
|||||||
@Singleton
|
@Singleton
|
||||||
class AppUpdateController @Inject constructor(
|
class AppUpdateController @Inject constructor(
|
||||||
private val appUpdateRepository: AppUpdateRepository,
|
private val appUpdateRepository: AppUpdateRepository,
|
||||||
private val appUpdateInstaller: AppUpdateInstaller
|
private val appUpdateInstaller: AppUpdateInstaller,
|
||||||
|
private val appVersionProvider: AppVersionProvider
|
||||||
) : SettingsGroupProvider {
|
) : SettingsGroupProvider {
|
||||||
private val _isCheckingForUpdates = MutableStateFlow(false)
|
private val _isCheckingForUpdates = MutableStateFlow(false)
|
||||||
val isCheckingForUpdates: StateFlow<Boolean> = _isCheckingForUpdates.asStateFlow()
|
val isCheckingForUpdates: StateFlow<Boolean> = _isCheckingForUpdates.asStateFlow()
|
||||||
@@ -34,16 +37,17 @@ class AppUpdateController @Inject constructor(
|
|||||||
|
|
||||||
override val settingGroups: Flow<List<SettingGroup>> = availableUpdate
|
override val settingGroups: Flow<List<SettingGroup>> = availableUpdate
|
||||||
.map { update ->
|
.map { update ->
|
||||||
if (update == null) {
|
val options = listOfNotNull<SettingOption<*>>(
|
||||||
emptyList()
|
buildNumberSetting(),
|
||||||
} else {
|
update?.let { installUpdateSetting(it) }
|
||||||
listOf(
|
)
|
||||||
SettingGroup(
|
|
||||||
title = "App",
|
listOf(
|
||||||
options = listOf(installUpdateSetting(update))
|
SettingGroup(
|
||||||
)
|
title = "App",
|
||||||
|
options = options
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun checkForUpdates(
|
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 {
|
private companion object {
|
||||||
|
const val BUILD_NUMBER_KEY = "build_number"
|
||||||
const val INSTALL_APP_UPDATE_KEY = "install_app_update"
|
const val INSTALL_APP_UPDATE_KEY = "install_app_update"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ data class StringSetting(
|
|||||||
override val defaultValue: String
|
override val defaultValue: String
|
||||||
) : SettingOption<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(
|
data class VoidSetting(
|
||||||
override val key: String,
|
override val key: String,
|
||||||
override val title: String,
|
override val title: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user