mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Fix download button bug display in adapter
I had a patch-fix for this before so it does not really happen anymore but this should fix the actual issue behind it also, making it more reliable than relying on `setItemViewCacheSize`
This commit is contained in:
parent
e5c9e96c83
commit
27d0bba95c
2 changed files with 47 additions and 35 deletions
|
@ -4,6 +4,7 @@ import android.annotation.SuppressLint
|
|||
import android.text.format.Formatter.formatShortFileSize
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
|
@ -13,9 +14,8 @@ import com.lagradost.cloudstream3.R
|
|||
import com.lagradost.cloudstream3.databinding.DownloadChildEpisodeBinding
|
||||
import com.lagradost.cloudstream3.databinding.DownloadHeaderEpisodeBinding
|
||||
import com.lagradost.cloudstream3.mvvm.logError
|
||||
import com.lagradost.cloudstream3.utils.AppContextUtils.getNameFull
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper
|
||||
import com.lagradost.cloudstream3.ui.download.button.DownloadStatusTell
|
||||
import com.lagradost.cloudstream3.utils.AppContextUtils.getNameFull
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.fixVisual
|
||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
|
||||
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
||||
|
@ -135,8 +135,15 @@ class DownloadAdapter(
|
|||
downloadButton.applyMetaData(card.child.id, card.currentBytes, card.totalBytes)
|
||||
// We will let the view model handle this
|
||||
downloadButton.doSetProgress = false
|
||||
downloadButton.progressBar.progressDrawable =
|
||||
downloadButton.getDrawableFromStatus(status)
|
||||
?.let { ContextCompat.getDrawable(downloadButton.context, it) }
|
||||
downloadHeaderInfo.text = formattedSizeString
|
||||
} else downloadButton.doSetProgress = true
|
||||
} else {
|
||||
downloadButton.doSetProgress = true
|
||||
downloadButton.progressBar.progressDrawable =
|
||||
ContextCompat.getDrawable(downloadButton.context, downloadButton.progressDrawable)
|
||||
}
|
||||
|
||||
downloadButton.setDefaultClickListener(card.child, downloadHeaderInfo, mediaClickCallback)
|
||||
downloadButton.isVisible = true
|
||||
|
@ -197,8 +204,15 @@ class DownloadAdapter(
|
|||
downloadButton.applyMetaData(d.id, card.currentBytes, card.totalBytes)
|
||||
// We will let the view model handle this
|
||||
downloadButton.doSetProgress = false
|
||||
downloadButton.progressBar.progressDrawable =
|
||||
downloadButton.getDrawableFromStatus(status)
|
||||
?.let { ContextCompat.getDrawable(downloadButton.context, it) }
|
||||
downloadChildEpisodeTextExtra.text = formatShortFileSize(downloadChildEpisodeTextExtra.context, card.totalBytes)
|
||||
} else downloadButton.doSetProgress = true
|
||||
} else {
|
||||
downloadButton.doSetProgress = true
|
||||
downloadButton.progressBar.progressDrawable =
|
||||
ContextCompat.getDrawable(downloadButton.context, downloadButton.progressDrawable)
|
||||
}
|
||||
|
||||
downloadButton.setDefaultClickListener(d, downloadChildEpisodeTextExtra, mediaClickCallback)
|
||||
downloadButton.isVisible = true
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.lagradost.cloudstream3.ui.download.button
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Looper
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
|
@ -45,6 +44,8 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
|||
private var iconPaused: Int = 0
|
||||
private var hideWhenIcon: Boolean = true
|
||||
|
||||
var progressDrawable: Int = 0
|
||||
|
||||
var overrideLayout: Int? = null
|
||||
|
||||
companion object {
|
||||
|
@ -127,13 +128,15 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
|||
R.styleable.PieFetchButton_download_icon_removed, R.drawable.netflix_download
|
||||
)
|
||||
|
||||
if (doSetProgress) {
|
||||
val fillIndex = getInt(R.styleable.PieFetchButton_download_fill, 0)
|
||||
|
||||
val progressDrawable = getResourceId(
|
||||
progressDrawable = getResourceId(
|
||||
R.styleable.PieFetchButton_download_fill_override, fillArray[fillIndex]
|
||||
)
|
||||
|
||||
progressBar.progressDrawable = ContextCompat.getDrawable(context, progressDrawable)
|
||||
}
|
||||
|
||||
recycle()
|
||||
}
|
||||
|
@ -262,7 +265,8 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
|||
progressBarBackground.background =
|
||||
ContextCompat.getDrawable(context, progressDrawable)
|
||||
|
||||
val drawable = getDrawableFromStatus(status)
|
||||
val drawable =
|
||||
getDrawableFromStatus(status)?.let { ContextCompat.getDrawable(this.context, it) }
|
||||
statusView.setImageDrawable(drawable)
|
||||
val isDrawable = drawable != null
|
||||
|
||||
|
@ -280,12 +284,12 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
|||
override fun setStatus(status: DownloadStatusTell?) {
|
||||
currentStatus = status
|
||||
|
||||
// runs on the main thread, but also instant if it already is
|
||||
// Runs on the main thread, but also instant if it already is
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
try {
|
||||
setStatusInternal(status)
|
||||
} catch (t : Throwable) {
|
||||
logError(t) // just in case setStatusInternal throws because thread
|
||||
logError(t) // Just in case setStatusInternal throws because thread
|
||||
progressBarBackground.post {
|
||||
setStatusInternal(status)
|
||||
}
|
||||
|
@ -325,19 +329,13 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
|||
}
|
||||
}
|
||||
|
||||
open fun getDrawableFromStatus(status: DownloadStatusTell?): Drawable? {
|
||||
val drawableInt = when (status) {
|
||||
open fun getDrawableFromStatus(status: DownloadStatusTell?): Int? = when (status) {
|
||||
DownloadStatusTell.IsPaused -> iconPaused
|
||||
DownloadStatusTell.IsPending -> iconWaiting
|
||||
DownloadStatusTell.IsDownloading -> iconActive
|
||||
DownloadStatusTell.IsFailed -> iconError
|
||||
DownloadStatusTell.IsDone -> iconComplete
|
||||
DownloadStatusTell.IsStopped -> iconRemoved
|
||||
null -> iconInit
|
||||
}
|
||||
if (drawableInt == 0) {
|
||||
return null
|
||||
}
|
||||
return ContextCompat.getDrawable(this.context, drawableInt)
|
||||
}
|
||||
else -> iconInit
|
||||
}.takeIf { it != 0 }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue