delete bookmarks and watch history

This commit is contained in:
LagradOst 2022-07-29 17:51:28 +02:00
parent 65f9c71c44
commit 0c4a73a72f
3 changed files with 81 additions and 7 deletions

View file

@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.ui.home
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.res.Configuration
import android.net.Uri
@ -11,6 +12,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SearchView
import androidx.core.view.isGone
import androidx.core.view.isVisible
@ -50,6 +52,8 @@ import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult
import com.lagradost.cloudstream3.utils.DataStore.getKey
import com.lagradost.cloudstream3.utils.DataStore.setKey
import com.lagradost.cloudstream3.utils.DataStoreHelper
import com.lagradost.cloudstream3.utils.DataStoreHelper.deleteAllBookmarkedData
import com.lagradost.cloudstream3.utils.DataStoreHelper.deleteAllResumeStateIds
import com.lagradost.cloudstream3.utils.DataStoreHelper.removeLastWatched
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultWatchState
import com.lagradost.cloudstream3.utils.Event
@ -91,6 +95,7 @@ import kotlinx.android.synthetic.main.fragment_home.home_watch_holder
import kotlinx.android.synthetic.main.fragment_home.home_watch_parent_item_title
import kotlinx.android.synthetic.main.fragment_home.result_error_text
import kotlinx.android.synthetic.main.fragment_home_tv.*
import kotlinx.android.synthetic.main.home_episodes_expanded.*
import java.util.*
const val HOME_BOOKMARK_VALUE_LIST = "home_bookmarked_last_list"
@ -117,7 +122,7 @@ class HomeFragment : Fragment() {
val errorProfilePic = errorProfilePics.random()
fun Activity.loadHomepageList(item: HomePageList) {
fun Activity.loadHomepageList(item: HomePageList, deleteCallback: (() -> Unit)? = null) {
val context = this
val bottomSheetDialogBuilder = BottomSheetDialog(context)
bottomSheetDialogBuilder.setContentView(R.layout.home_episodes_expanded)
@ -128,10 +133,44 @@ class HomeFragment : Fragment() {
val titleHolder =
bottomSheetDialogBuilder.findViewById<FrameLayout>(R.id.home_expanded_drag_down)!!
val delete = bottomSheetDialogBuilder.home_expanded_delete
delete.isGone = deleteCallback == null
if (deleteCallback != null) {
delete.setOnClickListener {
try {
val builder: AlertDialog.Builder = AlertDialog.Builder(context)
val dialogClickListener =
DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_POSITIVE -> {
deleteCallback.invoke()
bottomSheetDialogBuilder.dismissSafe(this)
}
DialogInterface.BUTTON_NEGATIVE -> {}
}
}
builder.setTitle(R.string.delete_file)
.setMessage(
context.getString(R.string.delete_message).format(
item.name
)
)
.setPositiveButton(R.string.delete, dialogClickListener)
.setNegativeButton(R.string.cancel, dialogClickListener)
.show()
} catch (e: Exception) {
logError(e)
// ye you somehow fucked up formatting did you?
}
}
}
titleHolder.setOnClickListener {
bottomSheetDialogBuilder.dismissSafe(this)
}
// Span settings
recycle.spanCount = currentSpan
@ -642,7 +681,10 @@ class HomeFragment : Fragment() {
getString(R.string.error_bookmarks_text), //home_bookmarked_parent_item_title?.text?.toString() ?: getString(R.string.error_bookmarks_text),
bookmarks
)
)
) {
deleteAllBookmarkedData()
homeViewModel.loadStoredData(null)
}
}
}
@ -665,7 +707,10 @@ class HomeFragment : Fragment() {
?: getString(R.string.continue_watching),
resumeWatching
)
)
) {
deleteAllResumeStateIds()
homeViewModel.loadResumeWatching()
}
}
}

View file

@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
import com.lagradost.cloudstream3.AcraApplication.Companion.getKeys
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKeys
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
import com.lagradost.cloudstream3.DubStatus
import com.lagradost.cloudstream3.SearchQuality
@ -76,6 +77,18 @@ object DataStoreHelper {
}
}
fun deleteAllResumeStateIds() {
val folder = "$currentAccount/$RESULT_RESUME_WATCHING"
removeKeys(folder)
}
fun deleteAllBookmarkedData() {
val folder1 = "$currentAccount/$RESULT_WATCH_STATE"
val folder2 = "$currentAccount/$RESULT_WATCH_STATE_DATA"
removeKeys(folder1)
removeKeys(folder2)
}
fun getAllResumeStateIds(): List<Int>? {
val folder = "$currentAccount/$RESULT_RESUME_WATCHING"
return getKeys(folder)?.mapNotNull {

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="?attr/primaryGrayBackground"
@ -17,10 +18,25 @@
<requestFocus />
<TextView
android:id="@+id/home_expanded_text"
style="@style/WatchHeaderText"
tools:text="Trending" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
app:tint="?attr/textColor"
android:id="@+id/home_expanded_delete"
android:layout_marginEnd="10dp"
android:layout_gravity="start|center_vertical"
android:src="@drawable/ic_baseline_delete_outline_24"
android:layout_width="30dp"
android:layout_height="match_parent"
android:contentDescription="@string/delete" />
<TextView
android:id="@+id/home_expanded_text"
style="@style/WatchHeaderText"
tools:text="Trending" />
</LinearLayout>
<ImageView
android:layout_marginEnd="5dp"