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() private var mangas: List<LibraryItem> = emptyList()
val libraryListener: LibraryListener = controller
// SY --> // SY -->
val onItemReleaseListener: CategoryAdapter.OnItemReleaseListener = view val onItemReleaseListener: CategoryAdapter.OnItemReleaseListener = view
// SY <-- // 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 // (well technically we can cancel it by invoking filterItems again but that doesn't work when
// we want to perform a no-op filter) // we want to perform a no-op filter)
suspend fun performFilter(scope: CoroutineScope) { suspend fun performFilter(scope: CoroutineScope) {
isLongPressDragEnabled = mode != Mode.MULTI && searchText.isBlank()
lastFilterJob?.cancel() lastFilterJob?.cancel()
if (mangas.isNotEmpty() && searchText.isNotBlank()) { if (mangas.isNotEmpty() && searchText.isNotBlank()) {
val savedSearchText = searchText val savedSearchText = searchText
@ -228,9 +227,5 @@ class LibraryCategoryAdapter(view: LibraryCategoryView, val controller: LibraryC
return@any false return@any false
} }
} }
interface LibraryListener {
fun startReading(manga: Manga, adapter: LibraryCategoryAdapter)
}
// EXH <-- // 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.util.view.inflate
import eu.kanade.tachiyomi.widget.AutofitRecyclerView import eu.kanade.tachiyomi.widget.AutofitRecyclerView
import exh.ui.LoadingHandle import exh.ui.LoadingHandle
import exh.util.removeArticles
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlinx.android.synthetic.main.library_category.view.fast_scroller import kotlinx.android.synthetic.main.library_category.view.fast_scroller
import kotlinx.android.synthetic.main.library_category.view.swipe_refresh 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 reactivecircus.flowbinding.swiperefreshlayout.refreshes
import rx.android.schedulers.AndroidSchedulers import rx.android.schedulers.AndroidSchedulers
import rx.subscriptions.CompositeSubscription import rx.subscriptions.CompositeSubscription
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
/** /**
@ -145,8 +146,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
SelectableAdapter.Mode.SINGLE SelectableAdapter.Mode.SINGLE
} }
// SY --> // SY -->
val sortingMode = preferences.librarySortingMode().get() adapter.isLongPressDragEnabled = canDrag()
adapter.isLongPressDragEnabled = sortingMode == LibrarySort.DRAG_AND_DROP
// SY <-- // SY <--
// EXH --> // EXH -->
@ -209,33 +209,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
} }
controller.invalidateActionMode() 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() { fun onRecycle() {
@ -264,7 +237,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
// Get the manga list for this category. // Get the manga list for this category.
// SY --> // SY -->
val sortingMode = preferences.librarySortingMode().get() val sortingMode = preferences.librarySortingMode().get()
adapter.isLongPressDragEnabled = sortingMode == LibrarySort.DRAG_AND_DROP adapter.isLongPressDragEnabled = canDrag()
var mangaForCategory = event.getMangaForCategory(category).orEmpty() var mangaForCategory = event.getMangaForCategory(category).orEmpty()
if (sortingMode == LibrarySort.DRAG_AND_DROP) { if (sortingMode == LibrarySort.DRAG_AND_DROP) {
if (category.name == "Default") { if (category.name == "Default") {
@ -307,7 +280,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
if (adapter.mode != SelectableAdapter.Mode.MULTI) { if (adapter.mode != SelectableAdapter.Mode.MULTI) {
adapter.mode = SelectableAdapter.Mode.MULTI adapter.mode = SelectableAdapter.Mode.MULTI
// SY --> // SY -->
adapter.isLongPressDragEnabled = false adapter.isLongPressDragEnabled = canDrag()
// SY <-- // SY <--
} }
findAndToggleSelection(event.manga) findAndToggleSelection(event.manga)
@ -318,8 +291,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
if (controller.selectedMangas.isEmpty()) { if (controller.selectedMangas.isEmpty()) {
adapter.mode = SelectableAdapter.Mode.SINGLE adapter.mode = SelectableAdapter.Mode.SINGLE
// SY --> // SY -->
adapter.isLongPressDragEnabled = preferences.librarySortingMode() adapter.isLongPressDragEnabled = canDrag()
.get() == LibrarySort.DRAG_AND_DROP
// SY <-- // SY <--
} }
} }
@ -328,13 +300,14 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
adapter.clearSelection() adapter.clearSelection()
lastClickPosition = -1 lastClickPosition = -1
// SY --> // SY -->
adapter.isLongPressDragEnabled = preferences.librarySortingMode() adapter.isLongPressDragEnabled = canDrag()
.get() == LibrarySort.DRAG_AND_DROP
// SY <-- // SY <--
} }
} }
} }
fun canDrag() = adapter.mode != SelectableAdapter.Mode.MULTI && adapter.searchText.isBlank()
/** /**
* Toggles the selection for the given manga and updates the view if needed. * 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 lastClickPosition = position
} }
// SY --> // SY -->
override fun onItemMove(fromPosition: Int, toPosition: Int) {
}
override fun onItemReleased(position: Int) { override fun onItemReleased(position: Int) {
if (adapter.selectedItemCount == 0) { controller.invalidateActionMode()
val mangaIds = adapter.currentItems.mapNotNull { it.manga.id } val mangaIds = adapter.currentItems.mapNotNull { it.manga.id }
category.mangaOrder = mangaIds category.mangaOrder = mangaIds
val db: DatabaseHelper by injectLazy()
if (category.name == "Default") { if (category.name == "Default") {
preferences.defaultMangaOrder().set(mangaIds.joinToString("/")) preferences.defaultMangaOrder().set(mangaIds.joinToString("/"))
} else { } else {
db.insertCategory(category).asRxObservable().subscribe() 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 { override fun shouldMoveItem(fromPosition: Int, toPosition: Int): Boolean {
if (adapter.selectedItemCount > 1) { if (adapter.isSelected(fromPosition)) toggleSelection(fromPosition)
return false if (toPosition < 1) return false
} return adapter.getItem(fromPosition) is LibraryItem
if (adapter.isSelected(fromPosition)) {
toggleSelection(fromPosition)
}
return true
} }
override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { override fun onActionStateChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
@ -422,6 +391,10 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
onItemLongClick(position) onItemLongClick(position)
} }
} }
override fun onItemMove(fromPosition: Int, toPosition: Int) {
return
}
// SY <-- // SY <--
/** /**

View File

@ -71,8 +71,7 @@ class LibraryController(
TabbedController, TabbedController,
ActionMode.Callback, ActionMode.Callback,
ChangeMangaCategoriesDialog.Listener, ChangeMangaCategoriesDialog.Listener,
DeleteLibraryMangasDialog.Listener, DeleteLibraryMangasDialog.Listener {
LibraryCategoryAdapter.LibraryListener {
/** /**
* Position of the active category. * Position of the active category.
@ -119,13 +118,6 @@ class LibraryController(
*/ */
val selectInverseRelay: PublishRelay<Int> = PublishRelay.create() 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. * Number of manga per row in grid mode.
*/ */
@ -397,11 +389,6 @@ class LibraryController(
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.library, menu) 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 searchItem = menu.findItem(R.id.action_search)
val searchView = searchItem.actionView as SearchView val searchView = searchItem.actionView as SearchView
searchView.maxWidth = Int.MAX_VALUE searchView.maxWidth = Int.MAX_VALUE
@ -489,24 +476,12 @@ class LibraryController(
presenter.favoritesSync.runSync() 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 <-- // SY <--
} }
return super.onOptionsItemSelected(item) 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. * Invalidates the action mode, forcing it to refresh its content.
*/ */
@ -796,7 +771,7 @@ class LibraryController(
oldSyncStatus = status oldSyncStatus = status
} }
override fun startReading(manga: Manga, adapter: LibraryCategoryAdapter) { fun startReading(manga: Manga, adapter: LibraryCategoryAdapter) {
if (adapter.mode == SelectableAdapter.Mode.MULTI) { if (adapter.mode == SelectableAdapter.Mode.MULTI) {
toggleSelection(manga) toggleSelection(manga)
return return
@ -807,5 +782,9 @@ class LibraryController(
destroyActionModeIfNeeded() destroyActionModeIfNeeded()
startActivity(intent) startActivity(intent)
} }
fun refreshSort() {
settingsSheet?.refreshSort()
}
// <-- EXH // <-- EXH
} }

View File

@ -38,5 +38,12 @@ abstract class LibraryHolder(
super.onItemReleased(position) super.onItemReleased(position)
(adapter as? LibraryCategoryAdapter)?.onItemReleaseListener?.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 <-- // SY <--
} }

View File

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

View File

@ -37,24 +37,4 @@
android:title="@string/source_migration" android:title="@string/source_migration"
app:showAsAction="never"/> 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> </menu>

View File

@ -1,10 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<!-- Activities and fragments labels (toolbar title) -->
<string name="label_reorganize_by">Reordenar</string>
<string name="label_alpha_reverse">Alfa (decrescente)</string>
<!-- Actions --> <!-- Actions -->
<string name="action_sort_first_checked">Primeira verificação</string> <string name="action_sort_first_checked">Primeira verificação</string>
<string name="action_sort_drag_and_drop">Arraste e solte</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"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<!-- Activities and fragments labels (toolbar title) -->
<string name="label_reorganize_by">Reorder</string>
<string name="label_alpha_reverse">Alpha. (descending)</string>
<!-- Actions --> <!-- Actions -->
<string name="action_sort_first_checked">First checked</string> <string name="action_sort_first_checked">First checked</string>
<string name="action_sort_drag_and_drop">Drag &amp; Drop</string> <string name="action_sort_drag_and_drop">Drag &amp; Drop</string>