修复分屏模式下状态栏高度始终存在的bug

pull/368/head
gedoor 4 years ago
parent 16e7da2b6a
commit 649c5ef704
  1. 1
      app/build.gradle
  2. 33
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  3. 21
      app/src/main/java/io/legado/app/base/BaseFragment.kt
  4. 3
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  5. 2
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  6. 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:flexbox:1.1.0'
implementation 'com.google.code.gson:gson:2.8.6'
testImplementation "androidx.room:room-testing:2.2.5"
//lifecycle
def lifecycle_version = '2.2.0'

@ -1,6 +1,7 @@
package io.legado.app.base
import android.content.Context
import android.content.res.Configuration
import android.os.Bundle
import android.util.AttributeSet
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.backgroundColor
import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.TitleBar
import io.legado.app.utils.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
@ -23,13 +25,22 @@ import kotlinx.coroutines.cancel
abstract class BaseActivity(
private val layoutID: Int,
private val fullScreen: Boolean = true,
val fullScreen: Boolean = true,
private val theme: Theme = Theme.Auto,
private val toolBarTheme: Theme = Theme.Auto,
private val transparent: Boolean = false
) : AppCompatActivity(),
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) {
super.attachBaseContext(LanguageUtils.setConfiguration(newBase))
}
@ -52,10 +63,28 @@ abstract class BaseActivity(
setupSystemBar()
super.onCreate(savedInstanceState)
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)
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() {
super.onDestroy()
cancel()
@ -120,7 +149,7 @@ abstract class BaseActivity(
}
private fun setupSystemBar() {
if (fullScreen) {
if (fullScreen && !isInMultiWindow) {
window.clearFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION

@ -1,11 +1,14 @@
package io.legado.app.base
import android.annotation.SuppressLint
import android.content.res.Configuration
import android.os.Bundle
import android.view.*
import androidx.appcompat.view.SupportMenuInflater
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import io.legado.app.R
import io.legado.app.ui.widget.TitleBar
import io.legado.app.utils.applyTint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -36,12 +39,30 @@ abstract class BaseFragment(layoutID: Int) : Fragment(layoutID),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
onMultiWindowModeChanged()
onFragmentCreated(view, savedInstanceState)
observeLiveBus()
}
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() {
super.onDestroy()
job.cancel()

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

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

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

Loading…
Cancel
Save