diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index fd1e8d5f1..1b5424edb 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -122,6 +122,7 @@ class BackupConfigFragment : BasePreferenceFragment(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + activity?.setTitle(R.string.backup_restore) preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) ATH.applyEdgeEffectColor(listView) setHasOptionsMenu(true) 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 b022a2fe2..4d97b0bc5 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 @@ -1,55 +1,40 @@ package io.legado.app.ui.config import android.os.Bundle -import androidx.activity.viewModels +import androidx.fragment.app.Fragment import io.legado.app.R -import io.legado.app.base.VMBaseActivity +import io.legado.app.base.BaseActivity import io.legado.app.constant.EventBus import io.legado.app.databinding.ActivityConfigBinding - import io.legado.app.utils.observeEvent import io.legado.app.utils.viewbindingdelegate.viewBinding -class ConfigActivity : VMBaseActivity() { +class ConfigActivity : BaseActivity() { override val binding by viewBinding(ActivityConfigBinding::inflate) - override val viewModel by viewModels() override fun onActivityCreated(savedInstanceState: Bundle?) { - intent.getIntExtra("configType", -1).let { - if (it != -1) viewModel.configType = it + when (val configTag = intent.getStringExtra("configTag")) { + ConfigTag.OTHER_CONFIG -> replaceFragment(configTag) + ConfigTag.THEME_CONFIG -> replaceFragment(configTag) + ConfigTag.BACKUP_CONFIG -> replaceFragment(configTag) + ConfigTag.COVER_CONFIG -> replaceFragment(configTag) + else -> finish() } + } - when (viewModel.configType) { - ConfigViewModel.TYPE_CONFIG -> { - binding.titleBar.title = getString(R.string.other_setting) - val fTag = "otherConfigFragment" - var configFragment = supportFragmentManager.findFragmentByTag(fTag) - if (configFragment == null) configFragment = OtherConfigFragment() - supportFragmentManager.beginTransaction() - .replace(R.id.configFrameLayout, configFragment, fTag) - .commit() - } - ConfigViewModel.TYPE_THEME_CONFIG -> { - binding.titleBar.title = getString(R.string.theme_setting) - val fTag = "themeConfigFragment" - var configFragment = supportFragmentManager.findFragmentByTag(fTag) - if (configFragment == null) configFragment = ThemeConfigFragment() - supportFragmentManager.beginTransaction() - .replace(R.id.configFrameLayout, configFragment, fTag) - .commit() - } - ConfigViewModel.TYPE_WEB_DAV_CONFIG -> { - binding.titleBar.title = getString(R.string.backup_restore) - val fTag = "backupConfigFragment" - var configFragment = supportFragmentManager.findFragmentByTag(fTag) - if (configFragment == null) configFragment = BackupConfigFragment() - supportFragmentManager.beginTransaction() - .replace(R.id.configFrameLayout, configFragment, fTag) - .commit() - } - } + override fun setTitle(resId: Int) { + super.setTitle(resId) + binding.titleBar.setTitle(resId) + } + inline fun replaceFragment(configTag: String) { + intent.putExtra("configTag", configTag) + val configFragment = supportFragmentManager.findFragmentByTag(configTag) + ?: T::class.java.newInstance() + supportFragmentManager.beginTransaction() + .replace(R.id.configFrameLayout, configFragment, configTag) + .commit() } override fun observeLiveBus() { @@ -58,4 +43,13 @@ class ConfigActivity : VMBaseActivity() recreate() } } + + override fun finish() { + if (supportFragmentManager.findFragmentByTag(ConfigTag.COVER_CONFIG) != null) { + replaceFragment(ConfigTag.THEME_CONFIG) + } else { + super.finish() + } + } + } \ No newline at end of file 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 new file mode 100644 index 000000000..dda212c3d --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/config/ConfigTag.kt @@ -0,0 +1,10 @@ +package io.legado.app.ui.config + +object ConfigTag { + + const val OTHER_CONFIG = "otherConfig" + const val THEME_CONFIG = "themeConfig" + const val BACKUP_CONFIG = "backupConfig" + const val COVER_CONFIG = "coverConfig" + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/ConfigViewModel.kt b/app/src/main/java/io/legado/app/ui/config/ConfigViewModel.kt deleted file mode 100644 index 6f86c66d7..000000000 --- a/app/src/main/java/io/legado/app/ui/config/ConfigViewModel.kt +++ /dev/null @@ -1,15 +0,0 @@ -package io.legado.app.ui.config - -import android.app.Application -import androidx.lifecycle.AndroidViewModel - -class ConfigViewModel(application: Application) : AndroidViewModel(application) { - companion object { - const val TYPE_CONFIG = 0 - const val TYPE_THEME_CONFIG = 1 - const val TYPE_WEB_DAV_CONFIG = 2 - } - - var configType: Int = TYPE_CONFIG - -} \ 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 new file mode 100644 index 000000000..4863f25f5 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt @@ -0,0 +1,119 @@ +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.ATH +import io.legado.app.ui.widget.image.CoverImageView +import io.legado.app.utils.* + +class CoverConfigFragment : BasePreferenceFragment(), + SharedPreferences.OnSharedPreferenceChangeListener { + + private val requestCodeCover = 111 + private val requestCodeCoverDark = 112 + private val selectImage = registerForActivityResult(SelectImageContract()) { + val uri = it?.second ?: return@registerForActivityResult + when (it.first) { + requestCodeCover -> setCoverFromUri(PreferKey.defaultCover, uri) + requestCodeCoverDark -> setCoverFromUri(PreferKey.defaultCoverDark, uri) + } + } + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.pref_config_cover) + upPreferenceSummary(PreferKey.defaultCover, getPrefString(PreferKey.defaultCover)) + upPreferenceSummary(PreferKey.defaultCoverDark, getPrefString(PreferKey.defaultCoverDark)) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + activity?.setTitle(R.string.cover_config) + ATH.applyEdgeEffectColor(listView) + 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.defaultCover, + PreferKey.defaultCoverDark -> { + upPreferenceSummary(key, getPrefString(key)) + } + } + } + + @SuppressLint("PrivateResource") + override fun onPreferenceTreeClick(preference: Preference?): Boolean { + when (val key = preference?.key) { + PreferKey.defaultCover -> + if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) { + selectImage.launch(requestCodeCover) + } else { + context?.selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> + if (i == 0) { + removePref(PreferKey.defaultCover) + CoverImageView.upDefaultCover() + } else { + selectImage.launch(requestCodeCover) + } + } + } + PreferKey.defaultCoverDark -> + if (getPrefString(PreferKey.defaultCoverDark).isNullOrEmpty()) { + selectImage.launch(requestCodeCoverDark) + } else { + context?.selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> + if (i == 0) { + removePref(PreferKey.defaultCoverDark) + CoverImageView.upDefaultCover() + } else { + selectImage.launch(requestCodeCoverDark) + } + } + } + } + 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) + CoverImageView.upDefaultCover() + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 56932d152..859da6433 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -48,6 +48,7 @@ class OtherConfigFragment : BasePreferenceFragment(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + activity?.setTitle(R.string.other_setting) preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) ATH.applyEdgeEffectColor(listView) } 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 775956ee1..e77bd0297 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 @@ -24,7 +24,6 @@ import io.legado.app.help.ThemeConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.selector import io.legado.app.lib.theme.ATH -import io.legado.app.ui.widget.image.CoverImageView import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.ui.widget.prefs.ColorPreference import io.legado.app.ui.widget.seekbar.SeekBarChangeListener @@ -34,15 +33,12 @@ import io.legado.app.utils.* @Suppress("SameParameterValue") class ThemeConfigFragment : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { - private val requestCodeCover = 111 - private val requestCodeCoverDark = 112 + private val requestCodeBgLight = 121 private val requestCodeBgDark = 122 private val selectImage = registerForActivityResult(SelectImageContract()) { val uri = it?.second ?: return@registerForActivityResult when (it.first) { - requestCodeCover -> setCoverFromUri(PreferKey.defaultCover, uri) - requestCodeCoverDark -> setCoverFromUri(PreferKey.defaultCoverDark, uri) requestCodeBgLight -> setBgFromUri(uri, PreferKey.bgImage) { upTheme(false) } @@ -60,8 +56,6 @@ class ThemeConfigFragment : BasePreferenceFragment(), upPreferenceSummary(PreferKey.bgImage, getPrefString(PreferKey.bgImage)) upPreferenceSummary(PreferKey.bgImageN, getPrefString(PreferKey.bgImageN)) upPreferenceSummary(PreferKey.barElevation, AppConfig.elevation.toString()) - upPreferenceSummary(PreferKey.defaultCover, getPrefString(PreferKey.defaultCover)) - upPreferenceSummary(PreferKey.defaultCoverDark, getPrefString(PreferKey.defaultCoverDark)) findPreference(PreferKey.cBackground)?.let { it.onSaveColor = { color -> if (!ColorUtils.isColorLight(color)) { @@ -86,6 +80,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + activity?.setTitle(R.string.theme_setting) ATH.applyEdgeEffectColor(listView) setHasOptionsMenu(true) } @@ -134,9 +129,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), upTheme(true) } PreferKey.bgImage, - PreferKey.bgImageN, - PreferKey.defaultCover, - PreferKey.defaultCoverDark -> { + PreferKey.bgImageN -> { upPreferenceSummary(key, getPrefString(key)) } } @@ -159,36 +152,13 @@ class ThemeConfigFragment : BasePreferenceFragment(), AppConfig.elevation = it recreateActivities() } - "themeList" -> ThemeListDialog().show(childFragmentManager, "themeList") - "saveDayTheme", "saveNightTheme" -> alertSaveTheme(key) PreferKey.bgImage -> selectBgAction(false) PreferKey.bgImageN -> selectBgAction(true) - PreferKey.defaultCover -> - if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) { - selectImage.launch(requestCodeCover) - } else { - context?.selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> - if (i == 0) { - removePref(PreferKey.defaultCover) - CoverImageView.upDefaultCover() - } else { - selectImage.launch(requestCodeCover) - } - } - } - PreferKey.defaultCoverDark -> - if (getPrefString(PreferKey.defaultCoverDark).isNullOrEmpty()) { - selectImage.launch(requestCodeCoverDark) - } else { - context?.selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> - if (i == 0) { - removePref(PreferKey.defaultCoverDark) - CoverImageView.upDefaultCover() - } else { - selectImage.launch(requestCodeCoverDark) - } - } - } + "themeList" -> ThemeListDialog().show(childFragmentManager, "themeList") + "saveDayTheme", + "saveNightTheme" -> alertSaveTheme(key) + "coverConfig" -> (activity as? ConfigActivity) + ?.replaceFragment(ConfigTag.COVER_CONFIG) } return super.onPreferenceTreeClick(preference) } @@ -293,9 +263,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), PreferKey.barElevation -> preference.summary = getString(R.string.bar_elevation_s, value) PreferKey.bgImage, - PreferKey.bgImageN, - PreferKey.defaultCover, - PreferKey.defaultCoverDark -> preference.summary = if (value.isNullOrBlank()) { + PreferKey.bgImageN -> preference.summary = if (value.isNullOrBlank()) { getString(R.string.select_image) } else { value @@ -314,14 +282,4 @@ class ThemeConfigFragment : BasePreferenceFragment(), } } - 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) - CoverImageView.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 bf09a6171..b823523ab 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 @@ -21,7 +21,7 @@ import io.legado.app.ui.about.DonateActivity import io.legado.app.ui.about.ReadRecordActivity import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.config.ConfigActivity -import io.legado.app.ui.config.ConfigViewModel +import io.legado.app.ui.config.ConfigTag import io.legado.app.ui.replace.ReplaceRuleActivity import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.prefs.NameListPreference @@ -128,13 +128,13 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { "bookSourceManage" -> startActivity() "replaceManage" -> startActivity() "setting" -> startActivity { - putExtra("configType", ConfigViewModel.TYPE_CONFIG) + putExtra("configTag", ConfigTag.OTHER_CONFIG) } "web_dav_setting" -> startActivity { - putExtra("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG) + putExtra("configTag", ConfigTag.BACKUP_CONFIG) } "theme_setting" -> startActivity { - putExtra("configType", ConfigViewModel.TYPE_THEME_CONFIG) + putExtra("configTag", ConfigTag.THEME_CONFIG) } "readRecord" -> startActivity() "donate" -> startActivity() diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index a371b69f0..3fe8a704f 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -14,6 +14,7 @@ import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig import io.legado.app.help.glide.ImageLoader +import io.legado.app.lib.theme.accentColor import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefString import io.legado.app.utils.textHeight @@ -91,7 +92,7 @@ class CoverImageView @JvmOverloads constructor( canvas.clipPath(filletPath) } super.onDraw(canvas) - if (defaultCover && drawBookName) { + if (defaultCover && drawBookName && !isInEditMode) { drawName(canvas) } } @@ -101,12 +102,12 @@ class CoverImageView @JvmOverloads constructor( var startY = height * 0.2f name?.toStringArray()?.let { name -> namePaint.textSize = width / 7 - namePaint.strokeWidth = namePaint.textSize / 10 + namePaint.strokeWidth = namePaint.textSize / 5 name.forEach { namePaint.color = Color.WHITE namePaint.style = Paint.Style.STROKE canvas.drawText(it, startX, startY, namePaint) - namePaint.color = Color.DKGRAY + namePaint.color = context.accentColor namePaint.style = Paint.Style.FILL canvas.drawText(it, startX, startY, namePaint) startY += namePaint.textHeight @@ -119,12 +120,12 @@ class CoverImageView @JvmOverloads constructor( startX = width * 0.8f startY = height * 0.7f authorPaint.textSize = width / 9 - authorPaint.strokeWidth = authorPaint.textSize / 10 + authorPaint.strokeWidth = authorPaint.textSize / 5 author.forEach { authorPaint.color = Color.WHITE authorPaint.style = Paint.Style.STROKE canvas.drawText(it, startX, startY, authorPaint) - authorPaint.color = Color.DKGRAY + authorPaint.color = context.accentColor authorPaint.style = Paint.Style.FILL canvas.drawText(it, startX, startY, authorPaint) startY += authorPaint.textHeight diff --git a/app/src/main/res/drawable/image_cover_default.png b/app/src/main/res/drawable/image_cover_default.png index 025897101..7f061e71b 100644 Binary files a/app/src/main/res/drawable/image_cover_default.png and b/app/src/main/res/drawable/image_cover_default.png differ diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 406b83c4e..c321df3b3 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -874,5 +874,7 @@ 设置源变量 设置书籍变量 注释 + 封面设置 + 设置默认封面样式 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 5906f08a8..4ffb2e13b 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -878,5 +878,7 @@ 设置源变量 设置书籍变量 注释 + 封面设置 + 设置默认封面样式 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index c5ed32423..10169456c 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -878,5 +878,7 @@ 设置源变量 设置书籍变量 注释 + 封面设置 + 设置默认封面样式 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 7e99f47d4..21f400c83 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -875,5 +875,7 @@ 设置源变量 设置书籍变量 注释 + 封面设置 + 设置默认封面样式 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index e1ae6c551..1067e2a60 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -877,5 +877,7 @@ 設定源變數 設定書籍變數 注释 + 封面设置 + 设置默认封面样式 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index ac9cd51b6..ab182152c 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -877,5 +877,7 @@ 设置源变量 设置书籍变量 注释 + 封面设置 + 设置默认封面样式 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ff752af6c..d9589a226 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -878,5 +878,7 @@ 设置源变量 设置书籍变量 注释 + 封面设置 + 设置默认封面样式 diff --git a/app/src/main/res/xml/pref_config_cover.xml b/app/src/main/res/xml/pref_config_cover.xml new file mode 100644 index 000000000..26b1461c7 --- /dev/null +++ b/app/src/main/res/xml/pref_config_cover.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index a30c3c603..f2e80790b 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -33,11 +33,11 @@ android:title="@string/bar_elevation" app:iconSpaceReserved="false" /> - @@ -96,10 +96,6 @@ android:key="backgroundImage" android:title="@string/background_image" /> - - - -