From 649c5ef7046fba378899d8a178c285d04bd418fe Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 10:32:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=86=E5=B1=8F=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E7=8A=B6=E6=80=81=E6=A0=8F=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E5=A7=8B=E7=BB=88=E5=AD=98=E5=9C=A8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 1 - .../java/io/legado/app/base/BaseActivity.kt | 33 +++++++++++++++++-- .../java/io/legado/app/base/BaseFragment.kt | 21 ++++++++++++ .../io/legado/app/data/entities/BookSource.kt | 3 +- .../io/legado/app/ui/main/MainActivity.kt | 2 +- .../java/io/legado/app/ui/widget/TitleBar.kt | 4 +++ 6 files changed, 59 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6d2ad3726..4367e9856 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/src/main/java/io/legado/app/base/BaseActivity.kt b/app/src/main/java/io/legado/app/base/BaseActivity.kt index 3ca496783..745813403 100644 --- a/app/src/main/java/io/legado/app/base/BaseActivity.kt +++ b/app/src/main/java/io/legado/app/base/BaseActivity.kt @@ -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(R.id.title_bar) + ?.onMultiWindowModeChanged(isInMultiWindowMode, fullScreen) + } onActivityCreated(savedInstanceState) observeLiveBus() } + override fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean, newConfig: Configuration?) { + super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig) + findViewById(R.id.title_bar) + ?.onMultiWindowModeChanged(isInMultiWindowMode, fullScreen) + setupSystemBar() + } + + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + findViewById(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 diff --git a/app/src/main/java/io/legado/app/base/BaseFragment.kt b/app/src/main/java/io/legado/app/base/BaseFragment.kt index c19033aa8..155bb6076 100644 --- a/app/src/main/java/io/legado/app/base/BaseFragment.kt +++ b/app/src/main/java/io/legado/app/base/BaseFragment.kt @@ -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(R.id.title_bar) + ?.onMultiWindowModeChanged(it.isInMultiWindow, it.fullScreen) + } + } + override fun onDestroy() { super.onDestroy() job.cancel() diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 9248a0a71..68a23b636 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 7d6c71134..934bb56f8 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -38,7 +38,7 @@ class MainActivity : VMBaseActivity(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( + private val fragmentMap = mapOf( Pair(fragmentId[0], BookshelfFragment()), Pair(fragmentId[1], ExploreFragment()), Pair(fragmentId[2], RssFragment()), diff --git a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt index 3b9d28757..39e1cd441 100644 --- a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt @@ -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 {