From cc5c9a4699fdd164244327fb27c737a33c9003fc Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 3 Nov 2019 15:36:56 -0800 Subject: [PATCH] Fixed snackbar in categories + Fixed touch offset when tabs needs to appear --- .../ui/category/CategoryController.kt | 35 +++++++++++++++---- .../tachiyomi/ui/manga/MangaController.kt | 3 +- .../main/res/layout/categories_controller.xml | 8 +++-- 3 files changed, 36 insertions(+), 10 deletions(-) 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 8e6a77216f..8c6a8a026c 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 @@ -6,6 +6,7 @@ import androidx.appcompat.view.ActionMode import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import android.view.* +import com.google.android.material.snackbar.BaseTransientBottomBar import com.jakewharton.rxbinding.view.clicks import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.SelectableAdapter @@ -15,6 +16,7 @@ import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.util.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.marginBottom +import eu.kanade.tachiyomi.util.snack import eu.kanade.tachiyomi.util.toast import eu.kanade.tachiyomi.util.updateLayoutParams import eu.kanade.tachiyomi.util.updatePaddingRelative @@ -45,7 +47,7 @@ class CategoryController : NucleusController(), /** * Undo helper used for restoring a deleted category. */ - private var undoHelper: UndoHelper? = null + private var undoHelper: Snackbar? = null /** * Creates the presenter for this controller. Not to be manually called. @@ -104,7 +106,8 @@ class CategoryController : NucleusController(), */ override fun onDestroyView(view: View) { // Manually call callback to delete categories if required - undoHelper?.onDeleteConfirmed(Snackbar.Callback.DISMISS_EVENT_MANUAL) + undoHelper?.dismiss() + confirmDelete() undoHelper = null actionMode = null adapter = null @@ -178,10 +181,24 @@ class CategoryController : NucleusController(), when (item.itemId) { R.id.action_delete -> { - undoHelper = UndoHelper(adapter, this) - undoHelper?.start(adapter.selectedPositions, view!!, - R.string.snack_categories_deleted, R.string.action_undo, 3000) - + //undoHelper = UndoHelper(adapter, this) + // undoHelper?.start(adapter.selectedPositions, view!!, + // R.string.snack_categories_deleted, R.string.action_undo, 3000) + adapter.removeItems(adapter.selectedPositions) + undoHelper = view?.snack(R.string.snack_categories_deleted, 3000) { + var undoing = false + setAction(R.string.action_undo) { + adapter.restoreDeletedItems() + undoing = true + } + addCallback(object : BaseTransientBottomBar.BaseCallback() { + override fun onDismissed(transientBottomBar: Snackbar?, event: Int) { + super.onDismissed(transientBottomBar, event) + if (!undoing) + confirmDelete() + } + }) + } mode.finish() } R.id.action_edit -> { @@ -297,6 +314,12 @@ class CategoryController : NucleusController(), undoHelper = null } + fun confirmDelete() { + val adapter = adapter ?: return + presenter.deleteCategories(adapter.deletedItems.map { it.category }) + undoHelper = null + } + /** * Show a dialog to let the user change the category name. * 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 695bec88ca..326c61dfae 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 @@ -174,10 +174,11 @@ class MangaController : RxController, TabbedController { } override fun configureRouter(router: Router, position: Int) { + val touchOffset = if (activity?.tabs?.height == 0) 144f else 0f if (!router.hasRootController()) { val controller = when (position) { INFO_CONTROLLER -> MangaInfoController() - CHAPTERS_CONTROLLER -> ChaptersController(startingChapterYPos) + CHAPTERS_CONTROLLER -> ChaptersController(startingChapterYPos?.minus(touchOffset)) TRACK_CONTROLLER -> TrackController() else -> error("Wrong position $position") } diff --git a/app/src/main/res/layout/categories_controller.xml b/app/src/main/res/layout/categories_controller.xml index 0857605033..86427223d8 100644 --- a/app/src/main/res/layout/categories_controller.xml +++ b/app/src/main/res/layout/categories_controller.xml @@ -1,9 +1,11 @@ - + android:layout_height="match_parent" + android:clipToPadding="false" + android:orientation="vertical"> - \ No newline at end of file + \ No newline at end of file