From f0a6a554906f1db967e5b18759ca6cafd82881eb Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 5 Mar 2022 23:27:31 +0800 Subject: [PATCH] =?UTF-8?q?pro=E7=89=88=E6=9C=AC=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=90=AF=E5=8A=A8=E7=94=BB=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/PreferKey.kt | 4 + .../io/legado/app/ui/config/ConfigActivity.kt | 1 + .../java/io/legado/app/ui/config/ConfigTag.kt | 1 + .../app/ui/config/CoverConfigFragment.kt | 22 ++- .../app/ui/config/ThemeConfigFragment.kt | 5 + .../app/ui/config/WelcomeConfigFragment.kt | 130 ++++++++++++++++++ .../io/legado/app/ui/main/my/MyFragment.kt | 8 +- app/src/main/res/values-es-rES/strings.xml | 6 + app/src/main/res/values-ja-rJP/strings.xml | 6 + app/src/main/res/values-pt-rBR/strings.xml | 6 + app/src/main/res/values-zh-rHK/strings.xml | 6 + app/src/main/res/values-zh-rTW/strings.xml | 6 + app/src/main/res/values-zh/strings.xml | 6 + app/src/main/res/values/strings.xml | 6 + app/src/main/res/xml/pref_config_theme.xml | 8 +- app/src/main/res/xml/pref_config_welcome.xml | 66 +++++++++ 16 files changed, 274 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt create mode 100644 app/src/main/res/xml/pref_config_welcome.xml diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 21f0db261..2b52b04da 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -95,6 +95,10 @@ object PreferKey { const val uploadRule = "uploadRule" const val tocUiUseReplace = "tocUiUseReplace" const val enableReadRecord = "enableReadRecord" + const val welcomeImage = "welcomeImagePath" + const val welcomeImageDark = "welcomeImagePathDark" + const val welcomeShowText = "welcomeShowText" + const val welcomeShowTextDark = "welcomeShowTextDark" const val cPrimary = "colorPrimary" const val cAccent = "colorAccent" diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt index 4d97b0bc5..fcae15584 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt @@ -19,6 +19,7 @@ class ConfigActivity : BaseActivity() { ConfigTag.THEME_CONFIG -> replaceFragment(configTag) ConfigTag.BACKUP_CONFIG -> replaceFragment(configTag) ConfigTag.COVER_CONFIG -> replaceFragment(configTag) + ConfigTag.WELCOME_CONFIG -> replaceFragment(configTag) else -> finish() } } diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigTag.kt b/app/src/main/java/io/legado/app/ui/config/ConfigTag.kt index dda212c3d..81148bd58 100644 --- a/app/src/main/java/io/legado/app/ui/config/ConfigTag.kt +++ b/app/src/main/java/io/legado/app/ui/config/ConfigTag.kt @@ -6,5 +6,6 @@ object ConfigTag { const val THEME_CONFIG = "themeConfig" const val BACKUP_CONFIG = "backupConfig" const val COVER_CONFIG = "coverConfig" + const val WELCOME_CONFIG = "welcomeConfig" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt index 1ce842670..d59c760a3 100644 --- a/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt @@ -84,12 +84,17 @@ class CoverConfigFragment : BasePreferenceFragment(), override fun onPreferenceTreeClick(preference: Preference): Boolean { when (preference.key) { PreferKey.defaultCover -> - if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) { + if (getPrefString(preference.key).isNullOrEmpty()) { selectImage.launch(requestCodeCover) } else { - context?.selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> + context?.selector( + items = arrayListOf( + getString(R.string.delete), + getString(R.string.select_image) + ) + ) { _, i -> if (i == 0) { - removePref(PreferKey.defaultCover) + removePref(preference.key) BookCover.upDefaultCover() } else { selectImage.launch(requestCodeCover) @@ -97,12 +102,17 @@ class CoverConfigFragment : BasePreferenceFragment(), } } PreferKey.defaultCoverDark -> - if (getPrefString(PreferKey.defaultCoverDark).isNullOrEmpty()) { + if (getPrefString(preference.key).isNullOrEmpty()) { selectImage.launch(requestCodeCoverDark) } else { - context?.selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> + context?.selector( + items = arrayListOf( + getString(R.string.delete), + getString(R.string.select_image) + ) + ) { _, i -> if (i == 0) { - removePref(PreferKey.defaultCoverDark) + removePref(preference.key) BookCover.upDefaultCover() } else { selectImage.launch(requestCodeCoverDark) 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 167f692ae..516079948 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 @@ -55,6 +55,9 @@ class ThemeConfigFragment : BasePreferenceFragment(), if (Build.VERSION.SDK_INT < 26) { preferenceScreen.removePreferenceRecursively(PreferKey.launcherIcon) } + if (!AppConfig.isGooglePlay) { + preferenceScreen.removePreferenceRecursively("welcomeStyle") + } upPreferenceSummary(PreferKey.bgImage, getPrefString(PreferKey.bgImage)) upPreferenceSummary(PreferKey.bgImageN, getPrefString(PreferKey.bgImageN)) upPreferenceSummary(PreferKey.barElevation, AppConfig.elevation.toString()) @@ -175,6 +178,8 @@ class ThemeConfigFragment : BasePreferenceFragment(), "saveNightTheme" -> alertSaveTheme(key) "coverConfig" -> (activity as? ConfigActivity) ?.replaceFragment(ConfigTag.COVER_CONFIG) + "welcomeStyle" -> (activity as? ConfigActivity) + ?.replaceFragment(ConfigTag.WELCOME_CONFIG) } return super.onPreferenceTreeClick(preference) } diff --git a/app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt new file mode 100644 index 000000000..76bc3eb43 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt @@ -0,0 +1,130 @@ +package io.legado.app.ui.config + +import android.annotation.SuppressLint +import android.content.SharedPreferences +import android.net.Uri +import android.os.Bundle +import android.view.View +import androidx.preference.Preference +import io.legado.app.R +import io.legado.app.base.BasePreferenceFragment +import io.legado.app.constant.PreferKey +import io.legado.app.lib.dialogs.selector +import io.legado.app.lib.theme.primaryColor +import io.legado.app.model.BookCover +import io.legado.app.utils.* + +class WelcomeConfigFragment : BasePreferenceFragment(), + SharedPreferences.OnSharedPreferenceChangeListener { + + private val requestWelcomeImage = 221 + private val requestWelcomeImageDark = 222 + private val selectImage = registerForActivityResult(SelectImageContract()) { + it.uri?.let { uri -> + when (it.requestCode) { + requestWelcomeImage -> setCoverFromUri(PreferKey.defaultCover, uri) + requestWelcomeImageDark -> setCoverFromUri(PreferKey.defaultCoverDark, uri) + } + } + } + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.pref_config_welcome) + upPreferenceSummary(PreferKey.welcomeImage, getPrefString(PreferKey.welcomeImage)) + upPreferenceSummary(PreferKey.welcomeImageDark, getPrefString(PreferKey.welcomeImageDark)) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + activity?.setTitle(R.string.cover_config) + listView.setEdgeEffectColor(primaryColor) + setHasOptionsMenu(true) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) + } + + override fun onDestroy() { + super.onDestroy() + preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) + } + + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { + sharedPreferences ?: return + when (key) { + PreferKey.welcomeImage, + PreferKey.welcomeImageDark -> { + upPreferenceSummary(key, getPrefString(key)) + } + } + } + + @SuppressLint("PrivateResource") + override fun onPreferenceTreeClick(preference: Preference): Boolean { + when (preference.key) { + PreferKey.welcomeImage -> + if (getPrefString(preference.key).isNullOrEmpty()) { + selectImage.launch(requestWelcomeImage) + } else { + context?.selector( + items = arrayListOf( + getString(R.string.delete), + getString(R.string.select_image) + ) + ) { _, i -> + if (i == 0) { + removePref(preference.key) + BookCover.upDefaultCover() + } else { + selectImage.launch(requestWelcomeImage) + } + } + } + PreferKey.welcomeImageDark -> + if (getPrefString(preference.key).isNullOrEmpty()) { + selectImage.launch(requestWelcomeImageDark) + } else { + context?.selector( + items = arrayListOf( + getString(R.string.delete), + getString(R.string.select_image) + ) + ) { _, i -> + if (i == 0) { + removePref(preference.key) + BookCover.upDefaultCover() + } else { + selectImage.launch(requestWelcomeImageDark) + } + } + } + } + return super.onPreferenceTreeClick(preference) + } + + private fun upPreferenceSummary(preferenceKey: String, value: String?) { + val preference = findPreference(preferenceKey) ?: return + when (preferenceKey) { + PreferKey.defaultCover, + PreferKey.defaultCoverDark -> preference.summary = if (value.isNullOrBlank()) { + getString(R.string.select_image) + } else { + value + } + else -> preference.summary = value + } + } + + private fun setCoverFromUri(preferenceKey: String, uri: Uri) { + readUri(uri) { name, bytes -> + var file = requireContext().externalFiles + file = FileUtils.createFileIfNotExist(file, "covers", name) + file.writeBytes(bytes) + putPrefString(preferenceKey, file.absolutePath) + BookCover.upDefaultCover() + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 4e0636931..e4464a17c 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -66,6 +66,10 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { putPrefBoolean(PreferKey.webService, WebService.isRun) addPreferencesFromResource(R.xml.pref_main) + if (AppConfig.isGooglePlay) { + findPreference("aboutCategory") + ?.removePreferenceRecursively("donate") + } findPreference("webService")?.onLongClick { if (!WebService.isRun) { return@onLongClick false @@ -94,10 +98,6 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { true } } - if (AppConfig.isGooglePlay) { - findPreference("aboutCategory") - ?.removePreferenceRecursively("donate") - } } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 944484364..26f2996d9 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -946,5 +946,11 @@ 拷贝所有 自动补全 大小排序 + 启动界面样式 + 启动界面图片和是否显示文字等 + 显示文字 + 阅读|享受美好时光 + 自定义欢迎页 + 是否使用自定义欢迎页 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 621b764b8..735e71f62 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -949,5 +949,11 @@ 拷贝所有 自动补全 大小排序 + 启动界面样式 + 启动界面图片和是否显示文字等 + 显示文字 + 阅读|享受美好时光 + 自定义欢迎页 + 是否使用自定义欢迎页 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index fb7be3584..f7d1d3205 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -949,5 +949,11 @@ 拷贝所有 自动补全 大小排序 + 启动界面样式 + 启动界面图片和是否显示文字等 + 显示文字 + 阅读|享受美好时光 + 自定义欢迎页 + 是否使用自定义欢迎页 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 792a1d623..d5d161398 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -946,5 +946,11 @@ 拷贝所有 自动补全 大小排序 + 启动界面样式 + 启动界面图片和是否显示文字等 + 显示文字 + 阅读|享受美好时光 + 自定义欢迎页 + 是否使用自定义欢迎页 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 8b142d6d8..a56779e27 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -948,5 +948,11 @@ 拷贝所有 自动补全 大小排序 + 启动界面样式 + 启动界面图片和是否显示文字等 + 显示文字 + 阅读|享受美好时光 + 自定义欢迎页 + 是否使用自定义欢迎页 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 4e7c4e81d..29d4b61ae 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -948,5 +948,11 @@ 拷贝所有 自动补全 大小排序 + 启动界面样式 + 启动界面图片和是否显示文字等 + 显示文字 + 阅读|享受美好时光 + 自定义欢迎页 + 是否使用自定义欢迎页 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c742dd773..3eb526734 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -949,5 +949,11 @@ 拷贝所有 自动补全 Sort by size + 启动界面样式 + 启动界面图片和是否显示文字等 + 显示文字 + 阅读|享受美好时光 + 自定义欢迎页 + 是否使用自定义欢迎页 diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index 602235647..ed40078be 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -12,6 +12,11 @@ app:iconSpaceReserved="false" app:icons="@array/icons" /> + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file