HACK store lastRepoUpdate as Int, because ComposePreference lib can't handle Long

see: https://github.com/zhanghai/ComposePreference/issues/24
This commit is contained in:
Torsten Grote
2025-10-27 10:12:18 -03:00
parent c22352dd05
commit d5df52a2de
3 changed files with 11 additions and 4 deletions

View File

@@ -5,7 +5,7 @@ import org.fdroid.database.AppListSortOrder
object SettingsConstants {
const val PREF_KEY_LAST_UPDATE_CHECK = "lastUpdateCheck"
const val PREF_DEFAULT_LAST_UPDATE_CHECK = -1L
const val PREF_DEFAULT_LAST_UPDATE_CHECK = -1
const val PREF_KEY_THEME = "theme"
const val PREF_DEFAULT_THEME = "followSystem"

View File

@@ -42,9 +42,16 @@ class SettingsManager @Inject constructor(
val theme get() = prefs.getString(PREF_KEY_THEME, PREF_DEFAULT_THEME)!!
val themeFlow = prefsFlow.map { it.get<String>(PREF_KEY_THEME) }
var lastRepoUpdate: Long
get() = prefs.getLong(PREF_KEY_LAST_UPDATE_CHECK, PREF_DEFAULT_LAST_UPDATE_CHECK)
get() = try {
prefs.getInt(PREF_KEY_LAST_UPDATE_CHECK, PREF_DEFAULT_LAST_UPDATE_CHECK)
.toLong() * 1000
} catch (_: Exception) {
// TODO remove Int hack, because preferences library crashes on Long
// see: https://github.com/zhanghai/ComposePreference/issues/24
PREF_DEFAULT_LAST_UPDATE_CHECK.toLong()
}
set(value) {
prefs.edit { putLong(PREF_KEY_LAST_UPDATE_CHECK, value) }
prefs.edit { putInt(PREF_KEY_LAST_UPDATE_CHECK, (value / 1000).toInt()) }
_lastRepoUpdateFlow.update { value }
}
private val _lastRepoUpdateFlow = MutableStateFlow(lastRepoUpdate)

View File

@@ -28,7 +28,7 @@ fun DiscoverPresenter(
// So if we don't have those, we are still loading, have no enabled repo, or this is first start
return if (recentlyUpdatedApps.isNullOrEmpty()) {
val repositories = repositoriesFlow.collectAsState(null).value
val isFirstStart = lastRepoUpdate == PREF_DEFAULT_LAST_UPDATE_CHECK
val isFirstStart = lastRepoUpdate < PREF_DEFAULT_LAST_UPDATE_CHECK.toLong()
if (newApps == null && recentlyUpdatedApps == null) {
// we don't know yet if this
LoadingDiscoverModel(isFirstStart)