diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index 7367de734..b62d0e850 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi import eu.kanade.tachiyomi.data.backup.BackupCreatorJob import eu.kanade.tachiyomi.data.library.LibraryUpdateJob import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.updater.UpdaterJob import eu.kanade.tachiyomi.extension.ExtensionUpdateJob import java.io.File @@ -18,7 +17,7 @@ object Migrations { */ fun upgrade(preferences: PreferencesHelper): Boolean { val context = preferences.context - val oldVersion = preferences.lastVersionCode().getOrDefault() + val oldVersion = preferences.lastVersionCode().get() if (oldVersion < BuildConfig.VERSION_CODE) { preferences.lastVersionCode().set(BuildConfig.VERSION_CODE) 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 2de9ed1a9..fa7514daf 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 @@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values import eu.kanade.tachiyomi.data.track.TrackService +import eu.kanade.tachiyomi.data.track.anilist.Anilist import java.io.File import java.text.DateFormat import java.text.SimpleDateFormat @@ -131,7 +132,7 @@ class PreferencesHelper(val context: Context) { fun lastUsedCategory() = rxPrefs.getInteger(Keys.lastUsedCategory, 0) - fun lastVersionCode() = rxPrefs.getInteger("last_version_code", 0) + fun lastVersionCode() = flowPrefs.getInt("last_version_code", 0) fun catalogueAsList() = rxPrefs.getBoolean(Keys.catalogueAsList, false) @@ -150,7 +151,7 @@ class PreferencesHelper(val context: Context) { fun trackToken(sync: TrackService) = rxPrefs.getString(Keys.trackToken(sync.id), "") - fun anilistScoreType() = rxPrefs.getString("anilist_score_type", "POINT_10") + fun anilistScoreType() = rxPrefs.getString("anilist_score_type", Anilist.POINT_10) fun backupsDirectory() = rxPrefs.getString(Keys.backupDirectory, defaultBackupDir.toString()) @@ -194,7 +195,7 @@ class PreferencesHelper(val context: Context) { fun automaticExtUpdates() = flowPrefs.getBoolean(Keys.automaticExtUpdates, true) - fun extensionUpdatesCount() = rxPrefs.getInteger("ext_updates_count", 0) + fun extensionUpdatesCount() = flowPrefs.getInt("ext_updates_count", 0) fun lastExtCheck() = flowPrefs.getLong("last_ext_check", 0) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt index b00153fa9..90d0664c2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt @@ -12,8 +12,6 @@ import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.RestoreViewOnCreateController import kotlinx.android.extensions.LayoutContainer import kotlinx.android.synthetic.clearFindViewByIdCache -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import timber.log.Timber abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateController(bundle), @@ -43,8 +41,6 @@ abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateContr }) } - val uiScope = CoroutineScope(Dispatchers.Main) - override val containerView: View? get() = view diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt index 55d746f48..4388fa8d1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt @@ -9,8 +9,6 @@ import com.bluelinelabs.conductor.RestoreViewOnCreateController import com.bluelinelabs.conductor.Router import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers /** * A controller that displays a dialog window, floating on top of its activity's window. @@ -26,8 +24,6 @@ abstract class DialogController : RestoreViewOnCreateController { private var dismissed = false - val uiScope = CoroutineScope(Dispatchers.Main) - /** * Convenience constructor for use when no arguments are needed. */ 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 4f5938f35..084f019ea 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 @@ -12,7 +12,6 @@ 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.getOrDefault import eu.kanade.tachiyomi.databinding.MainActivityBinding import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.ui.base.activity.BaseActivity @@ -30,10 +29,12 @@ import eu.kanade.tachiyomi.ui.recent.history.HistoryController import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController import eu.kanade.tachiyomi.ui.source.SourceController import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController +import eu.kanade.tachiyomi.util.lang.launchInUI import java.util.Date import java.util.concurrent.TimeUnit import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import timber.log.Timber @@ -141,10 +142,11 @@ class MainActivity : BaseActivity() { ChangelogDialogController().showDialog(router) } } - preferences.extensionUpdatesCount().asObservable().subscribe { - setExtensionsBadge() - } + setExtensionsBadge() + preferences.extensionUpdatesCount().asFlow() + .onEach { setExtensionsBadge() } + .launchInUI() } override fun onNewIntent(intent: Intent) { @@ -159,7 +161,7 @@ class MainActivity : BaseActivity() { } private fun setExtensionsBadge() { - val updates = preferences.extensionUpdatesCount().getOrDefault() + val updates = preferences.extensionUpdatesCount().get() if (updates > 0) { binding.bottomNav.getOrCreateBadge(R.id.nav_more).number = updates } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt index 7c3cefb5a..70a426e88 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.more import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.download.DownloadController @@ -34,7 +33,7 @@ class MoreController : SettingsController(), RootController { titleRes = R.string.label_extensions iconRes = R.drawable.ic_extension_24dp iconTint = tintColor - setBadge(Injekt.get().extensionUpdatesCount().getOrDefault()) + setBadge(Injekt.get().extensionUpdatesCount().get()) onClick { router.pushController(ExtensionController().withFadeTransaction()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt index a95d29c64..14e458f7c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerConfig.kt @@ -2,9 +2,9 @@ package eu.kanade.tachiyomi.ui.reader.viewer.pager import com.f2prateek.rx.preferences.Preference import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig import eu.kanade.tachiyomi.util.lang.addTo import rx.subscriptions.CompositeSubscription -import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt index 98fa704cf..471b817db 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonConfig.kt @@ -2,9 +2,9 @@ package eu.kanade.tachiyomi.ui.reader.viewer.webtoon import com.f2prateek.rx.preferences.Preference import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig import eu.kanade.tachiyomi.util.lang.addTo import rx.subscriptions.CompositeSubscription -import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get