Skip to content

Commit

Permalink
feat:added way to clear saved manga progress (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
grayankit authored Nov 12, 2024
1 parent 5c1c639 commit a993935
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/src/main/java/ani/dantotsu/media/manga/MangaReadAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/ani/dantotsu/settings/saving/PrefManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit a993935

Please sign in to comment.