feat:added way to clear saved manga progress (#522)

This commit is contained in:
Ankit Grai 2024-11-12 22:49:03 +05:30 committed by GitHub
parent 5c1c639f53
commit a993935433
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 0 deletions

View file

@ -40,6 +40,7 @@ import ani.dantotsu.px
import ani.dantotsu.settings.FAQActivity
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.snackString
import ani.dantotsu.toast
import ani.dantotsu.util.customAlertDialog
import com.google.android.material.chip.Chip
@ -86,6 +87,27 @@ class MangaReadAdapter(
)
}
val offline = !isOnline(binding.root.context) || PrefManager.getVal(PrefName.OfflineMode)
//for removing saved progress
binding.sourceTitle.setOnLongClickListener{
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){
val currentChapters = PrefManager.getAllCustomValsForMedia("${media.id}_Chapter")
currentChapters.forEach { (key) ->
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}")
}
setNegButton(R.string.no)
show()
}
true
}
binding.mediaSourceNameContainer.isGone = offline
binding.mediaSourceSettings.isGone = offline

View file

@ -235,6 +235,19 @@ object PrefManager {
apply()
}
}
fun getAllCustomValsForMedia(prefix: String): Map<String, Any?> {
val allEntries = mutableMapOf<String, Any?>()
irrelevantPreferences?.all?.forEach { (key, value) ->
if (key.startsWith(prefix)) {
allEntries[key] = value
}
}
return allEntries
}
@Suppress("UNCHECKED_CAST")
fun <T> getLiveVal(prefName: PrefName, default: T): SharedPreferenceLiveData<T> {