diff --git a/app/src/main/java/ani/dantotsu/media/manga/MangaReadAdapter.kt b/app/src/main/java/ani/dantotsu/media/manga/MangaReadAdapter.kt index a98f0570ac5..e75b1aa9313 100644 --- a/app/src/main/java/ani/dantotsu/media/manga/MangaReadAdapter.kt +++ b/app/src/main/java/ani/dantotsu/media/manga/MangaReadAdapter.kt @@ -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 diff --git a/app/src/main/java/ani/dantotsu/settings/saving/PrefManager.kt b/app/src/main/java/ani/dantotsu/settings/saving/PrefManager.kt index 2a2438d94ae..e173231f86f 100644 --- a/app/src/main/java/ani/dantotsu/settings/saving/PrefManager.kt +++ b/app/src/main/java/ani/dantotsu/settings/saving/PrefManager.kt @@ -235,6 +235,19 @@ object PrefManager { apply() } } + fun getAllCustomValsForMedia(prefix: String): Map { + val allEntries = mutableMapOf() + + irrelevantPreferences?.all?.forEach { (key, value) -> + if (key.startsWith(prefix)) { + allEntries[key] = value + } + } + + return allEntries + } + + @Suppress("UNCHECKED_CAST") fun getLiveVal(prefName: PrefName, default: T): SharedPreferenceLiveData {