Dark Theme based on system

This commit is contained in:
Jay 2019-10-23 23:43:18 -07:00
parent b4b78e0f6b
commit c0e4b9bb38
9 changed files with 161 additions and 89 deletions

View File

@ -3,12 +3,18 @@ package eu.kanade.tachiyomi.ui.main
import android.animation.ObjectAnimator import android.animation.ObjectAnimator
import android.app.SearchManager import android.app.SearchManager
import android.content.Intent import android.content.Intent
import android.content.res.Configuration
import android.graphics.Color import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.support.v4.view.GravityCompat import android.support.v4.view.GravityCompat
import android.support.v4.widget.DrawerLayout 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.support.v7.graphics.drawable.DrawerArrowDrawable
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.WindowInsets
import android.widget.LinearLayout
import com.bluelinelabs.conductor.* import com.bluelinelabs.conductor.*
import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.Migrations
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -50,10 +56,14 @@ class MainActivity : BaseActivity() {
lateinit var tabAnimator: TabsAnimator lateinit var tabAnimator: TabsAnimator
override fun onCreate(savedInstanceState: Bundle?) { 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()) { setTheme(when (preferences.theme()) {
2 -> R.style.Theme_Tachiyomi_Dark 3, 6 -> R.style.Theme_Tachiyomi_Amoled
3 -> R.style.Theme_Tachiyomi_Amoled 4, 7 -> R.style.Theme_Tachiyomi_DarkBlue
4 -> R.style.Theme_Tachiyomi_DarkBlue
else -> R.style.Theme_Tachiyomi else -> R.style.Theme_Tachiyomi
}) })
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -63,7 +73,7 @@ class MainActivity : BaseActivity() {
finish() finish()
return return
} }
//AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO)
setContentView(R.layout.main_activity) setContentView(R.layout.main_activity)
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
@ -103,6 +113,15 @@ class MainActivity : BaseActivity() {
val container: ViewGroup = findViewById(R.id.controller_container) 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) router = Conductor.attachRouter(this, container, savedInstanceState)
if (!router.hasRootController()) { if (!router.hasRootController()) {
// Set start screen // 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
}
}

View File

@ -1,8 +1,10 @@
package eu.kanade.tachiyomi.ui.setting package eu.kanade.tachiyomi.ui.setting
import android.app.Dialog import android.app.Dialog
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.support.v7.app.AppCompatDelegate
import android.support.v7.preference.PreferenceScreen import android.support.v7.preference.PreferenceScreen
import android.view.View import android.view.View
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
@ -53,12 +55,18 @@ class SettingsGeneralController : SettingsController() {
key = Keys.theme key = Keys.theme
titleRes = R.string.pref_theme titleRes = R.string.pref_theme
entriesRes = arrayOf(R.string.light_theme, R.string.dark_theme, entriesRes = arrayOf(R.string.light_theme, R.string.dark_theme,
R.string.amoled_theme, R.string.darkblue_theme) R.string.amoled_theme, R.string.darkblue_theme,
entryValues = arrayOf("1", "2", "3", "4") R.string.system_theme, R.string.system_amoled_theme, R.string.system_darkblue_theme)
defaultValue = "1" entryValues = arrayOf("1", "2", "3", "4", "5", "6", "7")
defaultValue = "5"
summary = "%s" 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() activity?.recreate()
true true
} }

View File

@ -178,13 +178,14 @@ object ImageUtil {
darkBG = false darkBG = false
if (topIsBlackStreak && bottomIsBlackStreak) if (topIsBlackStreak && bottomIsBlackStreak)
darkBG = true darkBG = true
val whiteColor = android.R.attr.colorBackground
if (darkBG) { if (darkBG) {
if (isWhite(image.getPixel(left, bot)) && isWhite(image.getPixel(right, bot))) if (isWhite(image.getPixel(left, bot)) && isWhite(image.getPixel(right, bot)))
return GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, 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))) else if (isWhite(image.getPixel(left, top)) && isWhite(image.getPixel(right, top)))
return GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, return GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
intArrayOf(Color.WHITE, Color.WHITE, blackPixel, blackPixel)) intArrayOf(whiteColor, whiteColor, blackPixel, blackPixel))
else else
return ColorDrawable(blackPixel) return ColorDrawable(blackPixel)
} }
@ -192,13 +193,13 @@ object ImageUtil {
&& isDark(image.getPixel(left - offsetX, top)) && isDark(image.getPixel(right + offsetX, top)) && isDark(image.getPixel(left - offsetX, top)) && isDark(image.getPixel(right + offsetX, top))
&& (topMidIsDark || overallBlackPixels > 9))) && (topMidIsDark || overallBlackPixels > 9)))
return GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, return GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
intArrayOf(blackPixel, blackPixel, Color.WHITE, Color.WHITE)) intArrayOf(blackPixel, blackPixel, whiteColor, whiteColor))
else if (bottomIsBlackStreak || (botLeftIsDark && botRightIsDark else if (bottomIsBlackStreak || (botLeftIsDark && botRightIsDark
&& isDark(image.getPixel(left - offsetX, bot)) && isDark(image.getPixel(right + offsetX, bot)) && isDark(image.getPixel(left - offsetX, bot)) && isDark(image.getPixel(right + offsetX, bot))
&& (isDark(image.getPixel(midX, bot)) || overallBlackPixels > 9))) && (isDark(image.getPixel(midX, bot)) || overallBlackPixels > 9)))
return GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, return GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
intArrayOf(Color.WHITE, Color.WHITE, blackPixel, blackPixel)) intArrayOf(whiteColor, whiteColor, blackPixel, blackPixel))
return ColorDrawable(Color.WHITE) return ColorDrawable(whiteColor)
} }
fun Boolean.toInt() = if (this) 1 else 0 fun Boolean.toInt() = if (this) 1 else 0

