diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryActivity.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryActivity.kt index 4fd75679a..4f830d65f 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryActivity.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryActivity.kt @@ -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().filter { it.isSelected } -// presenter.deleteHistory(deleteList) + historyViewModel.actions.offer( + DeleteHistoryItems(historyAdapter.items.filterIsInstance().filter { it.isSelected }) + ) + historyViewModel.actions.offer(Action.ExitActionModeMenu) mode.finish() }) return true } + historyViewModel.actions.offer(Action.ExitActionModeMenu) return false } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/history/viewmodel/Action.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/history/viewmodel/Action.kt index 59b6db18b..14e83f261 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/history/viewmodel/Action.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/history/viewmodel/Action.kt @@ -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) : Action() data class UserClickedItem(val historyItem: HistoryItem) : Action() data class ShowAllSwitchToggled(val isToggled: Boolean) : Action() data class ConfirmedDelete(val historyListItems: List) : Action() diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/history/viewmodel/HistoryViewModel.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/history/viewmodel/HistoryViewModel.kt index 1b0c4449b..72ca0f2d3 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/history/viewmodel/HistoryViewModel.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/history/viewmodel/HistoryViewModel.kt @@ -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))