Fixed reader crashing for lower android versions

Gotta love not using Compat
This commit is contained in:
Jays2Kings 2021-04-11 16:10:24 -04:00
parent 05c0c63f4c
commit d651b896ba
5 changed files with 18 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import android.content.ClipData
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.content.res.ColorStateList
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Color import android.graphics.Color
@ -25,6 +26,7 @@ import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils import androidx.core.graphics.ColorUtils
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.GestureDetectorCompat import androidx.core.view.GestureDetectorCompat
import androidx.core.view.ViewCompat
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import com.google.android.material.bottomsheet.BottomSheetBehavior 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.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.GLUtil import eu.kanade.tachiyomi.util.system.GLUtil
import eu.kanade.tachiyomi.util.system.ThemeUtil 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.dpToPx
import eu.kanade.tachiyomi.util.system.getPrefTheme import eu.kanade.tachiyomi.util.system.getPrefTheme
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
@ -212,6 +215,11 @@ class ReaderActivity :
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
systemUiFlag = systemUiFlag.or(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR) 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) { binding.readerLayout.systemUiVisibility = when (lightStatusBar) {
true -> binding.readerLayout.systemUiVisibility.or(systemUiFlag) true -> binding.readerLayout.systemUiVisibility.or(systemUiFlag)
false -> binding.readerLayout.systemUiVisibility.rem(systemUiFlag) false -> binding.readerLayout.systemUiVisibility.rem(systemUiFlag)
@ -595,7 +603,6 @@ class ReaderActivity :
setMenuVisibility(menuVisible) setMenuVisibility(menuVisible)
binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.isHideable = !menuVisible binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.isHideable = !menuVisible
if (!menuVisible) binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.hide() if (!menuVisible) binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.hide()
// val peek = binding.chaptersSheet.chaptersBottomSheet.sheetBehavior?.peekHeight ?: 30.dpToPx
binding.readerLayout.doOnApplyWindowInsets { v, insets, _ -> binding.readerLayout.doOnApplyWindowInsets { v, insets, _ ->
sheetManageNavColor = when { sheetManageNavColor = when {
insets.isBottomTappable() -> { insets.isBottomTappable() -> {
@ -628,6 +635,11 @@ class ReaderActivity :
leftMargin = 12.dpToPx + insets.systemWindowInsetLeft leftMargin = 12.dpToPx + insets.systemWindowInsetLeft
rightMargin = 12.dpToPx + insets.systemWindowInsetRight 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.chaptersSheet.chapterRecycler.updatePaddingRelative(bottom = insets.systemWindowInsetBottom)
binding.viewerContainer.requestLayout() binding.viewerContainer.requestLayout()
} }

View File

@ -19,8 +19,8 @@ import eu.kanade.tachiyomi.databinding.ReaderChaptersSheetBinding
import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.ui.reader.ReaderPresenter import eu.kanade.tachiyomi.ui.reader.ReaderPresenter
import eu.kanade.tachiyomi.ui.reader.settings.TabbedReaderSettingsSheet 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.dpToPx
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.view.collapse import eu.kanade.tachiyomi.util.view.collapse
import eu.kanade.tachiyomi.util.view.expand import eu.kanade.tachiyomi.util.view.expand
@ -53,7 +53,8 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
fun setup(activity: ReaderActivity) { fun setup(activity: ReaderActivity) {
presenter = activity.presenter presenter = activity.presenter
val fullPrimary = activity.getResourceColor(R.attr.colorSecondary) val fullPrimary = activity.contextCompatColor(R.color.secondary_alpha)
val primary = ColorUtils.setAlphaComponent(fullPrimary, 200) val primary = ColorUtils.setAlphaComponent(fullPrimary, 200)
sheetBehavior = BottomSheetBehavior.from(this) sheetBehavior = BottomSheetBehavior.from(this)

View File

@ -2,5 +2,5 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"> android:shape="rectangle">
<corners android:radius="50dp" /> <corners android:radius="50dp" />
<solid android:color="@color/secondary_alpha" /> <solid android:color="?colorSecondary" />
</shape> </shape>

View File

@ -51,8 +51,7 @@
<FrameLayout <FrameLayout
android:id="@+id/app_bar" android:id="@+id/app_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:background="@color/secondary_alpha">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"

View File

@ -6,7 +6,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="300dp" android:layout_height="300dp"
android:background="@drawable/bottom_sheet_rounded_background" android:background="@drawable/bottom_sheet_rounded_background"
android:backgroundTint="@color/secondary_alpha"
android:orientation="vertical" android:orientation="vertical"
app:behavior_peekHeight="60dp" app:behavior_peekHeight="60dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"> app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">