fix: manga opening
This commit is contained in:
parent
1bb5f4d0ab
commit
986d0fa4a8
11 changed files with 94 additions and 71 deletions
|
@ -60,7 +60,7 @@ class DownloadsManager(private val context: Context) {
|
||||||
onFinished: () -> Unit
|
onFinished: () -> Unit
|
||||||
) {
|
) {
|
||||||
removeDownloadCompat(context, downloadedType, toast)
|
removeDownloadCompat(context, downloadedType, toast)
|
||||||
downloadsList.remove(downloadedType)
|
downloadsList.removeAll { it.titleName == downloadedType.titleName && it.chapterName == downloadedType.chapterName }
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
removeDirectory(downloadedType, toast)
|
removeDirectory(downloadedType, toast)
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
|
@ -234,7 +234,7 @@ class DownloadsManager(private val context: Context) {
|
||||||
val directory =
|
val directory =
|
||||||
baseDirectory?.findFolder(downloadedType.titleName)
|
baseDirectory?.findFolder(downloadedType.titleName)
|
||||||
?.findFolder(downloadedType.chapterName)
|
?.findFolder(downloadedType.chapterName)
|
||||||
downloadsList.remove(downloadedType)
|
downloadsList.removeAll { it.titleName == downloadedType.titleName && it.chapterName == downloadedType.chapterName }
|
||||||
// Check if the directory exists and delete it recursively
|
// Check if the directory exists and delete it recursively
|
||||||
if (directory?.exists() == true) {
|
if (directory?.exists() == true) {
|
||||||
val deleted = directory.deleteRecursively(context, false)
|
val deleted = directory.deleteRecursively(context, false)
|
||||||
|
@ -401,10 +401,13 @@ data class DownloadedType(
|
||||||
@Deprecated("use pTitle instead")
|
@Deprecated("use pTitle instead")
|
||||||
private val title: String? = null,
|
private val title: String? = null,
|
||||||
@Deprecated("use pChapter instead")
|
@Deprecated("use pChapter instead")
|
||||||
private val chapter: String? = null
|
private val chapter: String? = null,
|
||||||
|
val scanlator: String = "Unknown"
|
||||||
) : Serializable {
|
) : Serializable {
|
||||||
val titleName: String
|
val titleName: String
|
||||||
get() = title ?: pTitle.findValidName()
|
get() = title ?: pTitle.findValidName()
|
||||||
val chapterName: String
|
val chapterName: String
|
||||||
get() = chapter ?: pChapter.findValidName()
|
get() = chapter ?: pChapter.findValidName()
|
||||||
|
val uniqueName: String
|
||||||
|
get() = "$chapterName-${scanlator}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,7 +243,7 @@ class MangaDownloaderService : Service() {
|
||||||
builder.setProgress(task.imageData.size, farthest, false)
|
builder.setProgress(task.imageData.size, farthest, false)
|
||||||
|
|
||||||
broadcastDownloadProgress(
|
broadcastDownloadProgress(
|
||||||
task.chapter,
|
task.uniqueName,
|
||||||
farthest * 100 / task.imageData.size
|
farthest * 100 / task.imageData.size
|
||||||
)
|
)
|
||||||
if (notifi) {
|
if (notifi) {
|
||||||
|
@ -270,17 +270,18 @@ class MangaDownloaderService : Service() {
|
||||||
DownloadedType(
|
DownloadedType(
|
||||||
task.title,
|
task.title,
|
||||||
task.chapter,
|
task.chapter,
|
||||||
MediaType.MANGA
|
MediaType.MANGA,
|
||||||
|
scanlator = task.scanlator,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
broadcastDownloadFinished(task.chapter)
|
broadcastDownloadFinished(task.uniqueName)
|
||||||
snackString("${task.title} - ${task.chapter} Download finished")
|
snackString("${task.title} - ${task.chapter} Download finished")
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Logger.log("Exception while downloading file: ${e.message}")
|
Logger.log("Exception while downloading file: ${e.message}")
|
||||||
snackString("Exception while downloading file: ${e.message}")
|
snackString("Exception while downloading file: ${e.message}")
|
||||||
Injekt.get<CrashlyticsInterface>().logException(e)
|
Injekt.get<CrashlyticsInterface>().logException(e)
|
||||||
broadcastDownloadFailed(task.chapter)
|
broadcastDownloadFailed(task.uniqueName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,11 +424,15 @@ class MangaDownloaderService : Service() {
|
||||||
data class DownloadTask(
|
data class DownloadTask(
|
||||||
val title: String,
|
val title: String,
|
||||||
val chapter: String,
|
val chapter: String,
|
||||||
|
val scanlator: String,
|
||||||
val imageData: List<ImageData>,
|
val imageData: List<ImageData>,
|
||||||
val sourceMedia: Media? = null,
|
val sourceMedia: Media? = null,
|
||||||
val retries: Int = 2,
|
val retries: Int = 2,
|
||||||
val simultaneousDownloads: Int = 2,
|
val simultaneousDownloads: Int = 2,
|
||||||
)
|
) {
|
||||||
|
val uniqueName: String
|
||||||
|
get() = "$chapter-$scanlator"
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val NOTIFICATION_ID = 1103
|
private const val NOTIFICATION_ID = 1103
|
||||||
|
|
|
@ -5,7 +5,7 @@ import java.io.Serializable
|
||||||
|
|
||||||
data class Manga(
|
data class Manga(
|
||||||
var totalChapters: Int? = null,
|
var totalChapters: Int? = null,
|
||||||
var selectedChapter: String? = null,
|
var selectedChapter: MangaChapter? = null,
|
||||||
var chapters: MutableMap<String, MangaChapter>? = null,
|
var chapters: MutableMap<String, MangaChapter>? = null,
|
||||||
var slug: String? = null,
|
var slug: String? = null,
|
||||||
var author: Author? = null,
|
var author: Author? = null,
|
||||||
|
|
|
@ -40,4 +40,6 @@ data class MangaChapter(
|
||||||
private val dualPages = mutableListOf<Pair<MangaImage, MangaImage?>>()
|
private val dualPages = mutableListOf<Pair<MangaImage, MangaImage?>>()
|
||||||
fun dualPages(): List<Pair<MangaImage, MangaImage?>> = dualPages
|
fun dualPages(): List<Pair<MangaImage, MangaImage?>> = dualPages
|
||||||
|
|
||||||
|
fun uniqueNumber(): String = "${number}-${scanlator ?: "Unknown"}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ class MangaChapterAdapter(
|
||||||
init {
|
init {
|
||||||
itemView.setOnClickListener {
|
itemView.setOnClickListener {
|
||||||
if (0 <= bindingAdapterPosition && bindingAdapterPosition < arr.size)
|
if (0 <= bindingAdapterPosition && bindingAdapterPosition < arr.size)
|
||||||
fragment.onMangaChapterClick(arr[bindingAdapterPosition].number)
|
fragment.onMangaChapterClick(arr[bindingAdapterPosition])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ class MangaChapterAdapter(
|
||||||
fun startDownload(chapterNumber: String) {
|
fun startDownload(chapterNumber: String) {
|
||||||
activeDownloads.add(chapterNumber)
|
activeDownloads.add(chapterNumber)
|
||||||
// Find the position of the chapter and notify only that item
|
// Find the position of the chapter and notify only that item
|
||||||
val position = arr.indexOfFirst { it.number == chapterNumber }
|
val position = arr.indexOfFirst { it.uniqueNumber() == chapterNumber }
|
||||||
if (position != -1) {
|
if (position != -1) {
|
||||||
notifyItemChanged(position)
|
notifyItemChanged(position)
|
||||||
}
|
}
|
||||||
|
@ -84,17 +84,17 @@ class MangaChapterAdapter(
|
||||||
activeDownloads.remove(chapterNumber)
|
activeDownloads.remove(chapterNumber)
|
||||||
downloadedChapters.add(chapterNumber)
|
downloadedChapters.add(chapterNumber)
|
||||||
// Find the position of the chapter and notify only that item
|
// Find the position of the chapter and notify only that item
|
||||||
val position = arr.indexOfFirst { it.number == chapterNumber }
|
val position = arr.indexOfFirst { it.uniqueNumber() == chapterNumber }
|
||||||
if (position != -1) {
|
if (position != -1) {
|
||||||
arr[position].progress = "Downloaded"
|
arr[position].progress = "Downloaded"
|
||||||
notifyItemChanged(position)
|
notifyItemChanged(position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteDownload(chapterNumber: String) {
|
fun deleteDownload(chapterNumber: MangaChapter) {
|
||||||
downloadedChapters.remove(chapterNumber)
|
downloadedChapters.remove(chapterNumber.uniqueNumber())
|
||||||
// Find the position of the chapter and notify only that item
|
// Find the position of the chapter and notify only that item
|
||||||
val position = arr.indexOfFirst { it.number == chapterNumber }
|
val position = arr.indexOfFirst { it.uniqueNumber() == chapterNumber.uniqueNumber() }
|
||||||
if (position != -1) {
|
if (position != -1) {
|
||||||
arr[position].progress = ""
|
arr[position].progress = ""
|
||||||
notifyItemChanged(position)
|
notifyItemChanged(position)
|
||||||
|
@ -105,7 +105,7 @@ class MangaChapterAdapter(
|
||||||
activeDownloads.remove(chapterNumber)
|
activeDownloads.remove(chapterNumber)
|
||||||
downloadedChapters.remove(chapterNumber)
|
downloadedChapters.remove(chapterNumber)
|
||||||
// Find the position of the chapter and notify only that item
|
// Find the position of the chapter and notify only that item
|
||||||
val position = arr.indexOfFirst { it.number == chapterNumber }
|
val position = arr.indexOfFirst { it.uniqueNumber() == chapterNumber }
|
||||||
if (position != -1) {
|
if (position != -1) {
|
||||||
arr[position].progress = ""
|
arr[position].progress = ""
|
||||||
notifyItemChanged(position)
|
notifyItemChanged(position)
|
||||||
|
@ -114,7 +114,7 @@ class MangaChapterAdapter(
|
||||||
|
|
||||||
fun updateDownloadProgress(chapterNumber: String, progress: Int) {
|
fun updateDownloadProgress(chapterNumber: String, progress: Int) {
|
||||||
// Find the position of the chapter and notify only that item
|
// Find the position of the chapter and notify only that item
|
||||||
val position = arr.indexOfFirst { it.number == chapterNumber }
|
val position = arr.indexOfFirst { it.uniqueNumber() == chapterNumber }
|
||||||
if (position != -1) {
|
if (position != -1) {
|
||||||
arr[position].progress = "Downloading: ${progress}%"
|
arr[position].progress = "Downloading: ${progress}%"
|
||||||
|
|
||||||
|
@ -127,7 +127,8 @@ class MangaChapterAdapter(
|
||||||
if (position < 0 || position >= arr.size) return
|
if (position < 0 || position >= arr.size) return
|
||||||
for (i in 0..<n) {
|
for (i in 0..<n) {
|
||||||
if (position + i < arr.size) {
|
if (position + i < arr.size) {
|
||||||
val chapterNumber = arr[position + i].number
|
val chapter = arr[position + i]
|
||||||
|
val chapterNumber = chapter.uniqueNumber()
|
||||||
if (activeDownloads.contains(chapterNumber)) {
|
if (activeDownloads.contains(chapterNumber)) {
|
||||||
//do nothing
|
//do nothing
|
||||||
continue
|
continue
|
||||||
|
@ -135,8 +136,8 @@ class MangaChapterAdapter(
|
||||||
//do nothing
|
//do nothing
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
fragment.onMangaChapterDownloadClick(chapterNumber)
|
fragment.onMangaChapterDownloadClick(chapter)
|
||||||
startDownload(chapterNumber)
|
startDownload(chapter.uniqueNumber())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,28 +202,29 @@ class MangaChapterAdapter(
|
||||||
init {
|
init {
|
||||||
itemView.setOnClickListener {
|
itemView.setOnClickListener {
|
||||||
if (0 <= bindingAdapterPosition && bindingAdapterPosition < arr.size)
|
if (0 <= bindingAdapterPosition && bindingAdapterPosition < arr.size)
|
||||||
fragment.onMangaChapterClick(arr[bindingAdapterPosition].number)
|
fragment.onMangaChapterClick(arr[bindingAdapterPosition])
|
||||||
}
|
}
|
||||||
binding.itemDownload.setOnClickListener {
|
binding.itemDownload.setOnClickListener {
|
||||||
if (0 <= bindingAdapterPosition && bindingAdapterPosition < arr.size) {
|
if (0 <= bindingAdapterPosition && bindingAdapterPosition < arr.size) {
|
||||||
val chapterNumber = arr[bindingAdapterPosition].number
|
val chapter = arr[bindingAdapterPosition]
|
||||||
|
val chapterNumber = chapter.uniqueNumber()
|
||||||
if (activeDownloads.contains(chapterNumber)) {
|
if (activeDownloads.contains(chapterNumber)) {
|
||||||
fragment.onMangaChapterStopDownloadClick(chapterNumber)
|
fragment.onMangaChapterStopDownloadClick(chapter)
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
} else if (downloadedChapters.contains(chapterNumber)) {
|
} else if (downloadedChapters.contains(chapterNumber)) {
|
||||||
it.context.customAlertDialog().apply {
|
it.context.customAlertDialog().apply {
|
||||||
setTitle("Delete Chapter")
|
setTitle("Delete Chapter")
|
||||||
setMessage("Are you sure you want to delete ${chapterNumber}?")
|
setMessage("Are you sure you want to delete ${chapterNumber}?")
|
||||||
setPosButton(R.string.delete) {
|
setPosButton(R.string.delete) {
|
||||||
fragment.onMangaChapterRemoveDownloadClick(chapterNumber)
|
fragment.onMangaChapterRemoveDownloadClick(chapter)
|
||||||
}
|
}
|
||||||
setNegButton(R.string.cancel)
|
setNegButton(R.string.cancel)
|
||||||
show()
|
show()
|
||||||
}
|
}
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
} else {
|
} else {
|
||||||
fragment.onMangaChapterDownloadClick(chapterNumber)
|
fragment.onMangaChapterDownloadClick(chapter)
|
||||||
startDownload(chapterNumber)
|
startDownload(chapter.uniqueNumber())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,7 +279,7 @@ class MangaChapterAdapter(
|
||||||
is ChapterListViewHolder -> {
|
is ChapterListViewHolder -> {
|
||||||
val binding = holder.binding
|
val binding = holder.binding
|
||||||
val ep = arr[position]
|
val ep = arr[position]
|
||||||
holder.bind(ep.number, ep.progress)
|
holder.bind(ep.uniqueNumber(), ep.progress)
|
||||||
setAnimation(fragment.requireContext(), holder.binding.root)
|
setAnimation(fragment.requireContext(), holder.binding.root)
|
||||||
binding.itemChapterNumber.text = ep.number
|
binding.itemChapterNumber.text = ep.number
|
||||||
|
|
||||||
|
|
|
@ -422,12 +422,12 @@ class MangaReadAdapter(
|
||||||
val startChapter = MediaNameAdapter.findChapterNumber(names[limit * (position)])
|
val startChapter = MediaNameAdapter.findChapterNumber(names[limit * (position)])
|
||||||
val endChapter = MediaNameAdapter.findChapterNumber(names[last - 1])
|
val endChapter = MediaNameAdapter.findChapterNumber(names[last - 1])
|
||||||
val startChapterString = if (startChapter != null) {
|
val startChapterString = if (startChapter != null) {
|
||||||
"Ch.$startChapter"
|
"Ch.%.1f".format(startChapter)
|
||||||
} else {
|
} else {
|
||||||
names[limit * (position)]
|
names[limit * (position)]
|
||||||
}
|
}
|
||||||
val endChapterString = if (endChapter != null) {
|
val endChapterString = if (endChapter != null) {
|
||||||
"Ch.$endChapter"
|
"Ch.%.1f".format(endChapter)
|
||||||
} else {
|
} else {
|
||||||
names[last - 1]
|
names[last - 1]
|
||||||
}
|
}
|
||||||
|
@ -472,7 +472,6 @@ class MangaReadAdapter(
|
||||||
val binding = _binding
|
val binding = _binding
|
||||||
if (binding != null) {
|
if (binding != null) {
|
||||||
if (media.manga?.chapters != null) {
|
if (media.manga?.chapters != null) {
|
||||||
val chapters = media.manga.chapters!!.keys.toTypedArray()
|
|
||||||
val anilistEp = (media.userProgress ?: 0).plus(1)
|
val anilistEp = (media.userProgress ?: 0).plus(1)
|
||||||
val appEp = PrefManager.getNullableCustomVal(
|
val appEp = PrefManager.getNullableCustomVal(
|
||||||
"${media.id}_current_chp",
|
"${media.id}_current_chp",
|
||||||
|
@ -480,37 +479,39 @@ class MangaReadAdapter(
|
||||||
String::class.java
|
String::class.java
|
||||||
)
|
)
|
||||||
?.toIntOrNull() ?: 1
|
?.toIntOrNull() ?: 1
|
||||||
var continueEp = (if (anilistEp > appEp) anilistEp else appEp).toString()
|
val continueNumber = (if (anilistEp > appEp) anilistEp else appEp).toString()
|
||||||
val filteredChapters = chapters.filter { chapterKey ->
|
val filteredChapters = media.manga.chapters!!.filter { chapter ->
|
||||||
val chapter = media.manga.chapters!![chapterKey]!!
|
if (mangaReadSources[media.selected!!.sourceIndex] is OfflineMangaParser) {
|
||||||
chapter.scanlator !in hiddenScanlators
|
true
|
||||||
|
} else {
|
||||||
|
chapter.value.scanlator !in hiddenScanlators
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val formattedChapters = filteredChapters.map {
|
val formattedChapters = filteredChapters.map {
|
||||||
MediaNameAdapter.findChapterNumber(it)?.toInt()?.toString()
|
MediaNameAdapter.findChapterNumber(it.value.number)?.toInt()?.toString() to it.key
|
||||||
}
|
}
|
||||||
if (formattedChapters.contains(continueEp)) {
|
if (formattedChapters.any { it.first == continueNumber }) {
|
||||||
continueEp = chapters[formattedChapters.indexOf(continueEp)]
|
var continueEp = media.manga.chapters!![formattedChapters.first { it.first == continueNumber }.second]
|
||||||
binding.sourceContinue.visibility = View.VISIBLE
|
binding.sourceContinue.visibility = View.VISIBLE
|
||||||
handleProgress(
|
handleProgress(
|
||||||
binding.itemMediaProgressCont,
|
binding.itemMediaProgressCont,
|
||||||
binding.itemMediaProgress,
|
binding.itemMediaProgress,
|
||||||
binding.itemMediaProgressEmpty,
|
binding.itemMediaProgressEmpty,
|
||||||
media.id,
|
media.id,
|
||||||
continueEp
|
continueEp!!.number
|
||||||
)
|
)
|
||||||
if ((binding.itemMediaProgress.layoutParams as LinearLayout.LayoutParams).weight > 0.8f) {
|
if ((binding.itemMediaProgress.layoutParams as LinearLayout.LayoutParams).weight > 0.8f) {
|
||||||
val e = chapters.indexOf(continueEp)
|
val numberPlusOne = formattedChapters.indexOfFirst { it.first?.toIntOrNull() == continueNumber.toInt() + 1 }
|
||||||
if (e != -1 && e + 1 < chapters.size) {
|
if (numberPlusOne != -1) {
|
||||||
continueEp = chapters[e + 1]
|
continueEp = media.manga.chapters!![formattedChapters[numberPlusOne].second]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val ep = media.manga.chapters!![continueEp]!!
|
|
||||||
binding.itemMediaImage.loadImage(media.banner ?: media.cover)
|
binding.itemMediaImage.loadImage(media.banner ?: media.cover)
|
||||||
binding.mediaSourceContinueText.text =
|
binding.mediaSourceContinueText.text =
|
||||||
currActivity()!!.getString(
|
currActivity()!!.getString(
|
||||||
R.string.continue_chapter,
|
R.string.continue_chapter,
|
||||||
ep.number,
|
continueEp!!.number,
|
||||||
if (!ep.title.isNullOrEmpty()) ep.title else ""
|
if (!continueEp.title.isNullOrEmpty()) continueEp.title else ""
|
||||||
)
|
)
|
||||||
binding.sourceContinue.setOnClickListener {
|
binding.sourceContinue.setOnClickListener {
|
||||||
fragment.onMangaChapterClick(continueEp)
|
fragment.onMangaChapterClick(continueEp)
|
||||||
|
|
|
@ -52,6 +52,7 @@ import ani.dantotsu.parsers.DynamicMangaParser
|
||||||
import ani.dantotsu.parsers.HMangaSources
|
import ani.dantotsu.parsers.HMangaSources
|
||||||
import ani.dantotsu.parsers.MangaParser
|
import ani.dantotsu.parsers.MangaParser
|
||||||
import ani.dantotsu.parsers.MangaSources
|
import ani.dantotsu.parsers.MangaSources
|
||||||
|
import ani.dantotsu.parsers.OfflineMangaParser
|
||||||
import ani.dantotsu.setNavigationTheme
|
import ani.dantotsu.setNavigationTheme
|
||||||
import ani.dantotsu.settings.extensionprefs.MangaSourcePreferencesFragment
|
import ani.dantotsu.settings.extensionprefs.MangaSourcePreferencesFragment
|
||||||
import ani.dantotsu.settings.saving.PrefManager
|
import ani.dantotsu.settings.saving.PrefManager
|
||||||
|
@ -195,7 +196,7 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
||||||
|
|
||||||
for (download in downloadManager.mangaDownloadedTypes) {
|
for (download in downloadManager.mangaDownloadedTypes) {
|
||||||
if (media.compareName(download.titleName)) {
|
if (media.compareName(download.titleName)) {
|
||||||
chapterAdapter.stopDownload(download.chapterName)
|
chapterAdapter.stopDownload(download.uniqueName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +250,7 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
||||||
|
|
||||||
|
|
||||||
for (chapter in chaptersToDownload) {
|
for (chapter in chaptersToDownload) {
|
||||||
onMangaChapterDownloadClick(chapter.title!!)
|
onMangaChapterDownloadClick(chapter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,8 +261,12 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
||||||
val chapters = loadedChapters[media.selected!!.sourceIndex]
|
val chapters = loadedChapters[media.selected!!.sourceIndex]
|
||||||
if (chapters != null) {
|
if (chapters != null) {
|
||||||
headerAdapter.options = getScanlators(chapters)
|
headerAdapter.options = getScanlators(chapters)
|
||||||
val filteredChapters = chapters.filterNot { (_, chapter) ->
|
val filteredChapters = if (model.mangaReadSources?.get(media.selected!!.sourceIndex) is OfflineMangaParser) {
|
||||||
chapter.scanlator in headerAdapter.hiddenScanlators
|
chapters
|
||||||
|
} else {
|
||||||
|
chapters.filterNot { (_, chapter) ->
|
||||||
|
chapter.scanlator in headerAdapter.hiddenScanlators
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
media.manga?.chapters = filteredChapters.toMutableMap()
|
media.manga?.chapters = filteredChapters.toMutableMap()
|
||||||
|
@ -430,9 +435,9 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMangaChapterClick(i: String) {
|
fun onMangaChapterClick(i: MangaChapter) {
|
||||||
model.continueMedia = false
|
model.continueMedia = false
|
||||||
media.manga?.chapters?.get(i)?.let {
|
media.manga?.chapters?.get(i.uniqueNumber())?.let {
|
||||||
media.manga?.selectedChapter = i
|
media.manga?.selectedChapter = i
|
||||||
model.saveSelected(media.id, media.selected!!)
|
model.saveSelected(media.id, media.selected!!)
|
||||||
ChapterLoaderDialog.newInstance(it, true)
|
ChapterLoaderDialog.newInstance(it, true)
|
||||||
|
@ -440,7 +445,7 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMangaChapterDownloadClick(i: String) {
|
fun onMangaChapterDownloadClick(i: MangaChapter) {
|
||||||
activity?.let {
|
activity?.let {
|
||||||
if (!isNotificationPermissionGranted()) {
|
if (!isNotificationPermissionGranted()) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
@ -453,7 +458,7 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
||||||
}
|
}
|
||||||
fun continueDownload() {
|
fun continueDownload() {
|
||||||
model.continueMedia = false
|
model.continueMedia = false
|
||||||
media.manga?.chapters?.get(i)?.let { chapter ->
|
media.manga?.chapters?.get(i.uniqueNumber())?.let { chapter ->
|
||||||
val parser =
|
val parser =
|
||||||
model.mangaReadSources?.get(media.selected!!.sourceIndex) as? DynamicMangaParser
|
model.mangaReadSources?.get(media.selected!!.sourceIndex) as? DynamicMangaParser
|
||||||
parser?.let {
|
parser?.let {
|
||||||
|
@ -464,6 +469,7 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
||||||
val downloadTask = MangaDownloaderService.DownloadTask(
|
val downloadTask = MangaDownloaderService.DownloadTask(
|
||||||
title = media.mainName(),
|
title = media.mainName(),
|
||||||
chapter = chapter.title!!,
|
chapter = chapter.title!!,
|
||||||
|
scanlator = chapter.scanlator ?: "Unknown",
|
||||||
imageData = images,
|
imageData = images,
|
||||||
sourceMedia = media,
|
sourceMedia = media,
|
||||||
retries = 2,
|
retries = 2,
|
||||||
|
@ -483,7 +489,7 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
||||||
|
|
||||||
// Inform the adapter that the download has started
|
// Inform the adapter that the download has started
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
chapterAdapter.startDownload(i)
|
chapterAdapter.startDownload(i.uniqueNumber())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -514,11 +520,11 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun onMangaChapterRemoveDownloadClick(i: String) {
|
fun onMangaChapterRemoveDownloadClick(i: MangaChapter) {
|
||||||
downloadManager.removeDownload(
|
downloadManager.removeDownload(
|
||||||
DownloadedType(
|
DownloadedType(
|
||||||
media.mainName(),
|
media.mainName(),
|
||||||
i,
|
i.number,
|
||||||
MediaType.MANGA
|
MediaType.MANGA
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
@ -526,7 +532,7 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMangaChapterStopDownloadClick(i: String) {
|
fun onMangaChapterStopDownloadClick(i: MangaChapter) {
|
||||||
val cancelIntent = Intent().apply {
|
val cancelIntent = Intent().apply {
|
||||||
action = MangaDownloaderService.ACTION_CANCEL_DOWNLOAD
|
action = MangaDownloaderService.ACTION_CANCEL_DOWNLOAD
|
||||||
putExtra(MangaDownloaderService.EXTRA_CHAPTER, i)
|
putExtra(MangaDownloaderService.EXTRA_CHAPTER, i)
|
||||||
|
@ -537,11 +543,11 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
||||||
downloadManager.removeDownload(
|
downloadManager.removeDownload(
|
||||||
DownloadedType(
|
DownloadedType(
|
||||||
media.mainName(),
|
media.mainName(),
|
||||||
i,
|
i.number,
|
||||||
MediaType.MANGA
|
MediaType.MANGA
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
chapterAdapter.purgeDownload(i)
|
chapterAdapter.purgeDownload(i.uniqueNumber())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,7 +590,7 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
|
||||||
|
|
||||||
// Find latest chapter for subscription
|
// Find latest chapter for subscription
|
||||||
selected.latest =
|
selected.latest =
|
||||||
media.manga?.chapters?.values?.maxOfOrNull { it.number.toFloatOrNull() ?: 0f } ?: 0f
|
media.manga?.chapters?.values?.maxOfOrNull { MediaNameAdapter.findChapterNumber(it.number) ?: 0f } ?: 0f
|
||||||
selected.latest =
|
selected.latest =
|
||||||
media.userProgress?.toFloat()?.takeIf { selected.latest < it } ?: selected.latest
|
media.userProgress?.toFloat()?.takeIf { selected.latest < it } ?: selected.latest
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,7 @@ class MangaReaderActivity : AppCompatActivity() {
|
||||||
finish()
|
finish()
|
||||||
return@addCallback
|
return@addCallback
|
||||||
}
|
}
|
||||||
val chapter = (MediaNameAdapter.findChapterNumber(media.manga!!.selectedChapter!!)
|
val chapter = (MediaNameAdapter.findChapterNumber(media.manga!!.selectedChapter!!.number)
|
||||||
?.minus(1L) ?: 0).toString()
|
?.minus(1L) ?: 0).toString()
|
||||||
if (chapter == "0.0" && PrefManager.getVal(PrefName.ChapterZeroReader)
|
if (chapter == "0.0" && PrefManager.getVal(PrefName.ChapterZeroReader)
|
||||||
// Not asking individually or incognito
|
// Not asking individually or incognito
|
||||||
|
@ -279,7 +279,7 @@ class MangaReaderActivity : AppCompatActivity() {
|
||||||
defaultSettings = loadReaderSettings("${media.id}_current_settings") ?: defaultSettings
|
defaultSettings = loadReaderSettings("${media.id}_current_settings") ?: defaultSettings
|
||||||
|
|
||||||
chapters = media.manga?.chapters ?: return
|
chapters = media.manga?.chapters ?: return
|
||||||
chapter = chapters[media.manga!!.selectedChapter] ?: return
|
chapter = chapters[media.manga!!.selectedChapter!!.uniqueNumber()] ?: return
|
||||||
|
|
||||||
model.mangaReadSources = if (media.isAdult) HMangaSources else MangaSources
|
model.mangaReadSources = if (media.isAdult) HMangaSources else MangaSources
|
||||||
binding.mangaReaderSource.isVisible = PrefManager.getVal(PrefName.ShowSource)
|
binding.mangaReaderSource.isVisible = PrefManager.getVal(PrefName.ShowSource)
|
||||||
|
@ -309,7 +309,7 @@ class MangaReaderActivity : AppCompatActivity() {
|
||||||
binding.mangaReaderTitle.text = media.userPreferredName
|
binding.mangaReaderTitle.text = media.userPreferredName
|
||||||
|
|
||||||
chaptersArr = chapters.keys.toList()
|
chaptersArr = chapters.keys.toList()
|
||||||
currentChapterIndex = chaptersArr.indexOf(media.manga!!.selectedChapter)
|
currentChapterIndex = chaptersArr.indexOf(media.manga!!.selectedChapter!!.uniqueNumber())
|
||||||
|
|
||||||
chaptersTitleArr = arrayListOf()
|
chaptersTitleArr = arrayListOf()
|
||||||
chapters.forEach {
|
chapters.forEach {
|
||||||
|
@ -394,10 +394,10 @@ class MangaReaderActivity : AppCompatActivity() {
|
||||||
model.getMangaChapter().observe(this) { chap ->
|
model.getMangaChapter().observe(this) { chap ->
|
||||||
if (chap != null) {
|
if (chap != null) {
|
||||||
chapter = chap
|
chapter = chap
|
||||||
media.manga!!.selectedChapter = chapter.number
|
media.manga!!.selectedChapter = chapter
|
||||||
media.selected = model.loadSelected(media)
|
media.selected = model.loadSelected(media)
|
||||||
PrefManager.setCustomVal("${media.id}_current_chp", chap.number)
|
PrefManager.setCustomVal("${media.id}_current_chp", chap.number)
|
||||||
currentChapterIndex = chaptersArr.indexOf(chap.number)
|
currentChapterIndex = chaptersArr.indexOf(chap.uniqueNumber())
|
||||||
binding.mangaReaderChapterSelect.setSelection(currentChapterIndex)
|
binding.mangaReaderChapterSelect.setSelection(currentChapterIndex)
|
||||||
if (directionRLBT) {
|
if (directionRLBT) {
|
||||||
binding.mangaReaderNextChap.text =
|
binding.mangaReaderNextChap.text =
|
||||||
|
@ -1036,7 +1036,7 @@ class MangaReaderActivity : AppCompatActivity() {
|
||||||
PrefManager.setCustomVal("${media.id}_save_progress", true)
|
PrefManager.setCustomVal("${media.id}_save_progress", true)
|
||||||
updateProgress(
|
updateProgress(
|
||||||
media,
|
media,
|
||||||
MediaNameAdapter.findChapterNumber(media.manga!!.selectedChapter!!)
|
MediaNameAdapter.findChapterNumber(media.manga!!.selectedChapter!!.number)
|
||||||
.toString()
|
.toString()
|
||||||
)
|
)
|
||||||
runnable.run()
|
runnable.run()
|
||||||
|
@ -1057,7 +1057,7 @@ class MangaReaderActivity : AppCompatActivity() {
|
||||||
)
|
)
|
||||||
updateProgress(
|
updateProgress(
|
||||||
media,
|
media,
|
||||||
MediaNameAdapter.findChapterNumber(media.manga!!.selectedChapter!!)
|
MediaNameAdapter.findChapterNumber(media.manga!!.selectedChapter!!.number)
|
||||||
.toString()
|
.toString()
|
||||||
)
|
)
|
||||||
runnable.run()
|
runnable.run()
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
package ani.dantotsu.parsers
|
package ani.dantotsu.parsers
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
|
|
|
@ -90,7 +90,7 @@ abstract class MangaReadSources : BaseSources() {
|
||||||
show.sManga?.let { sManga ->
|
show.sManga?.let { sManga ->
|
||||||
tryWithSuspend(true) {
|
tryWithSuspend(true) {
|
||||||
parser.loadChapters(show.link, show.extra, sManga).forEach {
|
parser.loadChapters(show.link, show.extra, sManga).forEach {
|
||||||
map["${it.number}-${it.hashCode()}"] = MangaChapter(it)
|
map["${it.number}-${it.scanlator}"] = MangaChapter(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ abstract class MangaReadSources : BaseSources() {
|
||||||
tryWithSuspend(true) {
|
tryWithSuspend(true) {
|
||||||
// Since we've checked, we can safely cast parser to OfflineMangaParser and call its methods
|
// Since we've checked, we can safely cast parser to OfflineMangaParser and call its methods
|
||||||
parser.loadChapters(show.link, show.extra, SManga.create()).forEach {
|
parser.loadChapters(show.link, show.extra, SManga.create()).forEach {
|
||||||
map["${it.number}-${it.hashCode()}"] = MangaChapter(it)
|
map["${it.number}-${it.scanlator}"] = MangaChapter(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -31,13 +31,17 @@ class OfflineMangaParser : MangaParser() {
|
||||||
val chapters = mutableListOf<MangaChapter>()
|
val chapters = mutableListOf<MangaChapter>()
|
||||||
if (directory?.exists() == true) {
|
if (directory?.exists() == true) {
|
||||||
directory.listFiles().forEach {
|
directory.listFiles().forEach {
|
||||||
|
val scanlator = downloadManager.mangaDownloadedTypes.find { items ->
|
||||||
|
items.titleName == mangaLink &&
|
||||||
|
items.chapterName == it.name
|
||||||
|
}?.scanlator ?: "Unknown"
|
||||||
if (it.isDirectory) {
|
if (it.isDirectory) {
|
||||||
val chapter = MangaChapter(
|
val chapter = MangaChapter(
|
||||||
it.name!!,
|
it.name!!,
|
||||||
"$mangaLink/${it.name}",
|
"$mangaLink/${it.name}",
|
||||||
it.name,
|
it.name,
|
||||||
null,
|
null,
|
||||||
null,
|
scanlator,
|
||||||
SChapter.create()
|
SChapter.create()
|
||||||
)
|
)
|
||||||
chapters.add(chapter)
|
chapters.add(chapter)
|
||||||
|
@ -45,8 +49,7 @@ class OfflineMangaParser : MangaParser() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chapters.addAll(loadChaptersCompat(mangaLink, extra, sManga))
|
chapters.addAll(loadChaptersCompat(mangaLink, extra, sManga))
|
||||||
return chapters.distinctBy { it.number }
|
return chapters.sortedBy { MediaNameAdapter.findChapterNumber(it.number) }
|
||||||
.sortedBy { MediaNameAdapter.findChapterNumber(it.number) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun loadImages(chapterLink: String, sChapter: SChapter): List<MangaImage> {
|
override suspend fun loadImages(chapterLink: String, sChapter: SChapter): List<MangaImage> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue