Merge pull request #1 from gedoor/master

Pull Update from owner repo
pull/368/head
SkyNight 4 years ago committed by GitHub
commit 245374237f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/build.gradle
  2. 4
      app/src/main/assets/updateLog.md
  3. 33
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  4. 21
      app/src/main/java/io/legado/app/base/BaseFragment.kt
  5. 3
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  6. 3
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  7. 13
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivityHelp.kt
  8. 6
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  9. 8
      app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt
  10. 20
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  11. 8
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  12. 2
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  13. 4
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt

@ -135,7 +135,6 @@ dependencies {
implementation 'com.google.android.material:material:1.2.1' implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.android:flexbox:1.1.0' implementation 'com.google.android:flexbox:1.1.0'
implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.google.code.gson:gson:2.8.6'
testImplementation "androidx.room:room-testing:2.2.5"
//lifecycle //lifecycle
def lifecycle_version = '2.2.0' def lifecycle_version = '2.2.0'
@ -211,4 +210,3 @@ dependencies {
} }
apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android-extensions'

@ -3,6 +3,10 @@
* 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。
- 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。
**2020/09/08**
* 修复主题导入导出bug
* 优化分屏模式状态栏
**2020/09/08** **2020/09/08**
* 页眉页脚跟随背景 * 页眉页脚跟随背景
* 主题导入导出 * 主题导入导出