View File

@ -11,6 +11,7 @@
android:orientation="vertical" android:orientation="vertical"
android:id="@+id/main_content" android:id="@+id/main_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent"> android:layout_height="match_parent">
<eu.kanade.tachiyomi.widget.ElevationAppBarLayout <eu.kanade.tachiyomi.widget.ElevationAppBarLayout

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Base" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="colorPrimary">@color/colorDarkPrimary</item>
<item name="colorPrimaryDark">@color/colorDarkPrimaryDark</item>
<item name="colorAccent">@color/colorAccentDark</item>
<item name="android:textColorPrimary">@color/textColorPrimaryDark</item>
<item name="android:textColorSecondary">@color/textColorSecondaryDark</item>
<item name="android:textColorHint">@color/textColorHintDark</item>
<item name="android:textColorPrimaryInverse">@color/textColorPrimaryLight</item>
<item name="android:textColorSecondaryInverse">@color/textColorSecondaryLight</item>
<item name="android:textColorHintInverse">@color/textColorHintLight</item>
<item name="android:colorBackground">@color/backgroundDark</item>
<item name="android:listSelector">?colorAccent</item>
<item name="android:divider">@color/dividerDark</item>
<item name="android:listDivider">@drawable/line_divider_dark</item>
<!-- Themes -->
<item name="windowActionModeOverlay">true</item>
<item name="actionBarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.Material</item>
<item name="md_background_color">@color/dialogDark</item>
<item name="alertDialogTheme">@style/Theme.AlertDialog.Dark</item>
<!-- Custom Attributes-->
<item name="navigation_view_theme">@style/Theme.Widget.NavigationView.Dark</item>
<item name="selectable_list_drawable">@drawable/list_item_selector_dark</item>
<item name="selectable_library_drawable">@drawable/library_item_selector_dark</item>
<item name="text_color_primary">@color/textColorPrimaryDark</item>
<item name="background_card">@color/dialogDark</item>
<item name="icon_color">@color/iconColorDark</item>
<!-- Attributes specific for SDK 21 and up -->
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@color/colorDarkPrimaryDark</item>
</style>
<style name="Theme.Tachiyomi" parent="Theme.Base">
<!-- Attributes specific for SDK 21 and up -->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@color/colorDarkPrimaryDark</item>
</style>
<style name="Theme.Base.Reader.Light" parent="Theme.Base">
<item name="colorPrimary">@color/colorDarkPrimary</item>
<item name="colorPrimaryDark">@color/colorDarkPrimaryDark</item>
<item name="android:colorBackground">@color/backgroundDark</item>
</style>
<style name="Theme.Tachiyomi.DarkBlue" parent="Theme.Base">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>
<!--==============-->
<!-- Amoled Theme -->
<!--==============-->
<style name="Theme.Base.Amoled" parent="Theme.Base">
<item name="colorPrimary">@color/colorAmoledPrimary</item>
<item name="colorPrimaryDark">@color/colorAmoledPrimary</item>
<item name="android:colorBackground">@color/md_black_1000</item>
<!-- Custom Attributes-->
<item name="selectable_list_drawable">@drawable/list_item_selector_amoled</item>
<item name="selectable_library_drawable">@drawable/library_item_selector_amoled</item>
<item name="background_card">@color/dialog_amoled</item>
</style>
</resources>

View File

@ -10,17 +10,7 @@
<item name="android:navigationBarColor">@color/colorPrimaryDark</item> <item name="android:navigationBarColor">@color/colorPrimaryDark</item>
</style> </style>
<!--=============--> <style name="Theme.Tachiyomi.DarkBlue" parent="Theme.Base">
<!-- Dark Themes -->
<!--=============-->
<style name="Theme.Tachiyomi.Dark" parent="Theme.Base.Dark">
<!-- Attributes specific for SDK 21 and up -->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@color/colorDarkPrimaryDark</item>
</style>
<style name="Theme.Tachiyomi.DarkBlue" parent="Theme.Base.Dark">
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- values-v29/themes.xml -->
<style name="Theme.Tachiyomi" parent="Theme.Base">
<!-- Attributes specific for SDK 21 and up -->
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>
<style name="Theme.Tachiyomi.DarkBlue" parent="Theme.Base">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<!-- Attributes specific for SDK 21 and up -->
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>
<!--==============-->
<!-- Amoled Theme -->
<!--==============-->
<style name="Theme.Tachiyomi.Amoled" parent="Theme.Base.Amoled">
<!-- Attributes specific for SDK 21 and up -->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>
</resources>

