Skip to content

Commit

Permalink
Merge pull request #33 from BobbyESP/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbyESP authored May 4, 2023
2 parents e7f6435 + 69225f1 commit 90417a4
Show file tree
Hide file tree
Showing 18 changed files with 188 additions and 146 deletions.
7 changes: 6 additions & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sealed class Version(
val currentVersion: Version = Version.Stable(
versionMajor = 1,
versionMinor = 3,
versionPatch = 0,
versionPatch = 1,
)

val keystorePropertiesFile = rootProject.file("keystore.properties")
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/bobbyesp/spowlo/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class App : Application() {
}
} catch (e: Exception) {
Looper.prepare()
ToastUtil.makeToast(text = e.message ?: "Unknown error")
e.printStackTrace()
clipboard.setPrimaryClip(ClipData.newPlainText(null, e.message))
ToastUtil.makeToast(text = e.message ?: "Unknown error")
}
}
audioDownloadDir = AUDIO_DIRECTORY.getString(
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/bobbyesp/spowlo/Downloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ object Downloader {
if (it) startService()
else stopService()
}

}
}

Expand All @@ -199,7 +198,7 @@ object Downloader {
currentLine = "",
taskName = name
).run {
mutableTaskList.put(this.toKey(), this)
mutableTaskList[this.toKey()] = this

val key = makeKey(url, url.reversed())
NotificationsUtil.notifyProgress(
Expand Down Expand Up @@ -519,9 +518,11 @@ object Downloader {

fun executeParallelDownloadWithUrl(url: String, name: String) =
applicationScope.launch(Dispatchers.IO) {

DownloaderUtil.executeParallelDownload(
url, name
)

}

fun onProcessStarted() = mutableProcessCount.update { it + 1 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.bobbyesp.spowlo.utils.NotificationsUtil.SERVICE_NOTIFICATION_ID
private val TAG = DownloaderKeepUpService::class.java.simpleName
class DownloaderKeepUpService: Service() {
override fun onBind(intent: Intent): IBinder {
Log.d(TAG, "onBind: ")
val pendingIntent: PendingIntent =
Intent(this, MainActivity::class.java).let { notificationIntent ->
PendingIntent.getActivity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fun SongMetadataCard(

}
FilledTonalButton(
modifier = Modifier,
modifier = Modifier.padding(start = 8.dp),
onClick = { ChromeCustomTabsUtil.openUrl(song.url) },
colors = ButtonDefaults.filledTonalButtonColors(
containerColor = Color(red = 30, green = 215, blue = 96).harmonizeWithPrimary(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import com.bobbyesp.spowlo.ui.pages.settings.spotify.SpotifyClientIDDialog
import com.bobbyesp.spowlo.ui.pages.settings.spotify.SpotifyClientSecretDialog
import com.bobbyesp.spowlo.utils.COOKIES
import com.bobbyesp.spowlo.utils.DONT_FILTER_RESULTS
import com.bobbyesp.spowlo.utils.GEO_BYPASS
import com.bobbyesp.spowlo.utils.ORIGINAL_AUDIO
import com.bobbyesp.spowlo.utils.PreferencesUtil
import com.bobbyesp.spowlo.utils.SKIP_INFO_FETCH
Expand Down Expand Up @@ -126,14 +125,6 @@ fun DownloaderSettingsDialog(
)
}

var useGeoBypass by remember {
mutableStateOf(
settings.getValue(
GEO_BYPASS
)
)
}

var skipInfoFetch by remember { mutableStateOf(settings.getValue(SKIP_INFO_FETCH)) }

var showAudioFormatDialog by remember { mutableStateOf(false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Album
import androidx.compose.material.icons.outlined.AudioFile
import androidx.compose.material.icons.outlined.Cancel
import androidx.compose.material.icons.outlined.Dataset
Expand Down Expand Up @@ -51,7 +52,6 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavController
import com.bobbyesp.spowlo.App
import com.bobbyesp.spowlo.R
Expand All @@ -60,14 +60,12 @@ import com.bobbyesp.spowlo.ui.components.ButtonChip
import com.bobbyesp.spowlo.ui.components.DrawerSheetSubtitle
import com.bobbyesp.spowlo.ui.components.FilledButtonWithIcon
import com.bobbyesp.spowlo.ui.components.OutlinedButtonWithIcon
import com.bobbyesp.spowlo.ui.pages.downloader.DownloaderViewModel
import com.bobbyesp.spowlo.ui.pages.settings.format.AudioFormatDialog
import com.bobbyesp.spowlo.ui.pages.settings.format.AudioQualityDialog
import com.bobbyesp.spowlo.ui.pages.settings.spotify.SpotifyClientIDDialog
import com.bobbyesp.spowlo.ui.pages.settings.spotify.SpotifyClientSecretDialog
import com.bobbyesp.spowlo.utils.COOKIES
import com.bobbyesp.spowlo.utils.DONT_FILTER_RESULTS
import com.bobbyesp.spowlo.utils.GEO_BYPASS
import com.bobbyesp.spowlo.utils.ORIGINAL_AUDIO
import com.bobbyesp.spowlo.utils.PreferencesUtil
import com.bobbyesp.spowlo.utils.SKIP_INFO_FETCH
Expand All @@ -85,33 +83,35 @@ import kotlinx.coroutines.launch
@Composable
fun DownloaderBottomSheet(
onBackPressed: () -> Unit,
downloaderViewModel: DownloaderViewModel,
url: String,
navController: NavController,
navigateToPlaylist: (String) -> Unit
onDownloadPressed : () -> Unit,
onRequestMetadata : () -> Unit,
hide: () -> Unit,
navigateToPlaylist: (String) -> Unit,
navigateToAlbum: (String) -> Unit,
) {
val scope = rememberCoroutineScope()
val pagerState = rememberPagerState(initialPage = 0)

val pages =
listOf(BottomSheetPages.MAIN, BottomSheetPages.TERTIARY) //, BottomSheetPages.SECONDARY

val viewState by downloaderViewModel.viewStateFlow.collectAsStateWithLifecycle()

val roundedTopShape =
RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp, bottomStart = 0.dp, bottomEnd = 0.dp)

val storagePermission = rememberPermissionState(
permission = Manifest.permission.WRITE_EXTERNAL_STORAGE
) { b: Boolean ->
if (b) {
downloaderViewModel.startDownloadSong()
onDownloadPressed()
} else {
ToastUtil.makeToast(R.string.permission_denied)
}
}

val checkPermissionOrDownload = {
if (Build.VERSION.SDK_INT > 29 || storagePermission.status == PermissionStatus.Granted) downloaderViewModel.startDownloadSong()
if (Build.VERSION.SDK_INT > 29 || storagePermission.status == PermissionStatus.Granted) onDownloadPressed()
else {
storagePermission.launchPermissionRequest()
}
Expand Down Expand Up @@ -173,14 +173,6 @@ fun DownloaderBottomSheet(
)
}

var useGeoBypass by remember {
mutableStateOf(
settings.getValue(
GEO_BYPASS
)
)
}

var skipInfoFetch by remember { mutableStateOf(settings.getValue(SKIP_INFO_FETCH)) }

var showAudioFormatDialog by remember { mutableStateOf(false) }
Expand All @@ -189,13 +181,13 @@ fun DownloaderBottomSheet(
var showClientSecretDialog by remember { mutableStateOf(false) }

val downloadButtonCallback = {
navController.popBackStack()
hide()
checkPermissionOrDownload()
}

val requestMetadata = {
navController.popBackStack()
downloaderViewModel.requestMetadata()
hide()
onRequestMetadata()
}

Column(
Expand Down Expand Up @@ -402,15 +394,6 @@ fun DownloaderBottomSheet(
settings.updateValue(SYNCED_LYRICS, useSyncedLyrics)
}
})
AudioFilterChip(label = stringResource(id = R.string.geo_bypass),
selected = useGeoBypass,
animated = true,
onClick = {
useGeoBypass = !useGeoBypass
scope.launch {
settings.updateValue(GEO_BYPASS, useGeoBypass)
}
})
AudioFilterChip(label = stringResource(id = R.string.dont_filter_results),
selected = dontFilter,
animated = true,
Expand Down Expand Up @@ -474,27 +457,39 @@ fun DownloaderBottomSheet(
)
}
item {
if (viewState.url.contains("playlist")) {
//https://open.spotify.com/playlist/4aKFWQtn0Tstw68SIMURye?si=c9e7282b0c354d34
//get playlist id after the playlist/ and before the ?
var playlistId = viewState.url.substringAfter("playlist/").substringBefore("?")

if (viewState.url == "playlist")
run {
playlistId = "7804lpXmApCGPd2Rdai6k1"
}
FilledButtonWithIcon(
onClick = { navigateToPlaylist(playlistId) },
icon = Icons.Outlined.PlaylistAddCheck,
text = stringResource(R.string.see_playlist)
)

} else {
FilledButtonWithIcon(
onClick = downloadButtonCallback,
icon = Icons.Outlined.DownloadDone,
text = stringResource(R.string.start_download)
)
val playlistPattern = "^https?://open.spotify.com/playlist/([a-zA-Z0-9]+)(\\?.*)?\$"
val playlistRegex = Regex(playlistPattern)

val albumPattern = "^https?://open.spotify.com/album/([a-zA-Z0-9]+)(\\?.*)?\$"
val albumRegex = Regex(albumPattern)

when {
playlistRegex.matches(url) -> {
val playlistId = playlistRegex.find(url)!!.groupValues[1]
FilledButtonWithIcon(
modifier = Modifier.padding(end = 12.dp),
onClick = { navigateToPlaylist(playlistId) },
icon = Icons.Outlined.PlaylistAddCheck,
text = stringResource(R.string.see_playlist)
)
}
albumRegex.matches(url) -> {
val albumId = albumRegex.find(url)!!.groupValues[1]
FilledButtonWithIcon(
modifier = Modifier.padding(end = 12.dp),
onClick = { navigateToAlbum(albumId) },
icon = Icons.Outlined.Album,
text = stringResource(R.string.see_album)
)
}
else -> {
FilledButtonWithIcon(
modifier = Modifier.padding(end = 12.dp),
onClick = downloadButtonCallback,
icon = Icons.Outlined.DownloadDone,
text = stringResource(R.string.start_download)
)
}
}
}
}
Expand Down
62 changes: 52 additions & 10 deletions app/src/main/java/com/bobbyesp/spowlo/ui/pages/InitialEntry.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bobbyesp.spowlo.ui.pages

import android.Manifest
import android.content.Intent
import android.net.Uri
import android.os.Build
Expand Down Expand Up @@ -44,6 +45,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavType
Expand Down Expand Up @@ -108,6 +110,9 @@ import com.google.accompanist.navigation.material.ExperimentalMaterialNavigation
import com.google.accompanist.navigation.material.ModalBottomSheetLayout
import com.google.accompanist.navigation.material.bottomSheet
import com.google.accompanist.navigation.material.rememberBottomSheetNavigator
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.PermissionStatus
import com.google.accompanist.permissions.rememberPermissionState
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
Expand All @@ -117,7 +122,7 @@ private const val TAG = "InitialEntry"

@OptIn(
ExperimentalAnimationApi::class, ExperimentalMaterialNavigationApi::class,
ExperimentalLayoutApi::class, ExperimentalMaterialApi::class
ExperimentalLayoutApi::class, ExperimentalMaterialApi::class, ExperimentalPermissionsApi::class
)
@Composable
fun InitialEntry(
Expand Down Expand Up @@ -449,15 +454,53 @@ fun InitialEntry(
rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden, skipHalfExpanded = true),
)
) {*/
DownloaderBottomSheet(
onBackPressed,
downloaderViewModel,
navController
) { id -> navController.navigate(Route.PLAYLIST_PAGE + "/" + "playlist" + "/" + id, navOptions = navOptions {
launchSingleTop = true
}) }
// }
//val viewModel = hiltViewModel<DownloaderViewModel>()

val storagePermission = rememberPermissionState(
permission = Manifest.permission.WRITE_EXTERNAL_STORAGE
) { b: Boolean ->
if (b) {
downloaderViewModel.startDownloadSong()
} else {
ToastUtil.makeToast(R.string.permission_denied)
}
}

val viewModelState =
downloaderViewModel.viewStateFlow.collectAsStateWithLifecycle().value
DownloaderBottomSheet(
onBackPressed,
viewModelState.url,
navController,
onDownloadPressed = {
if (Build.VERSION.SDK_INT > 29 || storagePermission.status == PermissionStatus.Granted) downloaderViewModel.startDownloadSong()
else {
storagePermission.launchPermissionRequest()
}
},
onRequestMetadata = {
downloaderViewModel.requestMetadata()
},
hide = {
navController.popBackStack()
},
navigateToPlaylist = { id ->
navController.navigate(
Route.PLAYLIST_PAGE + "/" + "playlist" + "/" + id,
navOptions = navOptions {
launchSingleTop = true
restoreState = true
})
},
navigateToAlbum = { id ->
navController.navigate(
Route.PLAYLIST_PAGE + "/" + "album" + "/" + id,
navOptions = navOptions {
launchSingleTop = true
restoreState = true
})
},
)
}
}

Expand Down Expand Up @@ -488,7 +531,6 @@ fun InitialEntry(
type = NavType.StringType
}


//We build the route with the type of the destination and the id of it
val routeWithIdPattern: String =
StringBuilder().append(Route.PLAYLIST_PAGE).append("/{type}")
Expand Down
Loading

0 comments on commit 90417a4

Please sign in to comment.