mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Cleanup
This commit is contained in:
parent
8286119062
commit
cb21eff44a
6 changed files with 112 additions and 32 deletions
app/src/main/java/com/lagradost/cloudstream3/ui/download
|
@ -1,6 +1,5 @@
|
|||
package com.lagradost.cloudstream3.ui.download
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.text.format.Formatter.formatShortFileSize
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
|
@ -114,7 +113,12 @@ class DownloadAdapter(
|
|||
}
|
||||
} else {
|
||||
setOnClickListener {
|
||||
onHeaderClickEvent.invoke(DownloadHeaderClickEvent(DOWNLOAD_ACTION_LOAD_RESULT, data))
|
||||
onHeaderClickEvent.invoke(
|
||||
DownloadHeaderClickEvent(
|
||||
DOWNLOAD_ACTION_LOAD_RESULT,
|
||||
data
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,7 +172,10 @@ class DownloadAdapter(
|
|||
} else {
|
||||
downloadButton.doSetProgress = true
|
||||
downloadButton.progressBar.progressDrawable =
|
||||
ContextCompat.getDrawable(downloadButton.context, downloadButton.progressDrawable)
|
||||
ContextCompat.getDrawable(
|
||||
downloadButton.context,
|
||||
downloadButton.progressDrawable
|
||||
)
|
||||
}
|
||||
|
||||
downloadButton.setDefaultClickListener(card.child, downloadHeaderInfo, onItemClickEvent)
|
||||
|
@ -176,12 +183,16 @@ class DownloadAdapter(
|
|||
|
||||
if (!isMultiDeleteState) {
|
||||
episodeHolder.setOnClickListener {
|
||||
onItemClickEvent.invoke(DownloadClickEvent(DOWNLOAD_ACTION_PLAY_FILE, card.child))
|
||||
onItemClickEvent.invoke(
|
||||
DownloadClickEvent(
|
||||
DOWNLOAD_ACTION_PLAY_FILE,
|
||||
card.child
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private fun DownloadHeaderEpisodeBinding.handleParentDownload(
|
||||
card: VisualDownloadCached.Header,
|
||||
formattedSize: String
|
||||
|
@ -190,19 +201,28 @@ class DownloadAdapter(
|
|||
downloadHeaderGotoChild.isVisible = !isMultiDeleteState
|
||||
|
||||
try {
|
||||
downloadHeaderInfo.text = downloadHeaderInfo.context.getString(R.string.extra_info_format).format(
|
||||
card.totalDownloads,
|
||||
downloadHeaderInfo.context.resources.getQuantityString(R.plurals.episodes, card.totalDownloads),
|
||||
formattedSize
|
||||
)
|
||||
downloadHeaderInfo.text =
|
||||
downloadHeaderInfo.context.getString(R.string.extra_info_format).format(
|
||||
card.totalDownloads,
|
||||
downloadHeaderInfo.context.resources.getQuantityString(
|
||||
R.plurals.episodes,
|
||||
card.totalDownloads
|
||||
),
|
||||
formattedSize
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
downloadHeaderInfo.text = "Error"
|
||||
downloadHeaderInfo.text = ""
|
||||
logError(e)
|
||||
}
|
||||
|
||||
if (!isMultiDeleteState) {
|
||||
episodeHolder.setOnClickListener {
|
||||
onHeaderClickEvent.invoke(DownloadHeaderClickEvent(DOWNLOAD_ACTION_GO_TO_CHILD, card.data))
|
||||
onHeaderClickEvent.invoke(
|
||||
DownloadHeaderClickEvent(
|
||||
DOWNLOAD_ACTION_GO_TO_CHILD,
|
||||
card.data
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -235,14 +255,22 @@ class DownloadAdapter(
|
|||
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
|
||||
downloadButton.progressBar.progressDrawable =
|
||||
ContextCompat.getDrawable(downloadButton.context, downloadButton.progressDrawable)
|
||||
ContextCompat.getDrawable(
|
||||
downloadButton.context,
|
||||
downloadButton.progressDrawable
|
||||
)
|
||||
}
|
||||
|
||||
downloadButton.setDefaultClickListener(data, downloadChildEpisodeTextExtra, onItemClickEvent)
|
||||
downloadButton.setDefaultClickListener(
|
||||
data,
|
||||
downloadChildEpisodeTextExtra,
|
||||
onItemClickEvent
|
||||
)
|
||||
downloadButton.isVisible = !isMultiDeleteState
|
||||
|
||||
downloadChildEpisodeText.apply {
|
||||
|
@ -261,9 +289,15 @@ class DownloadAdapter(
|
|||
toggleIsChecked(deleteCheckbox, card)
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
setOnClickListener {
|
||||
onItemClickEvent.invoke(DownloadClickEvent(DOWNLOAD_ACTION_PLAY_FILE, data))
|
||||
onItemClickEvent.invoke(
|
||||
DownloadClickEvent(
|
||||
DOWNLOAD_ACTION_PLAY_FILE,
|
||||
data
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -311,13 +345,14 @@ class DownloadAdapter(
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun setIsMultiDeleteState(value: Boolean) {
|
||||
if (isMultiDeleteState == value) return
|
||||
isMultiDeleteState = value
|
||||
if (!value) {
|
||||
selectedIds.clear()
|
||||
notifyDataSetChanged()
|
||||
currentList.forEachIndexed { index, _ ->
|
||||
notifyItemChanged(index)
|
||||
}
|
||||
} else notifyItemRangeChanged(0, itemCount)
|
||||
}
|
||||
|
||||
|
@ -349,11 +384,17 @@ class DownloadAdapter(
|
|||
}
|
||||
|
||||
class DiffCallback : DiffUtil.ItemCallback<VisualDownloadCached>() {
|
||||
override fun areItemsTheSame(oldItem: VisualDownloadCached, newItem: VisualDownloadCached): Boolean {
|
||||
override fun areItemsTheSame(
|
||||
oldItem: VisualDownloadCached,
|
||||
newItem: VisualDownloadCached
|
||||
): Boolean {
|
||||
return oldItem.data.id == newItem.data.id
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: VisualDownloadCached, newItem: VisualDownloadCached): Boolean {
|
||||
override fun areContentsTheSame(
|
||||
oldItem: VisualDownloadCached,
|
||||
newItem: VisualDownloadCached
|
||||
): Boolean {
|
||||
return oldItem == newItem
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,13 @@ object DownloadButtonSetup {
|
|||
DialogInterface.OnClickListener { _, which ->
|
||||
when (which) {
|
||||
DialogInterface.BUTTON_POSITIVE -> {
|
||||
VideoDownloadManager.deleteFilesAndUpdateSettings(ctx, listOf(id), MainScope())
|
||||
VideoDownloadManager.deleteFilesAndUpdateSettings(
|
||||
ctx,
|
||||
listOf(id),
|
||||
MainScope()
|
||||
)
|
||||
}
|
||||
|
||||
DialogInterface.BUTTON_NEGATIVE -> {
|
||||
}
|
||||
}
|
||||
|
@ -57,11 +62,13 @@ object DownloadButtonSetup {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
DOWNLOAD_ACTION_PAUSE_DOWNLOAD -> {
|
||||
VideoDownloadManager.downloadEvent.invoke(
|
||||
Pair(click.data.id, VideoDownloadManager.DownloadActionType.Pause)
|
||||
)
|
||||
}
|
||||
|
||||
DOWNLOAD_ACTION_RESUME_DOWNLOAD -> {
|
||||
activity?.let { ctx ->
|
||||
if (VideoDownloadManager.downloadStatus.containsKey(id) && VideoDownloadManager.downloadStatus[id] == VideoDownloadManager.DownloadType.IsPaused) {
|
||||
|
@ -80,6 +87,7 @@ object DownloadButtonSetup {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
DOWNLOAD_ACTION_LONG_CLICK -> {
|
||||
activity?.let { act ->
|
||||
val length =
|
||||
|
@ -97,6 +105,7 @@ object DownloadButtonSetup {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
DOWNLOAD_ACTION_PLAY_FILE -> {
|
||||
activity?.let { act ->
|
||||
val info =
|
||||
|
|
|
@ -116,14 +116,32 @@ class DownloadFragment : Fragment() {
|
|||
binding?.textNoDownloads?.isVisible = it.isEmpty()
|
||||
}
|
||||
observe(downloadsViewModel.availableBytes) {
|
||||
updateStorageInfo(view.context, it, R.string.free_storage, binding?.downloadFreeTxt, binding?.downloadFree)
|
||||
updateStorageInfo(
|
||||
view.context,
|
||||
it,
|
||||
R.string.free_storage,
|
||||
binding?.downloadFreeTxt,
|
||||
binding?.downloadFree
|
||||
)
|
||||
}
|
||||
observe(downloadsViewModel.usedBytes) {
|
||||
updateStorageInfo(view.context, it, R.string.used_storage, binding?.downloadUsedTxt, binding?.downloadUsed)
|
||||
updateStorageInfo(
|
||||
view.context,
|
||||
it,
|
||||
R.string.used_storage,
|
||||
binding?.downloadUsedTxt,
|
||||
binding?.downloadUsed
|
||||
)
|
||||
binding?.downloadStorageAppbar?.isVisible = it > 0
|
||||
}
|
||||
observe(downloadsViewModel.downloadBytes) {
|
||||
updateStorageInfo(view.context, it, R.string.app_storage, binding?.downloadAppTxt, binding?.downloadApp)
|
||||
updateStorageInfo(
|
||||
view.context,
|
||||
it,
|
||||
R.string.app_storage,
|
||||
binding?.downloadAppTxt,
|
||||
binding?.downloadApp
|
||||
)
|
||||
}
|
||||
observe(downloadsViewModel.selectedBytes) {
|
||||
updateDeleteButton(downloadsViewModel.selectedItems.value?.count() ?: 0, it)
|
||||
|
@ -204,13 +222,15 @@ class DownloadFragment : Fragment() {
|
|||
when (click.action) {
|
||||
DOWNLOAD_ACTION_GO_TO_CHILD -> {
|
||||
if (!click.data.type.isMovieType()) {
|
||||
val folder = DataStore.getFolderName(DOWNLOAD_EPISODE_CACHE, click.data.id.toString())
|
||||
val folder =
|
||||
DataStore.getFolderName(DOWNLOAD_EPISODE_CACHE, click.data.id.toString())
|
||||
activity?.navigate(
|
||||
R.id.action_navigation_downloads_to_navigation_download_child,
|
||||
DownloadChildFragment.newInstance(click.data.name, folder)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
DOWNLOAD_ACTION_LOAD_RESULT -> {
|
||||
(activity as AppCompatActivity?)?.loadResult(click.data.url, click.data.apiName)
|
||||
}
|
||||
|
@ -272,7 +292,10 @@ class DownloadFragment : Fragment() {
|
|||
textView: TextView?,
|
||||
view: View?
|
||||
) {
|
||||
textView?.text = getString(R.string.storage_size_format).format(getString(stringRes), formatShortFileSize(context, bytes))
|
||||
textView?.text = getString(R.string.storage_size_format).format(
|
||||
getString(stringRes),
|
||||
formatShortFileSize(context, bytes)
|
||||
)
|
||||
view?.setLayoutWidth(bytes)
|
||||
}
|
||||
|
||||
|
@ -305,7 +328,9 @@ class DownloadFragment : Fragment() {
|
|||
if (!preventAutoSwitching) activateSwitchOnHls(text?.toString(), binding)
|
||||
}
|
||||
|
||||
(activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager)?.primaryClip?.getItemAt(0)?.text?.toString()?.let { copy ->
|
||||
(activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager)?.primaryClip?.getItemAt(
|
||||
0
|
||||
)?.text?.toString()?.let { copy ->
|
||||
val fixedText = copy.trim()
|
||||
binding.streamUrl.setText(fixedText)
|
||||
activateSwitchOnHls(fixedText, binding)
|
||||
|
|
|
@ -321,16 +321,19 @@ class DownloadViewModel : ViewModel() {
|
|||
data.seriesNames.isNotEmpty() && data.names.isEmpty() -> {
|
||||
context.getString(R.string.delete_message_series_only).format(formattedSeriesNames)
|
||||
}
|
||||
|
||||
data.parentName != null && data.names.isNotEmpty() -> {
|
||||
context.getString(R.string.delete_message_series_episodes)
|
||||
.format(data.parentName, formattedNames)
|
||||
}
|
||||
|
||||
data.seriesNames.isNotEmpty() -> {
|
||||
val seriesSection = context.getString(R.string.delete_message_series_section)
|
||||
.format(formattedSeriesNames)
|
||||
context.getString(R.string.delete_message_multiple)
|
||||
.format(formattedNames) + "\n\n" + seriesSection
|
||||
}
|
||||
|
||||
else -> context.getString(R.string.delete_message_multiple).format(formattedNames)
|
||||
}
|
||||
|
||||
|
@ -345,6 +348,7 @@ class DownloadViewModel : ViewModel() {
|
|||
onDeleteConfirm.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
DialogInterface.BUTTON_NEGATIVE -> {
|
||||
// Do nothing on cancel
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ abstract class BaseFetchButton(context: Context, attributeSet: AttributeSet) :
|
|||
|
||||
abstract fun setStatus(status: VideoDownloadManager.DownloadType?)
|
||||
|
||||
fun getStatus(id:Int, downloadedBytes: Long, totalBytes: Long): DownloadStatusTell {
|
||||
fun getStatus(id: Int, downloadedBytes: Long, totalBytes: Long): DownloadStatusTell {
|
||||
// some extra padding for just in case
|
||||
return VideoDownloadManager.downloadStatus[id]
|
||||
?: if (downloadedBytes > 1024L && downloadedBytes + 1024L >= totalBytes) {
|
||||
|
@ -100,7 +100,7 @@ abstract class BaseFetchButton(context: Context, attributeSet: AttributeSet) :
|
|||
} else DownloadStatusTell.IsPaused
|
||||
}
|
||||
|
||||
fun applyMetaData(id:Int, downloadedBytes: Long, totalBytes: Long) {
|
||||
fun applyMetaData(id: Int, downloadedBytes: Long, totalBytes: Long) {
|
||||
val status = getStatus(id, downloadedBytes, totalBytes)
|
||||
|
||||
currentMetaData.apply {
|
||||
|
@ -139,7 +139,8 @@ abstract class BaseFetchButton(context: Context, attributeSet: AttributeSet) :
|
|||
} else {
|
||||
if (doSetProgress) {
|
||||
progressText?.apply {
|
||||
val currentFormattedSizeString = formatShortFileSize(context, downloadedBytes)
|
||||
val currentFormattedSizeString =
|
||||
formatShortFileSize(context, downloadedBytes)
|
||||
val totalFormattedSizeString = formatShortFileSize(context, totalBytes)
|
||||
text =
|
||||
// if (isTextPercentage) "%d%%".format(setCurrentBytes * 100L / setTotalBytes) else
|
||||
|
|
|
@ -248,7 +248,7 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
|||
} */
|
||||
|
||||
@MainThread
|
||||
private fun setStatusInternal(status : DownloadStatusTell?) {
|
||||
private fun setStatusInternal(status: DownloadStatusTell?) {
|
||||
val isPreActive = isZeroBytes && status == DownloadStatusTell.IsDownloading
|
||||
if (animateWaiting && (status == DownloadStatusTell.IsPending || isPreActive)) {
|
||||
val animation = AnimationUtils.loadAnimation(context, waitingAnimation)
|
||||
|
@ -286,7 +286,7 @@ open class PieFetchButton(context: Context, attributeSet: AttributeSet) :
|
|||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
try {
|
||||
setStatusInternal(status)
|
||||
} catch (t : Throwable) {
|
||||
} catch (t: Throwable) {
|
||||
logError(t) // Just in case setStatusInternal throws because thread
|
||||
progressBarBackground.post {
|
||||
setStatusInternal(status)
|
||||
|
|
Loading…
Reference in a new issue