Skip to content

Commit

Permalink
Add search history clear all confirmation dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ashiagr committed Feb 10, 2023
1 parent 9451d70 commit d3f5f06
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import au.com.shiftyjelly.pocketcasts.models.to.SearchHistoryEntry
import au.com.shiftyjelly.pocketcasts.search.SearchViewModel.SearchResultType
import au.com.shiftyjelly.pocketcasts.search.adapter.PodcastSearchAdapter
import au.com.shiftyjelly.pocketcasts.search.databinding.FragmentSearchBinding
import au.com.shiftyjelly.pocketcasts.search.searchhistory.SearchHistoryClearAllConfirmationDialog
import au.com.shiftyjelly.pocketcasts.search.searchhistory.SearchHistoryPage
import au.com.shiftyjelly.pocketcasts.search.searchhistory.SearchHistoryViewModel
import au.com.shiftyjelly.pocketcasts.ui.extensions.getThemeColor
Expand All @@ -36,6 +37,7 @@ import au.com.shiftyjelly.pocketcasts.ui.R as UR
private const val ARG_FLOATING = "arg_floating"
private const val ARG_ONLY_SEARCH_REMOTE = "arg_only_search_remote"
private const val ARG_SOURCE = "arg_source"
private const val SEARCH_HISTORY_CLEAR_ALL_CONFIRMATION_DIALOG_TAG = "search_history_clear_all_confirmation_dialog"

@AndroidEntryPoint
class SearchFragment : BaseFragment() {
Expand Down Expand Up @@ -230,7 +232,13 @@ class SearchFragment : BaseFragment() {
AppTheme(theme.activeTheme) {
SearchHistoryPage(
viewModel = searchHistoryViewModel,
onClick = ::navigateFromSearchHistoryEntry
onClick = ::navigateFromSearchHistoryEntry,
onShowClearAllConfirmation = {
SearchHistoryClearAllConfirmationDialog(
context = this@SearchFragment.requireContext(),
onConfirm = { searchHistoryViewModel.clearAll() }
).show(parentFragmentManager, SEARCH_HISTORY_CLEAR_ALL_CONFIRMATION_DIALOG_TAG)
}
)
if (viewModel.isFragmentChangingConfigurations && viewModel.showSearchHistory) {
binding.searchHistoryPanel.show()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package au.com.shiftyjelly.pocketcasts.search.searchhistory

import android.content.Context
import au.com.shiftyjelly.pocketcasts.views.dialog.ConfirmationDialog
import au.com.shiftyjelly.pocketcasts.localization.R as LR
import au.com.shiftyjelly.pocketcasts.views.R as VR

class SearchHistoryClearAllConfirmationDialog(
context: Context,
onConfirm: () -> Unit,
) : ConfirmationDialog() {
init {
setTitle(context.getString(LR.string.clear_all))
setSummary(context.getString(LR.string.search_history_clear_all_confirmation_message))
setIconId(VR.drawable.ic_delete)
setButtonType(ButtonType.Danger(context.getString(LR.string.delete)))
setOnConfirm { onConfirm() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,24 @@ import au.com.shiftyjelly.pocketcasts.images.R as IR
import au.com.shiftyjelly.pocketcasts.localization.R as LR

private val IconSize = 64.dp
private const val CLEAR_ALL_THRESHOLD = 3
@Composable
internal fun SearchHistoryPage(
viewModel: SearchHistoryViewModel,
onClick: (SearchHistoryEntry) -> Unit,
onShowClearAllConfirmation: () -> Unit,
) {
val state by viewModel.state.collectAsState()
SearchHistoryView(
state = state,
onCloseClick = { viewModel.remove(it) },
onClearAllClick = { viewModel.clearAll() },
onClearAllClick = {
if (state.entries.size > CLEAR_ALL_THRESHOLD) {
onShowClearAllConfirmation()
} else {
viewModel.clearAll()
}
},
onRowClick = onClick,
)
viewModel.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
<string name="search_no_podcasts_found_summary">Try more general or different keywords.</string>
<string name="search_podcasts">Search podcasts</string>
<string name="search_hint">Search by podcast name</string>
<string name="search_history_clear_all_confirmation_message">Are you sure you want to clear all your search history?</string>
<string name="search_history_recent_searches">Recent searches</string>

<string name="time_short_hours">%dh</string>
Expand Down

0 comments on commit d3f5f06

Please sign in to comment.