Update drag and drop to work like J2k's new version

Cleanup some stuff from the continue reading button
This commit is contained in:
Jobobby04 2020-08-07 23:34:58 -04:00
parent b6f6607d91
commit 5714f183a8
8 changed files with 52 additions and 118 deletions

View File

@ -61,8 +61,6 @@ class LibraryCategoryAdapter(view: LibraryCategoryView, val controller: LibraryC
*/
private var mangas: List<LibraryItem> = emptyList()
val libraryListener: LibraryListener = controller
// SY -->
val onItemReleaseListener: CategoryAdapter.OnItemReleaseListener = view
// SY <--
@ -93,6 +91,7 @@ class LibraryCategoryAdapter(view: LibraryCategoryView, val controller: LibraryC
// (well technically we can cancel it by invoking filterItems again but that doesn't work when
// we want to perform a no-op filter)
suspend fun performFilter(scope: CoroutineScope) {
isLongPressDragEnabled = mode != Mode.MULTI && searchText.isBlank()
lastFilterJob?.cancel()
if (mangas.isNotEmpty() && searchText.isNotBlank()) {
val savedSearchText = searchText
@ -228,9 +227,5 @@ class LibraryCategoryAdapter(view: LibraryCategoryView, val controller: LibraryC
return@any false
}
}
interface LibraryListener {
fun startReading(manga: Manga, adapter: LibraryCategoryAdapter)
}
// EXH <--
}

View File

@ -21,7 +21,6 @@ import eu.kanade.tachiyomi.util.system.toast
import eu.kanade.tachiyomi.util.view.inflate
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import exh.ui.LoadingHandle
import exh.util.removeArticles
import java.util.concurrent.TimeUnit
import kotlinx.android.synthetic.main.library_category.view.fast_scroller
import kotlinx.android.synthetic.main.library_category.view.swipe_refresh
@ -38,6 +37,8 @@ import reactivecircus.flowbinding.recyclerview.scrollStateChanges
import reactivecircus.flowbinding.swiperefreshlayout.refreshes
import rx.android.schedulers.AndroidSchedulers
import rx.subscriptions.CompositeSubscription
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
/**
@ -145,8 +146,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
SelectableAdapter.Mode.SINGLE
}
// SY -->
val sortingMode = preferences.librarySortingMode().get()
adapter.isLongPressDragEnabled = sortingMode == LibrarySort.DRAG_AND_DROP
adapter.isLongPressDragEnabled = canDrag()
// SY <--
// EXH -->
@ -209,33 +209,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
}
controller.invalidateActionMode()
}
// SY -->
subscriptions += controller.reorganizeRelay
.subscribe {
if (it.first == category.id) {
var items = when (it.second) {
1, 2 -> adapter.currentItems.sortedBy {
// if (preferences.removeArticles().getOrDefault())
it.manga.title.removeArticles()
// else
// it.manga.title
}
3, 4 -> adapter.currentItems.sortedBy { it.manga.last_update }
else -> {
adapter.currentItems.sortedBy { it.manga.title }
}
}
if (it.second % 2 == 0) {
items = items.reversed()
}
runBlocking { adapter.setItems(this, items) }
adapter.notifyDataSetChanged()
}
controller.invalidateActionMode()
}
// }
// SY <--
}
fun onRecycle() {
@ -264,7 +237,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
// Get the manga list for this category.
// SY -->
val sortingMode = preferences.librarySortingMode().get()
adapter.isLongPressDragEnabled = sortingMode == LibrarySort.DRAG_AND_DROP
adapter.isLongPressDragEnabled = canDrag()
var mangaForCategory = event.getMangaForCategory(category).orEmpty()
if (sortingMode == LibrarySort.DRAG_AND_DROP) {
if (category.name == "Default") {
@ -307,7 +280,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
if (adapter.mode != SelectableAdapter.Mode.MULTI) {
adapter.mode = SelectableAdapter.Mode.MULTI
// SY -->
adapter.isLongPressDragEnabled = false
adapter.isLongPressDragEnabled = canDrag()
// SY <--
}
findAndToggleSelection(event.manga)
@ -318,8 +291,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
if (controller.selectedMangas.isEmpty()) {
adapter.mode = SelectableAdapter.Mode.SINGLE
// SY -->
adapter.isLongPressDragEnabled = preferences.librarySortingMode()
.get() == LibrarySort.DRAG_AND_DROP
adapter.isLongPressDragEnabled = canDrag()
// SY <--
}
}
@ -328,13 +300,14 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
adapter.clearSelection()
lastClickPosition = -1
// SY -->
adapter.isLongPressDragEnabled = preferences.librarySortingMode()
.get() == LibrarySort.DRAG_AND_DROP
adapter.isLongPressDragEnabled = canDrag()
// SY <--
}
}
}
fun canDrag() = adapter.mode != SelectableAdapter.Mode.MULTI && adapter.searchText.isBlank()
/**
* Toggles the selection for the given manga and updates the view if needed.
*
@ -390,30 +363,26 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
lastClickPosition = position
}
// SY -->
override fun onItemMove(fromPosition: Int, toPosition: Int) {
}
override fun onItemReleased(position: Int) {
if (adapter.selectedItemCount == 0) {
val mangaIds = adapter.currentItems.mapNotNull { it.manga.id }
category.mangaOrder = mangaIds
val db: DatabaseHelper by injectLazy()
if (category.name == "Default") {
preferences.defaultMangaOrder().set(mangaIds.joinToString("/"))
} else {
db.insertCategory(category).asRxObservable().subscribe()
}
controller.invalidateActionMode()
val mangaIds = adapter.currentItems.mapNotNull { it.manga.id }
category.mangaOrder = mangaIds
if (category.name == "Default") {
preferences.defaultMangaOrder().set(mangaIds.joinToString("/"))
} else {
Injekt.get<DatabaseHelper>().insertCategory(category).asRxObservable().subscribe()
}
if (preferences.librarySortingMode().get() != LibrarySort.DRAG_AND_DROP) {
preferences.librarySortingAscending().set(true)
preferences.librarySortingMode().set(LibrarySort.DRAG_AND_DROP)
controller.refreshSort()
}
}
override fun shouldMoveItem(fromPosition: Int, toPosition: Int): Boolean {
if (adapter.selectedItemCount > 1) {
return false
}
if (adapter.isSelected(fromPosition)) {
toggleSelection(fromPosition)
}
return true
if (adapter.isSelected(fromPosition)) toggleSelection(fromPosition)
if (toPosition < 1) return false
return adapter.getItem(fromPosition) is LibraryItem
}
override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
@ -422,6 +391,10 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
onItemLongClick(position)
}
}
override fun onItemMove(fromPosition: Int, toPosition: Int) {
return
}
// SY <--
/**

View File

@ -71,8 +71,7 @@ class LibraryController(
TabbedController,
ActionMode.Callback,
ChangeMangaCategoriesDialog.Listener,
DeleteLibraryMangasDialog.Listener,
LibraryCategoryAdapter.LibraryListener {
DeleteLibraryMangasDialog.Listener {
/**
* Position of the active category.
@ -119,13 +118,6 @@ class LibraryController(
*/
val selectInverseRelay: PublishRelay<Int> = PublishRelay.create()
// SY -->
/**
* Relay to notify the library's viewpager to reotagnize all
*/
val reorganizeRelay: PublishRelay<Pair<Int, Int>> = PublishRelay.create()
// SY <--
/**
* Number of manga per row in grid mode.
*/
@ -397,11 +389,6 @@ class LibraryController(
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.library, menu)
// SY -->
val reorganizeItem = menu.findItem(R.id.action_reorganize)
reorganizeItem.isVisible = preferences.librarySortingMode().get() == LibrarySort.DRAG_AND_DROP
// SY <--
val searchItem = menu.findItem(R.id.action_search)
val searchView = searchItem.actionView as SearchView
searchView.maxWidth = Int.MAX_VALUE
@ -489,24 +476,12 @@ class LibraryController(
presenter.favoritesSync.runSync()
}
}
R.id.action_alpha_asc -> reOrder(1)
R.id.action_alpha_dsc -> reOrder(2)
R.id.action_update_asc -> reOrder(3)
R.id.action_update_dsc -> reOrder(4)
// SY <--
}
return super.onOptionsItemSelected(item)
}
// SY -->
private fun reOrder(type: Int) {
adapter?.categories?.getOrNull(binding.libraryPager.currentItem)?.id?.let {
reorganizeRelay.call(it to type)
}
}
// SY <--
/**
* Invalidates the action mode, forcing it to refresh its content.
*/
@ -796,7 +771,7 @@ class LibraryController(
oldSyncStatus = status
}
override fun startReading(manga: Manga, adapter: LibraryCategoryAdapter) {
fun startReading(manga: Manga, adapter: LibraryCategoryAdapter) {
if (adapter.mode == SelectableAdapter.Mode.MULTI) {
toggleSelection(manga)
return
@ -807,5 +782,9 @@ class LibraryController(
destroyActionModeIfNeeded()
startActivity(intent)
}
fun refreshSort() {
settingsSheet?.refreshSort()
}
// <-- EXH
}

View File

@ -38,5 +38,12 @@ abstract class LibraryHolder(
super.onItemReleased(position)
(adapter as? LibraryCategoryAdapter)?.onItemReleaseListener?.onItemReleased(position)
}
override fun onLongClick(view: View?): Boolean {
return if (adapter.isLongPressDragEnabled) {
super.onLongClick(view)
false
} else super.onLongClick(view)
}
// SY <--
}

View File

@ -37,6 +37,10 @@ class LibrarySettingsSheet(
display.onGroupClicked = onGroupClickListener
}
fun refreshSort() {
sort.refreshMode()
}
override fun getTabViews(): List<View> = listOf(
filters,
sort,
@ -141,6 +145,12 @@ class LibrarySettingsSheet(
setGroups(listOf(SortGroup()))
}
fun refreshMode() {
recycler.adapter = null
removeView(recycler)
setGroups(listOf(SortGroup()))
}
inner class SortGroup : Group {
private val alphabetically = Item.MultiSort(R.string.action_sort_alpha, this)

View File

@ -37,24 +37,4 @@
android:title="@string/source_migration"
app:showAsAction="never"/>
<item
android:id="@+id/action_reorganize"
android:title="@string/label_reorganize_by"
app:showAsAction="never">
<menu>
<item
android:id="@+id/action_alpha_asc"
android:title="@string/action_sort_alpha"/>
<item
android:id="@+id/action_alpha_dsc"
android:title="@string/label_alpha_reverse"/>
<item
android:id="@+id/action_update_asc"
android:title="@string/action_sort_last_checked"/>
<item
android:id="@+id/action_update_dsc"
android:title="@string/action_sort_first_checked"/>
</menu>
</item>
</menu>

View File

@ -1,10 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Activities and fragments labels (toolbar title) -->
<string name="label_reorganize_by">Reordenar</string>
<string name="label_alpha_reverse">Alfa (decrescente)</string>
<!-- Actions -->
<string name="action_sort_first_checked">Primeira verificação</string>
<string name="action_sort_drag_and_drop">Arraste e solte</string>

View File

@ -1,10 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Activities and fragments labels (toolbar title) -->
<string name="label_reorganize_by">Reorder</string>
<string name="label_alpha_reverse">Alpha. (descending)</string>
<!-- Actions -->
<string name="action_sort_first_checked">First checked</string>
<string name="action_sort_drag_and_drop">Drag &amp; Drop</string>