From d651b896ba45caba02796099ba66fbf02b561e8c Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sun, 11 Apr 2021 16:10:24 -0400 Subject: [PATCH] Fixed reader crashing for lower android versions Gotta love not using Compat --- .../kanade/tachiyomi/ui/reader/ReaderActivity.kt | 14 +++++++++++++- .../ui/reader/chapter/ReaderChapterSheet.kt | 5 +++-- app/src/main/res/drawable/chapter_nav.xml | 2 +- app/src/main/res/layout/reader_activity.xml | 3 +-- app/src/main/res/layout/reader_chapters_sheet.xml | 1 - 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 8e08b4a9a7..50d763c85a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -5,6 +5,7 @@ import android.content.ClipData import android.content.Context import android.content.Intent import android.content.pm.ActivityInfo +import android.content.res.ColorStateList import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.Color @@ -25,6 +26,7 @@ import androidx.core.content.ContextCompat import androidx.core.graphics.ColorUtils import androidx.core.view.isVisible import androidx.core.view.GestureDetectorCompat +import androidx.core.view.ViewCompat import com.afollestad.materialdialogs.MaterialDialog import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -57,6 +59,7 @@ import eu.kanade.tachiyomi.ui.webview.WebViewActivity import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.system.GLUtil import eu.kanade.tachiyomi.util.system.ThemeUtil +import eu.kanade.tachiyomi.util.system.contextCompatColor import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.getPrefTheme import eu.kanade.tachiyomi.util.system.getResourceColor @@ -212,6 +215,11 @@ class ReaderActivity : if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { systemUiFlag = systemUiFlag.or(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR) } + binding.appBar.setBackgroundColor(contextCompatColor(R.color.secondary_alpha)) + ViewCompat.setBackgroundTintList( + binding.readerNav.root, + ColorStateList.valueOf(contextCompatColor(R.color.secondary_alpha)) + ) binding.readerLayout.systemUiVisibility = when (lightStatusBar) { true -> binding.readerLayout.systemUiVisibility.or(systemUiFlag) false -> binding.readerLayout.systemUiVisibility.rem(systemUiFlag) @@ -595,7 +603,6 @@ class ReaderActivity : setMenuVisibility(menuVisible) binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.isHideable = !menuVisible if (!menuVisible) binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.hide() - // val peek = binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.peekHeight ?: 30.dpToPx binding.readerLayout.doOnApplyWindowInsets { v, insets, _ -> sheetManageNavColor = when { insets.isBottomTappable() -> { @@ -628,6 +635,11 @@ class ReaderActivity : leftMargin = 12.dpToPx + insets.systemWindowInsetLeft rightMargin = 12.dpToPx + insets.systemWindowInsetRight } + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + val peek = 50.dpToPx + binding.chaptersSheet.root.sheetBehavior?.peekHeight = + peek + insets.systemWindowInsetBottom + } binding.chaptersSheet.chapterRecycler.updatePaddingRelative(bottom = insets.systemWindowInsetBottom) binding.viewerContainer.requestLayout() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt index d8ed9185c6..0c1c99d88f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt @@ -19,8 +19,8 @@ import eu.kanade.tachiyomi.databinding.ReaderChaptersSheetBinding import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.ReaderPresenter import eu.kanade.tachiyomi.ui.reader.settings.TabbedReaderSettingsSheet +import eu.kanade.tachiyomi.util.system.contextCompatColor import eu.kanade.tachiyomi.util.system.dpToPx -import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.view.collapse import eu.kanade.tachiyomi.util.view.expand @@ -53,7 +53,8 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr fun setup(activity: ReaderActivity) { presenter = activity.presenter - val fullPrimary = activity.getResourceColor(R.attr.colorSecondary) + val fullPrimary = activity.contextCompatColor(R.color.secondary_alpha) + val primary = ColorUtils.setAlphaComponent(fullPrimary, 200) sheetBehavior = BottomSheetBehavior.from(this) diff --git a/app/src/main/res/drawable/chapter_nav.xml b/app/src/main/res/drawable/chapter_nav.xml index 05f82d7418..4a36479599 100644 --- a/app/src/main/res/drawable/chapter_nav.xml +++ b/app/src/main/res/drawable/chapter_nav.xml @@ -2,5 +2,5 @@ - + \ No newline at end of file diff --git a/app/src/main/res/layout/reader_activity.xml b/app/src/main/res/layout/reader_activity.xml index 0713bc5c62..752a04d3b0 100644 --- a/app/src/main/res/layout/reader_activity.xml +++ b/app/src/main/res/layout/reader_activity.xml @@ -51,8 +51,7 @@ + android:layout_height="wrap_content">