From 3ae44d56757a1605cc00f4a5c7d8a6501f935fa2 Mon Sep 17 00:00:00 2001 From: LagradOst <11805592+LagradOst@users.noreply.github.com> Date: Wed, 19 Jul 2023 17:27:47 +0200 Subject: [PATCH] readded download text progress --- .../ui/download/DownloadChildAdapter.kt | 2 +- .../ui/download/DownloadHeaderAdapter.kt | 2 +- .../ui/download/button/BaseFetchButton.kt | 25 ++++++++++++++++++- .../ui/download/button/DownloadButton.kt | 3 ++- .../ui/download/button/PieFetchButton.kt | 11 +++++--- .../cloudstream3/ui/result/EpisodeAdapter.kt | 4 +-- .../ui/result/ResultFragmentPhone.kt | 3 ++- 7 files changed, 40 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildAdapter.kt index 61981fca..b4774cf8 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildAdapter.kt @@ -78,7 +78,7 @@ class DownloadChildAdapter( } } - binding.downloadButton.setDefaultClickListener(card.data,clickCallback) + binding.downloadButton.setDefaultClickListener(card.data, binding.downloadChildEpisodeTextExtra, clickCallback) binding.downloadChildEpisodeText.apply { text = context.getNameFull(d.name, d.episode, d.season) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadHeaderAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadHeaderAdapter.kt index 74157d0d..65a6441f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadHeaderAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadHeaderAdapter.kt @@ -97,7 +97,7 @@ class DownloadHeaderAdapter( // downloadHeaderEpisodeDownload.visibility = View.VISIBLE binding.downloadHeaderGotoChild.visibility = View.GONE - downloadButton.setDefaultClickListener(card.child, movieClickCallback) + downloadButton.setDefaultClickListener(card.child, downloadHeaderInfo, movieClickCallback) downloadButton.isVisible = true /*setUpButton( card.currentBytes, 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 4067f719..05f630a0 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,10 +1,14 @@ package com.lagradost.cloudstream3.ui.download.button import android.content.Context +import android.text.format.Formatter import android.util.AttributeSet import android.widget.FrameLayout +import android.widget.TextView import androidx.annotation.LayoutRes +import androidx.core.view.isVisible import androidx.core.widget.ContentLoadingProgressBar +import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.utils.VideoDownloadManager typealias DownloadStatusTell = VideoDownloadManager.DownloadType @@ -15,7 +19,11 @@ data class DownloadMetadata( var totalLength: Long, var status: DownloadStatusTell? = null ) { - val progressPercentage : Long get() = if(downloadedLength < 1024) 0 else maxOf(0,minOf (100, (downloadedLength * 100L) / totalLength)) + val progressPercentage: Long + get() = if (downloadedLength < 1024) 0 else maxOf( + 0, + minOf(100, (downloadedLength * 100L) / totalLength) + ) } abstract class BaseFetchButton(context: Context, attributeSet: AttributeSet) : @@ -24,6 +32,7 @@ abstract class BaseFetchButton(context: Context, attributeSet: AttributeSet) : var persistentId: Int? = null // used to save sessions lateinit var progressBar: ContentLoadingProgressBar + var progressText: TextView? = null /*val gid: String? get() = sessionIdToGid[persistentId] @@ -109,6 +118,20 @@ abstract class BaseFetchButton(context: Context, attributeSet: AttributeSet) : else 0L } + + if (isZeroBytes) { + progressText?.isVisible = false + } else { + progressText?.apply { + val currentMbString = Formatter.formatShortFileSize(context, downloadedBytes) + val totalMbString = Formatter.formatShortFileSize(context, totalBytes) + text = + //if (isTextPercentage) "%d%%".format(setCurrentBytes * 100L / setTotalBytes) else + context?.getString(R.string.download_size_format) + ?.format(currentMbString, totalMbString) + } + } + progressBar.startAnimation(animation) } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/button/DownloadButton.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/button/DownloadButton.kt index 993bdeba..bb2ba7b1 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/button/DownloadButton.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/button/DownloadButton.kt @@ -13,7 +13,6 @@ import com.lagradost.cloudstream3.utils.VideoDownloadHelper class DownloadButton(context: Context, attributeSet: AttributeSet) : PieFetchButton(context, attributeSet) { - var progressText: TextView? = null var mainText: TextView? = null override fun onAttachedToWindow() { super.onAttachedToWindow() @@ -34,10 +33,12 @@ class DownloadButton(context: Context, attributeSet: AttributeSet) : override fun setDefaultClickListener( card: VideoDownloadHelper.DownloadEpisodeCached, + textView: TextView?, callback: (DownloadClickEvent) -> Unit ) { this.setDefaultClickListener( this.findViewById(R.id.download_movie_button), + textView, card, callback ) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/button/PieFetchButton.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/button/PieFetchButton.kt index db36f3a0..0b7a7fea 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/button/PieFetchButton.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/button/PieFetchButton.kt @@ -7,6 +7,7 @@ import android.util.Log import android.view.View import android.view.animation.AnimationUtils import android.widget.ImageView +import android.widget.TextView import androidx.core.content.ContextCompat import androidx.core.view.isGone import androidx.core.view.isVisible @@ -155,8 +156,11 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) : ) }*/ - protected fun setDefaultClickListener(view: View, card: VideoDownloadHelper.DownloadEpisodeCached, - callback: (DownloadClickEvent) -> Unit) { + protected fun setDefaultClickListener( + view: View, textView: TextView?, card: VideoDownloadHelper.DownloadEpisodeCached, + callback: (DownloadClickEvent) -> Unit + ) { + this.progressText = textView this.setPersistentId(card.id) view.setOnClickListener { if (isZeroBytes) { @@ -203,9 +207,10 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) : open fun setDefaultClickListener( card: VideoDownloadHelper.DownloadEpisodeCached, + textView: TextView?, callback: (DownloadClickEvent) -> Unit ) { - setDefaultClickListener(this,card,callback) + setDefaultClickListener(this, textView, card, callback) } /*open fun setDefaultClickListener(requestGetter: suspend BaseFetchButton.() -> List) { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt index d6e8273f..2cca69ed 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt @@ -179,7 +179,7 @@ class EpisodeAdapter( card.rating, card.description, System.currentTimeMillis(), - )) { + ), null) { if (it.action == DOWNLOAD_ACTION_DOWNLOAD) { clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card)) } else { @@ -284,7 +284,7 @@ class EpisodeAdapter( card.rating, card.description, System.currentTimeMillis(), - )) { + ), null) { if (it.action == DOWNLOAD_ACTION_DOWNLOAD) { clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card)) } else { diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentPhone.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentPhone.kt index e4ac13f8..fac6ee8f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentPhone.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultFragmentPhone.kt @@ -585,7 +585,8 @@ open class ResultFragmentPhone : FullScreenPlayer(), null, null, System.currentTimeMillis(), - ) + ), + null ) { click -> when (click.action) { DOWNLOAD_ACTION_DOWNLOAD -> {