From 649c5ef7046fba378899d8a178c285d04bd418fe Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 10:32:37 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=86=E5=B1=8F?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8B=E7=8A=B6=E6=80=81=E6=A0=8F=E9=AB=98?= =?UTF-8?q?=E5=BA=A6=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 { From 022c1e29b7f11560f6fc1a89fcbf97d285f35366 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 10:35:06 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4367e9856..43a086553 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -209,5 +209,4 @@ dependencies { //implementation 'fadeapp.widgets:scrollless-recyclerView:1.0.2' } -apply plugin: 'com.google.gms.google-services' -apply plugin: 'kotlin-android-extensions' \ No newline at end of file +apply plugin: 'com.google.gms.google-services' \ No newline at end of file From 7225449c41cf652400104c235c39e27a1bfbdb67 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 11:14:27 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=86=E5=B1=8F?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/ReadBookActivity.kt | 1 + .../ui/book/read/config/TipConfigDialog.kt | 8 ++------ .../app/ui/book/read/page/ContentView.kt | 20 ++++++++++++------- .../legado/app/ui/book/read/page/PageView.kt | 8 +++++++- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index fe21c3b40..22cf977c3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -125,6 +125,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) + page_view.upStatusBar() ReadBook.loadContent(resetPageOffset = false) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt index 325279977..583afb4d4 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt @@ -10,7 +10,6 @@ import io.legado.app.base.BaseDialogFragment import io.legado.app.constant.EventBus import io.legado.app.help.ReadTipConfig import io.legado.app.lib.dialogs.selector -import io.legado.app.ui.book.read.ReadBookActivityHelp import io.legado.app.utils.postEvent import kotlinx.android.synthetic.main.dialog_tip_config.* import org.jetbrains.anko.sdk27.listeners.onCheckedChange @@ -24,11 +23,8 @@ class TipConfigDialog : BaseDialogFragment() { activity?.let { it.windowManager?.defaultDisplay?.getMetrics(dm) } - dialog?.window?.let { - ReadBookActivityHelp.upSystemUiVisibility(it) - it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT) - } + dialog?.window + ?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) } override fun onCreateView( diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index 66333c901..e89ee5ae8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -7,17 +7,16 @@ import android.widget.FrameLayout import androidx.core.view.isGone import androidx.core.view.isInvisible import io.legado.app.R +import io.legado.app.base.BaseActivity import io.legado.app.constant.AppConst.timeFormat import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadTipConfig 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.widget.BatteryView -import io.legado.app.utils.dp -import io.legado.app.utils.getCompatColor -import io.legado.app.utils.statusBarHeight -import io.legado.app.utils.visible +import io.legado.app.utils.* import kotlinx.android.synthetic.main.view_book_page.view.* +import org.jetbrains.anko.topPadding import java.util.* @@ -65,9 +64,7 @@ class ContentView(context: Context) : FrameLayout(context) { tv_footer_left.setColor(textColor) tv_footer_middle.setColor(textColor) tv_footer_right.setColor(textColor) - //显示状态栏时隐藏header - vw_status_bar.setPadding(0, context.statusBarHeight, 0, 0) - vw_status_bar.isGone = hideStatusBar + upStatusBar() ll_header.setPadding( headerPaddingLeft.dp, headerPaddingTop.dp, @@ -88,6 +85,15 @@ class ContentView(context: Context) : FrameLayout(context) { upBattery(battery) } + /** + * 显示状态栏时隐藏header + */ + fun upStatusBar() { + vw_status_bar.topPadding = context.statusBarHeight + vw_status_bar.isGone = + ReadBookConfig.hideStatusBar || (activity as? BaseActivity)?.isInMultiWindow == true + } + fun upTipStyle() { ReadTipConfig.apply { tv_header_left.isInvisible = tipHeaderLeft != chapterTitle diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index b2871d38c..3d4d6e266 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -85,9 +85,9 @@ class PageView(context: Context, attrs: AttributeSet) : override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { super.onSizeChanged(w, h, oldw, oldh) + centerRectF.set(width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f) prevPage.x = -w.toFloat() pageDelegate?.setViewSize(w, h) - centerRectF.set(width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f) if (oldw != 0 && oldh != 0) { ReadBook.loadContent(resetPageOffset = false) } @@ -180,6 +180,12 @@ class PageView(context: Context, attrs: AttributeSet) : return true } + fun upStatusBar() { + curPage.upStatusBar() + prevPage.upStatusBar() + nextPage.upStatusBar() + } + /** * 保存开始位置 */ From e9261424c98be9212e4290ecb7207486d5bd0ced Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 11:28:02 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=86=E5=B1=8F?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/ReadBookActivity.kt | 2 +- .../legado/app/ui/book/read/ReadBookActivityHelp.kt | 13 +++++++++---- .../app/ui/book/read/config/BgTextConfigDialog.kt | 6 ++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 22cf977c3..7840123db 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -695,7 +695,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo * 更新状态栏,导航栏 */ override fun upSystemUiVisibility() { - ReadBookActivityHelp.upSystemUiVisibility(window, !read_menu.isVisible) + ReadBookActivityHelp.upSystemUiVisibility(window, isInMultiWindow, !read_menu.isVisible) upNavigationBarColor() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivityHelp.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivityHelp.kt index 558975cba..5360e08e6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivityHelp.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivityHelp.kt @@ -32,15 +32,20 @@ import org.jetbrains.anko.layoutInflater object ReadBookActivityHelp { - /** * 更新状态栏,导航栏 */ - fun upSystemUiVisibility(window: Window, toolBarHide: Boolean = true) { - var flag = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - or View.SYSTEM_UI_FLAG_LAYOUT_STABLE + fun upSystemUiVisibility( + window: Window, + 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_STICKY) + if (!isInMultiWindow) { + flag = flag or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + } if (ReadBookConfig.hideNavigationBar) { flag = flag or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index f785d522c..12ead916b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -31,7 +31,7 @@ import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.getPrimaryTextColor 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.FilePicker import io.legado.app.ui.widget.text.AutoCompleteTextView @@ -129,9 +129,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { sw_dark_status_icon.onCheckedChange { buttonView, isChecked -> if (buttonView?.isPressed == true) { setStatusIconDark(isChecked) - activity?.window?.let { - ReadBookActivityHelp.upSystemUiVisibility(it) - } + (activity as? ReadBookActivity)?.upSystemUiVisibility() } } tv_text_color.onClick { From af603073b7c063ad7084f1256c446c3085e59b95 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 11:29:25 +0800 Subject: [PATCH 5/5] update log --- app/src/main/assets/updateLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index a279010b1..274df8675 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,10 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 - 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/09/08** +* 修复主题导入导出bug +* 优化分屏模式状态栏 + **2020/09/08** * 页眉页脚跟随背景 * 主题导入导出