From c0e4b9bb3805c663598f258a707d6e1c354b133b Mon Sep 17 00:00:00 2001 From: Jay Date: Wed, 23 Oct 2019 23:43:18 -0700 Subject: [PATCH] Dark Theme based on system --- .../kanade/tachiyomi/ui/main/MainActivity.kt | 41 +++++++++-- .../ui/setting/SettingsGeneralController.kt | 16 +++-- .../eu/kanade/tachiyomi/util/ImageUtil.kt | 11 +-- app/src/main/res/layout/main_activity.xml | 1 + app/src/main/res/values-night/themes.xml | 71 +++++++++++++++++++ app/src/main/res/values-v21/themes.xml | 12 +--- app/src/main/res/values-v29/themes.xml | 28 ++++++++ app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/themes.xml | 67 +---------------- 9 files changed, 161 insertions(+), 89 deletions(-) create mode 100644 app/src/main/res/values-night/themes.xml create mode 100644 app/src/main/res/values-v29/themes.xml 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 9fc4fa6ccf..69dc5ab0e4 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 @@ -3,12 +3,18 @@ package eu.kanade.tachiyomi.ui.main import android.animation.ObjectAnimator import android.app.SearchManager import android.content.Intent +import android.content.res.Configuration import android.graphics.Color import android.os.Bundle import android.support.v4.view.GravityCompat import android.support.v4.widget.DrawerLayout +import android.support.v7.app.AppCompatDelegate +import android.support.v7.app.AppCompatDelegate.* import android.support.v7.graphics.drawable.DrawerArrowDrawable +import android.view.View import android.view.ViewGroup +import android.view.WindowInsets +import android.widget.LinearLayout import com.bluelinelabs.conductor.* import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R @@ -50,10 +56,14 @@ class MainActivity : BaseActivity() { lateinit var tabAnimator: TabsAnimator override fun onCreate(savedInstanceState: Bundle?) { + setDefaultNightMode(when (preferences.theme()) { + 1 -> MODE_NIGHT_NO + 2, 3, 4 -> MODE_NIGHT_YES + else -> MODE_NIGHT_FOLLOW_SYSTEM + }) setTheme(when (preferences.theme()) { - 2 -> R.style.Theme_Tachiyomi_Dark - 3 -> R.style.Theme_Tachiyomi_Amoled - 4 -> R.style.Theme_Tachiyomi_DarkBlue + 3, 6 -> R.style.Theme_Tachiyomi_Amoled + 4, 7 -> R.style.Theme_Tachiyomi_DarkBlue else -> R.style.Theme_Tachiyomi }) super.onCreate(savedInstanceState) @@ -63,7 +73,7 @@ class MainActivity : BaseActivity() { finish() return } - + //AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO) setContentView(R.layout.main_activity) setSupportActionBar(toolbar) @@ -103,6 +113,15 @@ class MainActivity : BaseActivity() { val container: ViewGroup = findViewById(R.id.controller_container) + val content: LinearLayout = findViewById(R.id.main_content) + container.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + content.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + content.setOnApplyWindowInsetsListener(NoopWindowInsetsListener) + router = Conductor.attachRouter(this, container, savedInstanceState) if (!router.hasRootController()) { // Set start screen @@ -280,3 +299,17 @@ class MainActivity : BaseActivity() { } } + +object NoopWindowInsetsListener : View.OnApplyWindowInsetsListener { + override fun onApplyWindowInsets(v: View, insets: WindowInsets): WindowInsets { + v.setPadding(0,insets.systemWindowInsetTop,0,0) + return insets + } +} + +object NoopWindowInsetsListener2 : View.OnApplyWindowInsetsListener { + override fun onApplyWindowInsets(v: View, insets: WindowInsets): WindowInsets { + v.setPadding(0,0,0,insets.systemWindowInsetBottom) + return insets + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index bc1eb64683..47fe4b8e40 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -1,8 +1,10 @@ package eu.kanade.tachiyomi.ui.setting import android.app.Dialog +import android.os.Build import android.os.Bundle import android.os.Handler +import android.support.v7.app.AppCompatDelegate import android.support.v7.preference.PreferenceScreen import android.view.View import com.afollestad.materialdialogs.MaterialDialog @@ -53,12 +55,18 @@ class SettingsGeneralController : SettingsController() { key = Keys.theme titleRes = R.string.pref_theme entriesRes = arrayOf(R.string.light_theme, R.string.dark_theme, - R.string.amoled_theme, R.string.darkblue_theme) - entryValues = arrayOf("1", "2", "3", "4") - defaultValue = "1" + R.string.amoled_theme, R.string.darkblue_theme, + R.string.system_theme, R.string.system_amoled_theme, R.string.system_darkblue_theme) + entryValues = arrayOf("1", "2", "3", "4", "5", "6", "7") + defaultValue = "5" summary = "%s" - onChange { + onChange {newValue -> + AppCompatDelegate.setDefaultNightMode(when (newValue) { + "1" -> AppCompatDelegate.MODE_NIGHT_NO + "2", "3", "4" -> AppCompatDelegate.MODE_NIGHT_YES + else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM + }) activity?.recreate() true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ImageUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ImageUtil.kt index 382b32430f..0d0524f0f8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ImageUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ImageUtil.kt @@ -178,13 +178,14 @@ object ImageUtil { darkBG = false if (topIsBlackStreak && bottomIsBlackStreak) darkBG = true + val whiteColor = android.R.attr.colorBackground if (darkBG) { if (isWhite(image.getPixel(left, bot)) && isWhite(image.getPixel(right, bot))) return GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, - intArrayOf(blackPixel, blackPixel, Color.WHITE, Color.WHITE)) + intArrayOf(blackPixel, blackPixel, whiteColor, whiteColor)) else if (isWhite(image.getPixel(left, top)) && isWhite(image.getPixel(right, top))) return GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, - intArrayOf(Color.WHITE, Color.WHITE, blackPixel, blackPixel)) + intArrayOf(whiteColor, whiteColor, blackPixel, blackPixel)) else return ColorDrawable(blackPixel) } @@ -192,13 +193,13 @@ object ImageUtil { && isDark(image.getPixel(left - offsetX, top)) && isDark(image.getPixel(right + offsetX, top)) && (topMidIsDark || overallBlackPixels > 9))) return GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, - intArrayOf(blackPixel, blackPixel, Color.WHITE, Color.WHITE)) + intArrayOf(blackPixel, blackPixel, whiteColor, whiteColor)) else if (bottomIsBlackStreak || (botLeftIsDark && botRightIsDark && isDark(image.getPixel(left - offsetX, bot)) && isDark(image.getPixel(right + offsetX, bot)) && (isDark(image.getPixel(midX, bot)) || overallBlackPixels > 9))) return GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, - intArrayOf(Color.WHITE, Color.WHITE, blackPixel, blackPixel)) - return ColorDrawable(Color.WHITE) + intArrayOf(whiteColor, whiteColor, blackPixel, blackPixel)) + return ColorDrawable(whiteColor) } fun Boolean.toInt() = if (this) 1 else 0 diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index cbc9d2a6f4..beeedf5c33 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -11,6 +11,7 @@ android:orientation="vertical" android:id="@+id/main_content" android:layout_width="match_parent" + android:fitsSystemWindows="true" android:layout_height="match_parent"> + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-v21/themes.xml b/app/src/main/res/values-v21/themes.xml index a7ff1d5c4b..2af45a9f12 100644 --- a/app/src/main/res/values-v21/themes.xml +++ b/app/src/main/res/values-v21/themes.xml @@ -10,17 +10,7 @@ @color/colorPrimaryDark - - - - - - + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 506a528dd2..ae22047bd8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -143,6 +143,9 @@ Dark theme AMOLED theme Dark blue + System default + System default (AMOLED) + System default (Dark blue) Start screen Language System default diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index c04866ac69..3d13686f1d 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -9,7 +9,7 @@ - - - - - - - - - - - - - - - - - -