From 0c814591438a0c023753afe8dc5c07701c4e6d11 Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 3 Mar 2020 12:58:35 -0800 Subject: [PATCH] Fixed snackbars and dialogs --- .../tachiyomi/ui/library/LibraryListController.kt | 15 ++++++++++++--- .../ui/library/filter/SortFilterBottomSheet.kt | 8 ++++---- .../eu/kanade/tachiyomi/ui/main/MainActivity.kt | 3 ++- .../ui/recent_updates/RecentChaptersController.kt | 7 +++++-- .../main/res/layout/library_list_controller.xml | 5 ----- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt index 58edc7344e..a425ab35d8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryListController.kt @@ -464,6 +464,8 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), override fun onItemMove(fromPosition: Int, toPosition: Int) { if (lastItemPosition == toPosition) lastItemPosition = null + else if (lastItemPosition == null) + lastItemPosition = fromPosition } override fun onItemReleased(position: Int) { @@ -472,6 +474,9 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), return } destroyActionModeIfNeeded() + // if nothing moved + if (lastItemPosition == null) + return val item = adapter.getItem(position) as? LibraryItem ?: return val newHeader = adapter.getSectionHeader(position) as? LibraryHeaderItem val libraryItems = adapter.getSectionItems(adapter.getSectionHeader(position)) @@ -482,7 +487,9 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), } else { if (presenter.mangaIsInCategory(item.manga, newHeader?.category?.id)) { adapter.moveItem(position, lastItemPosition!!) - snack = snackbar_layout?.snack(R.string.already_in_category) + snack = view?.snack(R.string.already_in_category) { + anchorView = bottom_sheet + } return } if (newHeader?.category?.mangaSort == null) { @@ -539,13 +546,15 @@ class LibraryListController(bundle: Bundle? = null) : LibraryController(bundle), return false val inQueue = LibraryUpdateService.categoryInQueue(category.id) snack?.dismiss() - snack = snackbar_layout.snack(resources!!.getString( + snack = view?.snack(resources!!.getString( when { inQueue -> R.string.category_already_in_queue LibraryUpdateService.isRunning() -> R.string.adding_category_to_queue else -> R.string.updating_category_x - }, category.name)) + }, category.name)) { + anchorView = bottom_sheet + } if (!inQueue) LibraryUpdateService.start(view!!.context, category) return true diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt index ad28922777..12e3391480 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt @@ -90,7 +90,7 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A pager = pagerView val shadow2:View = (pagerView.parent as ViewGroup).findViewById(R.id.shadow2) val shadow:View = (pagerView.parent as ViewGroup).findViewById(R.id.shadow) - val snackbarLayout:View = (pagerView.parent as ViewGroup).findViewById(R.id.snackbar_layout) +// val snackbarLayout:View = (pagerView.parent as ViewGroup).findViewById(R.id.snackbar_layout) if (phoneLandscape) { sheetBehavior?.state = BottomSheetBehavior.STATE_HIDDEN } @@ -115,7 +115,7 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A else shadow.alpha = 1f pager?.updatePaddingRelative(bottom = sheetBehavior?.peekHeight ?: 0) - snackbarLayout.updatePaddingRelative(bottom = sheetBehavior?.peekHeight ?: 0) +// snackbarLayout.updatePaddingRelative(bottom = sheetBehavior?.peekHeight ?: 0) if (!phoneLandscape) preferences.hideFiltersAtStart().set(false) } @@ -128,7 +128,7 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A reSortViews() shadow.alpha = 0f pager?.updatePaddingRelative(bottom = 0) - snackbarLayout.updatePaddingRelative(bottom = 0) +// snackbarLayout.updatePaddingRelative(bottom = 0) if (!phoneLandscape) preferences.hideFiltersAtStart().set(true) } @@ -142,7 +142,7 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A } else { pager?.updatePaddingRelative(bottom = sheetBehavior?.peekHeight ?: 0) - snackbarLayout.updatePaddingRelative(bottom = sheetBehavior?.peekHeight ?: 0) +// snackbarLayout.updatePaddingRelative(bottom = sheetBehavior?.peekHeight ?: 0) } if (phoneLandscape && shadow2.visibility != View.GONE) { shadow2.gone() 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 b5ec2149b6..de15c4f151 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 @@ -314,7 +314,8 @@ open class MainActivity : BaseActivity(), DownloadServiceListener { container: ViewGroup, handler: ControllerChangeHandler) { syncActivityViewWithController(to, from) - navigationView.visibility = if (router.backstackSize > 1) View.GONE else View.VISIBLE + if (to !is DialogController) + navigationView.visibility = if (router.backstackSize > 1) View.GONE else View.VISIBLE } override fun onChangeCompleted(to: Controller?, from: Controller?, isPush: Boolean, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt index 3af08dd2a6..af19b4290c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent_updates/RecentChaptersController.kt @@ -25,12 +25,12 @@ import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaChaptersController -import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.recently_read.RecentlyReadController import eu.kanade.tachiyomi.util.system.notificationManager import eu.kanade.tachiyomi.util.view.applyWindowInsetsForController import eu.kanade.tachiyomi.util.view.snack +import kotlinx.android.synthetic.main.main_activity.* import kotlinx.android.synthetic.main.recent_chapters_controller.* import timber.log.Timber import uy.kohesive.injekt.Injekt @@ -102,7 +102,10 @@ class RecentChaptersController : NucleusController(), swipe_refresh.refreshes().subscribeUntilDestroy { if (!LibraryUpdateService.isRunning()) { LibraryUpdateService.start(view.context) - view.snack(R.string.updating_library) + view.snack(R.string.updating_library) { + anchorView = (this@RecentChaptersController.activity as? MainActivity) + ?.navigationView + } } // It can be a very long operation, so we disable swipe refresh and show a snackbar. swipe_refresh.isRefreshing = false diff --git a/app/src/main/res/layout/library_list_controller.xml b/app/src/main/res/layout/library_list_controller.xml index 644e712381..052de96d3b 100644 --- a/app/src/main/res/layout/library_list_controller.xml +++ b/app/src/main/res/layout/library_list_controller.xml @@ -23,11 +23,6 @@ app:fastScrollerBubbleEnabled="false" tools:visibility="visible" /> - -