-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First steps to good progress support. What works: - render playlist entries - download individual playlist entries For todos see #117
- Loading branch information
1 parent
cd72b54
commit 9a22a03
Showing
11 changed files
with
290 additions
and
102 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/de/lobbenmeier/stefan/common/ui/ReloadUi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package de.lobbenmeier.stefan.common.ui | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import kotlin.time.Duration | ||
import kotlinx.coroutines.delay | ||
|
||
@Composable | ||
fun reloadUiEvery(interval: Duration): State<Long> { | ||
val currentTime = remember { mutableStateOf(System.currentTimeMillis()) } | ||
currentTimeEvery(interval) { currentTime.value = it } | ||
return currentTime | ||
} | ||
|
||
@Composable | ||
fun currentTimeEvery(interval: Duration, onIntervalPassed: (Long) -> Unit) { | ||
LaunchedEffect(Unit) { | ||
while (true) { | ||
delay(interval) | ||
onIntervalPassed(System.currentTimeMillis()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/de/lobbenmeier/stefan/downloadlist/business/LogLevel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package de.lobbenmeier.stefan.downloadlist.business | ||
|
||
enum class LogLevel { | ||
STDOUT, | ||
STDERR, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/main/kotlin/de/lobbenmeier/stefan/downloadlist/ui/DownloadItemPlaylistEntriesView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package de.lobbenmeier.stefan.downloadlist.ui | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.itemsIndexed | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import compose.icons.FeatherIcons | ||
import compose.icons.feathericons.Download | ||
import de.lobbenmeier.stefan.downloadlist.business.DownloadItem | ||
import de.lobbenmeier.stefan.downloadlist.business.VideoMetadata | ||
import de.lobbenmeier.stefan.downloadlist.business.entryThumbnail | ||
|
||
private val entryHeight = 50.dp | ||
|
||
@Composable | ||
fun DownloadItemPlaylistEntriesView(downloadItem: DownloadItem) { | ||
val metadata = downloadItem.metadata.collectAsState().value | ||
|
||
if (metadata == null || metadata.type != "playlist") { | ||
return | ||
} | ||
|
||
if (metadata.entries.isNullOrEmpty()) { | ||
return Text(text = "Playlist is empty") | ||
} | ||
|
||
LazyColumn( | ||
modifier = Modifier.height(entryHeight * minOf(metadata.entries.size, 5)), | ||
userScrollEnabled = true | ||
) { | ||
itemsIndexed( | ||
metadata.entries, | ||
itemContent = { index, entry -> PlaylistEntryView(downloadItem, index, entry) } | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
fun PlaylistEntryView(downloadItem: DownloadItem, index: Int, entry: VideoMetadata) { | ||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = Modifier.padding(all = 4.dp).height(entryHeight) | ||
) { | ||
Thumbnail(entry.entryThumbnail) | ||
Spacer(Modifier.width(4.dp)) | ||
|
||
Column( | ||
modifier = Modifier.fillMaxHeight().weight(1f), | ||
verticalArrangement = Arrangement.SpaceAround, | ||
) { | ||
Text( | ||
text = entry.title ?: "No Title", | ||
fontWeight = FontWeight.Bold, | ||
maxLines = 1, | ||
) | ||
|
||
val progressNonFinal by downloadItem.getProgress(index).collectAsState() | ||
val progress = progressNonFinal | ||
if (progress != null) { | ||
DownloadProgressIndicator(progress, modifier = Modifier.height(5.dp)) | ||
} | ||
} | ||
|
||
IconButton(onClick = { downloadItem.downloadPlaylistEntry(index) }) { | ||
Icon(FeatherIcons.Download, "Download") | ||
} | ||
val targetFile = downloadItem.getTargetFile(index).collectAsState().value | ||
if (targetFile != null) { | ||
BrowseFileButton(targetFile) | ||
} | ||
} | ||
} |
Oops, something went wrong.