Skip to content

Commit

Permalink
Update project icon in main menu after returning from Admin Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed May 5, 2021
1 parent fc9da78 commit 2883101
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected void onResume() {
mainMenuViewModel.resume();

setButtonsVisibility();
invalidateOptionsMenu();
currentProjectViewModel.refresh();
}

private void setButtonsVisibility() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> = _currentProject
Expand All @@ -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 <T : ViewModel?> create(modelClass: Class<T>): T {
return CurrentProjectViewModel(currentProjectProvider) as T
Expand Down

0 comments on commit 2883101

Please sign in to comment.