From fde6506842ee60222d8202867477703cf2b18a22 Mon Sep 17 00:00:00 2001
From: Jay <jays2kings@gmail.com>
Date: Tue, 24 Mar 2020 00:05:04 -0400
Subject: [PATCH] Fixes to swiping chapters

Fixes also to the bottom sheets
---
 .../catalogue/browse/CatalogueSearchSheet.kt  |  7 +--
 .../ui/library/DisplayBottomSheet.kt          |  5 +-
 .../kanade/tachiyomi/ui/main/MainActivity.kt  | 63 ++++++++++---------
 .../tachiyomi/ui/manga/MangaDetailsAdapter.kt |  2 +-
 .../ui/manga/MangaDetailsController.kt        |  7 +--
 .../ui/manga/MangaDetailsPresenter.kt         | 10 ++-
 .../tachiyomi/ui/manga/MangaHeaderHolder.kt   |  2 +-
 .../ui/manga/chapter/ChapterHolder.kt         | 19 +-----
 .../manga/chapter/ChaptersSortBottomSheet.kt  |  5 +-
 .../ui/manga/track/TrackingBottomSheet.kt     |  2 +-
 .../design/MigrationBottomSheetDialog.kt      |  5 +-
 .../ui/reader/ReaderColorFilterSheet.kt       |  2 +-
 .../tachiyomi/ui/reader/ReaderPageSheet.kt    |  2 +-
 .../ui/reader/ReaderSettingsSheet.kt          |  5 +-
 .../tachiyomi/util/view/ViewExtensions.kt     | 48 +++++---------
 .../res/layout/migration_bottom_sheet.xml     |  1 -
 app/src/main/res/values/styles.xml            |  5 --
 17 files changed, 76 insertions(+), 114 deletions(-)

diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueSearchSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueSearchSheet.kt
index 3a946a1deb..7cf208c26a 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueSearchSheet.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/CatalogueSearchSheet.kt
@@ -20,7 +20,7 @@ import kotlinx.android.synthetic.main.catalogue_drawer_content.*
 import uy.kohesive.injekt.injectLazy
 
 class CatalogueSearchSheet(activity: Activity) :
