优化封面

pull/1336/head
gedoor 3 years ago
parent 4cb8898793
commit 94e5065677
  1. 1
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt
  2. 62
      app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt
  3. 10
      app/src/main/java/io/legado/app/ui/config/ConfigTag.kt
  4. 15
      app/src/main/java/io/legado/app/ui/config/ConfigViewModel.kt
  5. 119
      app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt
  6. 1
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  7. 60
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  8. 8
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt
  9. 11
      app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt
  10. BIN
      app/src/main/res/drawable/image_cover_default.png
  11. 2
      app/src/main/res/values-es-rES/strings.xml
  12. 2
      app/src/main/res/values-ja-rJP/strings.xml
  13. 2
      app/src/main/res/values-pt-rBR/strings.xml
  14. 2
      app/src/main/res/values-zh-rHK/strings.xml
  15. 2
      app/src/main/res/values-zh-rTW/strings.xml
  16. 2
      app/src/main/res/values-zh/strings.xml
  17. 2
      app/src/main/res/values/strings.xml
  18. 49
      app/src/main/res/xml/pref_config_cover.xml
  19. 16
      app/src/main/res/xml/pref_config_theme.xml

@ -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)

@ -1,56 +1,41 @@
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<ActivityConfigBinding, ConfigViewModel>() {
class ConfigActivity : BaseActivity<ActivityConfigBinding>() {
override val binding by viewBinding(ActivityConfigBinding::inflate)
override val viewModel by viewModels<ConfigViewModel>()
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<OtherConfigFragment>(configTag)
ConfigTag.THEME_CONFIG -> replaceFragment<ThemeConfigFragment>(configTag)
ConfigTag.BACKUP_CONFIG -> replaceFragment<BackupConfigFragment>(configTag)
ConfigTag.COVER_CONFIG -> replaceFragment<CoverConfigFragment>(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()
override fun setTitle(resId: Int) {
super.setTitle(resId)
binding.titleBar.setTitle(resId)
}
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()
inline fun <reified T : Fragment> replaceFragment(configTag: String) {
intent.putExtra("configTag", configTag)
val configFragment = supportFragmentManager.findFragmentByTag(configTag)
?: T::class.java.newInstance()
supportFragmentManager.beginTransaction()
.replace(R.id.configFrameLayout, configFragment, fTag)
.replace(R.id.configFrameLayout, configFragment, configTag)
.commit()
}
}
}
override fun observeLiveBus() {
super.observeLiveBus()
@ -58,4 +43,13 @@ class ConfigActivity : VMBaseActivity<ActivityConfigBinding, ConfigViewModel>()
recreate()
}
}
override fun finish() {
if (supportFragmentManager.findFragmentByTag(ConfigTag.COVER_CONFIG) != null) {
replaceFragment<ThemeConfigFragment>(ConfigTag.THEME_CONFIG)
} else {
super.finish()
}
}
}

@ -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"
}

@ -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
}

@ -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<Preference>(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()
}
}
}

@ -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)
}

@ -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<ColorPreference>(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<CoverConfigFragment>(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()
}
}
}

