From 684a7f461723be16881b7f12acc07cc9ac67415d Mon Sep 17 00:00:00 2001 From: Invinciblelee <1760316362@qq.com> Date: Mon, 10 Jun 2019 09:32:14 +0800 Subject: [PATCH] update --- app/src/main/java/io/legado/app/App.kt | 7 ++++ .../main/java/io/legado/app/lib/theme/ATH.kt | 13 ++++++ .../app/lib/theme/MaterialValueHelper.kt | 42 +++++++++++++++++++ .../ui/main/bookshelf/BookshelfFragment.kt | 1 + .../app/ui/replacerule/ReplaceRuleActivity.kt | 2 +- .../java/io/legado/app/ui/widget/TitleBar.kt | 4 +- .../io/legado/app/utils/MenuExtensions.kt | 5 ++- .../main/res/layout/activity_source_edit.xml | 4 +- app/src/main/res/layout/view_titlebar.xml | 1 - 9 files changed, 71 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 41e8dffaf..c29ecf492 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -5,6 +5,8 @@ import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context import android.content.pm.PackageManager +import android.graphics.PorterDuff +import android.graphics.drawable.Drawable import android.os.Build import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatDelegate @@ -15,6 +17,7 @@ import io.legado.app.constant.AppConst.channelIdWeb import io.legado.app.data.AppDatabase import io.legado.app.lib.theme.ThemeStore import io.legado.app.utils.getCompatColor +import io.legado.app.utils.getCompatDrawable import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefInt import java.util.* @@ -42,14 +45,18 @@ class App : Application() { } catch (e: PackageManager.NameNotFoundException) { 0 } + if (!ThemeStore.isConfigured(this, versionCode)) upThemeStore() initNightTheme() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) createChannelId() + LiveEventBus.get() .config() .supportBroadcast(this) .lifecycleObserverAlwaysActive(true) .autoClear(false) + } fun initNightTheme() { diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index f3283b30f..dd644a6bf 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -7,8 +7,11 @@ import android.content.Context import android.os.Build import android.view.View import android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR +import android.widget.EdgeEffect import androidx.annotation.ColorInt import androidx.appcompat.app.AlertDialog +import androidx.recyclerview.widget.RecyclerView + /** * @author Karim Abou Zeid (kabouzeid) @@ -113,4 +116,14 @@ object ATH { } return dialog } + + fun setEdgeEffectColor(view: RecyclerView, color: Int) { + view.edgeEffectFactory = object : RecyclerView.EdgeEffectFactory() { + override fun createEdgeEffect(view: RecyclerView, direction: Int): EdgeEffect { + val edgeEffect = super.createEdgeEffect(view, direction) + edgeEffect.color = color + return edgeEffect + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt b/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt index c8c97a23f..1dc767f39 100644 --- a/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt +++ b/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt @@ -75,6 +75,48 @@ fun Fragment.getSecondaryDisabledTextColor(dark: Boolean): Int { } else ContextCompat.getColor(requireContext(), R.color.secondary_text_disabled_material_dark) } + +@ColorInt +fun Context.getPrimaryTextColor(): Int { + return getPrimaryTextColor(isDarkTheme()) +} + +@ColorInt +fun Context.getSecondaryTextColor(): Int { + return getSecondaryTextColor(isDarkTheme()) +} + +@ColorInt +fun Context.getPrimaryDisabledTextColor(): Int { + return getPrimaryDisabledTextColor(isDarkTheme()) +} + +@ColorInt +fun Context.getSecondaryDisabledTextColor(): Int { + return getSecondaryDisabledTextColor(isDarkTheme()) +} + + +@ColorInt +fun Fragment.getPrimaryTextColor(): Int { + return getPrimaryTextColor(isDarkTheme()) +} + +@ColorInt +fun Fragment.getSecondaryTextColor(): Int { + return getSecondaryTextColor(isDarkTheme()) +} + +@ColorInt +fun Fragment.getPrimaryDisabledTextColor(): Int { + return getPrimaryDisabledTextColor(isDarkTheme()) +} + +@ColorInt +fun Fragment.getSecondaryDisabledTextColor(): Int { + return getSecondaryDisabledTextColor(isDarkTheme()) +} + fun Context.isDarkTheme(): Boolean { return ColorUtils.isColorLight(ThemeStore.primaryColor(this)) } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index a50d9f32f..df6118f0f 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -3,6 +3,7 @@ package io.legado.app.ui.main.bookshelf import android.os.Bundle import android.view.Menu import android.view.View +import androidx.core.view.forEach import io.legado.app.R import io.legado.app.base.BaseFragment import kotlinx.android.synthetic.main.view_titlebar.* diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index 22d27b639..0ffeefc69 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -89,7 +89,7 @@ class ReplaceRuleActivity : BaseActivity() { ItemTouchHelper(object : ItemTouchHelper.Callback() { override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int { - return ItemTouchHelper.Callback.makeMovementFlags(0, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) + return makeMovementFlags(0, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) } override fun onMove( diff --git a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt index 3191f43a7..425c1e90d 100644 --- a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.widget import android.content.Context import android.content.res.ColorStateList +import android.graphics.Color import android.graphics.PorterDuff import android.graphics.drawable.Drawable import android.util.AttributeSet @@ -17,7 +18,6 @@ import io.legado.app.R import io.legado.app.lib.theme.DrawableUtils import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.getPrimaryTextColor -import io.legado.app.lib.theme.isDarkTheme import io.legado.app.utils.getStatusBarHeight import org.jetbrains.anko.bottomPadding import org.jetbrains.anko.topPadding @@ -142,7 +142,7 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a } private fun wrapAppTheme() { - val primaryTextColor = context.getPrimaryTextColor(context.isDarkTheme()) + val primaryTextColor = if (isInEditMode) Color.BLACK else context.getPrimaryTextColor() DrawableUtils.setTint(toolbar.overflowIcon, primaryTextColor) toolbar.setTitleTextColor(primaryTextColor) diff --git a/app/src/main/java/io/legado/app/utils/MenuExtensions.kt b/app/src/main/java/io/legado/app/utils/MenuExtensions.kt index 787f083dd..881d87867 100644 --- a/app/src/main/java/io/legado/app/utils/MenuExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/MenuExtensions.kt @@ -6,13 +6,14 @@ import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.view.menu.MenuItemImpl import androidx.core.view.forEach import io.legado.app.R -import io.legado.app.lib.theme.* +import io.legado.app.lib.theme.DrawableUtils +import io.legado.app.lib.theme.getPrimaryTextColor fun Menu.setIconColor(context: Context): Menu = this.let { menu -> if (menu is MenuBuilder) { menu.setOptionalIconsVisible(true) } - val primaryTextColor = context.getPrimaryTextColor(context.isDarkTheme()) + val primaryTextColor = context.getPrimaryTextColor() val defaultTextColor = context.getCompatColor(R.color.tv_text_default) menu.forEach { item -> (item as MenuItemImpl).let { impl -> diff --git a/app/src/main/res/layout/activity_source_edit.xml b/app/src/main/res/layout/activity_source_edit.xml index 024dedb49..22d7837e1 100644 --- a/app/src/main/res/layout/activity_source_edit.xml +++ b/app/src/main/res/layout/activity_source_edit.xml @@ -19,14 +19,14 @@ android:layout_height="wrap_content" android:orientation="horizontal"> - -