From 56e1e3e2050a24161130694b53c7be98b12de0b8 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 22 Nov 2020 22:57:58 -0500 Subject: [PATCH] Further abstract how bottom navbar padding is applied --- .../ui/base/controller/ConductorExtensions.kt | 10 ++++++++++ .../ui/browse/extension/ExtensionController.kt | 8 ++------ .../migration/sources/MigrationSourcesController.kt | 8 ++------ .../tachiyomi/ui/browse/source/SourceController.kt | 8 ++------ .../tachiyomi/ui/library/LibraryCategoryView.kt | 8 ++------ .../eu/kanade/tachiyomi/ui/more/MoreController.kt | 12 ++---------- .../tachiyomi/ui/recent/history/HistoryController.kt | 11 ++++------- .../tachiyomi/ui/recent/updates/UpdatesController.kt | 8 ++------ 8 files changed, 26 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ConductorExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ConductorExtensions.kt index 448f1c7c6f..ecf7a6ba07 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ConductorExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ConductorExtensions.kt @@ -2,8 +2,10 @@ package eu.kanade.tachiyomi.ui.base.controller import android.content.pm.PackageManager.PERMISSION_GRANTED import android.os.Build +import android.view.View import android.view.WindowInsets import androidx.core.content.ContextCompat +import androidx.core.view.updatePadding import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Router import com.bluelinelabs.conductor.RouterTransaction @@ -40,3 +42,11 @@ val Controller.insets: WindowInsets? } else { null } + +inline fun Controller.applyBottomInsetPadding(view: View, paddingBottom: Int = view.paddingBottom) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + view.updatePadding(bottom = paddingBottom + insets!!.systemWindowInsetBottom) + } else { + view.updatePadding(bottom = paddingBottom) + } +} 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 cf91dcaf4e..69401f1a1a 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 @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.ui.browse.extension -import android.os.Build import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater @@ -8,7 +7,6 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.SearchView -import androidx.core.view.updatePadding import androidx.recyclerview.widget.LinearLayoutManager import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType @@ -18,7 +16,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.ExtensionControllerBinding import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.ui.base.controller.NucleusController -import eu.kanade.tachiyomi.ui.base.controller.insets +import eu.kanade.tachiyomi.ui.base.controller.applyBottomInsetPadding import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.browse.BrowseController import eu.kanade.tachiyomi.ui.browse.extension.details.ExtensionDetailsController @@ -63,9 +61,7 @@ open class ExtensionController : override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = ExtensionControllerBinding.inflate(inflater) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - binding.recycler.updatePadding(bottom = binding.recycler.paddingBottom + insets!!.systemWindowInsetBottom) - } + applyBottomInsetPadding(binding.recycler) 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 d56a4d2a08..dbb5e456aa 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 @@ -1,19 +1,17 @@ package eu.kanade.tachiyomi.ui.browse.migration.sources -import android.os.Build import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup -import androidx.core.view.updatePadding import androidx.recyclerview.widget.LinearLayoutManager import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.MigrationSourcesControllerBinding import eu.kanade.tachiyomi.ui.base.controller.NucleusController -import eu.kanade.tachiyomi.ui.base.controller.insets +import eu.kanade.tachiyomi.ui.base.controller.applyBottomInsetPadding import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.browse.migration.manga.MigrationMangaController import eu.kanade.tachiyomi.util.system.openInBrowser @@ -35,9 +33,7 @@ class MigrationSourcesController : override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = MigrationSourcesControllerBinding.inflate(inflater) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - binding.recycler.updatePadding(bottom = binding.recycler.paddingBottom + insets!!.systemWindowInsetBottom) - } + applyBottomInsetPadding(binding.recycler) 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 6ed5cc6a7e..9865d0ab86 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 @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.browse.source import android.Manifest.permission.WRITE_EXTERNAL_STORAGE import android.app.Dialog -import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.Menu @@ -11,7 +10,6 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.SearchView -import androidx.core.view.updatePadding import androidx.recyclerview.widget.LinearLayoutManager import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.list.listItems @@ -29,7 +27,7 @@ import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.NucleusController -import eu.kanade.tachiyomi.ui.base.controller.insets +import eu.kanade.tachiyomi.ui.base.controller.applyBottomInsetPadding import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.browse.BrowseController @@ -85,9 +83,7 @@ class SourceController : override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = SourceMainControllerBinding.inflate(inflater) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - binding.recycler.updatePadding(bottom = binding.recycler.paddingBottom + insets!!.systemWindowInsetBottom) - } + applyBottomInsetPadding(binding.recycler) 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 416d2497dc..f2d3a94d44 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 @@ -1,11 +1,9 @@ package eu.kanade.tachiyomi.ui.library import android.content.Context -import android.os.Build import android.util.AttributeSet import android.view.View import android.widget.FrameLayout -import androidx.core.view.updatePadding import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import eu.davidea.flexibleadapter.FlexibleAdapter @@ -16,7 +14,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.library.LibraryUpdateService import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.ui.base.controller.insets +import eu.kanade.tachiyomi.ui.base.controller.applyBottomInsetPadding import eu.kanade.tachiyomi.util.lang.plusAssign import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.inflate @@ -86,9 +84,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att } } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - recycler.updatePadding(bottom = recycler.paddingBottom + controller.insets!!.systemWindowInsetBottom) - } + controller.applyBottomInsetPadding(recycler) adapter = LibraryCategoryAdapter(this) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt index c1a9749752..3d422ac862 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt @@ -1,13 +1,11 @@ package eu.kanade.tachiyomi.ui.more import android.content.Context -import android.os.Build import android.os.Bundle import android.util.AttributeSet import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.core.view.updatePadding import androidx.preference.Preference import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R @@ -15,7 +13,7 @@ import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController import eu.kanade.tachiyomi.ui.base.controller.RootController -import eu.kanade.tachiyomi.ui.base.controller.insets +import eu.kanade.tachiyomi.ui.base.controller.applyBottomInsetPadding import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.category.CategoryController import eu.kanade.tachiyomi.ui.download.DownloadController @@ -49,13 +47,7 @@ class MoreController : override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle?): View { val view = super.onCreateView(inflater, container, savedInstanceState) - // Padding for bottom nav - val paddingBottom = view.context.resources.getDimensionPixelSize(R.dimen.action_toolbar_list_padding) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - view.updatePadding(bottom = paddingBottom + insets!!.systemWindowInsetBottom) - } else { - view.updatePadding(bottom = paddingBottom) - } + applyBottomInsetPadding(view, view.context.resources.getDimensionPixelSize(R.dimen.action_toolbar_list_padding)) return view } 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 89a26b2108..b4874230c9 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 @@ -1,13 +1,11 @@ package eu.kanade.tachiyomi.ui.recent.history -import android.os.Build import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.SearchView -import androidx.core.view.updatePadding import androidx.recyclerview.widget.LinearLayoutManager import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.R @@ -18,7 +16,7 @@ import eu.kanade.tachiyomi.databinding.HistoryControllerBinding import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.RootController -import eu.kanade.tachiyomi.ui.base.controller.insets +import eu.kanade.tachiyomi.ui.base.controller.applyBottomInsetPadding import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.browse.source.browse.ProgressItem import eu.kanade.tachiyomi.ui.manga.MangaController @@ -71,6 +69,9 @@ class HistoryController : override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = HistoryControllerBinding.inflate(inflater) + + applyBottomInsetPadding(binding.recycler) + return binding.root } @@ -83,10 +84,6 @@ class HistoryController : binding.recycler.setHasFixedSize(true) binding.recycler.adapter = adapter adapter?.fastScroller = binding.fastScroller - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - binding.recycler.updatePadding(bottom = binding.recycler.paddingBottom + insets!!.systemWindowInsetBottom) - } } override fun onDestroyView(view: View) { 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 b34f728aec..40d79a2561 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 @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.ui.recent.updates -import android.os.Build import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater @@ -9,7 +8,6 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode -import androidx.core.view.updatePadding import androidx.recyclerview.widget.LinearLayoutManager import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.SelectableAdapter @@ -22,7 +20,7 @@ import eu.kanade.tachiyomi.databinding.UpdatesControllerBinding import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.RootController -import eu.kanade.tachiyomi.ui.base.controller.insets +import eu.kanade.tachiyomi.ui.base.controller.applyBottomInsetPadding import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.offsetAppbarHeight @@ -78,9 +76,7 @@ class UpdatesController : override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = UpdatesControllerBinding.inflate(inflater) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - binding.recycler.updatePadding(bottom = binding.recycler.paddingBottom + insets!!.systemWindowInsetBottom) - } + applyBottomInsetPadding(binding.recycler) return binding.root }