#1990 deletion of items works!

This commit is contained in:
Frans-Lukas 2020-05-15 10:14:15 +02:00
parent 84f7fc0393
commit 5faa933c41
3 changed files with 10 additions and 3 deletions

View File

@ -28,6 +28,7 @@ import org.kiwix.kiwixmobile.core.history.adapter.HistoryAdapter2
import org.kiwix.kiwixmobile.core.history.adapter.HistoryDelegate.HistoryItemDelegate
import org.kiwix.kiwixmobile.core.history.adapter.HistoryListItem.HistoryItem
import org.kiwix.kiwixmobile.core.history.viewmodel.Action
import org.kiwix.kiwixmobile.core.history.viewmodel.Action.DeleteHistoryItems
import org.kiwix.kiwixmobile.core.history.viewmodel.Action.Filter
import org.kiwix.kiwixmobile.core.history.viewmodel.Action.OnItemLongClick
import org.kiwix.kiwixmobile.core.history.viewmodel.Action.ToggleShowHistoryFromAllBooks
@ -78,15 +79,18 @@ class HistoryActivity : OnItemClickListener, BaseActivity() {
mode: ActionMode,
item: MenuItem
): Boolean {
historyViewModel.actions.offer(Action.ExitActionModeMenu)
if (item.itemId == id.menu_context_delete) {
dialogShower.show(DeleteHistory, {
val deleteList = historyAdapter.items.filterIsInstance<HistoryItem>().filter { it.isSelected }
// presenter.deleteHistory(deleteList)
historyViewModel.actions.offer(
DeleteHistoryItems(historyAdapter.items.filterIsInstance<HistoryItem>().filter { it.isSelected })
)
historyViewModel.actions.offer(Action.ExitActionModeMenu)
mode.finish()
})
return true
}
historyViewModel.actions.offer(Action.ExitActionModeMenu)
return false
}

View File

@ -34,6 +34,7 @@ sealed class Action {
data class OnItemLongClick(val historyItem: HistoryItem) : Action()
data class ToggleShowHistoryFromAllBooks(val isChecked: Boolean) : Action()
data class Filter(val searchTerm: String) : Action()
data class DeleteHistoryItems(val itemsToDelete: List<HistoryItem>) : Action()
data class UserClickedItem(val historyItem: HistoryItem) : Action()
data class ShowAllSwitchToggled(val isToggled: Boolean) : Action()
data class ConfirmedDelete(val historyListItems: List<HistoryListItem.HistoryItem>) : Action()

View File

@ -19,6 +19,7 @@ import org.kiwix.kiwixmobile.core.history.adapter.HistoryListItem
import org.kiwix.kiwixmobile.core.history.adapter.HistoryListItem.HistoryItem
import org.kiwix.kiwixmobile.core.history.viewmodel.Action.ConfirmedDelete
import org.kiwix.kiwixmobile.core.history.viewmodel.Action.CreatedWithIntent
import org.kiwix.kiwixmobile.core.history.viewmodel.Action.DeleteHistoryItems
import org.kiwix.kiwixmobile.core.history.viewmodel.Action.ExitActionModeMenu
import org.kiwix.kiwixmobile.core.history.viewmodel.Action.ExitHistory
import org.kiwix.kiwixmobile.core.history.viewmodel.Action.Filter
@ -122,6 +123,7 @@ class HistoryViewModel @Inject constructor(
is ConfirmedDelete -> deleteItemAndShowToast(it)
is OnItemLongClick -> selectItemAndOpenSelectionMode(it.historyItem)
is OnItemClick -> appendItemToSelectionOrOpenIt(it)
is DeleteHistoryItems -> historyDao.deleteHistory(it.itemsToDelete)
ReceivedPromptForSpeechInput -> effects.offer(StartSpeechInput(actions))
ExitActionModeMenu -> unselectAllItems.offer(true)
StartSpeechInputFailed -> effects.offer(ShowToast(R.string.speech_not_supported))