@ -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<BookSourceActivity>()
"replaceManage" -> startActivity<ReplaceRuleActivity>()
"setting" -> startActivity<ConfigActivity> {
putExtra("configType", ConfigViewModel.TYPE_CONFIG)
putExtra("configTag", ConfigTag.OTHER_CONFIG)
}
"web_dav_setting" -> startActivity<ConfigActivity> {
putExtra("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG)
putExtra("configTag", ConfigTag.BACKUP_CONFIG)
}
"theme_setting" -> startActivity<ConfigActivity> {
putExtra("configType", ConfigViewModel.TYPE_THEME_CONFIG)
putExtra("configTag", ConfigTag.THEME_CONFIG)
}
"readRecord" -> startActivity<ReadRecordActivity>()
"donate" -> startActivity<DonateActivity>()

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 260 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

@ -874,5 +874,7 @@
<string name="set_source_variable">设置源变量</string>
<string name="set_book_variable">设置书籍变量</string>
<string name="summary">注释</string>
<string name="cover_config">封面设置</string>
<string name="cover_config_summary">设置默认封面样式</string>
</resources>

@ -878,5 +878,7 @@
<string name="set_source_variable">设置源变量</string>
<string name="set_book_variable">设置书籍变量</string>
<string name="summary">注释</string>
<string name="cover_config">封面设置</string>
<string name="cover_config_summary">设置默认封面样式</string>
</resources>

@ -878,5 +878,7 @@
<string name="set_source_variable">设置源变量</string>
<string name="set_book_variable">设置书籍变量</string>
<string name="summary">注释</string>
<string name="cover_config">封面设置</string>
<string name="cover_config_summary">设置默认封面样式</string>
</resources>

@ -875,5 +875,7 @@
<string name="set_source_variable">设置源变量</string>
<string name="set_book_variable">设置书籍变量</string>
<string name="summary">注释</string>
<string name="cover_config">封面设置</string>
<string name="cover_config_summary">设置默认封面样式</string>
</resources>

@ -877,5 +877,7 @@
<string name="set_source_variable">設定源變數</string>
<string name="set_book_variable">設定書籍變數</string>
<string name="summary">注释</string>
<string name="cover_config">封面设置</string>
<string name="cover_config_summary">设置默认封面样式</string>
</resources>

@ -877,5 +877,7 @@
<string name="set_source_variable">设置源变量</string>
<string name="set_book_variable">设置书籍变量</string>
<string name="summary">注释</string>
<string name="cover_config">封面设置</string>
<string name="cover_config_summary">设置默认封面样式</string>
</resources>

@ -878,5 +878,7 @@
<string name="set_source_variable">设置源变量</string>
<string name="set_book_variable">设置书籍变量</string>
<string name="summary">注释</string>
<string name="cover_config">封面设置</string>
<string name="cover_config_summary">设置默认封面样式</string>
</resources>

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="false"
android:key="useDefaultCover"
android:summary="@string/use_default_cover_s"
android:title="@string/use_default_cover"
app:allowDividerAbove="false"
app:allowDividerBelow="false"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.PreferenceCategory
android:key="dayThemeCategory"
android:title="@string/day"
app:allowDividerAbove="true"
app:allowDividerBelow="false"
app:iconSpaceReserved="false"
app:layout="@layout/view_preference_category">
<io.legado.app.ui.widget.prefs.Preference
android:key="defaultCover"
android:title="@string/default_cover"
app:allowDividerAbove="false"
app:allowDividerBelow="false"
app:iconSpaceReserved="false" />
</io.legado.app.ui.widget.prefs.PreferenceCategory>
<io.legado.app.ui.widget.prefs.PreferenceCategory
android:key="nightThemeCategory"
android:title="@string/night"
app:allowDividerAbove="true"
app:allowDividerBelow="false"
app:iconSpaceReserved="false"
app:layout="@layout/view_preference_category">
<io.legado.app.ui.widget.prefs.Preference
android:key="defaultCoverDark"
android:title="@string/default_cover"
app:allowDividerAbove="false"
app:allowDividerBelow="false"
app:iconSpaceReserved="false" />
</io.legado.app.ui.widget.prefs.PreferenceCategory>
</androidx.preference.PreferenceScreen>

@ -33,11 +33,11 @@
android:title="@string/bar_elevation"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
<io.legado.app.ui.widget.prefs.Preference
android:defaultValue="false"
android:key="useDefaultCover"
android:title="@string/use_default_cover"
android:summary="@string/use_default_cover_s"
android:key="coverConfig"
android:title="@string/cover_config"
android:summary="@string/cover_config_summary"
app:allowDividerAbove="false"
app:allowDividerBelow="false"
app:iconSpaceReserved="false" />
@ -96,10 +96,6 @@
android:key="backgroundImage"
android:title="@string/background_image" />
<io.legado.app.ui.widget.prefs.Preference
android:key="defaultCover"
android:title="@string/default_cover" />
<io.legado.app.ui.widget.prefs.Preference
android:key="saveDayTheme"
android:summary="@string/save_day_theme_summary"
@ -154,10 +150,6 @@
android:key="backgroundImageNight"
android:title="@string/background_image" />
<io.legado.app.ui.widget.prefs.Preference
android:key="defaultCoverDark"
android:title="@string/default_cover" />
<io.legado.app.ui.widget.prefs.Preference
android:key="saveNightTheme"
android:summary="@string/save_night_theme_summary"

Loading…
Cancel
Save