@@ -7,6 +7,9 @@ import androidx.compose.foundation.lazy.LazyColumn
77import androidx.compose.foundation.lazy.items
88import androidx.compose.material.icons.Icons
99import androidx.compose.material.icons.filled.ArrowBack
10+ import androidx.compose.material.icons.filled.Close
11+ import androidx.compose.material.icons.filled.Pause
12+ import androidx.compose.material.icons.filled.PlayArrow
1013import androidx.compose.material3.*
1114import androidx.compose.runtime.*
1215import androidx.compose.ui.Alignment
@@ -16,14 +19,14 @@ import androidx.compose.ui.unit.dp
1619import androidx.compose.ui.unit.sp
1720import androidx.core.content.FileProvider
1821import androidx.lifecycle.viewmodel.compose.viewModel
19- import androidx.navigation.NavController
2022import dev.icerock.moko.resources.compose.stringResource
2123import kotlinx.coroutines.Dispatchers
2224import kotlinx.coroutines.GlobalScope
2325import kotlinx.coroutines.delay
2426import kotlinx.coroutines.launch
2527import project.pipepipe.app.MR
2628import project.pipepipe.app.SharedContext.navController
29+ import project.pipepipe.app.database.DatabaseOperations
2730import project.pipepipe.app.download.DownloadManagerHolder
2831import project.pipepipe.app.helper.ToastManager
2932import project.pipepipe.app.ui.component.CustomTopBar
@@ -41,6 +44,8 @@ fun DownloadScreen(
4144 val uiState by viewModel.uiState.collectAsState()
4245 val context = LocalContext .current
4346
47+ var showCancelAllDialog by remember { mutableStateOf(false ) }
48+
4449 // Auto-refresh downloads periodically
4550 LaunchedEffect (Unit ) {
4651 while (true ) {
@@ -65,7 +70,48 @@ fun DownloadScreen(
6570 IconButton (onClick = { navController.navigateUp() }) {
6671 Icon (
6772 imageVector = Icons .Default .ArrowBack ,
68- contentDescription = " Back"
73+ contentDescription = stringResource(MR .strings.back)
74+ )
75+ }
76+ },
77+ actions = {
78+ IconButton (
79+ onClick = {
80+ GlobalScope .launch(Dispatchers .IO ) {
81+ viewModel.getDownloadsByStatus(listOf (DownloadStatus .PAUSED )).forEach { download ->
82+ DownloadManagerHolder .instance.resumeDownload(download.id)
83+ }
84+ viewModel.refreshDownloads()
85+ }
86+ }
87+ ) {
88+ Icon (
89+ imageVector = Icons .Default .PlayArrow ,
90+ contentDescription = stringResource(MR .strings.start_all)
91+ )
92+ }
93+ IconButton (
94+ onClick = {
95+ GlobalScope .launch(Dispatchers .IO ) {
96+ viewModel.getActiveDownloads()
97+ .forEach { download ->
98+ DownloadManagerHolder .instance.pauseDownload(download.id)
99+ }
100+ viewModel.refreshDownloads()
101+ }
102+ }
103+ ) {
104+ Icon (
105+ imageVector = Icons .Default .Pause ,
106+ contentDescription = stringResource(MR .strings.pause_all)
107+ )
108+ }
109+ IconButton (
110+ onClick = { showCancelAllDialog = true }
111+ ) {
112+ Icon (
113+ imageVector = Icons .Default .Close ,
114+ contentDescription = stringResource(MR .strings.cancel_all)
69115 )
70116 }
71117 }
@@ -116,6 +162,7 @@ fun DownloadScreen(
116162 CircularProgressIndicator ()
117163 }
118164 }
165+
119166 filteredDownloads.isEmpty() -> {
120167 Box (
121168 modifier = Modifier .fillMaxSize(),
@@ -145,6 +192,7 @@ fun DownloadScreen(
145192 }
146193 }
147194 }
195+
148196 else -> {
149197 LazyColumn (
150198 modifier = Modifier
@@ -226,5 +274,49 @@ fun DownloadScreen(
226274 }
227275 }
228276 }
277+
278+ if (showCancelAllDialog) {
279+ AlertDialog (
280+ onDismissRequest = { showCancelAllDialog = false },
281+ title = {
282+ Text (stringResource(MR .strings.cancel_all))
283+ },
284+ text = {
285+ Text (stringResource(MR .strings.cancel_all_confirmation))
286+ },
287+ confirmButton = {
288+ TextButton (
289+ onClick = {
290+ showCancelAllDialog = false
291+ GlobalScope .launch(Dispatchers .IO ) {
292+ viewModel.getDownloadsByStatus(
293+ listOf (
294+ DownloadStatus .QUEUED ,
295+ DownloadStatus .FETCHING_INFO ,
296+ DownloadStatus .PREPROCESSING ,
297+ DownloadStatus .DOWNLOADING ,
298+ DownloadStatus .POSTPROCESSING ,
299+ DownloadStatus .PAUSED ,
300+ )
301+ )
302+ .forEach { download ->
303+ DownloadManagerHolder .instance.cancelDownload(download.id)
304+ }
305+ viewModel.refreshDownloads()
306+ }
307+ }
308+ ) {
309+ Text (stringResource(MR .strings.confirm))
310+ }
311+ },
312+ dismissButton = {
313+ TextButton (
314+ onClick = { showCancelAllDialog = false }
315+ ) {
316+ Text (stringResource(MR .strings.cancel))
317+ }
318+ }
319+ )
320+ }
229321 }
230322}
0 commit comments