From c06c071674b5aa0ede81c0b0c361c9311e96ac3d Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 26 Jan 2021 10:02:37 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=9B=BE=E7=89=87=E8=83=8C?= =?UTF-8?q?=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/google-services.json | 37 +++++++++++++++++++ .../java/io/legado/app/base/BaseActivity.kt | 6 +++ .../main/java/io/legado/app/constant/Theme.kt | 12 +++--- .../java/io/legado/app/help/ThemeConfig.kt | 14 ++++++- .../app/ui/config/ThemeConfigFragment.kt | 18 ++++++--- .../ui/main/bookshelf/BookshelfFragment.kt | 8 ++-- 6 files changed, 80 insertions(+), 15 deletions(-) diff --git a/app/google-services.json b/app/google-services.json index e60f39470..fcbc11f0d 100644 --- a/app/google-services.json +++ b/app/google-services.json @@ -108,6 +108,43 @@ ] } } + }, + { + "client_info": { + "mobilesdk_app_id": "1:453392274790:android:b891abd2331577dff624a7", + "android_client_info": { + "package_name": "io.legado.play.debug" + } + }, + "oauth_client": [ + { + "client_id": "453392274790-f8sjn6ohs72rg1dvp0pdvk42nkq54p0k.apps.googleusercontent.com", + "client_type": 1, + "android_info": { + "package_name": "io.legado.play.debug", + "certificate_hash": "00819ace9891386e535967cbafd6a88f3797bd5b" + } + }, + { + "client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyD90mfNLhA7cAzzI9SonpSz5mrF5BnmyJA" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } } ], "configuration_version": "1" diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index 4f1124ae4..31deca8e4 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -16,6 +16,7 @@ import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.constant.Theme import io.legado.app.help.AppConfig +import io.legado.app.help.ThemeConfig import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.backgroundColor @@ -151,6 +152,11 @@ abstract class BaseActivity( ATH.applyBackgroundTint(window.decorView) } } + if (AppConfig.isGooglePlay) { + ThemeConfig.getBgImage(this)?.let { + window.decorView.background = it + } + } } private fun setupSystemBar() { diff --git a/app/src/main/java/io/legado/app/constant/Theme.kt b/app/src/main/java/io/legado/app/constant/Theme.kt index 896e73ea0..8145f4d01 100644 --- a/app/src/main/java/io/legado/app/constant/Theme.kt +++ b/app/src/main/java/io/legado/app/constant/Theme.kt @@ -4,16 +4,18 @@ import io.legado.app.help.AppConfig import io.legado.app.utils.ColorUtils enum class Theme { - Dark, Light, Auto, Transparent; + Dark, Light, Auto, Transparent, EInk; companion object { - fun getTheme() = - if (AppConfig.isNightTheme) Dark - else Light + fun getTheme() = when { + AppConfig.isEInkMode -> EInk + AppConfig.isNightTheme -> Dark + else -> Light + } fun getTheme(backgroundColor: Int) = if (ColorUtils.isColorLight(backgroundColor)) Light else Dark - + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/ThemeConfig.kt index 0b0298e91..efaf72dc9 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -2,11 +2,14 @@ package io.legado.app.help import android.content.Context import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable import androidx.annotation.Keep import io.legado.app.App import io.legado.app.R import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey +import io.legado.app.constant.Theme import io.legado.app.lib.theme.ThemeStore import io.legado.app.utils.* import java.io.File @@ -20,6 +23,16 @@ object ThemeConfig { ArrayList(cList) } + fun getBgImage(context: Context): Drawable? { + val bgPath = when (Theme.getTheme()) { + Theme.Light -> context.getPrefString(PreferKey.bgImage) + Theme.Dark -> context.getPrefString(PreferKey.bgImageN) + else -> null + } + if (bgPath.isNullOrBlank()) return null + return BitmapDrawable.createFromPath(bgPath) + } + fun upConfig() { getConfigs()?.let { it.forEach { config -> @@ -204,7 +217,6 @@ object ThemeConfig { var primaryColor: String, var accentColor: String, var backgroundColor: String, - var backgroundImage: String? = null, var bottomBackground: String ) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 8248a840a..ce5cf3814 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -192,6 +192,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> if (i == 0) { removePref(PreferKey.bgImage) + upTheme(false) } else { selectImage(requestCodeBgImage) } @@ -203,6 +204,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> if (i == 0) { removePref(PreferKey.bgImageN) + upTheme(true) } else { selectImage(requestCodeBgImageN) } @@ -262,7 +264,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), } } - private fun setBgFromUri(uri: Uri, preferenceKey: String) { + private fun setBgFromUri(uri: Uri, preferenceKey: String, success: () -> Unit) { if (uri.isContentScheme()) { val doc = DocumentFile.fromSingleUri(requireContext(), uri) doc?.name?.let { @@ -273,7 +275,8 @@ class ThemeConfigFragment : BasePreferenceFragment(), }.getOrNull()?.let { byteArray -> file.writeBytes(byteArray) putPrefString(preferenceKey, file.absolutePath) - + upPreferenceSummary(preferenceKey, file.absolutePath) + success() } ?: toast("获取文件出错") } } else { @@ -291,7 +294,8 @@ class ThemeConfigFragment : BasePreferenceFragment(), file = FileUtils.createFileIfNotExist(file, preferenceKey, imgFile.name) file.writeBytes(imgFile.readBytes()) putPrefString(preferenceKey, file.absolutePath) - + upPreferenceSummary(preferenceKey, file.absolutePath) + success() } } } @@ -304,12 +308,16 @@ class ThemeConfigFragment : BasePreferenceFragment(), when (requestCode) { requestCodeBgImage -> if (resultCode == Activity.RESULT_OK) { data?.data?.let { uri -> - setBgFromUri(uri, PreferKey.bgImage) + setBgFromUri(uri, PreferKey.bgImage) { + upTheme(false) + } } } requestCodeBgImageN -> if (resultCode == Activity.RESULT_OK) { data?.data?.let { uri -> - setBgFromUri(uri, PreferKey.bgImageN) + setBgFromUri(uri, PreferKey.bgImageN) { + upTheme(true) + } } } } 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 300ba646d..fd67e259b 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 @@ -86,12 +86,12 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b R.id.menu_add_local -> startActivity() R.id.menu_add_url -> addBookByUrl() R.id.menu_arrange_bookshelf -> startActivity( - Pair("groupId", selectedGroup.groupId ?: 0), - Pair("groupName", selectedGroup.groupName ?: 0) + Pair("groupId", selectedGroup.groupId), + Pair("groupName", selectedGroup.groupName) ) R.id.menu_download -> startActivity( - Pair("groupId", selectedGroup.groupId ?: 0), - Pair("groupName", selectedGroup.groupName ?: 0) + Pair("groupId", selectedGroup.groupId), + Pair("groupName", selectedGroup.groupName) ) R.id.menu_export_bookshelf -> { val fragment = fragmentMap[selectedGroup.groupId]