update
This commit is contained in:
@@ -15,6 +15,9 @@ interface VideoApi {
|
||||
@POST("videos/{id}/download")
|
||||
suspend fun triggerDownload(@Path("id") id: Int): Map<String, String>
|
||||
|
||||
@retrofit2.http.DELETE("videos")
|
||||
suspend fun deleteNotDownloaded(@Query("profile_id") profileId: Int): Map<String, Int>
|
||||
|
||||
@GET("profiles")
|
||||
suspend fun getProfiles(): List<Profile>
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@ class VideoRepository(private val api: VideoApi = ApiClient.api) {
|
||||
response["status"] ?: "unknown"
|
||||
}
|
||||
|
||||
suspend fun deleteNotDownloaded(profileId: Int): Result<Int> = runCatching {
|
||||
val response = api.deleteNotDownloaded(profileId)
|
||||
response["deleted"] ?: 0
|
||||
}
|
||||
|
||||
suspend fun getProfiles(): Result<List<Profile>> = runCatching { api.getProfiles() }
|
||||
|
||||
fun getStreamUrl(videoId: Int): String = "${ApiClient.BASE_URL}videos/$videoId/stream"
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.youtubeapp.ui.navigation
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.DeleteSweep
|
||||
import androidx.compose.material.icons.filled.Download
|
||||
import androidx.compose.material.icons.filled.Person
|
||||
import androidx.compose.material.icons.filled.VideoLibrary
|
||||
@@ -64,6 +65,9 @@ fun AppNavigation() {
|
||||
TopAppBar(
|
||||
title = { Text("YouTube App") },
|
||||
actions = {
|
||||
IconButton(onClick = { viewModel.deleteNotDownloaded() }) {
|
||||
Icon(Icons.Default.DeleteSweep, contentDescription = "Aufraeumen")
|
||||
}
|
||||
IconButton(onClick = { showProfileMenu = true }) {
|
||||
Icon(Icons.Default.Person, contentDescription = "Profil")
|
||||
}
|
||||
|
||||
@@ -126,6 +126,14 @@ class VideoViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteNotDownloaded() {
|
||||
val profileId = _state.value.selectedProfileId ?: return
|
||||
viewModelScope.launch {
|
||||
repository.deleteNotDownloaded(profileId)
|
||||
loadAllVideos()
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteLocalVideo(videoId: Int) {
|
||||
localStorage?.deleteLocalFile(videoId)
|
||||
_state.value = _state.value.copy(downloadStatus = "Lokal gelöscht")
|
||||
|
||||
Reference in New Issue
Block a user