Skip to content

Commit

Permalink
Add quick settings to footer (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanLobbenmeier authored Jan 4, 2025
1 parent 9a22a03 commit 57c0875
Show file tree
Hide file tree
Showing 6 changed files with 428 additions and 66 deletions.
85 changes: 85 additions & 0 deletions src/main/kotlin/de/lobbenmeier/stefan/common/ui/icons/Subtitles.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package de.lobbenmeier.stefan.common.ui.icons

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PathFillType
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.StrokeJoin
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.unit.dp

// https://composeicons.com/icons/material-symbols/outlined/subtitles
val Subtitles: ImageVector
get() {
if (_Subtitles != null) {
return _Subtitles!!
}
_Subtitles =
ImageVector.Builder(
name = "Subtitles",
defaultWidth = 24.dp,
defaultHeight = 24.dp,
viewportWidth = 960f,
viewportHeight = 960f
)
.apply {
path(
fill = SolidColor(Color.Black),
fillAlpha = 1.0f,
stroke = null,
strokeAlpha = 1.0f,
strokeLineWidth = 1.0f,
strokeLineCap = StrokeCap.Butt,
strokeLineJoin = StrokeJoin.Miter,
strokeLineMiter = 1.0f,
pathFillType = PathFillType.NonZero
) {
moveTo(240f, 640f)
horizontalLineToRelative(320f)
verticalLineToRelative(-80f)
horizontalLineTo(240f)
close()
moveToRelative(400f, 0f)
horizontalLineToRelative(80f)
verticalLineToRelative(-80f)
horizontalLineToRelative(-80f)
close()
moveTo(240f, 480f)
horizontalLineToRelative(80f)
verticalLineToRelative(-80f)
horizontalLineToRelative(-80f)
close()
moveToRelative(160f, 0f)
horizontalLineToRelative(320f)
verticalLineToRelative(-80f)
horizontalLineTo(400f)
close()
moveTo(160f, 800f)
quadToRelative(-33f, 0f, -56.5f, -23.5f)
reflectiveQuadTo(80f, 720f)
verticalLineToRelative(-480f)
quadToRelative(0f, -33f, 23.5f, -56.5f)
reflectiveQuadTo(160f, 160f)
horizontalLineToRelative(640f)
quadToRelative(33f, 0f, 56.5f, 23.5f)
reflectiveQuadTo(880f, 240f)
verticalLineToRelative(480f)
quadToRelative(0f, 33f, -23.5f, 56.5f)
reflectiveQuadTo(800f, 800f)
close()
moveToRelative(0f, -80f)
horizontalLineToRelative(640f)
verticalLineToRelative(-480f)
horizontalLineTo(160f)
close()
moveToRelative(0f, 0f)
verticalLineToRelative(-480f)
close()
}
}
.build()
return _Subtitles!!
}

private var _Subtitles: ImageVector? = null
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package de.lobbenmeier.stefan.common.ui.icons

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PathFillType
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.StrokeJoin
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.path
import androidx.compose.ui.unit.dp

// https://composeicons.com/icons/material-symbols/outlined/subtitles_off
val SubtitlesOff: ImageVector
get() {
if (_SubtitlesOff != null) {
return _SubtitlesOff!!
}
_SubtitlesOff =
ImageVector.Builder(
name = "SubtitlesOff",
defaultWidth = 24.dp,
defaultHeight = 24.dp,
viewportWidth = 960f,
viewportHeight = 960f
)
.apply {
path(
fill = SolidColor(Color.Black),
fillAlpha = 1.0f,
stroke = null,
strokeAlpha = 1.0f,
strokeLineWidth = 1.0f,
strokeLineCap = StrokeCap.Butt,
strokeLineJoin = StrokeJoin.Miter,
strokeLineMiter = 1.0f,
pathFillType = PathFillType.NonZero
) {
moveTo(822f, 934f)
lineTo(686f, 800f)
horizontalLineTo(160f)
quadToRelative(-33f, 0f, -56.5f, -23.5f)
reflectiveQuadTo(80f, 720f)
verticalLineToRelative(-480f)
quadToRelative(0f, -33f, 23.5f, -56.5f)
reflectiveQuadTo(160f, 160f)
lineToRelative(80f, 80f)
horizontalLineToRelative(-80f)
verticalLineToRelative(480f)
horizontalLineToRelative(446f)
lineToRelative(-80f, -80f)
horizontalLineTo(240f)
verticalLineToRelative(-80f)
horizontalLineToRelative(206f)
lineTo(26f, 138f)
lineToRelative(56f, -56f)
lineTo(878f, 878f)
close()
moveToRelative(48f, -178f)
lineToRelative(-70f, -70f)
verticalLineToRelative(-446f)
horizontalLineTo(354f)
lineToRelative(-80f, -80f)
horizontalLineToRelative(526f)
quadToRelative(33f, 0f, 56.5f, 23.5f)
reflectiveQuadTo(880f, 240f)
verticalLineToRelative(476f)
quadToRelative(0f, 11f, -2f, 21f)
reflectiveQuadToRelative(-8f, 19f)
moveTo(594f, 480f)
lineToRelative(-80f, -80f)
horizontalLineToRelative(206f)
verticalLineToRelative(80f)
close()
moveToRelative(-354f, 0f)
verticalLineToRelative(-80f)
horizontalLineToRelative(80f)
verticalLineToRelative(80f)
close()
moveToRelative(143f, 17f)
}
}
.build()
return _SubtitlesOff!!
}

private var _SubtitlesOff: ImageVector? = null
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ class DownloadQueue {
fun remove(downloadItem: DownloadItem) {
items.remove(downloadItem)
}

fun clear() {
items.clear()
}

fun downloadAll() {
for (item in items) {
if (item.getTargetFile().value == null) {
item.download(null, null)
}
}
}
}
102 changes: 58 additions & 44 deletions src/main/kotlin/de/lobbenmeier/stefan/settings/ui/SettingsUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ import io.github.vinceglb.filekit.core.FileKitMacOSSettings
import io.github.vinceglb.filekit.core.FileKitPlatformSettings
import kotlin.io.path.absolutePathString

private val textFieldWidth = 350.dp
val textFieldWidth = 350.dp

@Composable
fun SettingsUI(settings: Settings, save: (Settings) -> Unit, cancel: () -> Unit) {
var mutableSettings by remember { mutableStateOf(settings.copy()) }
var mutableSettings by remember { mutableStateOf(settings) }

Column(
Modifier.padding(vertical = 32.dp)
Expand Down Expand Up @@ -103,7 +103,7 @@ fun SettingsUI(settings: Settings, save: (Settings) -> Unit, cancel: () -> Unit)
)
}

Section("Network & Authentication") {
Section("Network") {
TextInput(
"Proxy",
mutableSettings.proxy,
Expand All @@ -121,34 +121,11 @@ fun SettingsUI(settings: Settings, save: (Settings) -> Unit, cancel: () -> Unit)
mutableSettings.rateLimit,
onValueChange = { mutableSettings = mutableSettings.copy(rateLimit = it) }
)
TextInput(
"Header",
mutableSettings.header,
onValueChange = { mutableSettings = mutableSettings.copy(header = it) },
placeholder = "Bearer:yourTokenHere"
)
ChoiceInput(
"Cookies from browser",
mutableSettings.cookiesFromBrowser,
onValueChange = {
mutableSettings = mutableSettings.copy(cookiesFromBrowser = it)
},
options =
listOf(
"brave",
"chrome",
"chromium",
"edge",
"firefox",
"opera",
"safari",
"vivaldi",
)
)
FileInput(
"Cookies from file",
mutableSettings.cookiesFile,
onValueChange = { mutableSettings = mutableSettings.copy(cookiesFile = it) },
}
Section("Authentication") {
authenticationSettings(
settings = mutableSettings,
updateSettings = { mutableSettings = it }
)
}

Expand Down Expand Up @@ -256,7 +233,38 @@ fun SettingsUI(settings: Settings, save: (Settings) -> Unit, cancel: () -> Unit)
}

@Composable
private fun Section(sectionTitle: String, content: @Composable (ColumnScope.() -> Unit)) {
fun authenticationSettings(settings: Settings, updateSettings: (Settings) -> Unit) {
TextInput(
"Header",
settings.header,
onValueChange = { updateSettings(settings.copy(header = it)) },
placeholder = "Bearer:yourTokenHere"
)
ChoiceInput(
"Cookies from browser",
settings.cookiesFromBrowser,
onValueChange = { updateSettings(settings.copy(cookiesFromBrowser = it)) },
options =
listOf(
"brave",
"chrome",
"chromium",
"edge",
"firefox",
"opera",
"safari",
"vivaldi",
)
)
FileInput(
"Cookies from file",
settings.cookiesFile,
onValueChange = { updateSettings(settings.copy(cookiesFile = it)) },
)
}

@Composable
fun Section(sectionTitle: String, content: @Composable (ColumnScope.() -> Unit)) {
Column {
Text(sectionTitle, style = MaterialTheme.typography.h5)
Column(Modifier.padding(vertical = 8.dp), content = content)
Expand Down Expand Up @@ -377,6 +385,18 @@ private fun FileInput(description: String, value: String?, onValueChange: (Strin

@Composable
private fun DirectoryInput(description: String, value: String?, onValueChange: (String?) -> Unit) {
TextInput(
description,
value,
onValueChange,
trailingIcon = {
DirectoryPickerButton(description, value = value, onValueChange = onValueChange)
},
)
}

@Composable
fun DirectoryPickerButton(description: String, value: String?, onValueChange: (String) -> Unit) {
val launcher =
rememberDirectoryPickerLauncher(
title = description,
Expand All @@ -386,19 +406,13 @@ private fun DirectoryInput(description: String, value: String?, onValueChange: (
macOS = FileKitMacOSSettings(resolvesAliases = false),
),
) { file ->
if (file != null) {
onValueChange(file.path)
val filePath = file?.path
if (filePath != null) {
onValueChange(filePath)
}
}

TextInput(
description,
value,
onValueChange,
trailingIcon = {
IconButton(onClick = { launcher.launch() }) {
Icon(FeatherIcons.Folder, contentDescription = null)
}
},
)
return IconButton(onClick = { launcher.launch() }) {
Icon(FeatherIcons.Folder, contentDescription = description)
}
}
30 changes: 8 additions & 22 deletions src/main/kotlin/de/lobbenmeier/stefan/ui/App.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package de.lobbenmeier.stefan.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -78,28 +76,16 @@ private fun MainView(
onSettingsButtonClicked = { settingsOpen = true }
)
},
bottomBar = { Footer() }
bottomBar = {
Footer(
settings,
updateSettings,
clearDownloads = downloadQueue::clear,
downloadAll = downloadQueue::downloadAll
)
}
) {
DownloadList(downloadQueue)
}
}
}

@Composable
fun Footer() {
Column {
Text("Ready to download")
Row {
Text("Folder")
Text("Key")
Text("Subtitles")
Text("Spacer")
Text("Media")
Text("Quality")
Text("Spacer")
Text("When done")
Text("Delete")
Text("Download")
}
}
}
Loading

0 comments on commit 57c0875

Please sign in to comment.