Added option to move selected manga in drag & drop mode

This commit is contained in:
Jay 2020-01-13 18:33:38 -08:00
parent a44e9a19b0
commit 36b893efe1
3 changed files with 59 additions and 22 deletions

View file

@ -154,21 +154,29 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
subscriptions += controller.reorganizeRelay
.subscribe {
if (it.first == category.id) {
var items = when (it.second) {
var items:List<LibraryItem>
if (it.second in 5..6) {
items = adapter.currentItems.toMutableList()
val mangas = controller.selectedMangas
val selectedManga = items.filter { item -> item.manga in mangas }
items.removeAll(selectedManga)
if (it.second == 5) items.addAll(0, selectedManga)
else items.addAll(selectedManga)
}
else {
items = when (it.second) {
1, 2 -> adapter.currentItems.sortedBy {
if (preferences.removeArticles().getOrDefault())
it.manga.title.removeArticles()
else
it.manga.title
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 }
else -> adapter.currentItems.sortedBy { it.manga.title }
}
if (it.second % 2 == 0) items = items.reversed()
}
if (it.second % 2 == 0)
items = items.reversed()
adapter.setItems(items)
adapter.notifyDataSetChanged()
onItemReleased(0)
saveDragSort()
}
}
}
@ -321,16 +329,19 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
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()
saveDragSort()
}
}
private fun saveDragSort() {
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()
}
override fun shouldMoveItem(fromPosition: Int, toPosition: Int): Boolean {
if (adapter.selectedItemCount > 1)
return false

View file

@ -147,7 +147,7 @@ class LibraryController(
/**
* Drawer listener to allow swipe only for closing the drawer.
*/
private var drawerListener: androidx.drawerlayout.widget.DrawerLayout.DrawerListener? = null
private var drawerListener: DrawerLayout.DrawerListener? = null
private var tabsVisibilityRelay: BehaviorRelay<Boolean> = BehaviorRelay.create(false)
@ -247,7 +247,7 @@ class LibraryController(
return view
}
override fun cleanupSecondaryDrawer(drawer: androidx.drawerlayout.widget.DrawerLayout) {
override fun cleanupSecondaryDrawer(drawer: DrawerLayout) {
navView = null
}
@ -473,12 +473,18 @@ class LibraryController(
menu.findItem(R.id.action_hide_title)?.isVisible =
!preferences.libraryAsList().getOrDefault()
if (!preferences.libraryAsList().getOrDefault()) {
val showAll =
(selectedMangas.filter { (it as? LibraryManga)?.hide_title == true }).size == selectedMangas.size
val showAll = (selectedMangas.all { (it as? LibraryManga)?.hide_title == true })
menu.findItem(R.id.action_hide_title)?.title = activity?.getString(
if (showAll) R.string.action_show_title else R.string.action_hide_title
)
}
if (preferences.librarySortingMode().getOrDefault() == LibrarySort.DRAG_AND_DROP) {
val catId = (selectedMangas.first() as? LibraryManga)?.category
val sameCat = (adapter?.categories?.getOrNull(library_pager.currentItem)?.id
== catId) && selectedMangas.all { (it as? LibraryManga)?.category == catId }
menu.findItem(R.id.action_move_manga).isVisible = sameCat
}
else menu.findItem(R.id.action_move_manga).isVisible = false
}
return false
}
@ -516,6 +522,12 @@ class LibraryController(
presenter.hideShowTitle(selectedMangas.toList(), !showAll)
destroyActionModeIfNeeded()
}
R.id.action_to_top, R.id.action_to_bottom -> {
adapter?.categories?.getOrNull(library_pager.currentItem)?.id?.let {
reorganizeRelay.call(it to if (item.itemId == R.id.action_to_top) 5 else 6)
}
destroyActionModeIfNeeded()
}
else -> return false
}
return true

View file

@ -25,14 +25,28 @@
<item
android:id="@+id/action_migrate"
android:icon="@drawable/ic_swap_calls_white_24dp"
android:title="@string/label_migration"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_hide_title"
android:icon="@drawable/ic_swap_calls_white_24dp"
android:title="@string/action_hide_title"
app:showAsAction="never" />
<item
android:id="@+id/action_move_manga"
android:title="@string/action_move"
app:showAsAction="never"
>
<menu >
<item
android:id="@+id/action_to_top"
android:title="@string/action_move_to_top" />
<item
android:id="@+id/action_to_bottom"
android:title="@string/action_move_to_bottom" />
</menu>
</item>
</menu>