mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Add initial selected bytes to view model
This commit is contained in:
parent
4966398206
commit
3ce6b8074e
1 changed files with 25 additions and 0 deletions
|
@ -44,6 +44,9 @@ class DownloadViewModel : ViewModel() {
|
||||||
private val _downloadBytes = MutableLiveData<Long>()
|
private val _downloadBytes = MutableLiveData<Long>()
|
||||||
val downloadBytes: LiveData<Long> = _downloadBytes
|
val downloadBytes: LiveData<Long> = _downloadBytes
|
||||||
|
|
||||||
|
private val _selectedBytes = MutableLiveData<Long>(0)
|
||||||
|
val selectedBytes: LiveData<Long> = _selectedBytes
|
||||||
|
|
||||||
private val _isMultiDeleteState = MutableLiveData(false)
|
private val _isMultiDeleteState = MutableLiveData(false)
|
||||||
val isMultiDeleteState: LiveData<Boolean> = _isMultiDeleteState
|
val isMultiDeleteState: LiveData<Boolean> = _isMultiDeleteState
|
||||||
|
|
||||||
|
@ -61,6 +64,7 @@ class DownloadViewModel : ViewModel() {
|
||||||
if (!currentSelected.contains(item)) {
|
if (!currentSelected.contains(item)) {
|
||||||
currentSelected.add(item)
|
currentSelected.add(item)
|
||||||
_selectedItems.postValue(currentSelected)
|
_selectedItems.postValue(currentSelected)
|
||||||
|
updateSelectedBytes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +72,7 @@ class DownloadViewModel : ViewModel() {
|
||||||
selectedItems.value?.let { selected ->
|
selectedItems.value?.let { selected ->
|
||||||
selected.remove(item)
|
selected.remove(item)
|
||||||
_selectedItems.postValue(selected)
|
_selectedItems.postValue(selected)
|
||||||
|
updateSelectedBytes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +86,7 @@ class DownloadViewModel : ViewModel() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_selectedItems.postValue(currentSelected)
|
_selectedItems.postValue(currentSelected)
|
||||||
|
updateSelectedBytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearSelectedItems() {
|
fun clearSelectedItems() {
|
||||||
|
@ -104,6 +110,25 @@ class DownloadViewModel : ViewModel() {
|
||||||
return false
|
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 {
|
fun updateList(context: Context) = viewModelScope.launchSafe {
|
||||||
val children = withContext(Dispatchers.IO) {
|
val children = withContext(Dispatchers.IO) {
|
||||||
context.getKeys(DOWNLOAD_EPISODE_CACHE)
|
context.getKeys(DOWNLOAD_EPISODE_CACHE)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue