pro版本添加自定义启动画面

pull/1689/head
kunfei 3 years ago
parent 1e8dec42b1
commit f0a6a55490
  1. 4
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 1
      app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt
  3. 1
      app/src/main/java/io/legado/app/ui/config/ConfigTag.kt
  4. 22
      app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt
  5. 5
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  6. 130
      app/src/main/java/io/legado/app/ui/config/WelcomeConfigFragment.kt
  7. 8
      app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt
  8. 6
      app/src/main/res/values-es-rES/strings.xml
  9. 6
      app/src/main/res/values-ja-rJP/strings.xml
  10. 6
      app/src/main/res/values-pt-rBR/strings.xml
  11. 6
      app/src/main/res/values-zh-rHK/strings.xml
  12. 6
      app/src/main/res/values-zh-rTW/strings.xml
  13. 6
      app/src/main/res/values-zh/strings.xml
  14. 6
      app/src/main/res/values/strings.xml
  15. 8
      app/src/main/res/xml/pref_config_theme.xml
  16. 66
      app/src/main/res/xml/pref_config_welcome.xml

@ -95,6 +95,10 @@ object PreferKey {
const val uploadRule = "uploadRule" const val uploadRule = "uploadRule"
const val tocUiUseReplace = "tocUiUseReplace" const val tocUiUseReplace = "tocUiUseReplace"
const val enableReadRecord = "enableReadRecord" 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 cPrimary = "colorPrimary"
const val cAccent = "colorAccent" const val cAccent = "colorAccent"

@ -19,6 +19,7 @@ class ConfigActivity : BaseActivity<ActivityConfigBinding>() {
ConfigTag.THEME_CONFIG -> replaceFragment<ThemeConfigFragment>(configTag) ConfigTag.THEME_CONFIG -> replaceFragment<ThemeConfigFragment>(configTag)
ConfigTag.BACKUP_CONFIG -> replaceFragment<BackupConfigFragment>(configTag) ConfigTag.BACKUP_CONFIG -> replaceFragment<BackupConfigFragment>(configTag)
ConfigTag.COVER_CONFIG -> replaceFragment<CoverConfigFragment>(configTag) ConfigTag.COVER_CONFIG -> replaceFragment<CoverConfigFragment>(configTag)
ConfigTag.WELCOME_CONFIG -> replaceFragment<WelcomeConfigFragment>(configTag)
else -> finish() else -> finish()
} }
} }

@ -6,5 +6,6 @@ object ConfigTag {
const val THEME_CONFIG = "themeConfig" const val THEME_CONFIG = "themeConfig"
const val BACKUP_CONFIG = "backupConfig" const val BACKUP_CONFIG = "backupConfig"
const val COVER_CONFIG = "coverConfig" const val COVER_CONFIG = "coverConfig"
const val WELCOME_CONFIG = "welcomeConfig"
} }

@ -84,12 +84,17 @@ class CoverConfigFragment : BasePreferenceFragment(),
override fun onPreferenceTreeClick(preference: Preference): Boolean { override fun onPreferenceTreeClick(preference: Preference): Boolean {
when (preference.key) { when (preference.key) {
PreferKey.defaultCover -> PreferKey.defaultCover ->
if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) { if (getPrefString(preference.key).isNullOrEmpty()) {
selectImage.launch(requestCodeCover) selectImage.launch(requestCodeCover)
} else { } else {
context?.selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> context?.selector(
items = arrayListOf(
getString(R.string.delete),
getString(R.string.select_image)
)
) { _, i ->
if (i == 0) { if (i == 0) {
removePref(PreferKey.defaultCover) removePref(preference.key)
BookCover.upDefaultCover() BookCover.upDefaultCover()
} else { } else {
selectImage.launch(requestCodeCover) selectImage.launch(requestCodeCover)
@ -97,12 +102,17 @@ class CoverConfigFragment : BasePreferenceFragment(),
} }
} }
PreferKey.defaultCoverDark -> PreferKey.defaultCoverDark ->
if (getPrefString(PreferKey.defaultCoverDark).isNullOrEmpty()) { if (getPrefString(preference.key).isNullOrEmpty()) {
selectImage.launch(requestCodeCoverDark) selectImage.launch(requestCodeCoverDark)
} else { } else {
context?.selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> context?.selector(
items = arrayListOf(
getString(R.string.delete),
getString(R.string.select_image)
)
) { _, i ->
if (i == 0) { if (i == 0) {
removePref(PreferKey.defaultCoverDark) removePref(preference.key)
BookCover.upDefaultCover() BookCover.upDefaultCover()
} else { } else {
selectImage.launch(requestCodeCoverDark) selectImage.launch(requestCodeCoverDark)

@ -55,6 +55,9 @@ class ThemeConfigFragment : BasePreferenceFragment(),
if (Build.VERSION.SDK_INT < 26) { if (Build.VERSION.SDK_INT < 26) {
preferenceScreen.removePreferenceRecursively(PreferKey.launcherIcon) preferenceScreen.removePreferenceRecursively(PreferKey.launcherIcon)
} }
if (!AppConfig.isGooglePlay) {
preferenceScreen.removePreferenceRecursively("welcomeStyle")
}
upPreferenceSummary(PreferKey.bgImage, getPrefString(PreferKey.bgImage)) upPreferenceSummary(PreferKey.bgImage, getPrefString(PreferKey.bgImage))
upPreferenceSummary(PreferKey.bgImageN, getPrefString(PreferKey.bgImageN)) upPreferenceSummary(PreferKey.bgImageN, getPrefString(PreferKey.bgImageN))
upPreferenceSummary(PreferKey.barElevation, AppConfig.elevation.toString()) upPreferenceSummary(PreferKey.barElevation, AppConfig.elevation.toString())
@ -175,6 +178,8 @@ class ThemeConfigFragment : BasePreferenceFragment(),
"saveNightTheme" -> alertSaveTheme(key) "saveNightTheme" -> alertSaveTheme(key)
"coverConfig" -> (activity as? ConfigActivity) "coverConfig" -> (activity as? ConfigActivity)
?.replaceFragment<CoverConfigFragment>(ConfigTag.COVER_CONFIG) ?.replaceFragment<CoverConfigFragment>(ConfigTag.COVER_CONFIG)
"welcomeStyle" -> (activity as? ConfigActivity)
?.replaceFragment<CoverConfigFragment>(ConfigTag.WELCOME_CONFIG)
} }
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)
} }

@ -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<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)
BookCover.upDefaultCover()
}
}
}

