Skip to content

Commit

Permalink
feat: Added UNSTABLE downloads cancellation and see playlist option w…
Browse files Browse the repository at this point in the history
…hen the URL textbox contains a playlist, updated spotdl-android
  • Loading branch information
BobbyESP committed Apr 4, 2023
1 parent 885494f commit f0a7456
Show file tree
Hide file tree
Showing 19 changed files with 314 additions and 210 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ dependencies {
// implementation(libs.exoplayer.extension.mediasession)

implementation(libs.customtabs)
implementation(libs.shimmer)

debugImplementation(libs.crash.handler)

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/bobbyesp/spowlo/Downloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ object Downloader {

fun onCancel() {
toKey().run {
SpotDL.getInstance().destroyProcessById(this)
SpotDL.getInstance().destroyProcessById(this, true)
onProcessCanceled(this)
}
}
Expand Down Expand Up @@ -512,7 +512,7 @@ object Downloader {
updateState(State.Idle)
clearProgressState(isFinished = false)
taskState.value.taskId.run {
SpotDL.getInstance().destroyProcessById(this)
SpotDL.getInstance().destroyProcessById(this, true)
NotificationsUtil.cancelNotification(this.toNotificationId())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class NotificationActionReceiver : BroadcastReceiver() {
private fun cancelTask(taskId: String?, notificationId: Int) {
if (taskId.isNullOrEmpty()) return
NotificationsUtil.cancelNotification(notificationId)
val result = SpotDL.getInstance().destroyProcessById(taskId)
val result = SpotDL.getInstance().destroyProcessById(taskId, true)
NotificationsUtil.cancelNotification(notificationId)
if (result) {
Log.d(TAG, "Task (id:$taskId) was killed.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Cancel
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.Error
import androidx.compose.material.icons.outlined.Cancel
import androidx.compose.material.icons.outlined.ContentCopy
import androidx.compose.material.icons.outlined.ErrorOutline
import androidx.compose.material.icons.outlined.RestartAlt
Expand Down Expand Up @@ -72,6 +74,7 @@ fun DownloadingTaskItem(
onRestart: () -> Unit = {},
onShowLog: () -> Unit = {},
onCopyLink: () -> Unit = {},
onCancel: () -> Unit = {}
) {
CompositionLocalProvider(LocalTonalPalettes provides greenTonalPalettes) {
val greenScheme = dynamicColorScheme(!LocalDarkTheme.current.isDarkTheme())
Expand All @@ -80,6 +83,7 @@ fun DownloadingTaskItem(
TaskState.FINISHED -> greenScheme.primary
TaskState.RUNNING -> primary
TaskState.ERROR -> error.harmonizeWithPrimary()
TaskState.CANCELED -> Color.Gray.harmonizeWithPrimary()
}
}
val containerColor = MaterialTheme.colorScheme.run {
Expand All @@ -94,6 +98,7 @@ fun DownloadingTaskItem(
TaskState.FINISHED -> R.string.status_completed
TaskState.RUNNING -> R.string.downloading
TaskState.ERROR -> R.string.error
TaskState.CANCELED -> R.string.task_canceled
}
)
Surface(
Expand Down Expand Up @@ -153,6 +158,16 @@ fun DownloadingTaskItem(
contentDescription = stringResource(id = R.string.searching_error)
)
}
TaskState.CANCELED -> {
Icon(
modifier = Modifier
.padding(8.dp)
.size(24.dp),
imageVector = Icons.Filled.Cancel,
tint = accentColor,
contentDescription = stringResource(id = R.string.task_canceled)
)
}
}

Column(
Expand Down Expand Up @@ -234,12 +249,18 @@ fun DownloadingTaskItem(
iconColor = MaterialTheme.colorScheme.secondary,
) { onRestart() }
}
if (status == TaskState.RUNNING)
FlatButtonChip(
icon = Icons.Outlined.Cancel,
label = stringResource(id = R.string.cancel),
iconColor = MaterialTheme.colorScheme.secondary,
) { onCancel() }
}
}
}
}
}

enum class TaskState {
FINISHED, RUNNING, ERROR
FINISHED, RUNNING, ERROR, CANCELED
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ import com.bobbyesp.spowlo.utils.GeneralTextUtils
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SongCard(
modifier: Modifier = Modifier,
song: Song,
onClick: () -> Unit = {},
progress: Float = 0.69f,
isPreview: Boolean = false,
isExplicit: Boolean = true,
isLyrics: Boolean = false,
modifier: Modifier = Modifier,
) {
Box(modifier) {
ElevatedCard(
Expand Down Expand Up @@ -174,6 +174,7 @@ fun SongCard(
fun ShowSongCard() {
Surface {
SongCard(
song =
Song(
"Save Your Tears",
listOf("The Weekend"),
Expand Down Expand Up @@ -213,6 +214,7 @@ fun ShowSongCard() {
fun ShowSongCardNight() {
Surface {
SongCard(
song =
Song(
"mariposas",
listOf("sangiovanni"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand All @@ -27,6 +28,8 @@ import androidx.compose.runtime.mutableStateOf
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.layout.ContentScale
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
Expand All @@ -36,6 +39,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.PopupProperties
import com.bobbyesp.spowlo.R
import com.bobbyesp.spowlo.ui.common.AsyncImageImpl
import com.bobbyesp.spowlo.ui.components.MarqueeText
import com.bobbyesp.spowlo.ui.components.songs.ExplicitIcon
import com.bobbyesp.spowlo.ui.components.songs.LyricsIcon
Expand All @@ -53,6 +57,8 @@ fun TrackComponent(
spotifyUrl: String,
hasLyrics: Boolean = false,
isExplicit: Boolean = false,
isPlaylist: Boolean = false,
imageUrl : String = "",
onClick: () -> Unit = { ChromeCustomTabsUtil.openUrl(spotifyUrl) }
) {
val clipboardManager = LocalClipboardManager.current
Expand All @@ -72,9 +78,23 @@ fun TrackComponent(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
if(isPlaylist){
AsyncImageImpl(
modifier = Modifier
.size(40.dp)
.aspectRatio(
1f, matchHeightConstraintsFirst = true
)
.clip(MaterialTheme.shapes.extraSmall),
model = imageUrl,
contentDescription = stringResource(id = R.string.track_artwork),
contentScale = ContentScale.Crop,
)
}
Column(
modifier = Modifier
.padding(6.dp)
.padding(start = if(isPlaylist) 6.dp else 0.dp)
.weight(1f),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.Start
Expand Down
Loading

0 comments on commit f0a7456

Please sign in to comment.