From 14d16590a185acb27adff06d04f850cf62f50c1f Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:17:39 -0600 Subject: [PATCH] Show selected bytes in delete app bar --- .../ui/download/DownloadChildFragment.kt | 19 +++++++++++-------- .../ui/download/DownloadFragment.kt | 16 ++++++++++++---- app/src/main/res/values/strings.xml | 4 ++-- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt index 760fbe58..dbb02a06 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadChildFragment.kt @@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.ui.download import android.os.Bundle import android.os.Handler import android.os.Looper +import android.text.format.Formatter.formatShortFileSize import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -19,15 +20,9 @@ import com.lagradost.cloudstream3.ui.result.setLinearListLayout import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR import com.lagradost.cloudstream3.ui.settings.Globals.PHONE import com.lagradost.cloudstream3.ui.settings.Globals.isLayout -import com.lagradost.cloudstream3.utils.Coroutines.main -import com.lagradost.cloudstream3.utils.DataStore.getKey -import com.lagradost.cloudstream3.utils.DataStore.getKeys import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar import com.lagradost.cloudstream3.utils.UIHelper.setAppBarNoScrollFlagsOnTV -import com.lagradost.cloudstream3.utils.VideoDownloadHelper import com.lagradost.cloudstream3.utils.VideoDownloadManager -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext class DownloadChildFragment : Fragment() { private lateinit var downloadsViewModel: DownloadViewModel @@ -118,10 +113,12 @@ class DownloadChildFragment : Fragment() { downloadsViewModel.clearSelectedItems() } } + observe(downloadsViewModel.selectedBytes) { + updateDeleteButton(downloadsViewModel.selectedItems.value?.count() ?: 0, it) + } observe(downloadsViewModel.selectedItems) { handleSelectedChange(it) - binding?.btnDelete?.text = - getString(R.string.delete_count).format(it.count()) + updateDeleteButton(it.count(), downloadsViewModel.selectedBytes.value ?: 0L) binding?.btnDelete?.isVisible = it.isNotEmpty() binding?.selectItemsText?.isVisible = it.isEmpty() @@ -188,6 +185,12 @@ class DownloadChildFragment : Fragment() { } } + private fun updateDeleteButton(count: Int, selectedBytes: Long) { + val formattedSize = formatShortFileSize(context, selectedBytes) + binding?.btnDelete?.text = + getString(R.string.delete_format).format(count, formattedSize) + } + private fun setUpDownloadDeleteListener(folder: String) { downloadDeleteEventListener = { id: Int -> val list = (binding?.downloadChildList?.adapter as? DownloadAdapter)?.currentList diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt index 9ca47bb9..fce66894 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt @@ -125,6 +125,9 @@ class DownloadFragment : Fragment() { observe(downloadsViewModel.downloadBytes) { updateStorageInfo(view.context, it, R.string.app_storage, binding?.downloadAppTxt, binding?.downloadApp) } + observe(downloadsViewModel.selectedBytes) { + updateDeleteButton(downloadsViewModel.selectedItems.value?.count() ?: 0, it) + } observe(downloadsViewModel.isMultiDeleteState) { isMultiDeleteState -> val adapter = binding?.downloadList?.adapter as? DownloadAdapter adapter?.setIsMultiDeleteState(isMultiDeleteState) @@ -140,8 +143,7 @@ class DownloadFragment : Fragment() { } observe(downloadsViewModel.selectedItems) { handleSelectedChange(it) - binding?.btnDelete?.text = - getString(R.string.delete_count).format(it.count()) + updateDeleteButton(it.count(), downloadsViewModel.selectedBytes.value ?: 0L) binding?.btnDelete?.isVisible = it.isNotEmpty() binding?.selectItemsText?.isVisible = it.isEmpty() @@ -216,8 +218,8 @@ class DownloadFragment : Fragment() { } } - private fun handleSelectedChange(selected: MutableList) { - if (selected.isNotEmpty()) { + private fun handleSelectedChange(selectedItems: MutableList) { + if (selectedItems.isNotEmpty()) { binding?.downloadDeleteAppbar?.isVisible = true binding?.downloadStorageAppbar?.isVisible = false attachBackPressedCallback() @@ -244,6 +246,12 @@ class DownloadFragment : Fragment() { } } + private fun updateDeleteButton(count: Int, selectedBytes: Long) { + val formattedSize = formatShortFileSize(context, selectedBytes) + binding?.btnDelete?.text = + getString(R.string.delete_format).format(count, formattedSize) + } + private fun setUpDownloadDeleteListener() { downloadDeleteEventListener = { id -> val list = (binding?.downloadList?.adapter as? DownloadAdapter)?.currentList diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9ddb0265..827a117e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -303,10 +303,10 @@ S E No Episodes found + Delete Delete File Delete Files - Delete - Delete (%d) + Delete (%1$d | %2$s) Cancel Pause Start