Skip to content

Commit

Permalink
downloading from specific point
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Dec 6, 2023
1 parent 17e53a5 commit 55521ab
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/src/main/java/ani/dantotsu/media/manga/MangaChapterAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ani.dantotsu.media.manga

import android.app.AlertDialog
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.animation.LinearInterpolator
import android.widget.NumberPicker
import androidx.lifecycle.coroutineScope
import androidx.recyclerview.widget.RecyclerView
import ani.dantotsu.R
Expand Down Expand Up @@ -138,6 +140,25 @@ class MangaChapterAdapter(
}
}

fun downloadNChaptersFrom(position: Int, n: Int) {
//download next n chapters
for (i in 0..<n) {
if (position + i < arr.size) {
val chapterNumber = arr[position + i].number
if (activeDownloads.contains(chapterNumber)) {
//do nothing
continue
} else if (downloadedChapters.contains(chapterNumber)) {
//do nothing
continue
} else {
fragment.onMangaChapterDownloadClick(chapterNumber)
startDownload(chapterNumber)
}
}
}
}

inner class ChapterListViewHolder(val binding: ItemChapterListBinding) :
RecyclerView.ViewHolder(binding.root) {
private val activeCoroutines = mutableSetOf<String>()
Expand Down Expand Up @@ -224,6 +245,24 @@ class MangaChapterAdapter(
}
}
}
binding.itemDownload.setOnLongClickListener {
//Alert dialog asking for the number of chapters to download
val alertDialog = AlertDialog.Builder(currContext(), R.style.MyPopup)
alertDialog.setTitle("Multi Chapter Downloader")
alertDialog.setMessage("Enter the number of chapters to download")
val input = NumberPicker(currContext())
input.minValue = 1
input.maxValue = itemCount - bindingAdapterPosition
input.value = 1
alertDialog.setView(input)
alertDialog.setPositiveButton("OK") { dialog, which ->
downloadNChaptersFrom(bindingAdapterPosition, input.value)
}
alertDialog.setNegativeButton("Cancel") { dialog, _ -> dialog.cancel() }
val dialog = alertDialog.show()
dialog.window?.setDimAmount(0.8f)
true
}

}
}
Expand Down

0 comments on commit 55521ab

Please sign in to comment.