diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index 8169b738f924..30ca269635ce 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -243,7 +243,7 @@ class StatsListFragment : ViewPagerFragment(R.layout.stats_list_fragment) { navigator.navigate(activity, target) } - viewModel.selectedDate.observe(viewLifecycleOwner) { event -> + viewModel.selectedDate?.observe(viewLifecycleOwner) { event -> if (event != null) { viewModel.onDateChanged(event.selectedSection) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt index 386a6575a3a7..a3b14286a6f8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListViewModel.kt @@ -49,7 +49,7 @@ abstract class StatsListViewModel( defaultDispatcher: CoroutineDispatcher, private val statsUseCase: BaseListUseCase, private val analyticsTracker: AnalyticsTrackerWrapper, - protected val dateSelector: StatsDateSelector, + protected val dateSelector: StatsDateSelector?, popupMenuHandler: ItemPopupMenuHandler? = null, private val newsCardHandler: NewsCardHandler? = null, actionCardHandler: ActionCardHandler? = null @@ -72,7 +72,7 @@ abstract class StatsListViewModel( ANNUAL_STATS(R.string.stats_insights_annual_site_stats); } - val selectedDate = dateSelector.selectedDate + val selectedDate = dateSelector?.selectedDate private val mutableNavigationTarget = MutableLiveData>() val navigationTarget: LiveData> = mergeNotNull( @@ -85,9 +85,9 @@ abstract class StatsListViewModel( statsUseCase.data.throttle(viewModelScope, distinct = true) } - val dateSelectorData: LiveData = dateSelector.dateSelectorData.mapNullable { + val dateSelectorData: LiveData = dateSelector?.dateSelectorData?.mapNullable { it ?: DateSelectorUiModel(false) - } + } ?: MutableLiveData(DateSelectorUiModel(false)) val typesChanged = merge( popupMenuHandler?.typeMoved, @@ -115,13 +115,13 @@ abstract class StatsListViewModel( fun onNextDateSelected() { launch(Dispatchers.Default) { - dateSelector.onNextDateSelected() + dateSelector?.onNextDateSelected() } } fun onPreviousDateSelected() { launch(Dispatchers.Default) { - dateSelector.onPreviousDateSelected() + dateSelector?.onPreviousDateSelected() } } @@ -138,7 +138,7 @@ abstract class StatsListViewModel( } fun onListSelected() { - dateSelector.updateDateSelector() + dateSelector?.updateDateSelector() } fun onEmptyInsightsButtonClicked() { @@ -156,10 +156,10 @@ abstract class StatsListViewModel( isInitialized = true launch { statsUseCase.loadData() - dateSelector.updateDateSelector() + dateSelector?.updateDateSelector() } } - dateSelector.updateDateSelector() + dateSelector?.updateDateSelector() } sealed class UiModel { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/DetailListViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/DetailListViewModel.kt index 553ff06d2997..23199d7b74f4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/DetailListViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/DetailListViewModel.kt @@ -20,6 +20,6 @@ class DetailListViewModel ) : StatsListViewModel(mainDispatcher, detailUseCase, analyticsTracker, dateSelectorFactory.build(DETAIL)) { override fun onCleared() { super.onCleared() - dateSelector.clear() + dateSelector?.clear() } }