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:
@@ -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