downloads showing for all media fix

This commit is contained in:
rebelonion 2024-01-17 23:40:14 -06:00
parent 5459908201
commit 26b6564825
2 changed files with 19 additions and 4 deletions

View file

@ -527,9 +527,11 @@ class AnimeWatchFragment : Fragment() {
episodeAdapter.updateType(style ?: uiSettings.animeDefaultView) episodeAdapter.updateType(style ?: uiSettings.animeDefaultView)
episodeAdapter.notifyItemRangeInserted(0, arr.size) episodeAdapter.notifyItemRangeInserted(0, arr.size)
for (download in downloadManager.animeDownloadedTypes) { for (download in downloadManager.animeDownloadedTypes) {
if (download.title == media.mainName()) {
episodeAdapter.stopDownload(download.chapter) episodeAdapter.stopDownload(download.chapter)
} }
} }
}
override fun onDestroy() { override fun onDestroy() {
model.watchSources?.flushText() model.watchSources?.flushText()

View file

@ -12,6 +12,7 @@ import androidx.core.content.ContextCompat
import androidx.lifecycle.coroutineScope import androidx.lifecycle.coroutineScope
import androidx.media3.common.util.UnstableApi import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.offline.Download import androidx.media3.exoplayer.offline.Download
import androidx.media3.exoplayer.offline.DownloadIndex
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import ani.dantotsu.* import ani.dantotsu.*
import ani.dantotsu.connections.updateProgress import ani.dantotsu.connections.updateProgress
@ -45,6 +46,7 @@ fun handleProgress(cont: LinearLayout, bar: View, empty: View, mediaId: Int, ep:
} }
} }
@OptIn(UnstableApi::class)
class EpisodeAdapter( class EpisodeAdapter(
private var type: Int, private var type: Int,
private val media: Media, private val media: Media,
@ -53,6 +55,14 @@ class EpisodeAdapter(
var offlineMode: Boolean var offlineMode: Boolean
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { ) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private lateinit var index: DownloadIndex
init {
if (offlineMode) {
index = Helper.downloadManager(fragment.requireContext()).downloadIndex
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return (when (viewType) { return (when (viewType) {
0 -> EpisodeListViewHolder( 0 -> EpisodeListViewHolder(
@ -246,9 +256,12 @@ class EpisodeAdapter(
taskName, taskName,
"" ""
) ?: "" ) ?: ""
val index = Helper.downloadManager(fragment.requireContext()).downloadIndex val size = try {
val download = index.getDownload(id) val download = index.getDownload(id)
val size = bytesToHuman(download?.bytesDownloaded?:0) bytesToHuman(download?.bytesDownloaded ?: 0)
} catch (e: Exception) {
null
}
arr[position].downloadProgress = "Downloaded" + if (size != null) ": ($size)" else "" arr[position].downloadProgress = "Downloaded" + if (size != null) ": ($size)" else ""
notifyItemChanged(position) notifyItemChanged(position)