mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Show selected bytes in delete app bar
This commit is contained in:
parent
8b7b6659b0
commit
14d16590a1
3 changed files with 25 additions and 14 deletions
|
@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.ui.download
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.text.format.Formatter.formatShortFileSize
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
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.EMULATOR
|
||||||
import com.lagradost.cloudstream3.ui.settings.Globals.PHONE
|
import com.lagradost.cloudstream3.ui.settings.Globals.PHONE
|
||||||
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
|
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.fixPaddingStatusbar
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.setAppBarNoScrollFlagsOnTV
|
import com.lagradost.cloudstream3.utils.UIHelper.setAppBarNoScrollFlagsOnTV
|
||||||
import com.lagradost.cloudstream3.utils.VideoDownloadHelper
|
|
||||||
import com.lagradost.cloudstream3.utils.VideoDownloadManager
|
import com.lagradost.cloudstream3.utils.VideoDownloadManager
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
class DownloadChildFragment : Fragment() {
|
class DownloadChildFragment : Fragment() {
|
||||||
private lateinit var downloadsViewModel: DownloadViewModel
|
private lateinit var downloadsViewModel: DownloadViewModel
|
||||||
|
@ -118,10 +113,12 @@ class DownloadChildFragment : Fragment() {
|
||||||
downloadsViewModel.clearSelectedItems()
|
downloadsViewModel.clearSelectedItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
observe(downloadsViewModel.selectedBytes) {
|
||||||
|
updateDeleteButton(downloadsViewModel.selectedItems.value?.count() ?: 0, it)
|
||||||
|
}
|
||||||
observe(downloadsViewModel.selectedItems) {
|
observe(downloadsViewModel.selectedItems) {
|
||||||
handleSelectedChange(it)
|
handleSelectedChange(it)
|
||||||
binding?.btnDelete?.text =
|
updateDeleteButton(it.count(), downloadsViewModel.selectedBytes.value ?: 0L)
|
||||||
getString(R.string.delete_count).format(it.count())
|
|
||||||
|
|
||||||
binding?.btnDelete?.isVisible = it.isNotEmpty()
|
binding?.btnDelete?.isVisible = it.isNotEmpty()
|
||||||
binding?.selectItemsText?.isVisible = it.isEmpty()
|
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) {
|
private fun setUpDownloadDeleteListener(folder: String) {
|
||||||
downloadDeleteEventListener = { id: Int ->
|
downloadDeleteEventListener = { id: Int ->
|
||||||
val list = (binding?.downloadChildList?.adapter as? DownloadAdapter)?.currentList
|
val list = (binding?.downloadChildList?.adapter as? DownloadAdapter)?.currentList
|
||||||
|
|
|
@ -125,6 +125,9 @@ class DownloadFragment : Fragment() {
|
||||||
observe(downloadsViewModel.downloadBytes) {
|
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)
|
||||||
|
}
|
||||||
observe(downloadsViewModel.isMultiDeleteState) { isMultiDeleteState ->
|
observe(downloadsViewModel.isMultiDeleteState) { isMultiDeleteState ->
|
||||||
val adapter = binding?.downloadList?.adapter as? DownloadAdapter
|
val adapter = binding?.downloadList?.adapter as? DownloadAdapter
|
||||||
adapter?.setIsMultiDeleteState(isMultiDeleteState)
|
adapter?.setIsMultiDeleteState(isMultiDeleteState)
|
||||||
|
@ -140,8 +143,7 @@ class DownloadFragment : Fragment() {
|
||||||
}
|
}
|
||||||
observe(downloadsViewModel.selectedItems) {
|
observe(downloadsViewModel.selectedItems) {
|
||||||
handleSelectedChange(it)
|
handleSelectedChange(it)
|
||||||
binding?.btnDelete?.text =
|
updateDeleteButton(it.count(), downloadsViewModel.selectedBytes.value ?: 0L)
|
||||||
getString(R.string.delete_count).format(it.count())
|
|
||||||
|
|
||||||
binding?.btnDelete?.isVisible = it.isNotEmpty()
|
binding?.btnDelete?.isVisible = it.isNotEmpty()
|
||||||
binding?.selectItemsText?.isVisible = it.isEmpty()
|
binding?.selectItemsText?.isVisible = it.isEmpty()
|
||||||
|
@ -216,8 +218,8 @@ class DownloadFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleSelectedChange(selected: MutableList<VisualDownloadCached>) {
|
private fun handleSelectedChange(selectedItems: MutableList<VisualDownloadCached>) {
|
||||||
if (selected.isNotEmpty()) {
|
if (selectedItems.isNotEmpty()) {
|
||||||
binding?.downloadDeleteAppbar?.isVisible = true
|
binding?.downloadDeleteAppbar?.isVisible = true
|
||||||
binding?.downloadStorageAppbar?.isVisible = false
|
binding?.downloadStorageAppbar?.isVisible = false
|
||||||
attachBackPressedCallback()
|
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() {
|
private fun setUpDownloadDeleteListener() {
|
||||||
downloadDeleteEventListener = { id ->
|
downloadDeleteEventListener = { id ->
|
||||||
val list = (binding?.downloadList?.adapter as? DownloadAdapter)?.currentList
|
val list = (binding?.downloadList?.adapter as? DownloadAdapter)?.currentList
|
||||||
|
|
|
@ -303,10 +303,10 @@
|
||||||
<string name="season_short">S</string>
|
<string name="season_short">S</string>
|
||||||
<string name="episode_short">E</string>
|
<string name="episode_short">E</string>
|
||||||
<string name="no_episodes_found">No Episodes found</string>
|
<string name="no_episodes_found">No Episodes found</string>
|
||||||
|
<string name="delete">Delete</string>
|
||||||
<string name="delete_file">Delete File</string>
|
<string name="delete_file">Delete File</string>
|
||||||
<string name="delete_files">Delete Files</string>
|
<string name="delete_files">Delete Files</string>
|
||||||
<string name="delete">Delete</string>
|
<string name="delete_format">Delete (%1$d | %2$s)</string>
|
||||||
<string name="delete_count">Delete (%d)</string>
|
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
<string name="pause">Pause</string>
|
<string name="pause">Pause</string>
|
||||||
<string name="start">Start</string>
|
<string name="start">Start</string>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue