From 96ed04f7cde2a0e3c55639fdeedebbeee16d7bad Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Tue, 2 Jul 2024 10:39:00 -0600 Subject: [PATCH] Minor cleanup --- .../ui/download/DownloadAdapter.kt | 10 ++++---- .../ui/download/DownloadViewModel.kt | 4 ++-- .../ui/download/button/BaseFetchButton.kt | 24 +++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadAdapter.kt index 0a562f73..b0f625e9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadAdapter.kt @@ -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 { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadViewModel.kt index bb19d4ab..77330dc2 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadViewModel.kt @@ -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 diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/button/BaseFetchButton.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/button/BaseFetchButton.kt index 76a40384..f10e103e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/button/BaseFetchButton.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/button/BaseFetchButton.kt @@ -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 @@ -36,7 +36,7 @@ abstract class BaseFetchButton(context: Context, attributeSet: AttributeSet) : lateinit var progressBar: ContentLoadingProgressBar var progressText: TextView? = null - /*val gid: String? get() = sessionIdToGid[persistentId] + /* val gid: String? get() = sessionIdToGid[persistentId] // used for resuming data var _lastRequestOverride: UriRequest? = null @@ -46,7 +46,7 @@ abstract class BaseFetchButton(context: Context, attributeSet: AttributeSet) : _lastRequestOverride = value } - var files: List = emptyList()*/ + var files: List = emptyList() */ protected var isZeroBytes: Boolean = true fun inflate(@LayoutRes layout: Int) { @@ -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 + // if (isTextPercentage) "%d%%".format(setCurrentBytes * 100L / setTotalBytes) else context?.getString(R.string.download_size_format) - ?.format(currentMbString, totalMbString) + ?.format(currentFormattedSizeString, totalFormattedSizeString) } } } @@ -182,8 +182,8 @@ abstract class BaseFetchButton(context: Context, attributeSet: AttributeSet) : override fun onAttachedToWindow() { VideoDownloadManager.downloadStatusEvent += ::downloadStatusEvent - //VideoDownloadManager.downloadDeleteEvent += ::downloadDeleteEvent - //VideoDownloadManager.downloadEvent += ::downloadEvent + // VideoDownloadManager.downloadDeleteEvent += ::downloadDeleteEvent + // VideoDownloadManager.downloadEvent += ::downloadEvent VideoDownloadManager.downloadProgressEvent += ::downloadProgressEvent val pid = persistentId @@ -197,8 +197,8 @@ abstract class BaseFetchButton(context: Context, attributeSet: AttributeSet) : override fun onDetachedFromWindow() { VideoDownloadManager.downloadStatusEvent -= ::downloadStatusEvent - //VideoDownloadManager.downloadDeleteEvent -= ::downloadDeleteEvent - //VideoDownloadManager.downloadEvent -= ::downloadEvent + // VideoDownloadManager.downloadDeleteEvent -= ::downloadDeleteEvent + // VideoDownloadManager.downloadEvent -= ::downloadEvent VideoDownloadManager.downloadProgressEvent -= ::downloadProgressEvent super.onDetachedFromWindow()