From 6675de1a26610307175eef0933fda0fe3634d67b Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 19 Apr 2020 21:05:45 -0400 Subject: [PATCH] Fix extension update badge in bottom nav not updating --- .../tachiyomi/data/preference/PreferencesHelper.kt | 14 +++++++++++--- .../eu/kanade/tachiyomi/ui/main/MainActivity.kt | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 8df791152d..44f4490f17 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -5,9 +5,10 @@ import android.content.SharedPreferences import android.net.Uri import android.os.Environment import androidx.preference.PreferenceManager -import com.f2prateek.rx.preferences.Preference +import com.f2prateek.rx.preferences.Preference as RxPreference import com.f2prateek.rx.preferences.RxSharedPreferences import com.tfcporciuncula.flow.FlowSharedPreferences +import com.tfcporciuncula.flow.Preference import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values @@ -18,10 +19,17 @@ import java.text.DateFormat import java.text.SimpleDateFormat import java.util.Locale import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.Flow +import reactivecircus.flowbinding.common.startWithCurrentValue -fun Preference.getOrDefault(): T = get() ?: defaultValue()!! +fun RxPreference.getOrDefault(): T = get() ?: defaultValue()!! -private class DateFormatConverter : Preference.Adapter { +fun Preference.asImmediateFlow(): Flow { + return asFlow() + .startWithCurrentValue(true) { get() } +} + +private class DateFormatConverter : RxPreference.Adapter { override fun get(key: String, preferences: SharedPreferences): DateFormat { val dateFormat = preferences.getString(Keys.dateFormat, "")!! diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index e5a247c4ac..c75314dc75 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -13,6 +13,7 @@ import com.bluelinelabs.conductor.RouterTransaction import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.NotificationReceiver +import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.databinding.MainActivityBinding import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.ui.base.activity.BaseActivity @@ -153,7 +154,7 @@ class MainActivity : BaseActivity() { } } - preferences.extensionUpdatesCount().asFlow() + preferences.extensionUpdatesCount().asImmediateFlow() .onEach { setExtensionsBadge(it) } .launchInUI() }