From b94da6b3ed01933c7e820c5a0b9771d6b716238a Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 26 Oct 2019 16:27:24 -0700 Subject: [PATCH] Insets for snackbar --- .../ui/catalogue/browse/BrowseCatalogueController.kt | 7 ++++++- .../eu/kanade/tachiyomi/ui/library/LibraryController.kt | 6 ++++-- .../tachiyomi/ui/manga/chapter/ChaptersController.kt | 6 +++++- .../main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt | 3 +++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt index 63e3125f48..9027b12433 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/browse/BrowseCatalogueController.kt @@ -210,7 +210,9 @@ open class BrowseCatalogueController(bundle: Bundle) : recycler.adapter = adapter catalogue_view.addView(recycler, 1) - + recycler.doOnApplyWindowInsets { v, insets, padding -> + v.updatePaddingRelative(bottom = padding.bottom + insets.systemWindowInsetBottom) + } if (oldPosition != RecyclerView.NO_POSITION) { recycler.layoutManager?.scrollToPosition(oldPosition) } @@ -367,6 +369,9 @@ open class BrowseCatalogueController(bundle: Bundle) : presenter.requestNext() } } + snack?.view?.doOnApplyWindowInsets { v, _, padding -> + v.setPadding(padding.left,0,padding.right,0) + } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index a8bee9cdcc..96962297fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -33,11 +33,13 @@ import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.category.CategoryController import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.doOnApplyWindowInsets +import eu.kanade.tachiyomi.ui.main.marginBottom import eu.kanade.tachiyomi.ui.main.updateLayoutParams import eu.kanade.tachiyomi.ui.main.updatePaddingRelative import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.migration.MigrationController import eu.kanade.tachiyomi.util.inflate +import eu.kanade.tachiyomi.util.marginTop import eu.kanade.tachiyomi.util.toast import kotlinx.android.synthetic.main.chapters_controller.* import kotlinx.android.synthetic.main.library_controller.* @@ -200,8 +202,8 @@ class LibraryController( statusScrim.setOnApplyWindowInsetsListener(HeightTopWindowInsetsListener) view.doOnApplyWindowInsets { v, insets, padding -> view.recycler.updatePaddingRelative( - bottom = view.recycler.bottom + insets.systemWindowInsetBottom, - top = view.recycler.top + insets.systemWindowInsetTop + bottom = view.recycler.marginBottom + insets.systemWindowInsetBottom, + top = view.recycler.marginTop + insets.systemWindowInsetTop ) } return view diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 334988a550..e5e054c38b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -381,11 +381,15 @@ class ChaptersController : NucleusController(), destroyActionModeIfNeeded() presenter.downloadChapters(chapters) if (view != null && !presenter.manga.favorite) { - recycler?.snack(view.context.getString(R.string.snack_add_to_library), Snackbar.LENGTH_INDEFINITE) { + val snack = view.snack(view.context.getString(R.string.snack_add_to_library), Snackbar + .LENGTH_INDEFINITE) { setAction(R.string.action_add) { presenter.addToLibrary() } } + snack.view.doOnApplyWindowInsets { v, _, padding -> + v.setPadding(padding.left,0,padding.right,0) + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt index 5e3c94a57a..ed5027989c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt @@ -94,3 +94,6 @@ fun View.getRound(text: String, random : Boolean = true): TextDrawable { .endConfig() .buildRound(text, if (random) ColorGenerator.MATERIAL.randomColor else ColorGenerator.MATERIAL.getColor(text)) } + +inline val View.marginTop: Int + get() = (layoutParams as? ViewGroup.MarginLayoutParams)?.topMargin ?: 0