[Feature] Add button on General setting to clear watch history.

This commit is contained in:
Jace 2022-10-16 14:27:08 +08:00
parent cf08c958eb
commit f0bea10a2a
4 changed files with 47 additions and 1 deletions

View file

@ -29,6 +29,8 @@ import com.lagradost.cloudstream3.ui.EasterEggMonke
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.utils.DataStore.removeKeys
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showDialog
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog
@ -331,6 +333,36 @@ class SettingsGeneral : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true
}
getPref(R.string.key_clear_watching)?.setOnPreferenceClickListener {
val builder: AlertDialog.Builder =
AlertDialog.Builder(it.context, R.style.AlertDialogCustom)
builder.setTitle(R.string.clear_watching_pref)
builder.setMessage(R.string.clear_watching_prompt)
builder.setPositiveButton(getString(R.string.yes)
) { dialog, which -> // Clear Watch History data
var doneClearMessage = R.string.clear_watching_done
try {
it.context.removeKeys("${DataStoreHelper.currentAccount}/$RESULT_RESUME_WATCHING")
it.context.removeKeys("${DataStoreHelper.currentAccount}/$RESULT_RESUME_WATCHING_OLD")
} catch (e: Exception) {
logError(e)
doneClearMessage = R.string.clear_watching_error
}
dialog.dismiss()
val newBuilder = AlertDialog.Builder(it.context, R.style.AlertDialogCustom)
newBuilder.setTitle(R.string.clear_watching_pref)
newBuilder.setMessage(doneClearMessage)
newBuilder.show()
}
builder.setNegativeButton(getString(R.string.no)
) { dialog, which -> // Do nothing but close the dialog
dialog.dismiss()
}
builder.show()
return@setOnPreferenceClickListener true
}
try {
SettingsFragment.beneneCount =
settingsManager.getInt(getString(R.string.benene_count), 0)

View file

@ -69,7 +69,7 @@ object DataStoreHelper {
@JsonProperty("posterHeaders") override var posterHeaders: Map<String, String>? = null,
) : SearchResponse
private var currentAccount: String = "0" //TODO ACCOUNT IMPLEMENTATION
var currentAccount: String = "0" //TODO ACCOUNT IMPLEMENTATION
fun getAllWatchStateIds(): List<Int>? {
val folder = "$currentAccount/$RESULT_WATCH_STATE"

View file

@ -57,6 +57,7 @@
<string name="filter_sub_lang_key" translatable="false">filter_sub_lang_key</string>
<string name="pref_filter_search_quality_key" translatable="false">pref_filter_search_quality_key</string>
<string name="enable_nsfw_on_providers_key" translatable="false">enable_nsfw_on_providers_key</string>
<string name="key_clear_watching" translatable="false">key_clear_watching</string>
<!-- FORMAT MIGHT TRANSLATE, WILL CAUSE CRASH IF APPLIED WRONG -->
<string name="extra_info_format" formatted="true" translatable="false">%d %s | %s</string>
@ -413,6 +414,11 @@
<string name="add_site_summary">Add a clone of an existing site, with a different url</string>
<string name="download_path_pref">Download path</string>
<string name="clear_watching_pref">Clear Watch History</string>
<string name="clear_watching_summ">Clear \'Continue Watching\' history.</string>
<string name="clear_watching_prompt">Are you sure you want to clear watch history?</string>
<string name="clear_watching_done">Watch history successfully cleared!</string>
<string name="clear_watching_error">Failed to clear watch history!</string>
<string name="nginx_url_pref">Nginx server url</string>
@ -501,6 +507,8 @@
<string name="authenticated_user_fail" formatted="true">Failed to authenticate to %s</string>
<!-- ============ -->
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="none">None</string>
<string name="normal">Normal</string>
<string name="all">All</string>

View file

@ -23,6 +23,12 @@
android:title="@string/download_path_pref"
android:icon="@drawable/netflix_download" />
<Preference
android:key="@string/key_clear_watching"
android:title="@string/clear_watching_pref"
android:icon="@drawable/ic_baseline_playlist_play_24"
app:summary="@string/clear_watching_summ" />
<Preference
android:key="@string/legal_notice_key"
android:title="@string/legal_notice"