设置图片背景

pull/831/head
gedoor 4 years ago
parent e7eb59c6ef
commit c06c071674
  1. 37
      app/google-services.json
  2. 6
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  3. 12
      app/src/main/java/io/legado/app/constant/Theme.kt
  4. 14
      app/src/main/java/io/legado/app/help/ThemeConfig.kt
  5. 18
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  6. 8
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt

@ -108,6 +108,43 @@
] ]
} }
} }
},
{
"client_info": {
"mobilesdk_app_id": "1:453392274790:android:b891abd2331577dff624a7",
"android_client_info": {
"package_name": "io.legado.play.debug"
}
},
"oauth_client": [
{
"client_id": "453392274790-f8sjn6ohs72rg1dvp0pdvk42nkq54p0k.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "io.legado.play.debug",
"certificate_hash": "00819ace9891386e535967cbafd6a88f3797bd5b"
}
},
{
"client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyD90mfNLhA7cAzzI9SonpSz5mrF5BnmyJA"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
} }
], ],
"configuration_version": "1" "configuration_version": "1"

@ -16,6 +16,7 @@ import io.legado.app.R
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.Theme import io.legado.app.constant.Theme
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.ThemeConfig
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
@ -151,6 +152,11 @@ abstract class BaseActivity<VB : ViewBinding>(
ATH.applyBackgroundTint(window.decorView) ATH.applyBackgroundTint(window.decorView)
} }
} }
if (AppConfig.isGooglePlay) {
ThemeConfig.getBgImage(this)?.let {
window.decorView.background = it
}
}
} }
private fun setupSystemBar() { private fun setupSystemBar() {

@ -4,16 +4,18 @@ import io.legado.app.help.AppConfig
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
enum class Theme { enum class Theme {
Dark, Light, Auto, Transparent; Dark, Light, Auto, Transparent, EInk;
companion object { companion object {
fun getTheme() = fun getTheme() = when {
if (AppConfig.isNightTheme) Dark AppConfig.isEInkMode -> EInk
else Light AppConfig.isNightTheme -> Dark
else -> Light
}
fun getTheme(backgroundColor: Int) = fun getTheme(backgroundColor: Int) =
if (ColorUtils.isColorLight(backgroundColor)) Light if (ColorUtils.isColorLight(backgroundColor)) Light
else Dark else Dark
} }
} }

@ -2,11 +2,14 @@ package io.legado.app.help
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import androidx.annotation.Keep import androidx.annotation.Keep
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.constant.Theme
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.utils.* import io.legado.app.utils.*
import java.io.File import java.io.File
@ -20,6 +23,16 @@ object ThemeConfig {
ArrayList(cList) ArrayList(cList)
} }
fun getBgImage(context: Context): Drawable? {
val bgPath = when (Theme.getTheme()) {
Theme.Light -> context.getPrefString(PreferKey.bgImage)
Theme.Dark -> context.getPrefString(PreferKey.bgImageN)
else -> null
}
if (bgPath.isNullOrBlank()) return null
return BitmapDrawable.createFromPath(bgPath)
}
fun upConfig() { fun upConfig() {
getConfigs()?.let { getConfigs()?.let {
it.forEach { config -> it.forEach { config ->
@ -204,7 +217,6 @@ object ThemeConfig {
var primaryColor: String, var primaryColor: String,
var accentColor: String, var accentColor: String,
var backgroundColor: String, var backgroundColor: String,
var backgroundImage: String? = null,
var bottomBackground: String var bottomBackground: String
) )

@ -192,6 +192,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> selector(items = arrayListOf("删除图片", "选择图片")) { _, i ->
if (i == 0) { if (i == 0) {
removePref(PreferKey.bgImage) removePref(PreferKey.bgImage)
upTheme(false)
} else { } else {
selectImage(requestCodeBgImage) selectImage(requestCodeBgImage)
} }
@ -203,6 +204,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> selector(items = arrayListOf("删除图片", "选择图片")) { _, i ->
if (i == 0) { if (i == 0) {
removePref(PreferKey.bgImageN) removePref(PreferKey.bgImageN)
upTheme(true)
} else { } else {
selectImage(requestCodeBgImageN) selectImage(requestCodeBgImageN)
} }
@ -262,7 +264,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
} }
} }
private fun setBgFromUri(uri: Uri, preferenceKey: String) { private fun setBgFromUri(uri: Uri, preferenceKey: String, success: () -> Unit) {
if (uri.isContentScheme()) { if (uri.isContentScheme()) {
val doc = DocumentFile.fromSingleUri(requireContext(), uri) val doc = DocumentFile.fromSingleUri(requireContext(), uri)
doc?.name?.let { doc?.name?.let {
@ -273,7 +275,8 @@ class ThemeConfigFragment : BasePreferenceFragment(),
}.getOrNull()?.let { byteArray -> }.getOrNull()?.let { byteArray ->
file.writeBytes(byteArray) file.writeBytes(byteArray)
putPrefString(preferenceKey, file.absolutePath) putPrefString(preferenceKey, file.absolutePath)
upPreferenceSummary(preferenceKey, file.absolutePath)
success()
} ?: toast("获取文件出错") } ?: toast("获取文件出错")
} }
} else { } else {
@ -291,7 +294,8 @@ class ThemeConfigFragment : BasePreferenceFragment(),
file = FileUtils.createFileIfNotExist(file, preferenceKey, imgFile.name) file = FileUtils.createFileIfNotExist(file, preferenceKey, imgFile.name)
file.writeBytes(imgFile.readBytes()) file.writeBytes(imgFile.readBytes())
putPrefString(preferenceKey, file.absolutePath) putPrefString(preferenceKey, file.absolutePath)
upPreferenceSummary(preferenceKey, file.absolutePath)
success()
} }
} }
} }
@ -304,12 +308,16 @@ class ThemeConfigFragment : BasePreferenceFragment(),
when (requestCode) { when (requestCode) {
requestCodeBgImage -> if (resultCode == Activity.RESULT_OK) { requestCodeBgImage -> if (resultCode == Activity.RESULT_OK) {
data?.data?.let { uri -> data?.data?.let { uri ->
setBgFromUri(uri, PreferKey.bgImage) setBgFromUri(uri, PreferKey.bgImage) {
upTheme(false)
}
} }
} }
requestCodeBgImageN -> if (resultCode == Activity.RESULT_OK) { requestCodeBgImageN -> if (resultCode == Activity.RESULT_OK) {
data?.data?.let { uri -> data?.data?.let { uri ->
setBgFromUri(uri, PreferKey.bgImageN) setBgFromUri(uri, PreferKey.bgImageN) {
upTheme(true)
}
} }
} }
} }

@ -86,12 +86,12 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
R.id.menu_add_local -> startActivity<ImportBookActivity>() R.id.menu_add_local -> startActivity<ImportBookActivity>()
R.id.menu_add_url -> addBookByUrl() R.id.menu_add_url -> addBookByUrl()
R.id.menu_arrange_bookshelf -> startActivity<ArrangeBookActivity>( R.id.menu_arrange_bookshelf -> startActivity<ArrangeBookActivity>(
Pair("groupId", selectedGroup.groupId ?: 0), Pair("groupId", selectedGroup.groupId),
Pair("groupName", selectedGroup.groupName ?: 0) Pair("groupName", selectedGroup.groupName)
) )
R.id.menu_download -> startActivity<CacheActivity>( R.id.menu_download -> startActivity<CacheActivity>(
Pair("groupId", selectedGroup.groupId ?: 0), Pair("groupId", selectedGroup.groupId),
Pair("groupName", selectedGroup.groupName ?: 0) Pair("groupName", selectedGroup.groupName)
) )
R.id.menu_export_bookshelf -> { R.id.menu_export_bookshelf -> {
val fragment = fragmentMap[selectedGroup.groupId] val fragment = fragmentMap[selectedGroup.groupId]

Loading…
Cancel
Save