Prompt before search history clear
This commit is contained in:
@@ -2,6 +2,7 @@ package org.koitharu.kotatsu.settings
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -87,16 +88,7 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
AppSettings.KEY_SEARCH_HISTORY_CLEAR -> {
|
AppSettings.KEY_SEARCH_HISTORY_CLEAR -> {
|
||||||
viewLifecycleScope.launch {
|
clearSearchHistory(preference)
|
||||||
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()
|
|
||||||
}
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
AppSettings.KEY_UPDATES_FEED_CLEAR -> {
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -210,4 +210,5 @@
|
|||||||
<string name="other">Другие</string>
|
<string name="other">Другие</string>
|
||||||
<string name="languages">Языки</string>
|
<string name="languages">Языки</string>
|
||||||
<string name="welcome">Добро пожаловать</string>
|
<string name="welcome">Добро пожаловать</string>
|
||||||
|
<string name="text_clear_search_history_prompt">Вы действительно хотите удалить все недавние поисковые запросы? Это действие не может быть отменено.</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user