Fixed snackbar in categories + Fixed touch offset when tabs needs to appear
This commit is contained in:
parent
1265a3a790
commit
cc5c9a4699
@ -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<CategoryPresenter>(),
|
||||
/**
|
||||
* 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<CategoryPresenter>(),
|
||||
*/
|
||||
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<CategoryPresenter>(),
|
||||
|
||||
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<Snackbar>() {
|
||||
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<CategoryPresenter>(),
|
||||
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.
|
||||
*
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
<?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:app="http://schemas.android.com/apk/res-auto"
|
||||
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
|
||||
android:layout_width="match_parent"
|
||||
@ -27,4 +29,4 @@
|
||||
android:layout_gravity="center"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</FrameLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
Loading…
Reference in New Issue
Block a user