Skip to content

Commit

Permalink
Make dateSelector parameter nullable in StatsListViewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
irfano committed Jan 30, 2024
1 parent 71322d6 commit 0a04666
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Event<NavigationTarget>>()
val navigationTarget: LiveData<Event<NavigationTarget>> = mergeNotNull(
Expand All @@ -85,9 +85,9 @@ abstract class StatsListViewModel(
statsUseCase.data.throttle(viewModelScope, distinct = true)
}

val dateSelectorData: LiveData<DateSelectorUiModel> = dateSelector.dateSelectorData.mapNullable {
val dateSelectorData: LiveData<DateSelectorUiModel> = dateSelector?.dateSelectorData?.mapNullable {
it ?: DateSelectorUiModel(false)
}
} ?: MutableLiveData(DateSelectorUiModel(false))

val typesChanged = merge(
popupMenuHandler?.typeMoved,
Expand Down Expand Up @@ -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()
}
}

Expand All @@ -138,7 +138,7 @@ abstract class StatsListViewModel(
}

fun onListSelected() {
dateSelector.updateDateSelector()
dateSelector?.updateDateSelector()
}

fun onEmptyInsightsButtonClicked() {
Expand All @@ -156,10 +156,10 @@ abstract class StatsListViewModel(
isInitialized = true
launch {
statsUseCase.loadData()
dateSelector.updateDateSelector()
dateSelector?.updateDateSelector()
}
}
dateSelector.updateDateSelector()
dateSelector?.updateDateSelector()
}

sealed class UiModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class DetailListViewModel
) : StatsListViewModel(mainDispatcher, detailUseCase, analyticsTracker, dateSelectorFactory.build(DETAIL)) {
override fun onCleared() {
super.onCleared()
dateSelector.clear()
dateSelector?.clear()
}
}

0 comments on commit 0a04666

Please sign in to comment.