@ -2,6 +2,7 @@ package org.koitharu.kotatsu.settings
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.preference.Preference
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.Dispatchers
@ -87,16 +88,7 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
true
}
AppSettings . KEY _SEARCH _HISTORY _CLEAR -> {
viewLifecycleScope . launch {
searchRepository . clearSearchHistory ( )
preference . summary = preference . context . resources
. getQuantityString ( R . plurals . items , 0 , 0 )
Snackbar . make (
view ?: return @launch ,
R . string . search _history _cleared ,
Snackbar . LENGTH _SHORT
) . show ( )
}
clearSearchHistory ( preference )
true
}
AppSettings . KEY _UPDATES _FEED _CLEAR -> {
@ -133,4 +125,23 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
}
}
}
private fun clearSearchHistory ( preference : Preference ) {
AlertDialog . Builder ( context ?: return )
. setTitle ( R . string . clear _search _history )
. setMessage ( R . string . text _clear _search _history _prompt )
. setNegativeButton ( android . R . string . cancel , null )
. setPositiveButton ( R . string . clear ) { _ , _ ->
viewLifecycleScope . launch {
searchRepository . clearSearchHistory ( )
preference . summary = preference . context . resources
. getQuantityString ( R . plurals . items , 0 , 0 )
Snackbar . make (
view ?: return @launch ,
R . string . search _history _cleared ,
Snackbar . LENGTH _SHORT
) . show ( )
}
} . show ( )
}
}