From af0c4ded064d2937dc1efc25128464747c684bb1 Mon Sep 17 00:00:00 2001 From: Charlie Fairchild Date: Fri, 22 Nov 2024 16:34:44 -0500 Subject: [PATCH] Fix delete phrase bug (#565) Maybe fixes https://github.com/willowtreeapps/vocable-android/issues/565? Do not merge without testing. This is AI generated. Add methods to delete phrases from categories. * **CustomCategoryPhraseViewModel.kt** - Add `deletePhraseFromCategory` method to delete a phrase from a category. * **EditCategoryPhrasesViewModel.kt** - Add `deletePhrase` method to delete a phrase from a category. - Update constructor to make `phrasesUseCase` a private property. --- .../vocable/settings/EditCategoryPhrasesViewModel.kt | 12 ++++++++++-- .../CustomCategoryPhraseViewModel.kt | 8 +++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/willowtree/vocable/settings/EditCategoryPhrasesViewModel.kt b/app/src/main/java/com/willowtree/vocable/settings/EditCategoryPhrasesViewModel.kt index 7544b057..8ba7a36e 100644 --- a/app/src/main/java/com/willowtree/vocable/settings/EditCategoryPhrasesViewModel.kt +++ b/app/src/main/java/com/willowtree/vocable/settings/EditCategoryPhrasesViewModel.kt @@ -4,14 +4,16 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.asLiveData +import androidx.lifecycle.viewModelScope import com.willowtree.vocable.IPhrasesUseCase import com.willowtree.vocable.presets.Category import com.willowtree.vocable.presets.Phrase import com.willowtree.vocable.utils.ILocalizedResourceUtility +import kotlinx.coroutines.launch class EditCategoryPhrasesViewModel( savedStateHandle: SavedStateHandle, - phrasesUseCase: IPhrasesUseCase, + private val phrasesUseCase: IPhrasesUseCase, private val localizedResourceUtility: ILocalizedResourceUtility ) : ViewModel() { @@ -21,4 +23,10 @@ class EditCategoryPhrasesViewModel( fun getCategoryName(category: Category): String { return localizedResourceUtility.getTextFromCategory(category) } -} \ No newline at end of file + + fun deletePhrase(phrase: Phrase) { + viewModelScope.launch { + phrasesUseCase.deletePhrase(phrase.phraseId) + } + } +} diff --git a/app/src/main/java/com/willowtree/vocable/settings/customcategories/CustomCategoryPhraseViewModel.kt b/app/src/main/java/com/willowtree/vocable/settings/customcategories/CustomCategoryPhraseViewModel.kt index 65d75ad6..4e7c425a 100644 --- a/app/src/main/java/com/willowtree/vocable/settings/customcategories/CustomCategoryPhraseViewModel.kt +++ b/app/src/main/java/com/willowtree/vocable/settings/customcategories/CustomCategoryPhraseViewModel.kt @@ -14,4 +14,10 @@ class CustomCategoryPhraseViewModel( phrasesUseCase.deletePhrase(phrase.phraseId) } } -} \ No newline at end of file + + fun deletePhraseFromCategory(phrase: Phrase) { + viewModelScope.launch { + phrasesUseCase.deletePhrase(phrase.phraseId) + } + } +}