Fixed all bookmarks automatically selected if we select only one bookmark

This commit is contained in:
MohitMali 2023-09-05 18:18:23 +05:30
parent a7c4faddcb
commit f0aebc1eaa

View File

@ -20,6 +20,7 @@ package org.kiwix.kiwixmobile.core.page.viewmodel
import org.kiwix.kiwixmobile.core.page.adapter.Page
import org.kiwix.kiwixmobile.core.page.adapter.PageRelated
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.LibkiwixBookmarkItem
abstract class PageState<T : Page> {
abstract val pageItems: List<T>
@ -36,9 +37,18 @@ abstract class PageState<T : Page> {
fun getItemsAfterToggleSelectionOfItem(page: Page): List<T> {
return pageItems.map {
if (it.id == page.id) it.apply {
isSelected = !isSelected
} else it
// check if the current item is `LibkiwixBookmarkItem` because we have not saving
// the bookmarks in database so it does not have any unique value so to get the
// selected items we check for uri since url is unique for every bookmark.
if (it is LibkiwixBookmarkItem) {
if (it.url == page.url) it.apply {
isSelected = !isSelected
} else it
} else {
if (it.id == page.id) it.apply {
isSelected = !isSelected
} else it
}
}
}