From 3c2ceb79669f5bc42d27899b31efc03171c2facf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Font=C3=A1n?= Date: Thu, 23 Feb 2023 16:18:54 +0100 Subject: [PATCH] Added the ability to choose the audio provider and bumped up yt-dlp --- app/build.gradle.kts | 4 +- .../spowlo/ui/components/DialogItems.kt | 31 ++++++++ .../settings/format/AudioProviderDialog.kt | 76 +++++++++++++++++++ .../settings/format/FormatSettingsDialogs.kt | 18 +++-- .../settings/format/SettingsFormatsPage.kt | 15 ++++ .../bobbyesp/spowlo/utils/DownloaderUtil.kt | 2 + .../bobbyesp/spowlo/utils/PreferencesUtil.kt | 24 ++++++ app/src/main/res/drawable/icons8_youtube.xml | 6 ++ .../res/drawable/youtube_music_icons8.xml | 9 +++ app/src/main/res/values/strings.xml | 7 +- gradle/libs.versions.toml | 2 +- 11 files changed, 182 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/com/bobbyesp/spowlo/ui/pages/settings/format/AudioProviderDialog.kt create mode 100644 app/src/main/res/drawable/icons8_youtube.xml create mode 100644 app/src/main/res/drawable/youtube_music_icons8.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 3c7d7c47..0d3082d2 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -42,8 +42,8 @@ sealed class Version( } val currentVersion: Version = Version.Stable( - versionMajor = 0, - versionMinor = 2, + versionMajor = 1, + versionMinor = 1, versionPatch = 0, ) diff --git a/app/src/main/java/com/bobbyesp/spowlo/ui/components/DialogItems.kt b/app/src/main/java/com/bobbyesp/spowlo/ui/components/DialogItems.kt index 6928e294..88bcbd9d 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/ui/components/DialogItems.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/ui/components/DialogItems.kt @@ -5,9 +5,11 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.foundation.selection.selectable import androidx.compose.foundation.shape.CircleShape import androidx.compose.material3.Checkbox +import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.RadioButton import androidx.compose.material3.Text @@ -16,6 +18,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.unit.dp @@ -46,6 +49,34 @@ fun SingleChoiceItem( } } +@Composable +fun SingleChoiceItemWithIcon( + modifier: Modifier = Modifier, text: String, selected: Boolean, onClick: () -> Unit, icon: ImageVector +) { + Row( + modifier = modifier + .padding(vertical = 2.dp) + .clip(CircleShape) + .selectable( + selected = selected, + enabled = true, + onClick = onClick, + ) + .fillMaxWidth() +// .padding(vertical = 12.dp) + , verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Start + ) { + RadioButton( + modifier = Modifier.clearAndSetSemantics { }, selected = selected, onClick = onClick + ) + Icon(imageVector = icon, null, modifier = Modifier.padding(horizontal = 8.dp).size(32.dp)) + Text( +// modifier = Modifier.padding(start = 18.dp), + text = text, style = MaterialTheme.typography.bodyLarge + ) + } +} + @Composable fun MultiChoiceItem( modifier: Modifier = Modifier, diff --git a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/settings/format/AudioProviderDialog.kt b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/settings/format/AudioProviderDialog.kt new file mode 100644 index 00000000..86e5ef2d --- /dev/null +++ b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/settings/format/AudioProviderDialog.kt @@ -0,0 +1,76 @@ +package com.bobbyesp.spowlo.ui.pages.settings.format + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.MusicNote +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.setValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.bobbyesp.spowlo.R +import com.bobbyesp.spowlo.ui.components.ConfirmButton +import com.bobbyesp.spowlo.ui.components.SingleChoiceItemWithIcon +import com.bobbyesp.spowlo.utils.AUDIO_PROVIDER +import com.bobbyesp.spowlo.utils.PreferencesUtil + +@Composable +fun AudioProviderDialog( + onDismissRequest: () -> Unit +) { + var audioProvider by remember { mutableStateOf(PreferencesUtil.getAudioProvider()) } + AlertDialog( + onDismissRequest = onDismissRequest, + title = { Text(stringResource(id = R.string.audio_provider)) }, + icon = { Icon(Icons.Outlined.MusicNote, null) }, + text = { + Column() { + Text( + stringResource(id = R.string.audio_provider_desc), + modifier = Modifier + .fillMaxWidth() + .padding(bottom = 12.dp) + .padding(horizontal = 24.dp), + style = MaterialTheme.typography.bodyLarge + ) + LazyColumn { + for (i in 0..1) { + item { + SingleChoiceItemWithIcon( + text = PreferencesUtil.getAudioProviderDesc(i), + selected = audioProvider == i, + icon = PreferencesUtil.getAudioProviderIcon(i), + onClick = { + audioProvider = i + } + ) + } + } + } + } + }, + confirmButton = { + ConfirmButton( + onClick = { + PreferencesUtil.encodeInt(AUDIO_PROVIDER, audioProvider) + onDismissRequest() + } + ) + }, + dismissButton = { TextButton(onClick = { onDismissRequest() }) { + Text(text = stringResource(id = R.string.dismiss)) + } }, + ) + +} \ No newline at end of file diff --git a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/settings/format/FormatSettingsDialogs.kt b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/settings/format/FormatSettingsDialogs.kt index 224eb8b4..3efe396f 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/settings/format/FormatSettingsDialogs.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/settings/format/FormatSettingsDialogs.kt @@ -3,6 +3,8 @@ package com.bobbyesp.spowlo.ui.pages.settings.format import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons @@ -88,7 +90,7 @@ fun AudioQualityDialog(onDismissRequest: () -> Unit, onConfirm: () -> Unit = {}) Text(text = stringResource(R.string.confirm)) } }, text = { - Column(modifier = Modifier.verticalScroll(rememberScrollState())) { + Column(modifier = Modifier) { Text( modifier = Modifier .fillMaxWidth() @@ -96,11 +98,15 @@ fun AudioQualityDialog(onDismissRequest: () -> Unit, onConfirm: () -> Unit = {}) text = stringResource(R.string.audio_quality_desc), style = MaterialTheme.typography.bodyLarge ) - for (i in 0..17) - SingleChoiceItem( - text = PreferencesUtil.getAudioQualityDesc(i), - selected = audioQuality == i - ) { audioQuality = i } + LazyColumn(content = { + for (i in 0..17) + item { + SingleChoiceItem( + text = PreferencesUtil.getAudioQualityDesc(i), + selected = audioQuality == i + ) { audioQuality = i } + } + }, modifier = Modifier.size(400.dp)) } }) } diff --git a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/settings/format/SettingsFormatsPage.kt b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/settings/format/SettingsFormatsPage.kt index d9d21ab0..d3dc8844 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/ui/pages/settings/format/SettingsFormatsPage.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/ui/pages/settings/format/SettingsFormatsPage.kt @@ -45,6 +45,7 @@ fun SettingsFormatsPage(onBackPressed: () -> Unit) { var showAudioFormatDialog by remember { mutableStateOf(false) } var showAudioQualityDialog by remember { mutableStateOf(false) } + var showAudioProviderDialog by remember { mutableStateOf(false) } Scaffold( @@ -102,6 +103,14 @@ fun SettingsFormatsPage(onBackPressed: () -> Unit) { enabled = !preserveOriginalAudio, ) { showAudioQualityDialog = true } } + item { + PreferenceItem( + title = stringResource(R.string.audio_provider), + description = stringResource(R.string.audio_provider_desc), + icon = Icons.Outlined.HighQuality, + enabled = !isCustomCommandEnabled, + ) { showAudioProviderDialog = true } + } } }) if (showAudioFormatDialog) { @@ -118,4 +127,10 @@ fun SettingsFormatsPage(onBackPressed: () -> Unit) { audioQuality = PreferencesUtil.getAudioQualityDesc() } } + if (showAudioProviderDialog) { + AudioProviderDialog( + onDismissRequest = { showAudioProviderDialog = false } + ) + } + } \ No newline at end of file diff --git a/app/src/main/java/com/bobbyesp/spowlo/utils/DownloaderUtil.kt b/app/src/main/java/com/bobbyesp/spowlo/utils/DownloaderUtil.kt index 2d9a6cff..c002b003 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/utils/DownloaderUtil.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/utils/DownloaderUtil.kt @@ -255,6 +255,8 @@ object DownloaderUtil { addAudioFormat() } + addOption("--audio", PreferencesUtil.getAudioProviderDesc()) + if (useSpotifyPreferences) { addOption("--client-id", spotifyClientID) addOption("--client-secret", spotifyClientSecret) diff --git a/app/src/main/java/com/bobbyesp/spowlo/utils/PreferencesUtil.kt b/app/src/main/java/com/bobbyesp/spowlo/utils/PreferencesUtil.kt index e4827fb2..32eb9bd8 100644 --- a/app/src/main/java/com/bobbyesp/spowlo/utils/PreferencesUtil.kt +++ b/app/src/main/java/com/bobbyesp/spowlo/utils/PreferencesUtil.kt @@ -3,6 +3,7 @@ package com.bobbyesp.spowlo.utils import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.Composable +import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.core.os.LocaleListCompat import com.bobbyesp.spowlo.App @@ -11,6 +12,7 @@ import com.bobbyesp.spowlo.App.Companion.isFDroidBuild import com.bobbyesp.spowlo.R import com.bobbyesp.spowlo.database.CommandTemplate import com.bobbyesp.spowlo.database.CookieProfile +import com.bobbyesp.spowlo.ui.pages.settings.about.LocalAsset import com.bobbyesp.spowlo.ui.theme.DEFAULT_SEED_COLOR import com.google.android.material.color.DynamicColors import com.kyant.monet.PaletteStyle @@ -57,6 +59,8 @@ const val SPOTIFY_CLIENT_SECRET = "spotify_client_secret" const val USE_CACHING = "use_caching" const val DONT_FILTER_RESULTS = "dont_filter_results" +const val AUDIO_PROVIDER = "audio_provider" + const val TEMPLATE_ID = "template_id" const val MAX_FILE_SIZE = "max_file_size" const val COOKIES = "cookies" @@ -105,6 +109,7 @@ private val IntPreferenceDefaults = mapOf( WELCOME_DIALOG to 1, AUDIO_FORMAT to 5, AUDIO_QUALITY to 17, + AUDIO_PROVIDER to 0, UPDATE_CHANNEL to STABLE, ) @@ -141,6 +146,8 @@ object PreferencesUtil { fun getAudioFormat(): Int = AUDIO_FORMAT.getInt() + fun getAudioProvider(): Int = AUDIO_PROVIDER.getInt() + fun getAudioQuality(): Int = AUDIO_QUALITY.getInt() fun getAudioFormatDesc(audioQualityStr: Int = getAudioFormat()): String { @@ -155,6 +162,23 @@ object PreferencesUtil { } } + fun getAudioProviderDesc(audioProviderInt: Int = getAudioProvider()): String { + return when (audioProviderInt){ + 0 -> "youtube-music" + 1 -> "youtube" + else -> "youtube-music" + } + } + + @Composable + fun getAudioProviderIcon(audioProviderInt: Int = getAudioProvider()): ImageVector { + return when (audioProviderInt){ + 0 -> LocalAsset(id = R.drawable.youtube_music_icons8) + 1 -> LocalAsset(id = R.drawable.icons8_youtube) + else -> LocalAsset(id = R.drawable.youtube_music_icons8) + } + } + fun getAudioQualityDesc(audioQualityStr: Int = getAudioQuality()): String { return when (audioQualityStr) { 0 -> "8k" diff --git a/app/src/main/res/drawable/icons8_youtube.xml b/app/src/main/res/drawable/icons8_youtube.xml new file mode 100644 index 00000000..830dcec9 --- /dev/null +++ b/app/src/main/res/drawable/icons8_youtube.xml @@ -0,0 +1,6 @@ + + + + diff --git a/app/src/main/res/drawable/youtube_music_icons8.xml b/app/src/main/res/drawable/youtube_music_icons8.xml new file mode 100644 index 00000000..0033eb43 --- /dev/null +++ b/app/src/main/res/drawable/youtube_music_icons8.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 89c92ff3..a5e42bd8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -247,9 +247,10 @@ Azərbaycanca Nynorsk ਪੰਜਾਬੀ + A new update is available! Don\'t filter results - If your download wasn\'t succesful or the song not found, using this command should work all. - - + Do not filter searching results in the available platforms. + Audio provider + Choose from where you want to download the songs \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 232cab45..98733490 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,7 +19,7 @@ androidxHiltNavigationCompose = "1.0.0" androidxTestExt = "1.1.4" -spotdlAndroidVersion = "4.1.0-preview-SNAPSHOT" +spotdlAndroidVersion = "884fabd1ba" spotifyApiKotlinVersion = "3.8.8" crashHandlerVersion = "2.0.2"