Skip to content

Commit

Permalink
Update and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Nov 7, 2024
1 parent b2a6f2e commit e80be39
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 81 deletions.
10 changes: 10 additions & 0 deletions .idea/kotlinc.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -1260,11 +1260,10 @@ class SimpleMediaServiceHandler(
val liked =
mainRepository
.getSongById(id)
.first()
?.liked
if (liked != null) {
_controlState.value = _controlState.value.copy(isLiked = liked)
}
.singleOrNull()
?.liked ?: false
Log.w("Check liked", liked.toString())
_controlState.value = _controlState.value.copy(isLiked = liked)
setNotificationLayout?.invoke(
listOf(
CommandButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ class DownloadUtils (
)
}

fun removeDownload(videoId: String) {
DownloadService.sendRemoveDownload(
context,
MusicDownloadService::class.java,
videoId,
false
)
}

fun getDownload(songId: String): Flow<Download?> = downloads.map { it[songId] }

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ fun HomeItem(

if (bottomSheetShow) {
NowPlayingBottomSheet(
isBottomSheetVisible = bottomSheetShow,
onDismiss = { bottomSheetShow = false },
song = songEntity,
navController = navController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import com.maxrave.simpmusic.data.model.searchResult.songs.Artist
import com.maxrave.simpmusic.extension.connectArtists
import com.maxrave.simpmusic.extension.greyScale
import com.maxrave.simpmusic.extension.navigateSafe
import com.maxrave.simpmusic.extension.toListName
import com.maxrave.simpmusic.ui.theme.seed
import com.maxrave.simpmusic.ui.theme.typo
import com.maxrave.simpmusic.viewModel.NowPlayingBottomSheetUIEvent
Expand All @@ -97,7 +98,6 @@ import org.koin.androidx.compose.koinViewModel
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@Composable
fun NowPlayingBottomSheet(
isBottomSheetVisible: Boolean,
onDismiss: () -> Unit,
navController: NavController,
song: SongEntity?,
Expand Down Expand Up @@ -132,6 +132,13 @@ fun NowPlayingBottomSheet(
var sleepTimerWarning by remember {
mutableStateOf(false)
}
var isBottomSheetVisible by rememberSaveable { mutableStateOf(false) }

LaunchedEffect(uiState) {
if (uiState.songUIState.videoId.isNotEmpty() && !isBottomSheetVisible) {
isBottomSheetVisible = true
}
}

LaunchedEffect(key1 = song) {
viewModel.setSongEntity(song)
Expand All @@ -145,19 +152,13 @@ fun NowPlayingBottomSheet(
onClick = {
viewModel.onUIEvent(NowPlayingBottomSheetUIEvent.AddToPlaylist(it.id))
},
videoId = uiState.songEntity?.videoId ?: return
videoId = uiState.songUIState.videoId
)
}
if (artist) {
ArtistModalBottomSheet(
isBottomSheetVisible = artist,
artists =
uiState.songEntity?.artistName?.mapIndexed { index, name ->
Artist(
id = uiState.songEntity?.artistId?.get(index),
name = name,
)
} ?: arrayListOf(),
artists = uiState.songUIState.listArtists,
navController = navController,
onDismiss = { artist = false },
)
Expand Down Expand Up @@ -316,7 +317,7 @@ fun NowPlayingBottomSheet(
verticalAlignment = Alignment.CenterVertically,
) {
CoilImage(
imageModel = { uiState.songEntity?.thumbnails },
imageModel = { uiState.songUIState.thumbnails },
imageOptions =
ImageOptions(
contentScale = ContentScale.Inside,
Expand All @@ -339,7 +340,7 @@ fun NowPlayingBottomSheet(
verticalArrangement = Arrangement.Center,
) {
Text(
text = uiState.songEntity?.title ?: "",
text = uiState.songUIState.title,
style = typo.labelMedium,
maxLines = 1,
modifier =
Expand All @@ -351,7 +352,7 @@ fun NowPlayingBottomSheet(
.focusable(),
)
Text(
text = uiState.songEntity?.artistName?.connectArtists() ?: "",
text = uiState.songUIState.listArtists.toListName().connectArtists(),
style = typo.bodyMedium,
maxLines = 1,
modifier =
Expand Down Expand Up @@ -385,14 +386,14 @@ fun NowPlayingBottomSheet(
}
}
CheckBoxActionButton(
defaultChecked = uiState.songEntity?.liked ?: false,
defaultChecked = uiState.songUIState.liked,
onChangeListener = {
viewModel.onUIEvent(NowPlayingBottomSheetUIEvent.ToggleLike)
},
)
ActionButton(
icon =
when (uiState.songEntity?.downloadState) {
when (uiState.songUIState.downloadState) {
DownloadState.STATE_NOT_DOWNLOADED ->
painterResource(
R.drawable.outline_download_for_offline_24,
Expand All @@ -419,7 +420,7 @@ fun NowPlayingBottomSheet(
)
},
text =
when (uiState.songEntity?.downloadState) {
when (uiState.songUIState.downloadState) {
DownloadState.STATE_NOT_DOWNLOADED -> R.string.download
DownloadState.STATE_DOWNLOADING -> R.string.downloading
DownloadState.STATE_DOWNLOADED -> R.string.downloaded
Expand Down Expand Up @@ -455,14 +456,14 @@ fun NowPlayingBottomSheet(
}
ActionButton(
icon = painterResource(id = R.drawable.baseline_album_24),
text = if (uiState.songEntity?.albumName.isNullOrBlank()) R.string.no_album else null,
textString = uiState.songEntity?.albumName,
enable = !uiState.songEntity?.albumName.isNullOrBlank(),
text = if (uiState.songUIState.album == null) R.string.no_album else null,
textString = uiState.songUIState.album?.name,
enable = uiState.songUIState.album != null,
) {
navController.navigateSafe(
R.id.action_global_albumFragment,
Bundle().apply {
putString("browseId", uiState.songEntity?.albumId)
putString("browseId", uiState.songUIState.album?.id)
},
)
}
Expand All @@ -471,10 +472,10 @@ fun NowPlayingBottomSheet(
text = R.string.start_radio,
) {
val args = Bundle()
args.putString("radioId", "RDAMVM${uiState.songEntity?.videoId}")
args.putString("radioId", "RDAMVM${uiState.songUIState.videoId}")
args.putString(
"videoId",
uiState.songEntity?.videoId,
uiState.songUIState.videoId,
)
hideModalBottomSheet()
navController.navigateSafe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,6 @@ fun PlaylistScreen(
if (itemBottomSheetShow && currentItem != null) {
val track = currentItem ?: return
NowPlayingBottomSheet(
isBottomSheetVisible = true,
onDelete = { viewModel.deleteItem(uiState.id, track) },
onDismiss = {
itemBottomSheetShow = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ fun NowPlayingScreen(

if (showSheet) {
NowPlayingBottomSheet(
isBottomSheetVisible = showSheet,
onDismiss = {
showSheet = false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ class LocalPlaylistViewModel(
}
}
}
delay(500)
val fullTracks = localPlaylistManager.getFullPlaylistTracks(id = id)
val notDownloadedList = fullTracks.filter { it.downloadState != STATE_DOWNLOADED }.map { it.videoId }
if (fullTracks.all { it.downloadState == STATE_DOWNLOADED } && uiState.value.downloadState != STATE_DOWNLOADED) {
updatePlaylistDownloadState(uiState.value.id, STATE_DOWNLOADED)
} else if (
downloadUtils.downloads.value
.filter { it.value.state != Download.STATE_COMPLETED }
.map { it.key }.containsAll(notDownloadedList) && notDownloadedList.isNotEmpty()
&& uiState.value.downloadState != STATE_DOWNLOADING
) {
updatePlaylistDownloadState(uiState.value.id, STATE_DOWNLOADING)
} else if (uiState.value.downloadState != STATE_NOT_DOWNLOADED) {
updatePlaylistDownloadState(uiState.value.id, STATE_NOT_DOWNLOADED)
}
}
}
listTrackStringJob.join()
Expand Down Expand Up @@ -902,7 +917,10 @@ class LocalPlaylistViewModel(
if (listJob.isNotEmpty()) {
downloadTracks(listJob)
downloadFullPlaylistState(uiState.value.id, listJob)
} else {
} else if (fullTracks.isNotEmpty() && fullTracks.all { it.downloadState == STATE_DOWNLOADED}) {
updatePlaylistDownloadState(uiState.value.id, STATE_DOWNLOADED)
}
else {
makeToast(getString(R.string.playlist_is_empty))
}
}
Expand Down
Loading

0 comments on commit e80be39

Please sign in to comment.