Minor cleanup

This commit is contained in:
Luna712 2024-07-02 10:39:00 -06:00 committed by GitHub
parent 0e0e346bd0
commit 96ed04f7cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 19 deletions

View file

@ -15,8 +15,8 @@ import com.lagradost.cloudstream3.databinding.DownloadHeaderEpisodeBinding
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.ui.download.button.DownloadStatusTell
import com.lagradost.cloudstream3.utils.AppUtils.getNameFull
import com.lagradost.cloudstream3.utils.DataStoreHelper
import com.lagradost.cloudstream3.utils.DataStoreHelper.fixVisual
import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
import com.lagradost.cloudstream3.utils.UIHelper.setImage
import com.lagradost.cloudstream3.utils.VideoDownloadHelper
@ -116,7 +116,7 @@ class DownloadAdapter(
}
downloadHeaderTitle.text = d.name
val mbString = formatShortFileSize(itemView.context, card.totalBytes)
val formattedSizeString = formatShortFileSize(itemView.context, card.totalBytes)
if (card.child != null) {
downloadHeaderGotoChild.isVisible = false
@ -131,7 +131,7 @@ class DownloadAdapter(
downloadButton.applyMetaData(card.child.id, card.currentBytes, card.totalBytes)
// We will let the view model handle this
downloadButton.doSetProgress = false
downloadHeaderInfo.text = formatShortFileSize(downloadHeaderInfo.context, card.totalBytes)
downloadHeaderInfo.text = formattedSizeString
} else downloadButton.doSetProgress = true
downloadButton.setDefaultClickListener(card.child, downloadHeaderInfo, mediaClickCallback)
@ -152,7 +152,7 @@ class DownloadAdapter(
R.plurals.episodes,
card.totalDownloads
),
mbString
formattedSizeString
)
} catch (e: Exception) {
// You probably formatted incorrectly
@ -173,7 +173,7 @@ class DownloadAdapter(
val d = card.data
binding.apply {
val posDur = DataStoreHelper.getViewPos(d.id)
val posDur = getViewPos(d.id)
downloadChildEpisodeProgress.apply {
isVisible = posDur != null
posDur?.let {

View file

@ -16,7 +16,7 @@ import com.lagradost.cloudstream3.utils.DataStore.getFolderName
import com.lagradost.cloudstream3.utils.DataStore.getKey
import com.lagradost.cloudstream3.utils.DataStore.getKeys
import com.lagradost.cloudstream3.utils.VideoDownloadHelper
import com.lagradost.cloudstream3.utils.VideoDownloadManager
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getDownloadFileInfoAndUpdateSettings
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@ -57,7 +57,7 @@ class DownloadViewModel : ViewModel() {
// Gets all children downloads
withContext(Dispatchers.IO) {
children.forEach { c ->
val childFile = VideoDownloadManager.getDownloadFileInfoAndUpdateSettings(context, c.id) ?: return@forEach
val childFile = getDownloadFileInfoAndUpdateSettings(context, c.id) ?: return@forEach
if (childFile.fileLength <= 1) return@forEach
val len = childFile.totalBytes

View file

@ -1,7 +1,7 @@
package com.lagradost.cloudstream3.ui.download.button
import android.content.Context
import android.text.format.Formatter
import android.text.format.Formatter.formatShortFileSize
import android.util.AttributeSet
import android.widget.FrameLayout
import android.widget.TextView
@ -93,6 +93,7 @@ abstract class BaseFetchButton(context: Context, attributeSet: AttributeSet) :
abstract fun setStatus(status: VideoDownloadManager.DownloadType?)
fun getStatus(id:Int, downloadedBytes: Long, totalBytes: Long): DownloadStatusTell {
// some extra padding for just in case
return VideoDownloadManager.downloadStatus[id]
?: if (downloadedBytes > 1024L && downloadedBytes + 1024L >= totalBytes) {
DownloadStatusTell.IsDone
@ -138,13 +139,12 @@ abstract class BaseFetchButton(context: Context, attributeSet: AttributeSet) :
} else {
if (doSetProgress) {
progressText?.apply {
val currentMbString =
Formatter.formatShortFileSize(context, downloadedBytes)
val totalMbString = Formatter.formatShortFileSize(context, totalBytes)
val currentFormattedSizeString = formatShortFileSize(context, downloadedBytes)
val totalFormattedSizeString = formatShortFileSize(context, totalBytes)
text =
// if (isTextPercentage) "%d%%".format(setCurrentBytes * 100L / setTotalBytes) else
context?.getString(R.string.download_size_format)
?.format(currentMbString, totalMbString)
?.format(currentFormattedSizeString, totalFormattedSizeString)
}
}
}