restore clear buttons

This commit is contained in:
Bnyro 2022-08-13 22:51:32 +02:00
parent 7c95f5f252
commit 7d993fcd5c
6 changed files with 32 additions and 12 deletions

View File

@ -17,4 +17,7 @@ interface CustomInstanceDao {
@Delete
fun delete(customInstance: CustomInstance)
@Query("DELETE FROM customInstance")
fun deleteAll()
}

View File

@ -17,4 +17,7 @@ interface SearchHistoryDao {
@Delete
fun delete(searchHistoryItem: SearchHistoryItem)
@Query("DELETE FROM searchHistoryItem")
fun deleteAll()
}

View File

@ -20,4 +20,7 @@ interface WatchHistoryDao {
@Delete
fun delete(watchHistoryItem: WatchHistoryItem)
@Query("DELETE FROM watchHistoryItem")
fun deleteAll()
}

View File

@ -20,4 +20,7 @@ interface WatchPositionDao {
@Delete
fun delete(watchPosition: WatchPosition)
@Query("DELETE FROM watchPosition")
fun deleteAll()
}

View File

@ -4,6 +4,7 @@ import android.os.Bundle
import androidx.preference.Preference
import com.github.libretube.R
import com.github.libretube.activities.SettingsActivity
import com.github.libretube.database.DatabaseHolder
import com.github.libretube.views.MaterialPreferenceFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -18,33 +19,41 @@ class HistorySettings : MaterialPreferenceFragment() {
// clear search history
val clearHistory = findPreference<Preference>(PreferenceKeys.CLEAR_SEARCH_HISTORY)
clearHistory?.setOnPreferenceClickListener {
showClearDialog(R.string.clear_history, "search_history")
showClearDialog(R.string.clear_history) {
DatabaseHolder.database.searchHistoryDao().deleteAll()
}
true
}
// clear watch history and positions
val clearWatchHistory = findPreference<Preference>(PreferenceKeys.CLEAR_WATCH_HISTORY)
clearWatchHistory?.setOnPreferenceClickListener {
showClearDialog(R.string.clear_history, "watch_history")
showClearDialog(R.string.clear_history) {
DatabaseHolder.database.watchHistoryDao().deleteAll()
}
true
}
// clear watch positions
val clearWatchPositions = findPreference<Preference>(PreferenceKeys.CLEAR_WATCH_POSITIONS)
clearWatchPositions?.setOnPreferenceClickListener {
showClearDialog(R.string.reset_watch_positions, "watch_positions")
showClearDialog(R.string.reset_watch_positions) {
DatabaseHolder.database.watchPositionDao().deleteAll()
}
true
}
}
private fun showClearDialog(title: Int, preferenceKey: String) {
private fun showClearDialog(title: Int, action: () -> Unit) {
MaterialAlertDialogBuilder(requireContext())
.setTitle(title)
.setMessage(R.string.irreversible)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.okay) { _, _ ->
// clear the selected preference preferences
PreferenceHelper.removePreference(preferenceKey)
Thread {
action()
}.start()
}
.show()
}

View File

@ -18,6 +18,7 @@ import com.github.libretube.dialogs.CustomInstanceDialog
import com.github.libretube.dialogs.DeleteAccountDialog
import com.github.libretube.dialogs.LoginDialog
import com.github.libretube.dialogs.LogoutDialog
import com.github.libretube.extensions.await
import com.github.libretube.obj.CustomInstance
import com.github.libretube.util.ImportHelper
import com.github.libretube.util.PermissionHelper
@ -106,9 +107,10 @@ class InstanceSettings : MaterialPreferenceFragment() {
val clearCustomInstances = findPreference<Preference>(PreferenceKeys.CLEAR_CUSTOM_INSTANCES)
clearCustomInstances?.setOnPreferenceClickListener {
PreferenceHelper.removePreference("customInstances")
val intent = Intent(context, SettingsActivity::class.java)
startActivity(intent)
Thread {
DatabaseHolder.database.customInstanceDao().deleteAll()
}.await()
activity?.recreate()
true
}
@ -162,10 +164,7 @@ class InstanceSettings : MaterialPreferenceFragment() {
var customInstances = listOf<CustomInstance>()
Thread {
customInstances = DatabaseHolder.database.customInstanceDao().getAll()
}.apply {
start()
join()
}
}.await()
val instanceNames = arrayListOf<String>()
val instanceValues = arrayListOf<String>()