@ -1,6 +1,7 @@
package io.legado.app.base package io.legado.app.base
import android.content.Context import android.content.Context
import android.content.res.Configuration
import android.os.Bundle import android.os.Bundle
import android.util.AttributeSet import android.util.AttributeSet
import android.view.Menu import android.view.Menu
@ -15,6 +16,7 @@ import io.legado.app.constant.Theme
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.TitleBar
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope import kotlinx.coroutines.MainScope
@ -23,13 +25,22 @@ import kotlinx.coroutines.cancel
abstract class BaseActivity( abstract class BaseActivity(
private val layoutID: Int, private val layoutID: Int,
private val fullScreen: Boolean = true, val fullScreen: Boolean = true,
private val theme: Theme = Theme.Auto, private val theme: Theme = Theme.Auto,
private val toolBarTheme: Theme = Theme.Auto, private val toolBarTheme: Theme = Theme.Auto,
private val transparent: Boolean = false private val transparent: Boolean = false
) : AppCompatActivity(), ) : AppCompatActivity(),
CoroutineScope by MainScope() { CoroutineScope by MainScope() {
val isInMultiWindow: Boolean
get() {
return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
isInMultiWindowMode
} else {
false
}
}
override fun attachBaseContext(newBase: Context) { override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(LanguageUtils.setConfiguration(newBase)) super.attachBaseContext(LanguageUtils.setConfiguration(newBase))
} }
@ -52,10 +63,28 @@ abstract class BaseActivity(
setupSystemBar() setupSystemBar()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(layoutID) setContentView(layoutID)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
findViewById<TitleBar>(R.id.title_bar)
?.onMultiWindowModeChanged(isInMultiWindowMode, fullScreen)
}
onActivityCreated(savedInstanceState) onActivityCreated(savedInstanceState)
observeLiveBus() observeLiveBus()
} }
override fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean, newConfig: Configuration?) {
super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig)
findViewById<TitleBar>(R.id.title_bar)
?.onMultiWindowModeChanged(isInMultiWindowMode, fullScreen)
setupSystemBar()
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
findViewById<TitleBar>(R.id.title_bar)
?.onMultiWindowModeChanged(isInMultiWindow, fullScreen)
setupSystemBar()
}
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
cancel() cancel()
@ -120,7 +149,7 @@ abstract class BaseActivity(
} }
private fun setupSystemBar() { private fun setupSystemBar() {
if (fullScreen) { if (fullScreen && !isInMultiWindow) {
window.clearFlags( window.clearFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION

@ -1,11 +1,14 @@
package io.legado.app.base package io.legado.app.base
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.res.Configuration
import android.os.Bundle import android.os.Bundle
import android.view.* import android.view.*
import androidx.appcompat.view.SupportMenuInflater import androidx.appcompat.view.SupportMenuInflater
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import io.legado.app.R
import io.legado.app.ui.widget.TitleBar
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -36,12 +39,30 @@ abstract class BaseFragment(layoutID: Int) : Fragment(layoutID),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
onMultiWindowModeChanged()
onFragmentCreated(view, savedInstanceState) onFragmentCreated(view, savedInstanceState)
observeLiveBus() observeLiveBus()
} }
abstract fun onFragmentCreated(view: View, savedInstanceState: Bundle?) abstract fun onFragmentCreated(view: View, savedInstanceState: Bundle?)
override fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean) {
super.onMultiWindowModeChanged(isInMultiWindowMode)
onMultiWindowModeChanged()
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
onMultiWindowModeChanged()
}
private fun onMultiWindowModeChanged() {
(activity as? BaseActivity)?.let {
view?.findViewById<TitleBar>(R.id.title_bar)
?.onMultiWindowModeChanged(it.isInMultiWindow, it.fullScreen)
}
}
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
job.cancel() job.cancel()

@ -32,7 +32,7 @@ data class BookSource(
var enabledExplore: Boolean = true, // 启用发现 var enabledExplore: Boolean = true, // 启用发现
var header: String? = null, // 请求头 var header: String? = null, // 请求头
var loginUrl: String? = null, // 登录地址 var loginUrl: String? = null, // 登录地址
var bookSourceComment: String? = "", // 注释 var bookSourceComment: String? = null, // 注释
var lastUpdateTime: Long = 0, // 最后更新时间,用于排序 var lastUpdateTime: Long = 0, // 最后更新时间,用于排序
var weight: Int = 0, // 智能排序的权重 var weight: Int = 0, // 智能排序的权重
var exploreUrl: String? = null, // 发现url var exploreUrl: String? = null, // 发现url
@ -161,6 +161,7 @@ data class BookSource(
&& equal(bookSourceGroup, source.bookSourceGroup) && equal(bookSourceGroup, source.bookSourceGroup)
&& bookSourceType == source.bookSourceType && bookSourceType == source.bookSourceType
&& equal(bookUrlPattern, source.bookUrlPattern) && equal(bookUrlPattern, source.bookUrlPattern)
&& equal(bookSourceComment, source.bookSourceComment)
&& enabled == source.enabled && enabled == source.enabled
&& enabledExplore == source.enabledExplore && enabledExplore == source.enabledExplore
&& equal(header, source.header) && equal(header, source.header)

@ -125,6 +125,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override fun onConfigurationChanged(newConfig: Configuration) { override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)
page_view.upStatusBar()
ReadBook.loadContent(resetPageOffset = false) ReadBook.loadContent(resetPageOffset = false)
} }
@ -694,7 +695,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
* 更新状态栏,导航栏 * 更新状态栏,导航栏
*/ */
override fun upSystemUiVisibility() { override fun upSystemUiVisibility() {
ReadBookActivityHelp.upSystemUiVisibility(window, !read_menu.isVisible) ReadBookActivityHelp.upSystemUiVisibility(window, isInMultiWindow, !read_menu.isVisible)
upNavigationBarColor() upNavigationBarColor()
} }

@ -32,15 +32,20 @@ import org.jetbrains.anko.layoutInflater
object ReadBookActivityHelp { object ReadBookActivityHelp {
/** /**
* 更新状态栏,导航栏 * 更新状态栏,导航栏
*/ */
fun upSystemUiVisibility(window: Window, toolBarHide: Boolean = true) { fun upSystemUiVisibility(
var flag = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN window: Window,
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE isInMultiWindow: Boolean,
toolBarHide: Boolean = true
) {
var flag = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_IMMERSIVE or View.SYSTEM_UI_FLAG_IMMERSIVE
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
if (!isInMultiWindow) {
flag = flag or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
if (ReadBookConfig.hideNavigationBar) { if (ReadBookConfig.hideNavigationBar) {
flag = flag or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION flag = flag or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
} }

@ -31,7 +31,7 @@ import io.legado.app.lib.dialogs.okButton
import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.lib.theme.getSecondaryTextColor import io.legado.app.lib.theme.getSecondaryTextColor
import io.legado.app.ui.book.read.ReadBookActivityHelp import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.filechooser.FileChooserDialog
import io.legado.app.ui.filechooser.FilePicker import io.legado.app.ui.filechooser.FilePicker
import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.ui.widget.text.AutoCompleteTextView
@ -129,9 +129,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
sw_dark_status_icon.onCheckedChange { buttonView, isChecked -> sw_dark_status_icon.onCheckedChange { buttonView, isChecked ->
if (buttonView?.isPressed == true) { if (buttonView?.isPressed == true) {
setStatusIconDark(isChecked) setStatusIconDark(isChecked)
activity?.window?.let { (activity as? ReadBookActivity)?.upSystemUiVisibility()
ReadBookActivityHelp.upSystemUiVisibility(it)
}
} }
} }
tv_text_color.onClick { tv_text_color.onClick {

@ -10,7 +10,6 @@ import io.legado.app.base.BaseDialogFragment
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.help.ReadTipConfig import io.legado.app.help.ReadTipConfig
import io.legado.app.lib.dialogs.selector import io.legado.app.lib.dialogs.selector
import io.legado.app.ui.book.read.ReadBookActivityHelp
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import kotlinx.android.synthetic.main.dialog_tip_config.* import kotlinx.android.synthetic.main.dialog_tip_config.*
import org.jetbrains.anko.sdk27.listeners.onCheckedChange import org.jetbrains.anko.sdk27.listeners.onCheckedChange
@ -24,11 +23,8 @@ class TipConfigDialog : BaseDialogFragment() {
activity?.let { activity?.let {
it.windowManager?.defaultDisplay?.getMetrics(dm) it.windowManager?.defaultDisplay?.getMetrics(dm)
} }
dialog?.window?.let { dialog?.window
ReadBookActivityHelp.upSystemUiVisibility(it) ?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT)
}
} }
override fun onCreateView( override fun onCreateView(

@ -7,17 +7,16 @@ import android.widget.FrameLayout
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.core.view.isInvisible import androidx.core.view.isInvisible
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.constant.AppConst.timeFormat import io.legado.app.constant.AppConst.timeFormat
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ReadTipConfig import io.legado.app.help.ReadTipConfig
import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.ui.book.read.page.entities.TextPage
import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.ui.widget.BatteryView import io.legado.app.ui.widget.BatteryView
import io.legado.app.utils.dp import io.legado.app.utils.*
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.statusBarHeight
import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.view_book_page.view.* import kotlinx.android.synthetic.main.view_book_page.view.*
import org.jetbrains.anko.topPadding
import java.util.* import java.util.*
@ -65,9 +64,7 @@ class ContentView(context: Context) : FrameLayout(context) {
tv_footer_left.setColor(textColor) tv_footer_left.setColor(textColor)
tv_footer_middle.setColor(textColor) tv_footer_middle.setColor(textColor)
tv_footer_right.setColor(textColor) tv_footer_right.setColor(textColor)
//显示状态栏时隐藏header upStatusBar()
vw_status_bar.setPadding(0, context.statusBarHeight, 0, 0)
vw_status_bar.isGone = hideStatusBar
ll_header.setPadding( ll_header.setPadding(
headerPaddingLeft.dp, headerPaddingLeft.dp,
headerPaddingTop.dp, headerPaddingTop.dp,
@ -88,6 +85,15 @@ class ContentView(context: Context) : FrameLayout(context) {
upBattery(battery) upBattery(battery)
} }
/**
* 显示状态栏时隐藏header
*/
fun upStatusBar() {
vw_status_bar.topPadding = context.statusBarHeight
vw_status_bar.isGone =
ReadBookConfig.hideStatusBar || (activity as? BaseActivity)?.isInMultiWindow == true
}
fun upTipStyle() { fun upTipStyle() {
ReadTipConfig.apply { ReadTipConfig.apply {
tv_header_left.isInvisible = tipHeaderLeft != chapterTitle tv_header_left.isInvisible = tipHeaderLeft != chapterTitle

@ -85,9 +85,9 @@ class PageView(context: Context, attrs: AttributeSet) :
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh) super.onSizeChanged(w, h, oldw, oldh)
centerRectF.set(width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f)
prevPage.x = -w.toFloat() prevPage.x = -w.toFloat()
pageDelegate?.setViewSize(w, h) pageDelegate?.setViewSize(w, h)
centerRectF.set(width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f)
if (oldw != 0 && oldh != 0) { if (oldw != 0 && oldh != 0) {
ReadBook.loadContent(resetPageOffset = false) ReadBook.loadContent(resetPageOffset = false)
} }
@ -180,6 +180,12 @@ class PageView(context: Context, attrs: AttributeSet) :
return true return true
} }
fun upStatusBar() {
curPage.upStatusBar()
prevPage.upStatusBar()
nextPage.upStatusBar()
}
/** /**
* 保存开始位置 * 保存开始位置
*/ */

@ -38,7 +38,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
private var bookshelfReselected: Long = 0 private var bookshelfReselected: Long = 0
private var pagePosition = 0 private var pagePosition = 0
private val fragmentId = arrayOf(0, 1, 2, 3) private val fragmentId = arrayOf(0, 1, 2, 3)
private val fragmentMap = mapOf<Int, Fragment>( private val fragmentMap = mapOf(
Pair(fragmentId[0], BookshelfFragment()), Pair(fragmentId[0], BookshelfFragment()),
Pair(fragmentId[1], ExploreFragment()), Pair(fragmentId[1], ExploreFragment()),
Pair(fragmentId[2], RssFragment()), Pair(fragmentId[2], RssFragment()),

@ -196,6 +196,10 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
backgroundColor = Color.TRANSPARENT backgroundColor = Color.TRANSPARENT
} }
fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean, fullScreen: Boolean) {
topPadding = if (!isInMultiWindowMode && fullScreen) context.statusBarHeight else 0
}
private fun attachToActivity() { private fun attachToActivity() {
if (attachToActivity) { if (attachToActivity) {
activity?.let { activity?.let {

Loading…
Cancel
Save