multi download
This commit is contained in:
parent
0d422a57e7
commit
b8782b0507
5 changed files with 58 additions and 0 deletions
|
@ -204,6 +204,7 @@ class AnimeWatchAdapter(
|
||||||
fragment.onIconPressed(style, reversed)
|
fragment.onIconPressed(style, reversed)
|
||||||
}
|
}
|
||||||
binding.animeScanlatorTop.visibility = View.GONE
|
binding.animeScanlatorTop.visibility = View.GONE
|
||||||
|
binding.animeDownloadTop.visibility = View.GONE
|
||||||
//Episode Handling
|
//Episode Handling
|
||||||
handleEpisodes()
|
handleEpisodes()
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,30 @@ class MangaChapterAdapter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun downloadNextNChapters(n: Int) {
|
||||||
|
//find last viewed chapter
|
||||||
|
var lastViewedChapter = arr.indexOfFirst { MangaNameAdapter.findChapterNumber(it.number)?.toInt() == media.userProgress }
|
||||||
|
if (lastViewedChapter == -1) {
|
||||||
|
lastViewedChapter = 0
|
||||||
|
}
|
||||||
|
//download next n chapters
|
||||||
|
for (i in 1..n) {
|
||||||
|
if (lastViewedChapter + i < arr.size) {
|
||||||
|
val chapterNumber = arr[lastViewedChapter + 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) :
|
inner class ChapterListViewHolder(val binding: ItemChapterListBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
private val activeCoroutines = mutableSetOf<String>()
|
private val activeCoroutines = mutableSetOf<String>()
|
||||||
|
|
|
@ -5,10 +5,12 @@ import android.app.AlertDialog
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.view.WindowManager
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.CheckBox
|
import android.widget.CheckBox
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.NumberPicker
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
@ -185,6 +187,23 @@ class MangaReadAdapter(
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.animeDownloadTop.setOnClickListener {
|
||||||
|
//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 = 20
|
||||||
|
input.value = 1
|
||||||
|
alertDialog.setView(input)
|
||||||
|
alertDialog.setPositiveButton("OK") { dialog, which ->
|
||||||
|
fragment.multiDownload(input.value)
|
||||||
|
}
|
||||||
|
alertDialog.setNegativeButton("Cancel") { dialog, _ -> dialog.cancel() }
|
||||||
|
val dialog = alertDialog.show()
|
||||||
|
}
|
||||||
|
|
||||||
var selected = when (style) {
|
var selected = when (style) {
|
||||||
0 -> binding.animeSourceList
|
0 -> binding.animeSourceList
|
||||||
1 -> binding.animeSourceCompact
|
1 -> binding.animeSourceCompact
|
||||||
|
|
|
@ -197,6 +197,10 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
||||||
updateChapters()
|
updateChapters()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun multiDownload(n: Int) {
|
||||||
|
chapterAdapter.downloadNextNChapters(n)
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateChapters() {
|
private fun updateChapters() {
|
||||||
val loadedChapters = model.getMangaChapters().value
|
val loadedChapters = model.getMangaChapters().value
|
||||||
if (loadedChapters != null) {
|
if (loadedChapters != null) {
|
||||||
|
|
|
@ -246,6 +246,16 @@
|
||||||
app:tint="?attr/colorOnBackground"
|
app:tint="?attr/colorOnBackground"
|
||||||
tools:ignore="ContentDescription,ImageContrastCheck" />
|
tools:ignore="ContentDescription,ImageContrastCheck" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/animeDownloadTop"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:alpha="1"
|
||||||
|
android:padding="8dp"
|
||||||
|
app:srcCompat="@drawable/ic_round_download_24"
|
||||||
|
app:tint="?attr/colorOnBackground"
|
||||||
|
tools:ignore="ContentDescription,ImageContrastCheck" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/animeScanlatorTop"
|
android:id="@+id/animeScanlatorTop"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue