mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-02-14 17:12:12 -05:00
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:
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user