mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
readded download text progress
This commit is contained in:
parent
483ce2854f
commit
3ae44d5675
7 changed files with 40 additions and 10 deletions
|
@ -78,7 +78,7 @@ class DownloadChildAdapter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.downloadButton.setDefaultClickListener(card.data,clickCallback)
|
binding.downloadButton.setDefaultClickListener(card.data, binding.downloadChildEpisodeTextExtra, clickCallback)
|
||||||
|
|
||||||
binding.downloadChildEpisodeText.apply {
|
binding.downloadChildEpisodeText.apply {
|
||||||
text = context.getNameFull(d.name, d.episode, d.season)
|
text = context.getNameFull(d.name, d.episode, d.season)
|
||||||
|
|
|
@ -97,7 +97,7 @@ class DownloadHeaderAdapter(
|
||||||
// downloadHeaderEpisodeDownload.visibility = View.VISIBLE
|
// downloadHeaderEpisodeDownload.visibility = View.VISIBLE
|
||||||
binding.downloadHeaderGotoChild.visibility = View.GONE
|
binding.downloadHeaderGotoChild.visibility = View.GONE
|
||||||
|
|
||||||
downloadButton.setDefaultClickListener(card.child, movieClickCallback)
|
downloadButton.setDefaultClickListener(card.child, downloadHeaderInfo, movieClickCallback)
|
||||||
downloadButton.isVisible = true
|
downloadButton.isVisible = true
|
||||||
/*setUpButton(
|
/*setUpButton(
|
||||||
card.currentBytes,
|
card.currentBytes,
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package com.lagradost.cloudstream3.ui.download.button
|
package com.lagradost.cloudstream3.ui.download.button
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.text.format.Formatter
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.annotation.LayoutRes
|
import androidx.annotation.LayoutRes
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.widget.ContentLoadingProgressBar
|
import androidx.core.widget.ContentLoadingProgressBar
|
||||||
|
import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.utils.VideoDownloadManager
|
import com.lagradost.cloudstream3.utils.VideoDownloadManager
|
||||||
|
|
||||||
typealias DownloadStatusTell = VideoDownloadManager.DownloadType
|
typealias DownloadStatusTell = VideoDownloadManager.DownloadType
|
||||||
|
@ -15,7 +19,11 @@ data class DownloadMetadata(
|
||||||
var totalLength: Long,
|
var totalLength: Long,
|
||||||
var status: DownloadStatusTell? = null
|
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) :
|
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
|
var persistentId: Int? = null // used to save sessions
|
||||||
|
|
||||||
lateinit var progressBar: ContentLoadingProgressBar
|
lateinit var progressBar: ContentLoadingProgressBar
|
||||||
|
var progressText: TextView? = null
|
||||||
|
|
||||||
/*val gid: String? get() = sessionIdToGid[persistentId]
|
/*val gid: String? get() = sessionIdToGid[persistentId]
|
||||||
|
|
||||||
|
@ -109,6 +118,20 @@ abstract class BaseFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
else
|
else
|
||||||
0L
|
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)
|
progressBar.startAnimation(animation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ import com.lagradost.cloudstream3.utils.VideoDownloadHelper
|
||||||
class DownloadButton(context: Context, attributeSet: AttributeSet) :
|
class DownloadButton(context: Context, attributeSet: AttributeSet) :
|
||||||
PieFetchButton(context, attributeSet) {
|
PieFetchButton(context, attributeSet) {
|
||||||
|
|
||||||
var progressText: TextView? = null
|
|
||||||
var mainText: TextView? = null
|
var mainText: TextView? = null
|
||||||
override fun onAttachedToWindow() {
|
override fun onAttachedToWindow() {
|
||||||
super.onAttachedToWindow()
|
super.onAttachedToWindow()
|
||||||
|
@ -34,10 +33,12 @@ class DownloadButton(context: Context, attributeSet: AttributeSet) :
|
||||||
|
|
||||||
override fun setDefaultClickListener(
|
override fun setDefaultClickListener(
|
||||||
card: VideoDownloadHelper.DownloadEpisodeCached,
|
card: VideoDownloadHelper.DownloadEpisodeCached,
|
||||||
|
textView: TextView?,
|
||||||
callback: (DownloadClickEvent) -> Unit
|
callback: (DownloadClickEvent) -> Unit
|
||||||
) {
|
) {
|
||||||
this.setDefaultClickListener(
|
this.setDefaultClickListener(
|
||||||
this.findViewById<MaterialButton>(R.id.download_movie_button),
|
this.findViewById<MaterialButton>(R.id.download_movie_button),
|
||||||
|
textView,
|
||||||
card,
|
card,
|
||||||
callback
|
callback
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.animation.AnimationUtils
|
import android.view.animation.AnimationUtils
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
@ -155,8 +156,11 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
)
|
)
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
protected fun setDefaultClickListener(view: View, card: VideoDownloadHelper.DownloadEpisodeCached,
|
protected fun setDefaultClickListener(
|
||||||
callback: (DownloadClickEvent) -> Unit) {
|
view: View, textView: TextView?, card: VideoDownloadHelper.DownloadEpisodeCached,
|
||||||
|
callback: (DownloadClickEvent) -> Unit
|
||||||
|
) {
|
||||||
|
this.progressText = textView
|
||||||
this.setPersistentId(card.id)
|
this.setPersistentId(card.id)
|
||||||
view.setOnClickListener {
|
view.setOnClickListener {
|
||||||
if (isZeroBytes) {
|
if (isZeroBytes) {
|
||||||
|
@ -203,9 +207,10 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
|
|
||||||
open fun setDefaultClickListener(
|
open fun setDefaultClickListener(
|
||||||
card: VideoDownloadHelper.DownloadEpisodeCached,
|
card: VideoDownloadHelper.DownloadEpisodeCached,
|
||||||
|
textView: TextView?,
|
||||||
callback: (DownloadClickEvent) -> Unit
|
callback: (DownloadClickEvent) -> Unit
|
||||||
) {
|
) {
|
||||||
setDefaultClickListener(this,card,callback)
|
setDefaultClickListener(this, textView, card, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*open fun setDefaultClickListener(requestGetter: suspend BaseFetchButton.() -> List<UriRequest>) {
|
/*open fun setDefaultClickListener(requestGetter: suspend BaseFetchButton.() -> List<UriRequest>) {
|
||||||
|
|
|
@ -179,7 +179,7 @@ class EpisodeAdapter(
|
||||||
card.rating,
|
card.rating,
|
||||||
card.description,
|
card.description,
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
)) {
|
), null) {
|
||||||
if (it.action == DOWNLOAD_ACTION_DOWNLOAD) {
|
if (it.action == DOWNLOAD_ACTION_DOWNLOAD) {
|
||||||
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card))
|
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card))
|
||||||
} else {
|
} else {
|
||||||
|
@ -284,7 +284,7 @@ class EpisodeAdapter(
|
||||||
card.rating,
|
card.rating,
|
||||||
card.description,
|
card.description,
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
)) {
|
), null) {
|
||||||
if (it.action == DOWNLOAD_ACTION_DOWNLOAD) {
|
if (it.action == DOWNLOAD_ACTION_DOWNLOAD) {
|
||||||
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card))
|
clickCallback.invoke(EpisodeClickEvent(ACTION_DOWNLOAD_EPISODE, card))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -585,7 +585,8 @@ open class ResultFragmentPhone : FullScreenPlayer(),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
)
|
),
|
||||||
|
null
|
||||||
) { click ->
|
) { click ->
|
||||||
when (click.action) {
|
when (click.action) {
|
||||||
DOWNLOAD_ACTION_DOWNLOAD -> {
|
DOWNLOAD_ACTION_DOWNLOAD -> {
|
||||||
|
|
Loading…
Reference in a new issue