Skip to content

Commit

Permalink
beat & feat: Changed page headers to bold, added a new Downloader set…
Browse files Browse the repository at this point in the history
…tings page and improved notifications
  • Loading branch information
BobbyESP committed Mar 31, 2023
1 parent 1c0518d commit c3db8f2
Show file tree
Hide file tree
Showing 25 changed files with 562 additions and 218 deletions.
55 changes: 47 additions & 8 deletions app/src/main/java/com/bobbyesp/spowlo/Downloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -200,30 +200,69 @@ object Downloader {
taskName = name
).run {
mutableTaskList.put(this.toKey(), this)

val key = makeKey(url, url.reversed())
NotificationsUtil.notifyProgress(
name + " - " + context.getString(R.string.parallel_download),
notificationId = key.toNotificationId(),
progress = (state as DownloadTask.State.Running).progress.toInt(),
text = currentLine
)
}

fun updateTaskOutput(url: String, line: String, progress: Float) {
fun updateTaskOutput(url: String, line: String, progress: Float, isPlaylist: Boolean = false) {
val key = makeKey(url, url.reversed())
val oldValue = mutableTaskList[key] ?: return
val newValue = oldValue.run {
if (currentLine == line || line.containsEllipsis() || consoleOutput.contains(line)) return
copy(
consoleOutput = consoleOutput + line + "\n",
currentLine = line,
state = DownloadTask.State.Running(progress)
)
when(isPlaylist) {
true -> {
copy(
consoleOutput = consoleOutput + line + "\n",
currentLine = line,
state = DownloadTask.State.Running(
if (line.contains("Total")) {
getProgress(line)
} else {
(state as DownloadTask.State.Running).progress
}
)
)

}
false -> {
copy(
consoleOutput = consoleOutput + line + "\n",
currentLine = line,
state = DownloadTask.State.Running(progress)
)
}
}
}
mutableTaskList[key] = newValue
}

private fun getProgress(line: String): Float{
val PERCENT: Float
//Get the two numbers before an % in the line
val regex = Regex("(\\d+)%")
val matchResult = regex.find(line)
//Log the result
///if (BuildConfig.DEBUG) Log.d(TAG, "Progress: ${matchResult?.groupValues?.get(1)?.toFloat() ?: 0f}")
PERCENT = matchResult?.groupValues?.get(1)?.toFloat() ?: 0f
//divide percent by 100 to get a value between 0 and 1
return PERCENT / 100f
}

fun onTaskEnded(
url: String,
response: String? = null
response: String? = null,
notificationTitle : String? = null
) {
val key = makeKey(url, url.reversed())
NotificationsUtil.finishNotification(
notificationId = key.toNotificationId(),
title = key,
title = notificationTitle,
text = context.getString(R.string.status_completed),
)
mutableTaskList.run {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/bobbyesp/spowlo/ui/common/Route.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.bobbyesp.spowlo.ui.common

object Route {

const val DOWNLOADER_SETTINGS = "downloader_settings"
const val DOWNLOADER_SHEET = "downloader_sheet"
const val NavGraph = "nav_graph"
const val SearcherNavi = "searcher_navi"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp


@Composable
fun SettingTitle(text: String) {
fun SettingTitle(text: String, fontWeight: FontWeight = FontWeight.Normal) {
Text(
modifier = Modifier
.padding(top = 32.dp)
.padding(horizontal = 20.dp, vertical = 16.dp),
text = text,
style = MaterialTheme.typography.displaySmall
style = MaterialTheme.typography.displaySmall,
fontWeight = fontWeight,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ fun DownloaderBottomSheet(
Column(
modifier = Modifier.fillMaxWidth().padding(6.dp)
) {
DrawerSheetSubtitle(text = stringResource(id = R.string.general_settings))
DrawerSheetSubtitle(text = stringResource(id = R.string.general))
Row(
modifier = Modifier
.horizontalScroll(rememberScrollState())
Expand Down
21 changes: 9 additions & 12 deletions app/src/main/java/com/bobbyesp/spowlo/ui/pages/InitialEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import com.bobbyesp.spowlo.ui.pages.settings.cookies.CookiesSettingsViewModel
import com.bobbyesp.spowlo.ui.pages.settings.cookies.WebViewPage
import com.bobbyesp.spowlo.ui.pages.settings.directories.DownloadsDirectoriesPage
import com.bobbyesp.spowlo.ui.pages.settings.documentation.DocumentationPage
import com.bobbyesp.spowlo.ui.pages.settings.downloader.DownloaderSettingsPage
import com.bobbyesp.spowlo.ui.pages.settings.format.AudioQualityDialog
import com.bobbyesp.spowlo.ui.pages.settings.format.SettingsFormatsPage
import com.bobbyesp.spowlo.ui.pages.settings.general.GeneralSettingsPage
Expand Down Expand Up @@ -343,6 +344,11 @@ fun InitialEntry(
onBackPressed()
}
}
animatedComposable(Route.DOWNLOADER_SETTINGS) {
DownloaderSettingsPage {
onBackPressed()
}
}
slideInVerticallyComposable(Route.PLAYLIST_METADATA_PAGE) {
PlaylistMetadataPage(
onBackPressed,
Expand Down Expand Up @@ -489,6 +495,7 @@ fun InitialEntry(
onBackPressed,
id = id,
type = type,
playlistPageViewModel = playlistPageViewModel,
)
}
}
Expand Down Expand Up @@ -526,22 +533,12 @@ fun InitialEntry(
}.onFailure {
it.printStackTrace()
ToastUtil.makeToastSuspend(context.getString(R.string.spotify_api_error))
}.onSuccess {
val req = SpotifyApiRequests.provideSearchAllTypes("Faded Alan Walker")
Log.d("InitialEntry", "Name:" + req.tracks!![0].name)
Log.d("InitialEntry", "Artist:" + req.tracks!![0].artists[0].name)
Log.d("InitialEntry", "Album:" + req.tracks!![0].album.name)
Log.d("InitialEntry", "Album Image:" + req.tracks!![0].album.images[0].url)
Log.d("InitialEntry", "Duration:" + req.tracks!![0].durationMs)
Log.d("InitialEntry", "Popularity:" + req.tracks!![0].popularity)
Log.d("InitialEntry", "-------------------------------------------")
Log.d("InitialEntry", "Full response: $req")
}
}


LaunchedEffect(Unit) {
if (PreferencesUtil.isNetworkAvailableForDownload()) launch(Dispatchers.IO) {
if (PreferencesUtil.isNetworkAvailable()) launch(Dispatchers.IO) {
runCatching {
UpdateUtil.checkForUpdate()?.let {
latestRelease = it
Expand All @@ -559,7 +556,7 @@ fun InitialEntry(

LaunchedEffect(Unit) {
Log.d(TAG, "InitialEntry: Checking for mod updates")
if (PreferencesUtil.isNetworkAvailableForDownload()) ModsDownloaderAPI.getAPIResponse()
if (PreferencesUtil.isNetworkAvailable()) ModsDownloaderAPI.getAPIResponse()
.onSuccess {
Log.d(TAG, "InitialEntry: Mods API call success")
modsDownloaderViewModel.updateApiResponse(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ fun DownloaderPage(
onUrlChanged = { url -> downloaderViewModel.updateUrl(url) }) {}

with(viewState) {
DownloaderSettingsDialog(useDialog = useDialog,
DownloaderSettingsDialog(
useDialog = useDialog,
dialogState = showDownloadSettingDialog,
drawerState = drawerState,
confirm = { checkPermissionOrDownload() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.bobbyesp.spowlo.ui.pages.history
import android.content.Intent
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -144,9 +145,9 @@ fun DownloadHistoryBottomDrawerImpl(
val clipboardManager = LocalClipboardManager.current
val context = LocalContext.current

BottomDrawer(drawerState = drawerState, sheetContent = {
BottomDrawer(modifier = Modifier.animateContentSize(),drawerState = drawerState, sheetContent = {
AnimatedVisibility(visible = !showDeleteInfo) {
Column(modifier = Modifier.fillMaxWidth()) {
Column(modifier = Modifier.fillMaxWidth().animateContentSize()) {
Row(
modifier = Modifier
.fillMaxWidth(),
Expand Down Expand Up @@ -232,7 +233,8 @@ fun DownloadHistoryBottomDrawerImpl(
Column(
modifier = Modifier
.fillMaxWidth()
.padding(6.dp),
.padding(6.dp)
.animateContentSize(),
horizontalAlignment = Alignment.Start
) {
Row(
Expand Down Expand Up @@ -278,7 +280,7 @@ fun DownloadHistoryBottomDrawerImpl(
modifier = Modifier
.fillMaxWidth()
.horizontalScroll(rememberScrollState())
.padding(top = 24.dp),
.padding(top = 24.dp).animateContentSize(),
) {
OutlinedButtonWithIcon(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavController
import com.bobbyesp.spowlo.R
import com.bobbyesp.spowlo.ui.common.Route
import com.bobbyesp.spowlo.ui.components.AutoResizableText
import com.bobbyesp.spowlo.ui.components.HorizontalDivider
import com.bobbyesp.spowlo.ui.components.songs.search_feat.SearchingSongComponent
import com.bobbyesp.spowlo.ui.pages.metadata_viewer.binders.typeOfDataToString
Expand All @@ -66,7 +67,7 @@ fun SearcherPage(
.fillMaxSize()
.background(MaterialTheme.colorScheme.background),
) {
SearcherPageImpl(
SearcherPageImpl(
viewState = viewState,
onValueChange = { query ->
searcherPageViewModel.updateSearchText(query)
Expand Down Expand Up @@ -112,24 +113,16 @@ fun SearcherPageImpl(
Box(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
.background(MaterialTheme.colorScheme.background).padding(horizontal = 16.dp),
contentAlignment = Alignment.Center
) {
Column(
modifier = Modifier.align(Alignment.Center),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = stringResource(id = R.string.search),
modifier = Modifier.align(
Alignment.CenterHorizontally
),
style = MaterialTheme.typography.bodyMedium,
fontWeight = FontWeight.Bold
)
}

AutoResizableText(
text = stringResource(id = R.string.search),
style = MaterialTheme.typography.bodyMedium,
fontWeight = FontWeight.Bold
)
}

}
}

Expand Down Expand Up @@ -195,7 +188,7 @@ fun SearcherPageImpl(
mutableListOf<Any>() //TODO: Add the filters. Pagination should be done in the future
viewState.viewState.data.let { data ->
data.albums?.items?.let {/* allItems.addAll(it)*/ }
data.artists?.items?.let { /*allItems.addAll(it) */}
data.artists?.items?.let { /*allItems.addAll(it) */ }
data.playlists?.items?.let { allItems.addAll(it) }
data.tracks?.items?.let { allItems.addAll(it) }
data.episodes?.items?.let {/*
Expand Down Expand Up @@ -250,7 +243,7 @@ fun SearcherPageImpl(
songName = track.name,
artists = artists.joinToString(", "),
spotifyUrl = track.externalUrls.spotify ?: "",
onClick = { onItemClick(track.type ,track.id) },
onClick = { onItemClick(track.type, track.id) },
type = typeOfDataToString(
type = typeOfSpotifyDataType(
track.type
Expand All @@ -272,7 +265,12 @@ fun SearcherPageImpl(
artists = playlist.owner.displayName
?: stringResource(R.string.unknown),
spotifyUrl = playlist.externalUrls.spotify ?: "",
onClick = { onItemClick(playlist.type ,playlist.id) },
onClick = {
onItemClick(
playlist.type,
playlist.id
)
},
type = typeOfDataToString(
type = typeOfSpotifyDataType(
playlist.type
Expand Down
Loading

0 comments on commit c3db8f2

Please sign in to comment.