-    BottomSheetDialog(activity, R.style.BottomSheetDialogThemeCovered) {
+    BottomSheetDialog(activity, R.style.BottomSheetDialogTheme) {
 
     /**
      * Preferences helper.
@@ -61,11 +61,8 @@ class CatalogueSearchSheet(activity: Activity) :
         sheetBehavior.skipCollapsed = true
         sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
         setEdgeToEdge(
-            activity, recycler, view, 50.dpToPx
+            activity, view, 50.dpToPx
         )
-        //        window?.findViewById<View>(com.google.android.material.R.id.container)?.fitsSystemWindows =
-        //            false
-        window?.navigationBarColor = activity.window.navigationBarColor
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && preferences.readerTheme()
                 .getOrDefault() == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0
         ) window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt
index fd8b923bb1..220a639ffb 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt
@@ -20,7 +20,7 @@ import kotlinx.android.synthetic.main.display_bottom_sheet.*
 import uy.kohesive.injekt.injectLazy
 
 class DisplayBottomSheet(private val controller: LibraryController) : BottomSheetDialog
-    (controller.activity!!, R.style.BottomSheetDialogThemeCovered) {
+    (controller.activity!!, R.style.BottomSheetDialogTheme) {
 
     val activity = controller.activity!!
 
@@ -37,10 +37,9 @@ class DisplayBottomSheet(private val controller: LibraryController) : BottomShee
         setContentView(view)
 
         sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup)
-        setEdgeToEdge(activity, bottom_sheet, view)
+        setEdgeToEdge(activity, view)
         val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
         sheetBehavior.peekHeight = 220.dpToPx + height
-        window?.navigationBarColor = activity.window.navigationBarColor
 
         sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
             override fun onSlide(bottomSheet: View, progress: Float) { }
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
index c98b98b9dc..12b036c895 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
@@ -5,7 +5,6 @@ import android.animation.AnimatorSet
 import android.animation.ValueAnimator
 import android.app.SearchManager
 import android.content.Intent
-import android.content.res.Configuration
 import android.graphics.Color
 import android.graphics.Rect
 import android.graphics.drawable.Drawable
@@ -17,6 +16,7 @@ import android.view.MenuItem
 import android.view.MotionEvent
 import android.view.View
 import android.view.ViewGroup
+import android.view.WindowInsets
 import android.view.WindowManager
 import android.webkit.WebView
 import androidx.appcompat.content.res.AppCompatResources
@@ -59,6 +59,7 @@ import eu.kanade.tachiyomi.ui.setting.SettingsController
 import eu.kanade.tachiyomi.ui.setting.SettingsMainController
 import eu.kanade.tachiyomi.util.system.getResourceColor
 import eu.kanade.tachiyomi.util.system.launchUI
+import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets
 import eu.kanade.tachiyomi.util.view.updateLayoutParams
 import eu.kanade.tachiyomi.util.view.updatePadding
 import java.util.Date
@@ -196,29 +197,9 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
 
         supportActionBar?.setDisplayShowCustomEnabled(true)
 
-        content.setOnApplyWindowInsetsListener { v, insets ->
-            window.navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O_MR1) {
-                // basically if in landscape on a phone
-                // For lollipop, draw opaque nav bar
-                if (v.rootWindowInsets.systemWindowInsetLeft > 0 || v.rootWindowInsets.systemWindowInsetRight > 0)
-                    Color.BLACK
-                else Color.argb(179, 0, 0, 0)
-            }
-            // if the android q+ device has gesture nav, transparent nav bar
-            // this is here in case some crazy with a notch uses landscape
-            else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && (v.rootWindowInsets.systemWindowInsetBottom != v.rootWindowInsets.tappableElementInsets.bottom)) {
-                getColor(android.R.color.transparent)
-            }
-            // if in landscape with 2/3 button mode, fully opaque nav bar
-            else if (v.rootWindowInsets.systemWindowInsetLeft > 0 || v.rootWindowInsets.systemWindowInsetRight > 0) {
-                getResourceColor(R.attr.colorPrimaryVariant)
-            }
-            // if in portrait with 2/3 button mode, translucent nav bar
-            else {
-                ColorUtils.setAlphaComponent(
-                    getResourceColor(R.attr.colorPrimaryVariant), 179
-                )
-            }
+        setNavBarColor(content.rootWindowInsets)
+        content.doOnApplyWindowInsets { v, insets, _ ->
+            setNavBarColor(insets)
             val contextView = window?.decorView?.findViewById<View>(R.id.action_mode_bar)
             contextView?.updateLayoutParams<ViewGroup.MarginLayoutParams> {
                 leftMargin = insets.systemWindowInsetLeft
@@ -234,13 +215,10 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
             )
             bottom_nav.updatePadding(bottom = insets.systemWindowInsetBottom)
 
-            insets.replaceSystemWindowInsets(
+            /*insets.replaceSystemWindowInsets(
                 0, insets.systemWindowInsetTop, 0, insets.systemWindowInsetBottom
-            )
-
-            insets
+            )*/
         }
-        val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
 
         router = Conductor.attachRouter(this, container, savedInstanceState)
         if (!router.hasRootController()) {
@@ -305,6 +283,33 @@ open class MainActivity : BaseActivity(), DownloadServiceListener {
         setExtensionsBadge()
     }
 
+    private fun setNavBarColor(insets: WindowInsets?) {
+        if (insets == null) return
+        window.navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O_MR1) {
+            // basically if in landscape on a phone
+            // For lollipop, draw opaque nav bar
+            if (insets.systemWindowInsetLeft > 0 || insets.systemWindowInsetRight > 0)
+                Color.BLACK
+            else Color.argb(179, 0, 0, 0)
+        }
+        // if the android q+ device has gesture nav, transparent nav bar
+        // this is here in case some crazy with a notch uses landscape
+        else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && (insets
+                .systemWindowInsetBottom != insets.tappableElementInsets.bottom)) {
+            getColor(android.R.color.transparent)
+        }
+        // if in landscape with 2/3 button mode, fully opaque nav bar
+        else if (insets.systemWindowInsetLeft > 0 || insets.systemWindowInsetRight > 0) {
+            getResourceColor(R.attr.colorPrimaryVariant)
+        }
+        // if in portrait with 2/3 button mode, translucent nav bar
+        else {
+            ColorUtils.setAlphaComponent(
+                getResourceColor(R.attr.colorPrimaryVariant), 179
+            )
+        }
+    }
+
     fun updateRecentsIcon() {
         bottom_nav.menu.findItem(R.id.nav_recents).icon = AppCompatResources.getDrawable(
             this,
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt
index 935951f64e..f4000e1231 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt
@@ -52,7 +52,7 @@ class MangaDetailsAdapter(
     fun performFilter() {
         val s = getFilter(String::class.java)
         if (s.isNullOrBlank()) {
-            updateDataSet(items)
+            updateDataSet(items, true)
         } else {
             updateDataSet(items.filter { it.name.contains(s, true) ||
                 it.scanlator?.contains(s, true) == true })
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt
index 8e093a073a..dddb22d4f2 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt
@@ -526,14 +526,11 @@ class MangaDetailsController : BaseController,
     }
 
     private fun markAsRead(chapters: List<ChapterItem>) {
-        presenter.markChaptersRead(chapters, read = true)
-        if (presenter.preferences.removeAfterMarkedAsRead()) {
-            presenter.deleteChapters(chapters)
-        }
+        presenter.markChaptersRead(chapters, true)
     }
 
     private fun markAsUnread(chapters: List<ChapterItem>) {
-        presenter.markChaptersRead(chapters, read = false)
+        presenter.markChaptersRead(chapters, false)
     }
 
     private fun openChapter(chapter: Chapter) {
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt
index cdbadd0003..ce82769440 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt
@@ -292,14 +292,15 @@ class MangaDetailsPresenter(
      * Deletes the given list of chapter.
      * @param chapters the list of chapters to delete.
      */
-    fun deleteChapters(chapters: List<ChapterItem>) {
+    fun deleteChapters(chapters: List<ChapterItem>, update: Boolean = true) {
         deleteChaptersInternal(chapters)
 
         chapters.forEach { chapter ->
             this.chapters.find { it.id == chapter.id }?.download?.status = Download.NOT_DOWNLOADED
         }
 
-        controller.updateChapters(this.chapters)
+        if (update)
+            controller.updateChapters(this.chapters)
     }
 
     /**
@@ -404,6 +405,7 @@ class MangaDetailsPresenter(
                 it.bookmark = bookmarked
             }
             db.updateChaptersProgress(selectedChapters).executeAsBlocking()
+            getChapters()
             withContext(Dispatchers.Main) { controller.updateChapters(chapters) }
         }
     }
@@ -423,6 +425,10 @@ class MangaDetailsPresenter(
                 }
             }
             db.updateChaptersProgress(selectedChapters).executeAsBlocking()
+            if (read && preferences.removeAfterMarkedAsRead()) {
+                deleteChapters(selectedChapters, false)
+            }
+            getChapters()
             withContext(Dispatchers.Main) { controller.updateChapters(chapters) }
         }
     }
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt
index 9e1224b641..3f0e148b38 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt
@@ -169,7 +169,7 @@ class MangaHeaderHolder(
                     )
                 }
             } else {
-                text = resources.getString(R.string.start_reading)
+                text = resources.getString(R.string.all_chapters_read)
             }
         }
 
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt
index 8a4a75af13..febad68f32 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt
@@ -1,6 +1,5 @@
 package eu.kanade.tachiyomi.ui.manga.chapter
 
-import android.animation.Animator
 import android.text.format.DateUtils
 import android.view.View
 import androidx.appcompat.widget.PopupMenu
@@ -147,23 +146,7 @@ class ChapterHolder(
 
     private fun resetFrontView() {
         if (front_view.translationX == 0f) return
-        itemView.post {
-            adapter.recyclerView.itemAnimator?.changeDuration = 0
-            val anim = front_view.animate().translationX(0f).setDuration(250)
-            anim.setListener(object : Animator.AnimatorListener {
-                override fun onAnimationEnd(animation: Animator?) {
-                    adapter.itemTouchHelper.startSwipe(this@ChapterHolder)
-                    adapter.notifyItemChanged(adapterPosition)
-                }
-
-                override fun onAnimationCancel(animation: Animator?) {}
-
-                override fun onAnimationRepeat(animation: Animator?) {}
-
-                override fun onAnimationStart(animation: Animator?) {}
-            })
-            anim.start()
-        }
+        itemView.post { adapter.notifyItemChanged(adapterPosition) }
     }
 
     fun notifyStatus(status: Int, locked: Boolean, progress: Int) = with(download_button) {
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt
index 517a06a19d..0305663cf5 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersSortBottomSheet.kt
@@ -16,7 +16,7 @@ import eu.kanade.tachiyomi.util.view.visibleIf
 import kotlinx.android.synthetic.main.chapter_sort_bottom_sheet.*
 
 class ChaptersSortBottomSheet(controller: MangaDetailsController) : BottomSheetDialog
-    (controller.activity!!, R.style.BottomSheetDialogThemeCovered) {
+    (controller.activity!!, R.style.BottomSheetDialogTheme) {
 
     val activity = controller.activity!!
 
@@ -30,10 +30,9 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) : BottomSheetD
         setContentView(view)
 
         sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup)
-        setEdgeToEdge(activity, bottom_sheet, view)
+        setEdgeToEdge(activity, view)
         val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
         sheetBehavior.peekHeight = 380.dpToPx + height
-        window?.navigationBarColor = activity.window.navigationBarColor
 
         sheetBehavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
             override fun onSlide(bottomSheet: View, progress: Float) { }
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackingBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackingBottomSheet.kt
index cec3cb9cb4..6eaecfe638 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackingBottomSheet.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackingBottomSheet.kt
@@ -40,7 +40,7 @@ class TrackingBottomSheet(private val controller: MangaDetailsController) : Bott
         setContentView(view)
 
         sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup)
-        setEdgeToEdge(activity, display_bottom_sheet, view)
+        setEdgeToEdge(activity, view)
         val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
         sheetBehavior.peekHeight = 380.dpToPx + height
 
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationBottomSheetDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationBottomSheetDialog.kt
index 7b06675699..db113acf4b 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationBottomSheetDialog.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationBottomSheetDialog.kt
@@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.ui.migration.manga.design
 import android.app.Activity
 import android.content.res.Configuration
 import android.os.Bundle
-import android.view.WindowManager
 import android.widget.CompoundButton
 import android.widget.LinearLayout
 import android.widget.RadioButton
@@ -62,7 +61,7 @@ class MigrationBottomSheetDialog(
             params3.endToEnd = -1
             extra_search_param.layoutParams = params3
         }
-        setEdgeToEdge(activity, constraint_layout, view)
+        setEdgeToEdge(activity, view)
         setBottomEdge(
             if (activity.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE) extra_search_param_text
             else skip_step, activity
@@ -77,7 +76,7 @@ class MigrationBottomSheetDialog(
 
         initPreferences()
 
-            window?.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
+        // window?.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
 
         fab.setOnClickListener {
             preferences.skipPreMigration().set(skip_step.isChecked)
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt
index a4fb3a4f89..447c65596f 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt
@@ -54,7 +54,7 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog
         val view = activity.layoutInflater.inflate(R.layout.reader_color_filter_sheet, null)
         setContentView(view)
 
-        setEdgeToEdge(activity, constraint_layout, view, 0)
+        setEdgeToEdge(activity, view, 0)
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
             preferences.readerTheme().getOrDefault() == 0 &&
             activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 &&
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt
index 4291657eec..2fe1629dfc 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPageSheet.kt
@@ -32,7 +32,7 @@ class ReaderPageSheet(
 
     init {
         setContentView(view)
-        setEdgeToEdge(activity, view, view)
+        setEdgeToEdge(activity, view)
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
             Injekt.get<PreferencesHelper>().readerTheme().getOrDefault() == 0 &&
             activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 &&
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt
index 03b55d5a07..ec065b09ab 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt
@@ -49,10 +49,7 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) :
 
         sheetBehavior = BottomSheetBehavior.from(scroll.parent as ViewGroup)
         setEdgeToEdge(
-            activity,
-            constraint_layout,
-            scroll,
-            if (context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE)
+            activity, scroll, if (context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE)
                 0 else -1
         )
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && preferences.readerTheme()
diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt
index 0ba5cbf07d..4ed51ac4b6 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt
@@ -8,7 +8,6 @@ import android.content.res.Configuration
 import android.graphics.Color
 import android.graphics.Point
 import android.graphics.Typeface
-import android.graphics.drawable.GradientDrawable
 import android.os.Build
 import android.view.View
 import android.view.ViewGroup
@@ -21,8 +20,6 @@ import android.widget.ImageView
 import android.widget.TextView
 import androidx.annotation.Px
 import androidx.appcompat.widget.SearchView
-import androidx.constraintlayout.widget.ConstraintLayout
-import androidx.core.graphics.ColorUtils
 import androidx.core.math.MathUtils.clamp
 import androidx.core.view.ViewCompat
 import androidx.recyclerview.widget.LinearLayoutManager
@@ -37,11 +34,11 @@ import eu.kanade.tachiyomi.R
 import eu.kanade.tachiyomi.data.preference.PreferencesHelper
 import eu.kanade.tachiyomi.util.system.dpToPx
 import eu.kanade.tachiyomi.util.system.getResourceColor
-import kotlin.math.abs
-import kotlin.math.min
 import kotlinx.android.synthetic.main.main_activity.*
 import uy.kohesive.injekt.Injekt
 import uy.kohesive.injekt.api.get
+import kotlin.math.abs
+import kotlin.math.min
 
 /**
  * Returns coordinates of view.
@@ -396,42 +393,31 @@ inline fun View.updatePaddingRelative(
 
 fun BottomSheetDialog.setEdgeToEdge(
     activity: Activity,
-    layout: View,
     contentView: View,
     setTopMargin: Int = -1
 ) {
     window?.setBackgroundDrawable(null)
     val currentNightMode =
         activity.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
-    if (currentNightMode == Configuration.UI_MODE_NIGHT_NO) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
-        if (activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0 && activity.window.decorView.rootWindowInsets.systemWindowInsetLeft == 0) window?.decorView?.systemUiVisibility =
-            View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
-    } else if (layout is ConstraintLayout) {
-        val nView = View(context)
-        val height = activity.window.decorView.rootWindowInsets.systemWindowInsetBottom
-        val params = ConstraintLayout.LayoutParams(
-            ViewGroup.LayoutParams.MATCH_PARENT, height
-        )
-        params.bottomToBottom = layout.id
-        params.startToStart = layout.id
-        params.endToEnd = layout.id
-        nView.layoutParams = params
-        nView.background = GradientDrawable(
-            GradientDrawable.Orientation.BOTTOM_TOP, intArrayOf(
-                ColorUtils.setAlphaComponent(Color.BLACK, 179), Color.TRANSPARENT
-            )
-        )
-        layout.addView(nView)
-    }
+    window?.navigationBarColor = activity.window.navigationBarColor
+    val isLight = (activity.window?.decorView?.systemUiVisibility ?: 0) and View
+        .SYSTEM_UI_FLAG_LIGHT_STATUS_BAR == View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
+    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isLight)
+        window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
     window?.findViewById<View>(com.google.android.material.R.id.container)?.fitsSystemWindows =
         false
     contentView.systemUiVisibility =
-        View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
-    /*contentView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
-        if (setTopMargin > -1) topMargin =
-            activity.window.decorView.rootWindowInsets.systemWindowInsetTop + setTopMargin
-    }*/
+        View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN //
+            // or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
 
+    if (activity.window.decorView.rootWindowInsets.systemWindowInsetLeft +
+        activity.window.decorView.rootWindowInsets.systemWindowInsetRight == 0)
+        contentView.systemUiVisibility = contentView.systemUiVisibility
+            .or(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
+    /*contentView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
+        leftMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetLeft
+        rightMargin = activity.window.decorView.rootWindowInsets.systemWindowInsetRight
+    }*/
     if (setTopMargin > 0) (contentView.parent as View).updateLayoutParams<ViewGroup.MarginLayoutParams> {
         height =
             activity.window.decorView.height - activity.window.decorView.rootWindowInsets.systemWindowInsetTop - setTopMargin
diff --git a/app/src/main/res/layout/migration_bottom_sheet.xml b/app/src/main/res/layout/migration_bottom_sheet.xml
index 41818cf9a3..fba186983e 100644
--- a/app/src/main/res/layout/migration_bottom_sheet.xml
+++ b/app/src/main/res/layout/migration_bottom_sheet.xml
@@ -8,7 +8,6 @@
     style="@style/Theme.MaterialComponents.BottomSheetDialog"
     android:layout_height="match_parent"
     android:background="@android:color/transparent"
-    android:fitsSystemWindows="true"
     android:orientation="vertical">
 
 
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 5399e843fa..9e0156497f 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -210,11 +210,6 @@
     </style>
 
     <style name="BottomSheetDialogTheme" parent="@style/Theme.MaterialComponents.BottomSheetDialog">
-        <item name="android:colorBackground">@android:color/transparent</item>
-    </style>
-
-    <style name="BottomSheetDialogThemeCovered"
-        parent="@style/Theme.MaterialComponents.BottomSheetDialog">
         <item name="android:windowIsFloating">false</item>
         <item name="android:colorBackground">@android:color/transparent</item>
         <item name="android:statusBarColor">@android:color/transparent</item>