فهرست منبع

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

kunfei 4 سال پیش
والد
کامیت
45533b8f3c

+ 4 - 0
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"

+ 1 - 0
app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt

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

+ 1 - 0
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"
 
 }

+ 16 - 6
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)

+ 5 - 0
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<CoverConfigFragment>(ConfigTag.COVER_CONFIG)
+            "welcomeStyle" -> (activity as? ConfigActivity)
+                ?.replaceFragment<CoverConfigFragment>(ConfigTag.WELCOME_CONFIG)
         }
         return super.onPreferenceTreeClick(preference)
     }

+ 130 - 0
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<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()
+        }
+    }
+
+}

+ 4 - 4
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<PreferenceCategory>("aboutCategory")
+                    ?.removePreferenceRecursively("donate")
+            }
             findPreference<SwitchPreference>("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<PreferenceCategory>("aboutCategory")
-                    ?.removePreferenceRecursively("donate")
-            }
         }
 
         override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

+ 6 - 0
app/src/main/res/values-es-rES/strings.xml

@@ -946,5 +946,11 @@
     <string name="copy_all">拷贝所有</string>
     <string name="auto_complete">自动补全</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 -->
 </resources>

+ 6 - 0
app/src/main/res/values-ja-rJP/strings.xml

@@ -949,5 +949,11 @@
     <string name="copy_all">拷贝所有</string>
     <string name="auto_complete">自动补全</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 -->
 </resources>

+ 6 - 0
app/src/main/res/values-pt-rBR/strings.xml

@@ -949,5 +949,11 @@
     <string name="copy_all">拷贝所有</string>
     <string name="auto_complete">自动补全</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 -->
 </resources>

+ 6 - 0
app/src/main/res/values-zh-rHK/strings.xml

@@ -946,5 +946,11 @@
     <string name="copy_all">拷贝所有</string>
     <string name="auto_complete">自动补全</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 -->
 </resources>

+ 6 - 0
app/src/main/res/values-zh-rTW/strings.xml

@@ -948,5 +948,11 @@
     <string name="copy_all">拷贝所有</string>
     <string name="auto_complete">自动补全</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 -->
 </resources>

+ 6 - 0
app/src/main/res/values-zh/strings.xml

@@ -948,5 +948,11 @@
     <string name="copy_all">拷贝所有</string>
     <string name="auto_complete">自动补全</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 -->
 </resources>

+ 6 - 0
app/src/main/res/values/strings.xml

@@ -949,5 +949,11 @@
     <string name="copy_all">拷贝所有</string>
     <string name="auto_complete">自动补全</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 -->
 </resources>

+ 5 - 3
app/src/main/res/xml/pref_config_theme.xml

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

+ 66 - 0
app/src/main/res/xml/pref_config_welcome.xml

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