Fixed snackbar in categories + Fixed touch offset when tabs needs to appear

This commit is contained in:
Jay 2019-11-03 15:36:56 -08:00
parent 1265a3a790
commit cc5c9a4699
3 changed files with 36 additions and 10 deletions

View File

@ -6,6 +6,7 @@ import androidx.appcompat.view.ActionMode
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import android.view.* import android.view.*
import com.google.android.material.snackbar.BaseTransientBottomBar
import com.jakewharton.rxbinding.view.clicks import com.jakewharton.rxbinding.view.clicks
import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.SelectableAdapter 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.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.util.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.doOnApplyWindowInsets
import eu.kanade.tachiyomi.util.marginBottom import eu.kanade.tachiyomi.util.marginBottom
import eu.kanade.tachiyomi.util.snack
import eu.kanade.tachiyomi.util.toast import eu.kanade.tachiyomi.util.toast
import eu.kanade.tachiyomi.util.updateLayoutParams import eu.kanade.tachiyomi.util.updateLayoutParams
import eu.kanade.tachiyomi.util.updatePaddingRelative import eu.kanade.tachiyomi.util.updatePaddingRelative
@ -45,7 +47,7 @@ class CategoryController : NucleusController<CategoryPresenter>(),
/** /**
* Undo helper used for restoring a deleted category. * 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. * Creates the presenter for this controller. Not to be manually called.
@ -104,7 +106,8 @@ class CategoryController : NucleusController<CategoryPresenter>(),
*/ */
override fun onDestroyView(view: View) { override fun onDestroyView(view: View) {
// Manually call callback to delete categories if required // Manually call callback to delete categories if required
undoHelper?.onDeleteConfirmed(Snackbar.Callback.DISMISS_EVENT_MANUAL) undoHelper?.dismiss()
confirmDelete()
undoHelper = null undoHelper = null
actionMode = null actionMode = null
adapter = null adapter = null
@ -178,10 +181,24 @@ class CategoryController : NucleusController<CategoryPresenter>(),
when (item.itemId) { when (item.itemId) {
R.id.action_delete -> { R.id.action_delete -> {
undoHelper = UndoHelper(adapter, this) //undoHelper = UndoHelper(adapter, this)
undoHelper?.start(adapter.selectedPositions, view!!, // undoHelper?.start(adapter.selectedPositions, view!!,
R.string.snack_categories_deleted, R.string.action_undo, 3000) // 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<Snackbar>() {
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
super.onDismissed(transientBottomBar, event)
if (!undoing)
confirmDelete()
}
})
}
mode.finish() mode.finish()
} }
R.id.action_edit -> { R.id.action_edit -> {
@ -297,6 +314,12 @@ class CategoryController : NucleusController<CategoryPresenter>(),
undoHelper = null 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. * Show a dialog to let the user change the category name.
* *

View File

@ -174,10 +174,11 @@ class MangaController : RxController, TabbedController {
} }
override fun configureRouter(router: Router, position: Int) { override fun configureRouter(router: Router, position: Int) {
val touchOffset = if (activity?.tabs?.height == 0) 144f else 0f
if (!router.hasRootController()) { if (!router.hasRootController()) {
val controller = when (position) { val controller = when (position) {
INFO_CONTROLLER -> MangaInfoController() INFO_CONTROLLER -> MangaInfoController()
CHAPTERS_CONTROLLER -> ChaptersController(startingChapterYPos) CHAPTERS_CONTROLLER -> ChaptersController(startingChapterYPos?.minus(touchOffset))
TRACK_CONTROLLER -> TrackController() TRACK_CONTROLLER -> TrackController()
else -> error("Wrong position $position") else -> error("Wrong position $position")
} }

View File

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:clipToPadding="false"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent" android:layout_width="match_parent"
@ -27,4 +29,4 @@
android:layout_gravity="center" android:layout_gravity="center"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
</FrameLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>