From 10d514f8f492e64760402ed7b92163044123f2cb Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 29 Jan 2020 21:53:37 -0800 Subject: [PATCH] Move themeing to base activity --- .../ui/base/activity/BaseActivity.kt | 16 ++++++++++++ .../ui/library/LibraryCategoryAdapter.kt | 10 +++++--- .../tachiyomi/ui/library/LibraryController.kt | 2 -- .../tachiyomi/ui/library/LibraryGridHolder.kt | 2 +- .../tachiyomi/ui/library/LibraryListHolder.kt | 2 +- .../tachiyomi/ui/main/BiometricActivity.kt | 1 - .../kanade/tachiyomi/ui/main/MainActivity.kt | 25 ++++++------------- .../tachiyomi/ui/webview/WebViewActivity.kt | 5 ++-- 8 files changed, 34 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt index f9f867fae2..310c5e427f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt @@ -1,13 +1,29 @@ package eu.kanade.tachiyomi.ui.base.activity +import android.os.Bundle import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.app.AppCompatDelegate +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.LocaleHelper +import uy.kohesive.injekt.injectLazy abstract class BaseActivity : AppCompatActivity() { + val preferences: PreferencesHelper by injectLazy() + init { @Suppress("LeakingThis") LocaleHelper.updateConfiguration(this) } + override fun onCreate(savedInstanceState: Bundle?) { + setTheme(when (preferences.theme()) { + 3, 6 -> R.style.Theme_Tachiyomi_Amoled + 4, 7 -> R.style.Theme_Tachiyomi_DarkBlue + else -> R.style.Theme_Tachiyomi + }) + super.onCreate(savedInstanceState) + } + } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt index 16c9b9cf6e..21e2970eb3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt @@ -50,12 +50,14 @@ class LibraryCategoryAdapter(val view: LibraryCategoryView) : } fun performFilter() { - var s = getFilter(String::class.java) - if (s == null) { - s = "" + val s = getFilter(String::class.java) + if (s.isNullOrBlank()) { + updateDataSet(mangas) + } + else { + updateDataSet(mangas.filter { it.filter(s) }) } isLongPressDragEnabled = view.canDrag() && s.isNullOrBlank() - updateDataSet(mangas.filter { it.filter(s) }) } override fun onCreateBubbleText(position: Int):String { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index e919b77e24..5c7b646ace 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -96,8 +96,6 @@ class LibraryController( */ private var migratingMangas = mutableSetOf() - private var selectedCoverManga: Manga? = null - /** * Relay to notify the UI of selection updates. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt index 49bf5f54c5..b142bc29b6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryGridHolder.kt @@ -58,7 +58,7 @@ class LibraryGridHolder( GlideApp.with(view.context).clear(thumbnail) GlideApp.with(view.context) .load(item.manga) - .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) .signature(ObjectKey(MangaImpl.getLastCoverFetch(item.manga.id!!).toString())) .centerCrop() .into(thumbnail) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt index 09beb1e819..ab3a2ca3d8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListHolder.kt @@ -59,7 +59,7 @@ class LibraryListHolder( GlideApp.with(itemView.context).clear(thumbnail) GlideApp.with(itemView.context) .load(item.manga) - .diskCacheStrategy(DiskCacheStrategy.RESOURCE) + .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) .signature(ObjectKey(MangaImpl.getLastCoverFetch(item.manga.id!!).toString())) .centerCrop() .circleCrop() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/BiometricActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/BiometricActivity.kt index 1b18e44c16..b630cb849d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/BiometricActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/BiometricActivity.kt @@ -12,7 +12,6 @@ import java.util.concurrent.Executors class BiometricActivity : BaseActivity() { val executor = Executors.newSingleThreadExecutor() - val preferences: PreferencesHelper by injectLazy() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val biometricPrompt = BiometricPrompt(this, executor, object : BiometricPrompt 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 b2a016c528..0f79428f2a 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 @@ -17,6 +17,7 @@ import android.webkit.WebView import android.widget.FrameLayout import android.widget.LinearLayout import android.widget.TextView +import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES @@ -77,8 +78,6 @@ open class MainActivity : BaseActivity() { protected lateinit var router: Router - val preferences: PreferencesHelper by injectLazy() - protected var drawerArrow: DrawerArrowDrawable? = null protected open var trulyGoBack = false @@ -109,17 +108,14 @@ open class MainActivity : BaseActivity() { lateinit var tabAnimator: TabsAnimator - override fun getTheme(): Resources.Theme { - val theme = super.getTheme() - theme.applyStyle(when (preferences.theme()) { - 3, 6 -> R.style.Theme_Tachiyomi_Amoled - 4, 7 -> R.style.Theme_Tachiyomi_DarkBlue - else -> R.style.Theme_Tachiyomi - }, true) - return theme - } - override fun onCreate(savedInstanceState: Bundle?) { + setDefaultNightMode( + when (preferences.theme()) { + 1 -> MODE_NIGHT_NO + 2, 3, 4 -> MODE_NIGHT_YES + else -> MODE_NIGHT_FOLLOW_SYSTEM + } + ) // Some webview somewwhere breaks night mode, we create a webview to solve this: // https://stackoverflow.com/a/45430282 if (preferences.theme() in 2..4) { @@ -130,11 +126,6 @@ open class MainActivity : BaseActivity() { Timber.e(e, "Exception when creating webview at start") } } - setDefaultNightMode(when (preferences.theme()) { - 1 -> MODE_NIGHT_NO - 2, 3, 4 -> MODE_NIGHT_YES - else -> MODE_NIGHT_FOLLOW_SYSTEM - }) super.onCreate(savedInstanceState) if (trulyGoBack) return diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt index a0b910def1..80b6fdedf1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt @@ -38,7 +38,6 @@ class WebViewActivity : BaseActivity() { private val sourceManager by injectLazy() private var bundle:Bundle? = null - val preferences: PreferencesHelper by injectLazy() companion object { const val SOURCE_KEY = "source_key" @@ -55,7 +54,7 @@ class WebViewActivity : BaseActivity() { } } - override fun getTheme(): Resources.Theme { + /*override fun getTheme(): Resources.Theme { val theme = super.getTheme() theme.applyStyle(when (preferences.theme()) { 3, 6 -> R.style.Theme_Tachiyomi_Amoled @@ -63,7 +62,7 @@ class WebViewActivity : BaseActivity() { else -> R.style.Theme_Tachiyomi }, true) return theme - } + }*/ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState)