feat: Added anime clear progress (#531)
* feat: Added anime clear progress * more stuff added
This commit is contained in:
parent
ff3372754a
commit
d01e1c89e0
6 changed files with 142 additions and 9 deletions
|
@ -9,6 +9,7 @@ import android.widget.ArrayAdapter
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.content.ContextCompat.getString
|
||||||
import androidx.core.content.ContextCompat.startActivity
|
import androidx.core.content.ContextCompat.startActivity
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
@ -17,6 +18,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||||
import ani.dantotsu.FileUrl
|
import ani.dantotsu.FileUrl
|
||||||
import ani.dantotsu.R
|
import ani.dantotsu.R
|
||||||
import ani.dantotsu.currActivity
|
import ani.dantotsu.currActivity
|
||||||
|
import ani.dantotsu.currContext
|
||||||
import ani.dantotsu.databinding.DialogLayoutBinding
|
import ani.dantotsu.databinding.DialogLayoutBinding
|
||||||
import ani.dantotsu.databinding.ItemMediaSourceBinding
|
import ani.dantotsu.databinding.ItemMediaSourceBinding
|
||||||
import ani.dantotsu.databinding.ItemChipBinding
|
import ani.dantotsu.databinding.ItemChipBinding
|
||||||
|
@ -38,6 +40,7 @@ import ani.dantotsu.px
|
||||||
import ani.dantotsu.settings.FAQActivity
|
import ani.dantotsu.settings.FAQActivity
|
||||||
import ani.dantotsu.settings.saving.PrefManager
|
import ani.dantotsu.settings.saving.PrefManager
|
||||||
import ani.dantotsu.settings.saving.PrefName
|
import ani.dantotsu.settings.saving.PrefName
|
||||||
|
import ani.dantotsu.snackString
|
||||||
import ani.dantotsu.toast
|
import ani.dantotsu.toast
|
||||||
import ani.dantotsu.util.customAlertDialog
|
import ani.dantotsu.util.customAlertDialog
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
|
@ -278,6 +281,26 @@ class AnimeWatchAdapter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
resetProgress.setOnClickListener {
|
||||||
|
fragment.requireContext().customAlertDialog().apply {
|
||||||
|
setTitle(" Delete Progress for all episodes of ${media.nameRomaji}")
|
||||||
|
setMessage("This will delete all the locally stored progress for all episodes")
|
||||||
|
setPosButton(R.string.ok){
|
||||||
|
val prefix = "${media.id}_"
|
||||||
|
val regex = Regex("^${prefix}\\d+$")
|
||||||
|
|
||||||
|
PrefManager.getAllCustomValsForMedia(prefix)
|
||||||
|
.keys
|
||||||
|
.filter { it.matches(regex) }
|
||||||
|
.onEach { key -> PrefManager.removeCustomVal(key) }
|
||||||
|
snackString("Deleted the progress of all Episodes for ${media.nameRomaji}")
|
||||||
|
}
|
||||||
|
setNegButton(R.string.no)
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resetProgressDef.text = getString(currContext()!!,R.string.clear_stored_episode)
|
||||||
|
|
||||||
// Hidden
|
// Hidden
|
||||||
mangaScanlatorContainer.visibility = View.GONE
|
mangaScanlatorContainer.visibility = View.GONE
|
||||||
|
@ -298,6 +321,27 @@ class AnimeWatchAdapter(
|
||||||
}
|
}
|
||||||
// Episode Handling
|
// Episode Handling
|
||||||
handleEpisodes()
|
handleEpisodes()
|
||||||
|
|
||||||
|
//clear progress
|
||||||
|
binding.sourceTitle.setOnLongClickListener {
|
||||||
|
fragment.requireContext().customAlertDialog().apply {
|
||||||
|
setTitle(" Delete Progress for all episodes of ${media.nameRomaji}")
|
||||||
|
setMessage("This will delete all the locally stored progress for all episodes")
|
||||||
|
setPosButton(R.string.ok){
|
||||||
|
val prefix = "${media.id}_"
|
||||||
|
val regex = Regex("^${prefix}\\d+$")
|
||||||
|
|
||||||
|
PrefManager.getAllCustomValsForMedia(prefix)
|
||||||
|
.keys
|
||||||
|
.filter { it.matches(regex) }
|
||||||
|
.onEach { key -> PrefManager.removeCustomVal(key) }
|
||||||
|
snackString("Deleted the progress of all Episodes for ${media.nameRomaji}")
|
||||||
|
}
|
||||||
|
setNegButton(R.string.no)
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun subscribeButton(enabled: Boolean) {
|
fun subscribeButton(enabled: Boolean) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ani.dantotsu.media.manga
|
package ani.dantotsu.media.manga
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -10,6 +11,7 @@ import android.widget.ImageButton
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.NumberPicker
|
import android.widget.NumberPicker
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.content.ContextCompat.getString
|
||||||
import androidx.core.content.ContextCompat.startActivity
|
import androidx.core.content.ContextCompat.startActivity
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
@ -63,6 +65,15 @@ class MangaReadAdapter(
|
||||||
var scanlatorSelectionListener: ScanlatorSelectionListener? = null
|
var scanlatorSelectionListener: ScanlatorSelectionListener? = null
|
||||||
var options = listOf<String>()
|
var options = listOf<String>()
|
||||||
|
|
||||||
|
private fun clearCustomValsForMedia(mediaId: String, suffix: String) {
|
||||||
|
val customVals = PrefManager.getAllCustomValsForMedia("$mediaId$suffix")
|
||||||
|
customVals.forEach { (key) ->
|
||||||
|
PrefManager.removeCustomVal(key)
|
||||||
|
Log.d("PrefManager", "Removed key: $key")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
val bind = ItemMediaSourceBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
val bind = ItemMediaSourceBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
return ViewHolder(bind)
|
return ViewHolder(bind)
|
||||||
|
@ -93,14 +104,8 @@ class MangaReadAdapter(
|
||||||
setTitle(" Delete Progress for all chapters of ${media.nameRomaji}")
|
setTitle(" Delete Progress for all chapters of ${media.nameRomaji}")
|
||||||
setMessage("This will delete all the locally stored progress for chapters")
|
setMessage("This will delete all the locally stored progress for chapters")
|
||||||
setPosButton(R.string.ok){
|
setPosButton(R.string.ok){
|
||||||
val currentChapters = PrefManager.getAllCustomValsForMedia("${media.id}_Chapter")
|
clearCustomValsForMedia("${media.id}", "_Chapter")
|
||||||
currentChapters.forEach { (key) ->
|
clearCustomValsForMedia("${media.id}", "_Vol")
|
||||||
PrefManager.removeCustomVal(key)
|
|
||||||
}
|
|
||||||
val currentChapterWithVolume = PrefManager.getAllCustomValsForMedia("${media.id}_Vol")
|
|
||||||
currentChapterWithVolume.forEach { (key) ->
|
|
||||||
PrefManager.removeCustomVal(key)
|
|
||||||
}
|
|
||||||
snackString("Deleted the progress of Chapters for ${media.nameRomaji}")
|
snackString("Deleted the progress of Chapters for ${media.nameRomaji}")
|
||||||
}
|
}
|
||||||
setNegButton(R.string.no)
|
setNegButton(R.string.no)
|
||||||
|
@ -277,6 +282,22 @@ class MangaReadAdapter(
|
||||||
show()
|
show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
resetProgress.setOnClickListener {
|
||||||
|
fragment.requireContext().customAlertDialog().apply {
|
||||||
|
setTitle(" Delete Progress for all chapters of ${media.nameRomaji}")
|
||||||
|
setMessage("This will delete all the locally stored progress for chapters")
|
||||||
|
setPosButton(R.string.ok){
|
||||||
|
// Usage
|
||||||
|
clearCustomValsForMedia("${media.id}", "_Chapter")
|
||||||
|
clearCustomValsForMedia("${media.id}", "_Vol")
|
||||||
|
|
||||||
|
snackString("Deleted the progress of Chapters for ${media.nameRomaji}")
|
||||||
|
}
|
||||||
|
setNegButton(R.string.no)
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resetProgressDef.text = getString(currContext()!!,R.string.clear_stored_chapter)
|
||||||
|
|
||||||
// Scanlator
|
// Scanlator
|
||||||
mangaScanlatorContainer.isVisible = options.count() > 1
|
mangaScanlatorContainer.isVisible = options.count() > 1
|
||||||
|
|
|
@ -235,10 +235,18 @@ object PrefManager {
|
||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all SharedPreferences entries with keys starting with the specified prefix.
|
||||||
|
*
|
||||||
|
* @param prefix The prefix to filter keys.
|
||||||
|
* @return A map containing key-value pairs that match the prefix.
|
||||||
|
*/
|
||||||
fun getAllCustomValsForMedia(prefix: String): Map<String, Any?> {
|
fun getAllCustomValsForMedia(prefix: String): Map<String, Any?> {
|
||||||
|
val prefs = irrelevantPreferences ?: return emptyMap()
|
||||||
val allEntries = mutableMapOf<String, Any?>()
|
val allEntries = mutableMapOf<String, Any?>()
|
||||||
|
|
||||||
irrelevantPreferences?.all?.forEach { (key, value) ->
|
prefs.all.forEach { (key, value) ->
|
||||||
if (key.startsWith(prefix)) {
|
if (key.startsWith(prefix)) {
|
||||||
allEntries[key] = value
|
allEntries[key] = value
|
||||||
}
|
}
|
||||||
|
@ -249,6 +257,7 @@ object PrefManager {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun <T> getLiveVal(prefName: PrefName, default: T): SharedPreferenceLiveData<T> {
|
fun <T> getLiveVal(prefName: PrefName, default: T): SharedPreferenceLiveData<T> {
|
||||||
val pref = getPrefLocation(prefName.data.prefLocation)
|
val pref = getPrefLocation(prefName.data.prefLocation)
|
||||||
|
|
9
app/src/main/res/drawable/ic_delete.xml
Normal file
9
app/src/main/res/drawable/ic_delete.xml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960">
|
||||||
|
<path
|
||||||
|
android:pathData="M280,840q-33,0 -56.5,-23.5T200,760v-520h-40v-80h200v-40h240v40h200v80h-40v520q0,33 -23.5,56.5T680,840L280,840ZM680,240L280,240v520h400v-520ZM360,680h80v-360h-80v360ZM520,680h80v-360h-80v360ZM280,240v520,-520Z"
|
||||||
|
android:fillColor="#e8eaed"/>
|
||||||
|
</vector>
|
|
@ -292,5 +292,53 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/mediaProgressResetContainer"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="265dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="0.58"
|
||||||
|
android:fontFamily="@font/poppins_bold"
|
||||||
|
android:text="@string/reset" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/reset_progress_def"
|
||||||
|
android:fontFamily="@font/poppins_bold"
|
||||||
|
android:text=""
|
||||||
|
android:textColor="?attr/colorSecondary"
|
||||||
|
tools:ignore="TextContrastCheck" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="48dp"
|
||||||
|
android:layout_height="48dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/resetProgress"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="center|center_horizontal"
|
||||||
|
android:layout_marginStart="12dp"
|
||||||
|
android:background="?android:attr/selectableItemBackground"
|
||||||
|
app:srcCompat="@drawable/ic_delete"
|
||||||
|
app:tint="?attr/colorOnBackground"
|
||||||
|
tools:ignore="ContentDescription,ImageContrastCheck" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
|
@ -1083,6 +1083,8 @@ Non quae tempore quo provident laudantium qui illo dolor vel quia dolor et exerc
|
||||||
<string name="proxy_desc">Route All Your Network Traffic Through a Socks5 Proxy</string>
|
<string name="proxy_desc">Route All Your Network Traffic Through a Socks5 Proxy</string>
|
||||||
<string name="proxy_setup">Proxy Setup</string>
|
<string name="proxy_setup">Proxy Setup</string>
|
||||||
<string name="proxy_setup_desc">Configure your Socks5 Proxy</string>
|
<string name="proxy_setup_desc">Configure your Socks5 Proxy</string>
|
||||||
|
<string name="clear_stored_episode">Clear Stored Episode Data</string>
|
||||||
|
<string name="clear_stored_chapter">Clear Stored Chapter Data</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue