Explorar o código

Fix extension update badge in bottom nav not updating

arkon %!s(int64=5) %!d(string=hai) anos
pai
achega
6675de1a26

+ 11 - 3
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 <T> Preference<T>.getOrDefault(): T = get() ?: defaultValue()!!
+fun <T> RxPreference<T>.getOrDefault(): T = get() ?: defaultValue()!!
 
-private class DateFormatConverter : Preference.Adapter<DateFormat> {
+fun <T> Preference<T>.asImmediateFlow(): Flow<T> {
+    return asFlow()
+        .startWithCurrentValue(true) { get() }
+}
+
+private class DateFormatConverter : RxPreference.Adapter<DateFormat> {
     override fun get(key: String, preferences: SharedPreferences): DateFormat {
         val dateFormat = preferences.getString(Keys.dateFormat, "")!!
 

+ 2 - 1
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<MainActivityBinding>() {
             }
         }
 
-        preferences.extensionUpdatesCount().asFlow()
+        preferences.extensionUpdatesCount().asImmediateFlow()
             .onEach { setExtensionsBadge(it) }
             .launchInUI()
     }