Move themeing to base activity

This commit is contained in:
Jay 2020-01-29 21:53:37 -08:00
parent 0b6f7fab81
commit 10d514f8f4
8 changed files with 34 additions and 29 deletions

View File

@ -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)
}
}

View File

@ -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 {

View File

@ -96,8 +96,6 @@ class LibraryController(
*/
private var migratingMangas = mutableSetOf<Manga>()
private var selectedCoverManga: Manga? = null
/**
* Relay to notify the UI of selection updates.
*/

View File

@ -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)

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -38,7 +38,6 @@ class WebViewActivity : BaseActivity() {
private val sourceManager by injectLazy<SourceManager>()
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)