pull/79/head
kunfei 5 years ago
parent ecc6087be7
commit 81c6f449eb
  1. 12
      app/src/main/java/io/legado/app/App.kt
  2. 5
      app/src/main/java/io/legado/app/constant/Theme.kt
  3. 41
      app/src/main/java/io/legado/app/help/AppConfig.kt
  4. 21
      app/src/main/java/io/legado/app/help/PrefExtensions.kt
  5. 14
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  6. 11
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  7. 4
      app/src/main/java/io/legado/app/service/DownloadService.kt
  8. 4
      app/src/main/java/io/legado/app/ui/book/read/Help.kt
  9. 6
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  10. 4
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt
  11. 4
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt
  12. 6
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  13. 16
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@ -15,9 +15,9 @@ import io.legado.app.constant.AppConst.channelIdReadAloud
import io.legado.app.constant.AppConst.channelIdWeb import io.legado.app.constant.AppConst.channelIdWeb
import io.legado.app.data.AppDatabase import io.legado.app.data.AppDatabase
import io.legado.app.help.ActivityHelp import io.legado.app.help.ActivityHelp
import io.legado.app.help.AppConfig
import io.legado.app.help.CrashHandler import io.legado.app.help.CrashHandler
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.help.isNightTheme
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.ChapterProvider
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
@ -50,7 +50,7 @@ class App : Application() {
} }
if (!ThemeStore.isConfigured(this, versionCode)) applyTheme() if (!ThemeStore.isConfigured(this, versionCode)) applyTheme()
initNightTheme() initNightMode()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) createChannelId() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) createChannelId()
@ -67,7 +67,7 @@ class App : Application() {
* 更新主题 * 更新主题
*/ */
fun applyTheme() { fun applyTheme() {
if (isNightTheme) { if (AppConfig.isNightTheme) {
ThemeStore.editTheme(this) ThemeStore.editTheme(this)
.primaryColor( .primaryColor(
getPrefInt("colorPrimaryNight", getCompatColor(R.color.shine_color)) getPrefInt("colorPrimaryNight", getCompatColor(R.color.shine_color))
@ -98,11 +98,11 @@ class App : Application() {
fun applyDayNight() { fun applyDayNight() {
ReadBookConfig.upBg() ReadBookConfig.upBg()
applyTheme() applyTheme()
initNightTheme() initNightMode()
} }
private fun initNightTheme() { private fun initNightMode() {
val targetMode = if (isNightTheme) { val targetMode = if (AppConfig.isNightTheme) {
AppCompatDelegate.MODE_NIGHT_YES AppCompatDelegate.MODE_NIGHT_YES
} else { } else {
AppCompatDelegate.MODE_NIGHT_NO AppCompatDelegate.MODE_NIGHT_NO

@ -1,14 +1,13 @@
package io.legado.app.constant package io.legado.app.constant
import io.legado.app.App import io.legado.app.help.AppConfig
import io.legado.app.help.isNightTheme
enum class Theme { enum class Theme {
Dark, Light, Auto; Dark, Light, Auto;
companion object { companion object {
fun getTheme(): Theme { fun getTheme(): Theme {
return if (App.INSTANCE.isNightTheme) { return if (AppConfig.isNightTheme) {
Dark Dark
} else Light } else Light
} }

@ -0,0 +1,41 @@
package io.legado.app.help
import io.legado.app.App
import io.legado.app.constant.PreferKey
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.putPrefBoolean
import io.legado.app.utils.putPrefInt
object AppConfig {
var isNightTheme: Boolean
get() = App.INSTANCE.getPrefBoolean("isNightTheme")
set(value) {
App.INSTANCE.putPrefBoolean("isNightTheme", value)
}
var isTransparentStatusBar: Boolean
get() = App.INSTANCE.getPrefBoolean("transparentStatusBar")
set(value) {
App.INSTANCE.putPrefBoolean("transparentStatusBar", value)
}
var isShowRSS: Boolean
get() = App.INSTANCE.getPrefBoolean(PreferKey.showRss)
set(value) {
App.INSTANCE.putPrefBoolean(PreferKey.showRss, value)
}
var threadCount: Int
get() = App.INSTANCE.getPrefInt(PreferKey.threadCount)
set(value) {
App.INSTANCE.putPrefInt(PreferKey.threadCount, value)
}
var autoDarkMode: Boolean
get() = App.INSTANCE.getPrefBoolean(PreferKey.autoDarkMode)
set(value) {
App.INSTANCE.putPrefBoolean(PreferKey.autoDarkMode, value)
}
}

@ -1,21 +0,0 @@
package io.legado.app.help
import android.content.Context
import io.legado.app.constant.PreferKey
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefInt
val Context.isNightTheme: Boolean
get() = getPrefBoolean("isNightTheme")
val Context.isTransparentStatusBar: Boolean
get() = getPrefBoolean("transparentStatusBar", true)
val Context.isShowRSS: Boolean
get() = getPrefBoolean(PreferKey.showRss, true)
val Context.threadCount: Int
get() = getPrefInt(PreferKey.threadCount, 16)
val Context.autoDarkMode: Boolean
get() = getPrefBoolean(PreferKey.autoDarkMode, true)

@ -111,7 +111,7 @@ object ReadBookConfig {
var textSize: Int = 15 var textSize: Int = 15
) { ) {
fun setBg(bgType: Int, bg: String) { fun setBg(bgType: Int, bg: String) {
if (App.INSTANCE.isNightTheme) { if (AppConfig.isNightTheme) {
bgTypeNight = bgType bgTypeNight = bgType
bgStrNight = bg bgStrNight = bg
} else { } else {
@ -121,7 +121,7 @@ object ReadBookConfig {
} }
fun setTextColor(color: Int) { fun setTextColor(color: Int) {
if (App.INSTANCE.isNightTheme) { if (AppConfig.isNightTheme) {
textColorNight = "#${color.hexString}" textColorNight = "#${color.hexString}"
} else { } else {
textColor = "#${color.hexString}" textColor = "#${color.hexString}"
@ -129,7 +129,7 @@ object ReadBookConfig {
} }
fun setStatusIconDark(isDark: Boolean) { fun setStatusIconDark(isDark: Boolean) {
if (App.INSTANCE.isNightTheme) { if (AppConfig.isNightTheme) {
darkStatusIconNight = isDark darkStatusIconNight = isDark
} else { } else {
darkStatusIcon = isDark darkStatusIcon = isDark
@ -137,7 +137,7 @@ object ReadBookConfig {
} }
fun statusIconDark(): Boolean { fun statusIconDark(): Boolean {
return if (App.INSTANCE.isNightTheme) { return if (AppConfig.isNightTheme) {
darkStatusIconNight darkStatusIconNight
} else { } else {
darkStatusIcon darkStatusIcon
@ -145,17 +145,17 @@ object ReadBookConfig {
} }
fun textColor(): Int { fun textColor(): Int {
return if (App.INSTANCE.isNightTheme) Color.parseColor(textColorNight) return if (AppConfig.isNightTheme) Color.parseColor(textColorNight)
else Color.parseColor(textColor) else Color.parseColor(textColor)
} }
fun bgStr(): String { fun bgStr(): String {
return if (App.INSTANCE.isNightTheme) bgStrNight return if (AppConfig.isNightTheme) bgStrNight
else bgStr else bgStr
} }
fun bgType(): Int { fun bgType(): Int {
return if (App.INSTANCE.isNightTheme) bgTypeNight return if (AppConfig.isNightTheme) bgTypeNight
else bgType else bgType
} }

@ -16,8 +16,7 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
import io.legado.app.R import io.legado.app.R
import io.legado.app.help.isNightTheme import io.legado.app.help.AppConfig
import io.legado.app.help.isTransparentStatusBar
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import kotlinx.android.synthetic.main.activity_main.view.* import kotlinx.android.synthetic.main.activity_main.view.*
import org.jetbrains.anko.backgroundColor import org.jetbrains.anko.backgroundColor
@ -37,7 +36,7 @@ object ATH {
} }
fun setStatusBarColorAuto(activity: Activity, fullScreen: Boolean) { fun setStatusBarColorAuto(activity: Activity, fullScreen: Boolean) {
val isTransparentStatusBar = activity.isTransparentStatusBar val isTransparentStatusBar = AppConfig.isTransparentStatusBar
setStatusBarColor( setStatusBarColor(
activity, activity,
ThemeStore.statusBarColor(activity, isTransparentStatusBar), ThemeStore.statusBarColor(activity, isTransparentStatusBar),
@ -131,14 +130,14 @@ object ATH {
fun setTint( fun setTint(
view: View, view: View,
@ColorInt color: Int, @ColorInt color: Int,
isDark: Boolean = view.context.isNightTheme isDark: Boolean = AppConfig.isNightTheme
) { ) {
TintHelper.setTintAuto(view, color, false, isDark) TintHelper.setTintAuto(view, color, false, isDark)
} }
fun setBackgroundTint( fun setBackgroundTint(
view: View, @ColorInt color: Int, view: View, @ColorInt color: Int,
isDark: Boolean = view.context.isNightTheme isDark: Boolean = AppConfig.isNightTheme
) { ) {
TintHelper.setTintAuto(view, color, true, isDark) TintHelper.setTintAuto(view, color, true, isDark)
} }
@ -206,7 +205,7 @@ object ATH {
.setSelectedColor(ThemeStore.accentColor(bottom_navigation_view.context)).create() .setSelectedColor(ThemeStore.accentColor(bottom_navigation_view.context)).create()
itemIconTintList = colorStateList itemIconTintList = colorStateList
itemTextColor = colorStateList itemTextColor = colorStateList
itemBackgroundResource = when(context.isNightTheme) { itemBackgroundResource = when (AppConfig.isNightTheme) {
true -> R.drawable.item_bg_dark true -> R.drawable.item_bg_dark
false -> R.drawable.item_bg_light false -> R.drawable.item_bg_light
} }

@ -9,10 +9,10 @@ import io.legado.app.base.BaseService
import io.legado.app.constant.Action import io.legado.app.constant.Action
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.IntentHelp import io.legado.app.help.IntentHelp
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.threadCount
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -21,7 +21,7 @@ import java.util.concurrent.Executors
class DownloadService : BaseService() { class DownloadService : BaseService() {
private var searchPool = private var searchPool =
Executors.newFixedThreadPool(App.INSTANCE.threadCount).asCoroutineDispatcher() Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher()
private var tasks: ArrayList<Coroutine<*>> = arrayListOf() private var tasks: ArrayList<Coroutine<*>> = arrayListOf()
private val handler = Handler() private val handler = Handler()
private var runnable: Runnable = Runnable { upDownload() } private var runnable: Runnable = Runnable { upDownload() }

@ -9,8 +9,8 @@ import android.view.Window
import android.view.WindowManager import android.view.WindowManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.help.isTransparentStatusBar
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.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
@ -43,7 +43,7 @@ object Help {
} else { } else {
ATH.setLightStatusBarAuto( ATH.setLightStatusBarAuto(
activity, activity,
ThemeStore.statusBarColor(activity, activity.isTransparentStatusBar) ThemeStore.statusBarColor(activity, AppConfig.isTransparentStatusBar)
) )
} }
} }

@ -11,7 +11,7 @@ import androidx.core.view.isVisible
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.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.isNightTheme import io.legado.app.help.AppConfig
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.buttonDisabledColor import io.legado.app.lib.theme.buttonDisabledColor
import io.legado.app.service.help.ReadBook import io.legado.app.service.help.ReadBook
@ -42,7 +42,7 @@ class ReadMenu : FrameLayout {
init { init {
callBack = activity as? CallBack callBack = activity as? CallBack
inflate(context, R.layout.view_read_menu, this) inflate(context, R.layout.view_read_menu, this)
if (context.isNightTheme) { if (AppConfig.isNightTheme) {
fabNightTheme.setImageResource(R.drawable.ic_daytime) fabNightTheme.setImageResource(R.drawable.ic_daytime)
} else { } else {
fabNightTheme.setImageResource(R.drawable.ic_brightness) fabNightTheme.setImageResource(R.drawable.ic_brightness)
@ -145,7 +145,7 @@ class ReadMenu : FrameLayout {
//夜间模式 //夜间模式
fabNightTheme.onClick { fabNightTheme.onClick {
context.putPrefBoolean("isNightTheme", !context.isNightTheme) context.putPrefBoolean("isNightTheme", !AppConfig.isNightTheme)
App.INSTANCE.applyDayNight() App.INSTANCE.applyDayNight()
} }

@ -6,8 +6,8 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.data.entities.SearchKeyword import io.legado.app.data.entities.SearchKeyword
import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.threadCount
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
@ -18,7 +18,7 @@ import java.util.concurrent.Executors
class SearchViewModel(application: Application) : BaseViewModel(application) { class SearchViewModel(application: Application) : BaseViewModel(application) {
private var searchPool = private var searchPool =
Executors.newFixedThreadPool(context.threadCount).asCoroutineDispatcher() Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher()
private var task: Coroutine<*>? = null private var task: Coroutine<*>? = null
var callBack: CallBack? = null var callBack: CallBack? = null
var searchKey: String = "" var searchKey: String = ""

@ -8,8 +8,8 @@ import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.threadCount
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
@ -20,7 +20,7 @@ import java.util.concurrent.Executors
class ChangeSourceViewModel(application: Application) : BaseViewModel(application) { class ChangeSourceViewModel(application: Application) : BaseViewModel(application) {
private var searchPool = private var searchPool =
Executors.newFixedThreadPool(context.threadCount).asCoroutineDispatcher() Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher()
var callBack: CallBack? = null var callBack: CallBack? = null
val searchStateData = MutableLiveData<Boolean>() val searchStateData = MutableLiveData<Boolean>()
var name: String = "" var name: String = ""

@ -12,8 +12,8 @@ import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.threadCount
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.receiver.SharedReceiverActivity import io.legado.app.receiver.SharedReceiverActivity
import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.filechooser.FileChooserDialog
@ -61,7 +61,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(),
.setTitle(getString(R.string.threads_num_title)) .setTitle(getString(R.string.threads_num_title))
.setMaxValue(999) .setMaxValue(999)
.setMinValue(1) .setMinValue(1)
.setValue(requireContext().threadCount) .setValue(AppConfig.threadCount)
.show { .show {
requireContext().putPrefInt(PreferKey.threadCount, it) requireContext().putPrefInt(PreferKey.threadCount, it)
findPreference<Preference>(PreferKey.threadCount)?.summary = findPreference<Preference>(PreferKey.threadCount)?.summary =
@ -125,7 +125,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(),
PreferKey.downloadPath -> getPrefString(PreferKey.downloadPath) PreferKey.downloadPath -> getPrefString(PreferKey.downloadPath)
?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath
?: App.INSTANCE.cacheDir.absolutePath ?: App.INSTANCE.cacheDir.absolutePath
PreferKey.threadCount -> requireContext().threadCount PreferKey.threadCount -> AppConfig.threadCount
else -> getPrefString(key) ?: "" else -> getPrefString(key) ?: ""
} }
} }

@ -16,8 +16,8 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.isShowRSS
import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Backup
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
@ -47,7 +47,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
view_pager_main.adapter = TabFragmentPageAdapter(supportFragmentManager) view_pager_main.adapter = TabFragmentPageAdapter(supportFragmentManager)
view_pager_main.addOnPageChangeListener(this) view_pager_main.addOnPageChangeListener(this)
bottom_navigation_view.setOnNavigationItemSelectedListener(this) bottom_navigation_view.setOnNavigationItemSelectedListener(this)
bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = isShowRSS bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS
upVersion() upVersion()
} }
@ -68,10 +68,10 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
fragmentList.add(RssFragment()) fragmentList.add(RssFragment())
fragmentList.add(MyFragment()) fragmentList.add(MyFragment())
} }
if (isShowRSS && fragmentList.size < 4) { if (AppConfig.isShowRSS && fragmentList.size < 4) {
fragmentList.add(2, RssFragment()) fragmentList.add(2, RssFragment())
} }
if (!isShowRSS && fragmentList.size == 4) { if (!AppConfig.isShowRSS && fragmentList.size == 4) {
fragmentList.removeAt(2) fragmentList.removeAt(2)
} }
} }
@ -89,7 +89,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
pagePosition = position pagePosition = position
when (position) { when (position) {
0, 1, 3 -> bottom_navigation_view.menu.getItem(position).isChecked = true 0, 1, 3 -> bottom_navigation_view.menu.getItem(position).isChecked = true
2 -> if (isShowRSS) { 2 -> if (AppConfig.isShowRSS) {
bottom_navigation_view.menu.getItem(position).isChecked = true bottom_navigation_view.menu.getItem(position).isChecked = true
} else { } else {
bottom_navigation_view.menu.getItem(3).isChecked = true bottom_navigation_view.menu.getItem(3).isChecked = true
@ -147,10 +147,10 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
recreate() recreate()
} }
observeEvent<String>(Bus.SHOW_RSS) { observeEvent<String>(Bus.SHOW_RSS) {
bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = isShowRSS bottom_navigation_view.menu.findItem(R.id.menu_rss).isVisible = AppConfig.isShowRSS
upFragmentList() upFragmentList()
view_pager_main.adapter?.notifyDataSetChanged() view_pager_main.adapter?.notifyDataSetChanged()
if (isShowRSS) { if (AppConfig.isShowRSS) {
view_pager_main.setCurrentItem(3, false) view_pager_main.setCurrentItem(3, false)
} }
} }
@ -168,7 +168,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
} }
override fun getCount(): Int { override fun getCount(): Int {
return if (isShowRSS) 4 else 3 return if (AppConfig.isShowRSS) 4 else 3
} }
} }

Loading…
Cancel
Save