设置图片背景

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"

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

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

@ -2,11 +2,14 @@ package io.legado.app.help
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import androidx.annotation.Keep
import io.legado.app.App
import io.legado.app.R
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.constant.Theme
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.utils.*
import java.io.File
@ -20,6 +23,16 @@ object ThemeConfig {
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() {
getConfigs()?.let {
it.forEach { config ->
@ -204,7 +217,6 @@ object ThemeConfig {
var primaryColor: String,
var accentColor: String,
var backgroundColor: String,
var backgroundImage: String? = null,
var bottomBackground: String
)

@ -192,6 +192,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
selector(items = arrayListOf("删除图片", "选择图片")) { _, i ->
if (i == 0) {
removePref(PreferKey.bgImage)
upTheme(false)
} else {
selectImage(requestCodeBgImage)
}
@ -203,6 +204,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
selector(items = arrayListOf("删除图片", "选择图片")) { _, i ->
if (i == 0) {
removePref(PreferKey.bgImageN)
upTheme(true)
} else {
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()) {
val doc = DocumentFile.fromSingleUri(requireContext(), uri)
doc?.name?.let {
@ -273,7 +275,8 @@ class ThemeConfigFragment : BasePreferenceFragment(),
}.getOrNull()?.let { byteArray ->
file.writeBytes(byteArray)
putPrefString(preferenceKey, file.absolutePath)
upPreferenceSummary(preferenceKey, file.absolutePath)
success()
} ?: toast("获取文件出错")
}
} else {
@ -291,7 +294,8 @@ class ThemeConfigFragment : BasePreferenceFragment(),
file = FileUtils.createFileIfNotExist(file, preferenceKey, imgFile.name)
file.writeBytes(imgFile.readBytes())
putPrefString(preferenceKey, file.absolutePath)
upPreferenceSummary(preferenceKey, file.absolutePath)
success()
}
}
}
@ -304,12 +308,16 @@ class ThemeConfigFragment : BasePreferenceFragment(),
when (requestCode) {
requestCodeBgImage -> if (resultCode == Activity.RESULT_OK) {
data?.data?.let { uri ->
setBgFromUri(uri, PreferKey.bgImage)
setBgFromUri(uri, PreferKey.bgImage) {
upTheme(false)
}
}
}
requestCodeBgImageN -> if (resultCode == Activity.RESULT_OK) {
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_url -> addBookByUrl()
R.id.menu_arrange_bookshelf -> startActivity<ArrangeBookActivity>(
Pair("groupId", selectedGroup.groupId ?: 0),
Pair("groupName", selectedGroup.groupName ?: 0)
Pair("groupId", selectedGroup.groupId),
Pair("groupName", selectedGroup.groupName)
)
R.id.menu_download -> startActivity<CacheActivity>(
Pair("groupId", selectedGroup.groupId ?: 0),
Pair("groupName", selectedGroup.groupName ?: 0)
Pair("groupId", selectedGroup.groupId),
Pair("groupName", selectedGroup.groupName)
)
R.id.menu_export_bookshelf -> {
val fragment = fragmentMap[selectedGroup.groupId]

Loading…
Cancel
Save