@ -66,6 +66,10 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
putPrefBoolean(PreferKey.webService, WebService.isRun) putPrefBoolean(PreferKey.webService, WebService.isRun)
addPreferencesFromResource(R.xml.pref_main) addPreferencesFromResource(R.xml.pref_main)
if (AppConfig.isGooglePlay) {
findPreference<PreferenceCategory>("aboutCategory")
?.removePreferenceRecursively("donate")
}
findPreference<SwitchPreference>("webService")?.onLongClick { findPreference<SwitchPreference>("webService")?.onLongClick {
if (!WebService.isRun) { if (!WebService.isRun) {
return@onLongClick false return@onLongClick false
@ -94,10 +98,6 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) {
true true
} }
} }
if (AppConfig.isGooglePlay) {
findPreference<PreferenceCategory>("aboutCategory")
?.removePreferenceRecursively("donate")
}
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

@ -946,5 +946,11 @@
<string name="copy_all">拷贝所有</string> <string name="copy_all">拷贝所有</string>
<string name="auto_complete">自动补全</string> <string name="auto_complete">自动补全</string>
<string name="sort_by_size">大小排序</string> <string name="sort_by_size">大小排序</string>
<string name="welcome_style">启动界面样式</string>
<string name="welcome_style_summary">启动界面图片和是否显示文字等</string>
<string name="show_welcome_text">显示文字</string>
<string name="welcome_text">阅读|享受美好时光</string>
<string name="custom_welcome">自定义欢迎页</string>
<string name="custom_welcome_summary">是否使用自定义欢迎页</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -949,5 +949,11 @@
<string name="copy_all">拷贝所有</string> <string name="copy_all">拷贝所有</string>
<string name="auto_complete">自动补全</string> <string name="auto_complete">自动补全</string>
<string name="sort_by_size">大小排序</string> <string name="sort_by_size">大小排序</string>
<string name="welcome_style">启动界面样式</string>
<string name="welcome_style_summary">启动界面图片和是否显示文字等</string>
<string name="show_welcome_text">显示文字</string>
<string name="welcome_text">阅读|享受美好时光</string>
<string name="custom_welcome">自定义欢迎页</string>
<string name="custom_welcome_summary">是否使用自定义欢迎页</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -949,5 +949,11 @@
<string name="copy_all">拷贝所有</string> <string name="copy_all">拷贝所有</string>
<string name="auto_complete">自动补全</string> <string name="auto_complete">自动补全</string>
<string name="sort_by_size">大小排序</string> <string name="sort_by_size">大小排序</string>
<string name="welcome_style">启动界面样式</string>
<string name="welcome_style_summary">启动界面图片和是否显示文字等</string>
<string name="show_welcome_text">显示文字</string>
<string name="welcome_text">阅读|享受美好时光</string>
<string name="custom_welcome">自定义欢迎页</string>
<string name="custom_welcome_summary">是否使用自定义欢迎页</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -946,5 +946,11 @@
<string name="copy_all">拷贝所有</string> <string name="copy_all">拷贝所有</string>
<string name="auto_complete">自动补全</string> <string name="auto_complete">自动补全</string>
<string name="sort_by_size">大小排序</string> <string name="sort_by_size">大小排序</string>
<string name="welcome_style">启动界面样式</string>
<string name="welcome_style_summary">启动界面图片和是否显示文字等</string>
<string name="show_welcome_text">显示文字</string>
<string name="welcome_text">阅读|享受美好时光</string>
<string name="custom_welcome">自定义欢迎页</string>
<string name="custom_welcome_summary">是否使用自定义欢迎页</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -948,5 +948,11 @@
<string name="copy_all">拷贝所有</string> <string name="copy_all">拷贝所有</string>
<string name="auto_complete">自动补全</string> <string name="auto_complete">自动补全</string>
<string name="sort_by_size">大小排序</string> <string name="sort_by_size">大小排序</string>
<string name="welcome_style">启动界面样式</string>
<string name="welcome_style_summary">启动界面图片和是否显示文字等</string>
<string name="show_welcome_text">显示文字</string>
<string name="welcome_text">阅读|享受美好时光</string>
<string name="custom_welcome">自定义欢迎页</string>
<string name="custom_welcome_summary">是否使用自定义欢迎页</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -948,5 +948,11 @@
<string name="copy_all">拷贝所有</string> <string name="copy_all">拷贝所有</string>
<string name="auto_complete">自动补全</string> <string name="auto_complete">自动补全</string>
<string name="sort_by_size">大小排序</string> <string name="sort_by_size">大小排序</string>
<string name="welcome_style">启动界面样式</string>
<string name="welcome_style_summary">启动界面图片和是否显示文字等</string>
<string name="show_welcome_text">显示文字</string>
<string name="welcome_text">阅读|享受美好时光</string>
<string name="custom_welcome">自定义欢迎页</string>
<string name="custom_welcome_summary">是否使用自定义欢迎页</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -949,5 +949,11 @@
<string name="copy_all">拷贝所有</string> <string name="copy_all">拷贝所有</string>
<string name="auto_complete">自动补全</string> <string name="auto_complete">自动补全</string>
<string name="sort_by_size">Sort by size</string> <string name="sort_by_size">Sort by size</string>
<string name="welcome_style">启动界面样式</string>
<string name="welcome_style_summary">启动界面图片和是否显示文字等</string>
<string name="show_welcome_text">显示文字</string>
<string name="welcome_text">阅读|享受美好时光</string>
<string name="custom_welcome">自定义欢迎页</string>
<string name="custom_welcome_summary">是否使用自定义欢迎页</string>
<!-- string end --> <!-- string end -->
</resources> </resources>

