From f3660d88ddf21d92a80cc5e73bfa012ddf506e75 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sat, 10 Apr 2021 20:38:55 +0700 Subject: [PATCH] Draw edge-to-edge (#4802) --- app/build.gradle.kts | 2 ++ .../ui/base/activity/BaseThemedActivity.kt | 2 +- .../browse/extension/ExtensionController.kt | 6 ++++ .../details/ExtensionDetailsController.kt | 6 ++++ .../sources/MigrationSourcesController.kt | 6 ++++ .../ui/browse/source/SourceController.kt | 6 ++++ .../source/browse/BrowseSourceController.kt | 6 ++++ .../globalsearch/GlobalSearchController.kt | 6 ++++ .../ui/category/CategoryController.kt | 6 ++++ .../ui/download/DownloadController.kt | 6 ++++ .../ui/library/LibraryCategoryView.kt | 7 ++++ .../kanade/tachiyomi/ui/main/MainActivity.kt | 35 +++++++++++++++++++ .../tachiyomi/ui/manga/MangaController.kt | 6 ++++ .../ui/recent/history/HistoryController.kt | 6 ++++ .../ui/recent/updates/UpdatesController.kt | 6 ++++ .../ui/setting/SettingsController.kt | 7 ++++ app/src/main/res/values-v23/themes.xml | 2 +- app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/themes.xml | 4 ++- 19 files changed, 123 insertions(+), 3 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 79eff446e..91d04cc6f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -91,6 +91,7 @@ android { exclude("META-INF/LICENSE") exclude("META-INF/LICENSE.txt") exclude("META-INF/NOTICE") + exclude("META-INF/*.kotlin_module") } dependenciesInfo { @@ -221,6 +222,7 @@ dependencies { implementation("com.nightlynexus.viewstatepageradapter:viewstatepageradapter:1.1.0") implementation("com.github.chrisbanes:PhotoView:2.3.0") implementation("com.github.tachiyomiorg:DirectionalViewPager:1.0.0") + implementation("dev.chrisbanes.insetter:insetter:0.5.0") // 3.2.0+ introduces weird UI blinking or cut off issues on some devices val materialDialogsVersion = "3.1.1" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt index afd4d1028..5f9f48af9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt @@ -13,7 +13,7 @@ abstract class BaseThemedActivity : AppCompatActivity() { val preferences: PreferencesHelper by injectLazy() - private val isDarkMode: Boolean by lazy { + val isDarkMode: Boolean by lazy { val themeMode = preferences.themeMode().get() (themeMode == Values.ThemeMode.dark) || ( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt index bd44116bb..8adc75cdc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionController.kt @@ -10,6 +10,7 @@ import androidx.appcompat.widget.SearchView import androidx.recyclerview.widget.LinearLayoutManager import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType +import dev.chrisbanes.insetter.applyInsetter import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R @@ -58,6 +59,11 @@ open class ExtensionController : override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = ExtensionControllerBinding.inflate(inflater) + binding.recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } return binding.root } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt index 49a981e4f..52882285b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt @@ -22,6 +22,7 @@ import androidx.preference.PreferenceScreen import androidx.preference.SwitchPreferenceCompat import androidx.recyclerview.widget.ConcatAdapter import androidx.recyclerview.widget.LinearLayoutManager +import dev.chrisbanes.insetter.applyInsetter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.EmptyPreferenceDataStore import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -67,6 +68,11 @@ class ExtensionDetailsController(bundle: Bundle? = null) : override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { val themedInflater = inflater.cloneInContext(getPreferenceThemeContext()) binding = ExtensionDetailControllerBinding.inflate(themedInflater) + binding.extensionPrefsRecycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } return binding.root } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesController.kt index cb969b5b8..557c7db71 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/MigrationSourcesController.kt @@ -7,6 +7,7 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.LinearLayoutManager +import dev.chrisbanes.insetter.applyInsetter import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.MigrationSourcesControllerBinding @@ -31,6 +32,11 @@ class MigrationSourcesController : override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = MigrationSourcesControllerBinding.inflate(inflater) + binding.recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } return binding.root } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt index b04522311..e0cf253d2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt @@ -14,6 +14,7 @@ import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.list.listItems import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType +import dev.chrisbanes.insetter.applyInsetter import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R @@ -72,6 +73,11 @@ class SourceController : */ override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = SourceMainControllerBinding.inflate(inflater) + binding.recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } return binding.root } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt index 59620e789..4bd44af59 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt @@ -18,6 +18,7 @@ import com.afollestad.materialdialogs.list.listItems import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton import com.google.android.material.snackbar.Snackbar import com.tfcporciuncula.flow.Preference +import dev.chrisbanes.insetter.applyInsetter import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R @@ -237,6 +238,11 @@ open class BrowseSourceController(bundle: Bundle) : if (filterSheet != null) { // Add bottom padding if filter FAB is visible recycler.updatePadding(bottom = view.resources.getDimensionPixelOffset(R.dimen.fab_list_padding)) + recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } recycler.clipToPadding = false actionFab?.shrinkOnScroll(recycler) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt index e36e4d75c..bdd672ec0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchController.kt @@ -5,6 +5,7 @@ import android.view.* import androidx.appcompat.widget.SearchView import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager +import dev.chrisbanes.insetter.applyInsetter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -53,6 +54,11 @@ open class GlobalSearchController( */ override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = GlobalSearchControllerBinding.inflate(inflater) + binding.recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } return binding.root } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt index f4fc01a1d..af189e574 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt @@ -11,6 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton import com.google.android.material.snackbar.Snackbar +import dev.chrisbanes.insetter.applyInsetter import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.SelectableAdapter import eu.davidea.flexibleadapter.helpers.UndoHelper @@ -75,6 +76,11 @@ class CategoryController : */ override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = CategoriesControllerBinding.inflate(inflater) + binding.recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } return binding.root } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt index 944bc7386..72cacd907 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt @@ -10,6 +10,7 @@ import androidx.core.view.isVisible import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton +import dev.chrisbanes.insetter.applyInsetter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.data.download.model.Download @@ -56,6 +57,11 @@ class DownloadController : override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = DownloadControllerBinding.inflate(inflater) + binding.recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } return binding.root } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index e8b9febbb..79eba7168 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -6,6 +6,7 @@ import android.view.View import android.widget.FrameLayout import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import dev.chrisbanes.insetter.applyInsetter import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.SelectableAdapter import eu.kanade.tachiyomi.R @@ -82,6 +83,12 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att } } + recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } + adapter = LibraryCategoryAdapter(this) recycler.setHasFixedSize(true) 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 11576c697..8633e94be 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 @@ -2,11 +2,16 @@ package eu.kanade.tachiyomi.ui.main import android.app.SearchManager import android.content.Intent +import android.graphics.Color +import android.os.Build import android.os.Bundle import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.core.view.ViewCompat +import androidx.core.view.WindowCompat +import androidx.core.view.WindowInsetsCompat import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams import androidx.lifecycle.lifecycleScope @@ -18,6 +23,7 @@ import com.bluelinelabs.conductor.Router import com.bluelinelabs.conductor.RouterTransaction import com.google.android.material.appbar.AppBarLayout import com.google.android.material.behavior.HideBottomViewOnScrollBehavior +import dev.chrisbanes.insetter.applyInsetter import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R @@ -85,6 +91,35 @@ class MainActivity : BaseViewBindingActivity() { setContentView(binding.root) setSupportActionBar(binding.toolbar) + // Draw edge-to-edge + WindowCompat.setDecorFitsSystemWindows(window, false) + binding.appbar.applyInsetter { + type(navigationBars = true, statusBars = true) { + padding(left = true, top = true, right = true) + } + } + binding.bottomNav.applyInsetter { + type(navigationBars = true) { + padding() + } + } + binding.rootFab.applyInsetter { + type(navigationBars = true) { + margin() + } + } + + // Make sure navigation bar is on bottom when making it transparent + ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, insets -> + if (insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom > 0) { + // Keep scrim on light theme if windowLightNavigationBar is not available + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 || isDarkMode) { + window.navigationBarColor = Color.TRANSPARENT + } + } + insets + } + tabAnimator = ViewHeightAnimator(binding.tabs, 0L) bottomNavAnimator = ViewHeightAnimator(binding.bottomNav) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index 597fcfb4e..36c96e4d3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -26,6 +26,7 @@ import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton import com.google.android.material.snackbar.Snackbar +import dev.chrisbanes.insetter.applyInsetter import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.SelectableAdapter import eu.kanade.tachiyomi.R @@ -200,6 +201,11 @@ class MangaController : override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = MangaControllerBinding.inflate(inflater) + binding.recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } return binding.root } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt index ce36be7a5..7972a2a4a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/history/HistoryController.kt @@ -11,6 +11,7 @@ import android.view.ViewGroup import androidx.appcompat.widget.SearchView import androidx.recyclerview.widget.LinearLayoutManager import com.afollestad.materialdialogs.MaterialDialog +import dev.chrisbanes.insetter.applyInsetter import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.backup.BackupRestoreService @@ -77,6 +78,11 @@ class HistoryController : override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = HistoryControllerBinding.inflate(inflater) + binding.recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } return binding.root } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index b5ef1487b..b98517394 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -9,6 +9,7 @@ import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode import androidx.recyclerview.widget.LinearLayoutManager +import dev.chrisbanes.insetter.applyInsetter import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.SelectableAdapter import eu.davidea.flexibleadapter.items.IFlexible @@ -76,6 +77,11 @@ class UpdatesController : override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = UpdatesControllerBinding.inflate(inflater) + binding.recycler.applyInsetter { + type(navigationBars = true) { + padding() + } + } return binding.root } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt index d0553e774..cf655f178 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt @@ -17,6 +17,7 @@ import androidx.preference.PreferenceGroup import androidx.preference.PreferenceScreen import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType +import dev.chrisbanes.insetter.applyInsetter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.controller.BaseController @@ -49,6 +50,12 @@ abstract class SettingsController : PreferenceController() { view.updatePadding(bottom = view.context.resources.getDimensionPixelSize(R.dimen.action_toolbar_list_padding)) } + listView.applyInsetter { + type(navigationBars = true) { + padding() + } + } + return view } diff --git a/app/src/main/res/values-v23/themes.xml b/app/src/main/res/values-v23/themes.xml index bc8372bff..73607f42f 100644 --- a/app/src/main/res/values-v23/themes.xml +++ b/app/src/main/res/values-v23/themes.xml @@ -2,7 +2,7 @@ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index db5e681cf..2d914635b 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,6 +3,7 @@ #54759E #435E7E + #B354759E #242529 diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index def145cf5..a31c5a3e6 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -88,7 +88,7 @@