Added option to move selected manga in drag & drop mode
This commit is contained in:
parent
a44e9a19b0
commit
36b893efe1
3 changed files with 59 additions and 22 deletions
|
@ -154,21 +154,29 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||||
subscriptions += controller.reorganizeRelay
|
subscriptions += controller.reorganizeRelay
|
||||||
.subscribe {
|
.subscribe {
|
||||||
if (it.first == category.id) {
|
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 {
|
1, 2 -> adapter.currentItems.sortedBy {
|
||||||
if (preferences.removeArticles().getOrDefault())
|
if (preferences.removeArticles().getOrDefault()) it.manga.title.removeArticles()
|
||||||
it.manga.title.removeArticles()
|
else it.manga.title
|
||||||
else
|
|
||||||
it.manga.title
|
|
||||||
}
|
}
|
||||||
3, 4 -> adapter.currentItems.sortedBy { it.manga.last_update }
|
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)
|
if (it.second % 2 == 0) items = items.reversed()
|
||||||
items = items.reversed()
|
}
|
||||||
adapter.setItems(items)
|
adapter.setItems(items)
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
onItemReleased(0)
|
saveDragSort()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,6 +329,11 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||||
|
|
||||||
override fun onItemReleased(position: Int) {
|
override fun onItemReleased(position: Int) {
|
||||||
if (adapter.selectedItemCount == 0) {
|
if (adapter.selectedItemCount == 0) {
|
||||||
|
saveDragSort()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saveDragSort() {
|
||||||
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()
|
val db: DatabaseHelper by injectLazy()
|
||||||
|
@ -329,8 +342,6 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||||
else
|
else
|
||||||
db.insertCategory(category).asRxObservable().subscribe()
|
db.insertCategory(category).asRxObservable().subscribe()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun shouldMoveItem(fromPosition: Int, toPosition: Int): Boolean {
|
override fun shouldMoveItem(fromPosition: Int, toPosition: Int): Boolean {
|
||||||
if (adapter.selectedItemCount > 1)
|
if (adapter.selectedItemCount > 1)
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -147,7 +147,7 @@ class LibraryController(
|
||||||
/**
|
/**
|
||||||
* Drawer listener to allow swipe only for closing the drawer.
|
* 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)
|
private var tabsVisibilityRelay: BehaviorRelay<Boolean> = BehaviorRelay.create(false)
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ class LibraryController(
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun cleanupSecondaryDrawer(drawer: androidx.drawerlayout.widget.DrawerLayout) {
|
override fun cleanupSecondaryDrawer(drawer: DrawerLayout) {
|
||||||
navView = null
|
navView = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,12 +473,18 @@ class LibraryController(
|
||||||
menu.findItem(R.id.action_hide_title)?.isVisible =
|
menu.findItem(R.id.action_hide_title)?.isVisible =
|
||||||
!preferences.libraryAsList().getOrDefault()
|
!preferences.libraryAsList().getOrDefault()
|
||||||
if (!preferences.libraryAsList().getOrDefault()) {
|
if (!preferences.libraryAsList().getOrDefault()) {
|
||||||
val showAll =
|
val showAll = (selectedMangas.all { (it as? LibraryManga)?.hide_title == true })
|
||||||
(selectedMangas.filter { (it as? LibraryManga)?.hide_title == true }).size == selectedMangas.size
|
|
||||||
menu.findItem(R.id.action_hide_title)?.title = activity?.getString(
|
menu.findItem(R.id.action_hide_title)?.title = activity?.getString(
|
||||||
if (showAll) R.string.action_show_title else R.string.action_hide_title
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
@ -516,6 +522,12 @@ class LibraryController(
|
||||||
presenter.hideShowTitle(selectedMangas.toList(), !showAll)
|
presenter.hideShowTitle(selectedMangas.toList(), !showAll)
|
||||||
destroyActionModeIfNeeded()
|
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
|
else -> return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -25,14 +25,28 @@
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_migrate"
|
android:id="@+id/action_migrate"
|
||||||
android:icon="@drawable/ic_swap_calls_white_24dp"
|
|
||||||
android:title="@string/label_migration"
|
android:title="@string/label_migration"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_hide_title"
|
android:id="@+id/action_hide_title"
|
||||||
android:icon="@drawable/ic_swap_calls_white_24dp"
|
|
||||||
android:title="@string/action_hide_title"
|
android:title="@string/action_hide_title"
|
||||||
app:showAsAction="never" />
|
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>
|
</menu>
|
Reference in a new issue