mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Fix download button display bug in adapter (#1175)
This commit is contained in:
parent
e5c9e96c83
commit
c1b5f5c128
3 changed files with 42 additions and 33 deletions
|
@ -4,6 +4,7 @@ import android.annotation.SuppressLint
|
||||||
import android.text.format.Formatter.formatShortFileSize
|
import android.text.format.Formatter.formatShortFileSize
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.ListAdapter
|
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.DownloadChildEpisodeBinding
|
||||||
import com.lagradost.cloudstream3.databinding.DownloadHeaderEpisodeBinding
|
import com.lagradost.cloudstream3.databinding.DownloadHeaderEpisodeBinding
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
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.ui.download.button.DownloadStatusTell
|
||||||
|
import com.lagradost.cloudstream3.utils.AppContextUtils.getNameFull
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.fixVisual
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.fixVisual
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
import com.lagradost.cloudstream3.utils.UIHelper.setImage
|
||||||
|
@ -135,8 +135,15 @@ class DownloadAdapter(
|
||||||
downloadButton.applyMetaData(card.child.id, card.currentBytes, card.totalBytes)
|
downloadButton.applyMetaData(card.child.id, card.currentBytes, card.totalBytes)
|
||||||
// We will let the view model handle this
|
// We will let the view model handle this
|
||||||
downloadButton.doSetProgress = false
|
downloadButton.doSetProgress = false
|
||||||
|
downloadButton.progressBar.progressDrawable =
|
||||||
|
downloadButton.getDrawableFromStatus(status)
|
||||||
|
?.let { ContextCompat.getDrawable(downloadButton.context, it) }
|
||||||
downloadHeaderInfo.text = formattedSizeString
|
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.setDefaultClickListener(card.child, downloadHeaderInfo, mediaClickCallback)
|
||||||
downloadButton.isVisible = true
|
downloadButton.isVisible = true
|
||||||
|
@ -197,8 +204,15 @@ class DownloadAdapter(
|
||||||
downloadButton.applyMetaData(d.id, card.currentBytes, card.totalBytes)
|
downloadButton.applyMetaData(d.id, card.currentBytes, card.totalBytes)
|
||||||
// We will let the view model handle this
|
// We will let the view model handle this
|
||||||
downloadButton.doSetProgress = false
|
downloadButton.doSetProgress = false
|
||||||
|
downloadButton.progressBar.progressDrawable =
|
||||||
|
downloadButton.getDrawableFromStatus(status)
|
||||||
|
?.let { ContextCompat.getDrawable(downloadButton.context, it) }
|
||||||
downloadChildEpisodeTextExtra.text = formatShortFileSize(downloadChildEpisodeTextExtra.context, card.totalBytes)
|
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.setDefaultClickListener(d, downloadChildEpisodeTextExtra, mediaClickCallback)
|
||||||
downloadButton.isVisible = true
|
downloadButton.isVisible = true
|
||||||
|
|
|
@ -40,7 +40,6 @@ import com.lagradost.cloudstream3.ui.result.setLinearListLayout
|
||||||
import com.lagradost.cloudstream3.ui.settings.Globals.TV
|
import com.lagradost.cloudstream3.ui.settings.Globals.TV
|
||||||
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
|
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
|
||||||
import com.lagradost.cloudstream3.utils.AppContextUtils.loadResult
|
import com.lagradost.cloudstream3.utils.AppContextUtils.loadResult
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.main
|
|
||||||
import com.lagradost.cloudstream3.utils.DOWNLOAD_EPISODE_CACHE
|
import com.lagradost.cloudstream3.utils.DOWNLOAD_EPISODE_CACHE
|
||||||
import com.lagradost.cloudstream3.utils.DataStore
|
import com.lagradost.cloudstream3.utils.DataStore
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.lagradost.cloudstream3.ui.download.button
|
package com.lagradost.cloudstream3.ui.download.button
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
@ -45,6 +44,8 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
private var iconPaused: Int = 0
|
private var iconPaused: Int = 0
|
||||||
private var hideWhenIcon: Boolean = true
|
private var hideWhenIcon: Boolean = true
|
||||||
|
|
||||||
|
var progressDrawable: Int = 0
|
||||||
|
|
||||||
var overrideLayout: Int? = null
|
var overrideLayout: Int? = null
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -115,10 +116,10 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
R.styleable.PieFetchButton_download_icon_complete, R.drawable.download_icon_done
|
R.styleable.PieFetchButton_download_icon_complete, R.drawable.download_icon_done
|
||||||
)
|
)
|
||||||
iconPaused = getResourceId(
|
iconPaused = getResourceId(
|
||||||
R.styleable.PieFetchButton_download_icon_paused, 0//R.drawable.download_icon_pause
|
R.styleable.PieFetchButton_download_icon_paused, 0 // R.drawable.download_icon_pause
|
||||||
)
|
)
|
||||||
iconActive = getResourceId(
|
iconActive = getResourceId(
|
||||||
R.styleable.PieFetchButton_download_icon_active, 0 //R.drawable.download_icon_load
|
R.styleable.PieFetchButton_download_icon_active, 0 // R.drawable.download_icon_load
|
||||||
)
|
)
|
||||||
iconWaiting = getResourceId(
|
iconWaiting = getResourceId(
|
||||||
R.styleable.PieFetchButton_download_icon_waiting, 0
|
R.styleable.PieFetchButton_download_icon_waiting, 0
|
||||||
|
@ -129,7 +130,7 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
|
|
||||||
val fillIndex = getInt(R.styleable.PieFetchButton_download_fill, 0)
|
val fillIndex = getInt(R.styleable.PieFetchButton_download_fill, 0)
|
||||||
|
|
||||||
val progressDrawable = getResourceId(
|
progressDrawable = getResourceId(
|
||||||
R.styleable.PieFetchButton_download_fill_override, fillArray[fillIndex]
|
R.styleable.PieFetchButton_download_fill_override, fillArray[fillIndex]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -170,7 +171,7 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
if (isZeroBytes) {
|
if (isZeroBytes) {
|
||||||
removeKey(KEY_RESUME_PACKAGES, card.id.toString())
|
removeKey(KEY_RESUME_PACKAGES, card.id.toString())
|
||||||
callback(DownloadClickEvent(DOWNLOAD_ACTION_DOWNLOAD, card))
|
callback(DownloadClickEvent(DOWNLOAD_ACTION_DOWNLOAD, card))
|
||||||
//callback.invoke(DownloadClickEvent(DOWNLOAD_ACTION_DOWNLOAD, data))
|
// callback.invoke(DownloadClickEvent(DOWNLOAD_ACTION_DOWNLOAD, data))
|
||||||
} else {
|
} else {
|
||||||
val list = arrayListOf(
|
val list = arrayListOf(
|
||||||
Pair(DOWNLOAD_ACTION_PLAY_FILE, R.string.popup_play_file),
|
Pair(DOWNLOAD_ACTION_PLAY_FILE, R.string.popup_play_file),
|
||||||
|
@ -197,7 +198,7 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
list
|
list
|
||||||
) {
|
) {
|
||||||
callback(DownloadClickEvent(itemId, card))
|
callback(DownloadClickEvent(itemId, card))
|
||||||
//callback.invoke(DownloadClickEvent(itemId, data))
|
// callback.invoke(DownloadClickEvent(itemId, data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,7 +206,7 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
view.setOnLongClickListener {
|
view.setOnLongClickListener {
|
||||||
callback(DownloadClickEvent(DOWNLOAD_ACTION_LONG_CLICK, card))
|
callback(DownloadClickEvent(DOWNLOAD_ACTION_LONG_CLICK, card))
|
||||||
|
|
||||||
//clickCallback.invoke(DownloadClickEvent(DOWNLOAD_ACTION_LONG_CLICK, data))
|
// clickCallback.invoke(DownloadClickEvent(DOWNLOAD_ACTION_LONG_CLICK, data))
|
||||||
return@setOnLongClickListener true
|
return@setOnLongClickListener true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,7 +219,7 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
setDefaultClickListener(this, textView, card, callback)
|
setDefaultClickListener(this, textView, card, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*open fun setDefaultClickListener(requestGetter: suspend BaseFetchButton.() -> List<UriRequest>) {
|
/* open fun setDefaultClickListener(requestGetter: suspend BaseFetchButton.() -> List<UriRequest>) {
|
||||||
this.setOnClickListener {
|
this.setOnClickListener {
|
||||||
when (this.currentStatus) {
|
when (this.currentStatus) {
|
||||||
null -> {
|
null -> {
|
||||||
|
@ -244,7 +245,7 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
} */
|
||||||
|
|
||||||
@MainThread
|
@MainThread
|
||||||
private fun setStatusInternal(status : DownloadStatusTell?) {
|
private fun setStatusInternal(status : DownloadStatusTell?) {
|
||||||
|
@ -262,7 +263,8 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
progressBarBackground.background =
|
progressBarBackground.background =
|
||||||
ContextCompat.getDrawable(context, progressDrawable)
|
ContextCompat.getDrawable(context, progressDrawable)
|
||||||
|
|
||||||
val drawable = getDrawableFromStatus(status)
|
val drawable =
|
||||||
|
getDrawableFromStatus(status)?.let { ContextCompat.getDrawable(this.context, it) }
|
||||||
statusView.setImageDrawable(drawable)
|
statusView.setImageDrawable(drawable)
|
||||||
val isDrawable = drawable != null
|
val isDrawable = drawable != null
|
||||||
|
|
||||||
|
@ -280,12 +282,12 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
override fun setStatus(status: DownloadStatusTell?) {
|
override fun setStatus(status: DownloadStatusTell?) {
|
||||||
currentStatus = status
|
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()) {
|
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||||
try {
|
try {
|
||||||
setStatusInternal(status)
|
setStatusInternal(status)
|
||||||
} catch (t : Throwable) {
|
} catch (t : Throwable) {
|
||||||
logError(t) // just in case setStatusInternal throws because thread
|
logError(t) // Just in case setStatusInternal throws because thread
|
||||||
progressBarBackground.post {
|
progressBarBackground.post {
|
||||||
setStatusInternal(status)
|
setStatusInternal(status)
|
||||||
}
|
}
|
||||||
|
@ -325,19 +327,13 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun getDrawableFromStatus(status: DownloadStatusTell?): Drawable? {
|
open fun getDrawableFromStatus(status: DownloadStatusTell?): Int? = when (status) {
|
||||||
val drawableInt = when (status) {
|
|
||||||
DownloadStatusTell.IsPaused -> iconPaused
|
DownloadStatusTell.IsPaused -> iconPaused
|
||||||
DownloadStatusTell.IsPending -> iconWaiting
|
DownloadStatusTell.IsPending -> iconWaiting
|
||||||
DownloadStatusTell.IsDownloading -> iconActive
|
DownloadStatusTell.IsDownloading -> iconActive
|
||||||
DownloadStatusTell.IsFailed -> iconError
|
DownloadStatusTell.IsFailed -> iconError
|
||||||
DownloadStatusTell.IsDone -> iconComplete
|
DownloadStatusTell.IsDone -> iconComplete
|
||||||
DownloadStatusTell.IsStopped -> iconRemoved
|
DownloadStatusTell.IsStopped -> iconRemoved
|
||||||
null -> iconInit
|
else -> iconInit
|
||||||
}
|
}.takeIf { it != 0 }
|
||||||
if (drawableInt == 0) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
return ContextCompat.getDrawable(this.context, drawableInt)
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue