diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadViewModel.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadViewModel.kt index ca0bf54c..a812bddd 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadViewModel.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadViewModel.kt @@ -44,6 +44,9 @@ class DownloadViewModel : ViewModel() { private val _downloadBytes = MutableLiveData() val downloadBytes: LiveData = _downloadBytes + private val _selectedBytes = MutableLiveData(0) + val selectedBytes: LiveData = _selectedBytes + private val _isMultiDeleteState = MutableLiveData(false) val isMultiDeleteState: LiveData = _isMultiDeleteState @@ -61,6 +64,7 @@ class DownloadViewModel : ViewModel() { if (!currentSelected.contains(item)) { currentSelected.add(item) _selectedItems.postValue(currentSelected) + updateSelectedBytes() } } @@ -68,6 +72,7 @@ class DownloadViewModel : ViewModel() { selectedItems.value?.let { selected -> selected.remove(item) _selectedItems.postValue(selected) + updateSelectedBytes() } } @@ -81,6 +86,7 @@ class DownloadViewModel : ViewModel() { } } _selectedItems.postValue(currentSelected) + updateSelectedBytes() } fun clearSelectedItems() { @@ -104,6 +110,25 @@ class DownloadViewModel : ViewModel() { return false } + private fun updateSelectedBytes() = viewModelScope.launchSafe { + val selectedItemsList = selectedItems.value ?: return@launchSafe + var totalSelectedBytes = 0L + + selectedItemsList.forEach { item -> + totalSelectedBytes += when (item) { + is VisualDownloadCached.Header -> { + item.totalBytes + } + + is VisualDownloadCached.Child -> { + item.totalBytes + } + } + } + + _selectedBytes.postValue(totalSelectedBytes) + } + fun updateList(context: Context) = viewModelScope.launchSafe { val children = withContext(Dispatchers.IO) { context.getKeys(DOWNLOAD_EPISODE_CACHE)