readded download text progress

This commit is contained in:
LagradOst 2023-07-19 17:27:47 +02:00
parent 483ce2854f
commit 3ae44d5675
7 changed files with 40 additions and 10 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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)
}

View File

@ -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<MaterialButton>(R.id.download_movie_button),
textView,
card,
callback
)

View File

@ -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<UriRequest>) {

View File

@ -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 {

View File

@ -585,7 +585,8 @@ open class ResultFragmentPhone : FullScreenPlayer(),
null,
null,
System.currentTimeMillis(),
)
),
null
) { click ->
when (click.action) {
DOWNLOAD_ACTION_DOWNLOAD -> {