View File

@ -143,6 +143,9 @@
<string name="dark_theme">Dark theme</string> <string name="dark_theme">Dark theme</string>
<string name="amoled_theme">AMOLED theme</string> <string name="amoled_theme">AMOLED theme</string>
<string name="darkblue_theme">Dark blue</string> <string name="darkblue_theme">Dark blue</string>
<string name="system_theme">System default</string>
<string name="system_amoled_theme">System default (AMOLED)</string>
<string name="system_darkblue_theme">System default (Dark blue)</string>
<string name="pref_start_screen">Start screen</string> <string name="pref_start_screen">Start screen</string>
<string name="pref_language">Language</string> <string name="pref_language">Language</string>
<string name="system_default">System default</string> <string name="system_default">System default</string>

View File

@ -9,7 +9,7 @@
<!--==============--> <!--==============-->
<!-- Light Themes --> <!-- Light Themes -->
<!--=======-======--> <!--=======-======-->
<style name="Theme.Base" parent="Theme.AppCompat.Light.NoActionBar"> <style name="Theme.Base" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccentLight</item> <item name="colorAccent">@color/colorAccentLight</item>
@ -43,73 +43,10 @@
<!-- Attributes specific for SDK 16 to SDK 20 --> <!-- Attributes specific for SDK 16 to SDK 20 -->
</style> </style>
<!--=============-->
<!-- Dark Themes -->
<!--=============-->
<style name="Theme.Base.Dark" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorDarkPrimary</item>
<item name="colorPrimaryDark">@color/colorDarkPrimaryDark</item>
<item name="colorAccent">@color/colorAccentDark</item>
<item name="android:textColorPrimary">@color/textColorPrimaryDark</item>
<item name="android:textColorSecondary">@color/textColorSecondaryDark</item>
<item name="android:textColorHint">@color/textColorHintDark</item>
<item name="android:textColorPrimaryInverse">@color/textColorPrimaryLight</item>
<item name="android:textColorSecondaryInverse">@color/textColorSecondaryLight</item>
<item name="android:textColorHintInverse">@color/textColorHintLight</item>
<item name="android:colorBackground">@color/backgroundDark</item>
<item name="android:listSelector">?colorAccent</item>
<item name="android:divider">@color/dividerDark</item>
<item name="android:listDivider">@drawable/line_divider_dark</item>
<!-- Themes -->
<item name="windowActionModeOverlay">true</item>
<item name="actionBarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.Material</item>
<item name="md_background_color">@color/dialogDark</item>
<item name="alertDialogTheme">@style/Theme.AlertDialog.Dark</item>
<!-- Custom Attributes-->
<item name="navigation_view_theme">@style/Theme.Widget.NavigationView.Dark</item>
<item name="selectable_list_drawable">@drawable/list_item_selector_dark</item>
<item name="selectable_library_drawable">@drawable/library_item_selector_dark</item>
<item name="text_color_primary">@color/textColorPrimaryDark</item>
<item name="background_card">@color/dialogDark</item>
<item name="icon_color">@color/iconColorDark</item>
</style>
<style name="Theme.Tachiyomi.Dark" parent="Theme.Base.Dark">
<!-- Attributes specific for SDK 16 to SDK 20 -->
</style>
<style name="Theme.Tachiyomi.DarkBlue" parent="Theme.Base.Dark">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>
<!--==============-->
<!-- Amoled Theme -->
<!--==============-->
<style name="Theme.Base.Amoled" parent="Theme.Base.Dark">
<item name="colorPrimary">@color/colorAmoledPrimary</item>
<item name="colorPrimaryDark">@color/colorAmoledPrimary</item>
<item name="android:colorBackground">@color/md_black_1000</item>
<!-- Custom Attributes-->
<item name="selectable_list_drawable">@drawable/list_item_selector_amoled</item>
<item name="selectable_library_drawable">@drawable/library_item_selector_amoled</item>
<item name="background_card">@color/dialog_amoled</item>
</style>
<style name="Theme.Tachiyomi.Amoled" parent="Theme.Base.Amoled">
<!-- Attributes specific for SDK 16 to SDK 20 -->
</style>
<!--==============--> <!--==============-->
<!-- Reader Theme --> <!-- Reader Theme -->
<!--==============--> <!--==============-->
<style name="Theme.Base.Reader.Dark" parent="Theme.Base.Dark"> <style name="Theme.Base.Reader.Dark" parent="Theme.Base">
<item name="colorPrimary">@color/colorDarkPrimary</item> <item name="colorPrimary">@color/colorDarkPrimary</item>
<item name="colorPrimaryDark">@color/colorDarkPrimaryDark</item> <item name="colorPrimaryDark">@color/colorDarkPrimaryDark</item>
<item name="android:colorBackground">@android:color/black</item> <item name="android:colorBackground">@android:color/black</item>