From 10128248353c49b1f37e82b60e22873026d49b79 Mon Sep 17 00:00:00 2001 From: Paul Klauser Date: Wed, 12 Jun 2024 11:42:56 -0400 Subject: [PATCH] Fix race condition in updated phrase not immediately showing in settings --- .../com/willowtree/vocable/AppKoinModule.kt | 2 ++ .../settings/EditCategoryPhrasesViewModel.kt | 10 +--------- .../CustomCategoryPhraseListFragment.kt | 5 ++--- .../CustomCategoryPhraseViewModel.kt | 17 +++++++++++++++++ .../utils/VocableFragmentStateAdapter.kt | 1 + 5 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/com/willowtree/vocable/settings/customcategories/CustomCategoryPhraseViewModel.kt diff --git a/app/src/main/java/com/willowtree/vocable/AppKoinModule.kt b/app/src/main/java/com/willowtree/vocable/AppKoinModule.kt index 7f1332d3..82c7f3af 100644 --- a/app/src/main/java/com/willowtree/vocable/AppKoinModule.kt +++ b/app/src/main/java/com/willowtree/vocable/AppKoinModule.kt @@ -19,6 +19,7 @@ import com.willowtree.vocable.settings.AddUpdateCategoryViewModel import com.willowtree.vocable.settings.EditCategoriesViewModel import com.willowtree.vocable.settings.EditCategoryMenuViewModel import com.willowtree.vocable.settings.EditCategoryPhrasesViewModel +import com.willowtree.vocable.settings.customcategories.CustomCategoryPhraseViewModel import com.willowtree.vocable.settings.selectionmode.SelectionModeViewModel import com.willowtree.vocable.splash.SplashActivity import com.willowtree.vocable.splash.SplashViewModel @@ -106,4 +107,5 @@ val vocableKoinModule = module { viewModel { EditCategoryPhrasesViewModel(get(), get(), get()) } viewModel { AddUpdateCategoryViewModel(get(), get(), get()) } viewModel { EditCategoryMenuViewModel(get()) } + viewModel { CustomCategoryPhraseViewModel(get()) } } \ No newline at end of file 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 264f35e3..7544b057 100644 --- a/app/src/main/java/com/willowtree/vocable/settings/EditCategoryPhrasesViewModel.kt +++ b/app/src/main/java/com/willowtree/vocable/settings/EditCategoryPhrasesViewModel.kt @@ -4,16 +4,14 @@ 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, - private val phrasesUseCase: IPhrasesUseCase, + phrasesUseCase: IPhrasesUseCase, private val localizedResourceUtility: ILocalizedResourceUtility ) : ViewModel() { @@ -23,10 +21,4 @@ class EditCategoryPhrasesViewModel( fun getCategoryName(category: Category): String { return localizedResourceUtility.getTextFromCategory(category) } - - fun deletePhraseFromCategory(phrase: Phrase) { - viewModelScope.launch { - phrasesUseCase.deletePhrase(phrase.phraseId) - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/willowtree/vocable/settings/customcategories/CustomCategoryPhraseListFragment.kt b/app/src/main/java/com/willowtree/vocable/settings/customcategories/CustomCategoryPhraseListFragment.kt index 00bd5231..6ea8d4b1 100644 --- a/app/src/main/java/com/willowtree/vocable/settings/customcategories/CustomCategoryPhraseListFragment.kt +++ b/app/src/main/java/com/willowtree/vocable/settings/customcategories/CustomCategoryPhraseListFragment.kt @@ -13,7 +13,6 @@ import com.willowtree.vocable.databinding.FragmentCustomCategoryPhraseListBindin import com.willowtree.vocable.presets.Category import com.willowtree.vocable.presets.Phrase import com.willowtree.vocable.settings.EditCategoryPhrasesFragmentDirections -import com.willowtree.vocable.settings.EditCategoryPhrasesViewModel import com.willowtree.vocable.settings.customcategories.adapter.CustomCategoryPhraseAdapter import com.willowtree.vocable.utils.ItemOffsetDecoration import org.koin.androidx.viewmodel.ext.android.viewModel @@ -34,7 +33,7 @@ class CustomCategoryPhraseListFragment : BaseFragment @@ -88,7 +87,7 @@ class CustomCategoryPhraseListFragment : BaseFragment(fm: FragmentManager, lifecycle: Li with(this.items) { clear() addAll(items) + notifyDataSetChanged() } val oldNumPages = numPages