Hide clear history action menu item when total count is zero.

This commit is contained in:
Alex Hart 2023-06-07 14:25:48 -03:00
parent 7e0e6c2786
commit b0c4bb04e7
2 changed files with 5 additions and 0 deletions

View file

@ -84,6 +84,7 @@ class CallLogFragment : Fragment(R.layout.call_log_fragment), CallLogAdapter.Cal
val isFiltered = viewModel.filterSnapshot == CallLogFilter.MISSED
menu.findItem(R.id.action_clear_missed_call_filter).isVisible = isFiltered
menu.findItem(R.id.action_filter_missed_calls).isVisible = !isFiltered
menu.findItem(R.id.action_clear_call_history).isVisible = !viewModel.isEmpty
}
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {

View file

@ -40,8 +40,12 @@ class CallLogViewModel(
.stateFlowable
.map { it.selectionState to it.stagedDeletion }
private val _isEmpty: BehaviorProcessor<Boolean> = BehaviorProcessor.createDefault(false)
val isEmpty: Boolean get() = _isEmpty.value ?: false
val totalCount: Flowable<Int> = Flowable.combineLatest(distinctQueryFilterPairs, data) { a, _ -> a }
.map { (query, filter) -> callLogRepository.getCallsCount(query, filter) }
.doOnNext { _isEmpty.onNext(it <= 0) }
val selectionStateSnapshot: CallLogSelectionState
get() = callLogStore.state.selectionState