Skip to content

Commit

Permalink
Fix delete phrase bug (#565)
Browse files Browse the repository at this point in the history
Maybe fixes #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.
  • Loading branch information
imbeyondboredom committed Nov 22, 2024
1 parent 53c6671 commit af0c4de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -21,4 +23,10 @@ class EditCategoryPhrasesViewModel(
fun getCategoryName(category: Category): String {
return localizedResourceUtility.getTextFromCategory(category)
}
}

fun deletePhrase(phrase: Phrase) {
viewModelScope.launch {
phrasesUseCase.deletePhrase(phrase.phraseId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ class CustomCategoryPhraseViewModel(
phrasesUseCase.deletePhrase(phrase.phraseId)
}
}
}

fun deletePhraseFromCategory(phrase: Phrase) {
viewModelScope.launch {
phrasesUseCase.deletePhrase(phrase.phraseId)
}
}
}

0 comments on commit af0c4de

Please sign in to comment.