@ -12,6 +12,11 @@
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
app:icons="@array/icons" /> app:icons="@array/icons" />
<io.legado.app.ui.widget.prefs.Preference
android:key="welcomeStyle"
android:title="@string/welcome_style"
android:summary="@string/welcome_style_summary" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="transparentStatusBar" android:key="transparentStatusBar"
@ -27,21 +32,18 @@
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.Preference
android:defaultValue="true"
android:key="barElevation" android:key="barElevation"
android:summary="@string/bar_elevation_s" android:summary="@string/bar_elevation_s"
android:title="@string/bar_elevation" android:title="@string/bar_elevation"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.Preference
android:defaultValue="true"
android:key="fontScale" android:key="fontScale"
android:summary="@string/font_scale_summary" android:summary="@string/font_scale_summary"
android:title="@string/font_scale" android:title="@string/font_scale"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.Preference
android:defaultValue="false"
android:key="coverConfig" android:key="coverConfig"
android:title="@string/cover_config" android:title="@string/cover_config"
android:summary="@string/cover_config_summary" android:summary="@string/cover_config_summary"

@ -0,0 +1,66 @@
<?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="customWelcome"
android:summary="@string/custom_welcome_summary"
android:title="@string/custom_welcome"
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="welcomeImagePath"
android:title="@string/background_image"
app:allowDividerAbove="false"
app:allowDividerBelow="false"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true"
android:key="welcomeShowText"
android:summary="@string/welcome_text"
android:title="@string/show_welcome_text"
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="welcomeImagePathDark"
android:title="@string/background_image"
app:allowDividerAbove="false"
app:allowDividerBelow="false"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true"
android:key="welcomeShowTextDark"
android:summary="@string/welcome_text"
android:title="@string/show_welcome_text"
app:allowDividerAbove="false"
app:allowDividerBelow="false"
app:iconSpaceReserved="false" />
</io.legado.app.ui.widget.prefs.PreferenceCategory>
</androidx.preference.PreferenceScreen>
Loading…
Cancel
Save