From 2883101013a940086900f104c998ca6e76eacdf6 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Wed, 28 Apr 2021 19:48:48 +0200 Subject: [PATCH] Update project icon in main menu after returning from Admin Settings --- .../odk/collect/android/activities/MainMenuActivity.java | 2 +- .../activities/viewmodels/CurrentProjectViewModel.kt | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/MainMenuActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/MainMenuActivity.java index 0cd97867ca1..1fb08f75e07 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/MainMenuActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/MainMenuActivity.java @@ -212,7 +212,7 @@ protected void onResume() { mainMenuViewModel.resume(); setButtonsVisibility(); - invalidateOptionsMenu(); + currentProjectViewModel.refresh(); } private void setButtonsVisibility() { diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/viewmodels/CurrentProjectViewModel.kt b/collect_app/src/main/java/org/odk/collect/android/activities/viewmodels/CurrentProjectViewModel.kt index 4f4a8dca0e8..32410ee890a 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/viewmodels/CurrentProjectViewModel.kt +++ b/collect_app/src/main/java/org/odk/collect/android/activities/viewmodels/CurrentProjectViewModel.kt @@ -7,7 +7,7 @@ import androidx.lifecycle.ViewModelProvider import org.odk.collect.android.projects.CurrentProjectProvider import org.odk.collect.projects.Project -class CurrentProjectViewModel(currentProjectProvider: CurrentProjectProvider) : ViewModel() { +class CurrentProjectViewModel(private val currentProjectProvider: CurrentProjectProvider) : ViewModel() { private val _currentProject = MutableLiveData(currentProjectProvider.getCurrentProject()!!) val currentProject: LiveData = _currentProject @@ -16,6 +16,12 @@ class CurrentProjectViewModel(currentProjectProvider: CurrentProjectProvider) : _currentProject.postValue(project) } + fun refresh() { + if (currentProject.value != currentProjectProvider.getCurrentProject()) { + _currentProject.postValue(currentProjectProvider.getCurrentProject()) + } + } + open class Factory constructor(private val currentProjectProvider: CurrentProjectProvider) : ViewModelProvider.Factory { override fun create(modelClass: Class): T { return CurrentProjectViewModel(currentProjectProvider) as T