Skip to content

Commit

Permalink
v2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sosauce committed Dec 1, 2024
1 parent 92c2a3b commit a8e0b4e
Show file tree
Hide file tree
Showing 27 changed files with 568 additions and 507 deletions.
Binary file modified app/.DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId = "com.sosauce.cutemusic"
minSdk = 26
targetSdk = 35
versionCode = 17
versionName = "2.3.0"
versionCode = 18
versionName = "2.3.1"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
Expand Down Expand Up @@ -81,7 +81,7 @@ android {
implementation(libs.koin.androidx.compose)
//implementation("com.materialkolor:material-kolor:2.0.0")
implementation(libs.koin.androidx.startup)
implementation(libs.jaudiotagger)
implementation(libs.taglib)
debugImplementation(libs.androidx.ui.tooling)
}
}
Binary file modified app/release/baselineProfiles/0/app-release.dm
Binary file not shown.
Binary file modified app/release/baselineProfiles/1/app-release.dm
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 16,
"versionName": "2.2.5",
"versionCode": 17,
"versionName": "2.3.0",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ package com.sosauce.cutemusic.data.actions
import android.net.Uri

sealed interface MetadataActions {

data class LoadSong(
val path: String,
val uri: Uri
) : MetadataActions

data class UpdateAudioArt(
val newArtUri: Uri
) : MetadataActions

data object SaveChanges : MetadataActions

data object ClearState : MetadataActions
data object RemoveArtwork : MetadataActions

}
2 changes: 1 addition & 1 deletion app/src/main/java/com/sosauce/cutemusic/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val appModule = module {
MediaStoreHelperImpl(androidContext())
}
viewModel {
PostViewModel(get(), androidApplication())
PostViewModel(get())
}
viewModel {
MusicViewModel(androidApplication(), get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.media3.common.MediaItem
import com.sosauce.cutemusic.domain.model.Album
import com.sosauce.cutemusic.domain.model.Artist
import com.sosauce.cutemusic.domain.model.Folder
import kotlinx.coroutines.flow.Flow

interface MediaStoreHelper {

Expand All @@ -16,8 +17,10 @@ interface MediaStoreHelper {
val folders: List<Folder>

fun fetchMusics(): List<MediaItem>
fun fetchLatestMusics(): Flow<List<MediaItem>>

fun fetchAlbums(): List<Album>
fun fetchLatestAlbums(): Flow<List<Album>>

fun fetchArtists(): List<Artist>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package com.sosauce.cutemusic.domain.repository

import android.annotation.SuppressLint
import android.content.ContentUris
import android.content.ContentValues
import android.content.Context
Expand All @@ -19,21 +20,27 @@ import com.sosauce.cutemusic.data.datastore.getBlacklistedFolder
import com.sosauce.cutemusic.domain.model.Album
import com.sosauce.cutemusic.domain.model.Artist
import com.sosauce.cutemusic.domain.model.Folder
import com.sosauce.cutemusic.utils.observe
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.runBlocking

@SuppressLint("UnsafeOptInUsageError")
class MediaStoreHelperImpl(
private val context: Context
) : MediaStoreHelper {

private fun getBlacklistedFoldersAsync(): Set<String> =
runBlocking { getBlacklistedFolder(context) }
private fun getBlacklistedFoldersAsync(): Set<String> = runBlocking { getBlacklistedFolder(context) }

private val blacklistedFolders = getBlacklistedFoldersAsync()
private val selection =
blacklistedFolders.joinToString(" AND ") { "${MediaStore.Audio.Media.DATA} NOT LIKE ?" }
private val selection = blacklistedFolders.joinToString(" AND ") { "${MediaStore.Audio.Media.DATA} NOT LIKE ?" }
private val selectionArgs = blacklistedFolders.map { "$it%" }.toTypedArray()


override fun fetchLatestMusics(): Flow<List<MediaItem>> = context.contentResolver.observe(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI).map { fetchMusics() }
override fun fetchLatestAlbums(): Flow<List<Album>> = context.contentResolver.observe(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI).map { fetchAlbums() }

@UnstableApi
override fun fetchMusics(): List<MediaItem> {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.sosauce.cutemusic.ui.screens.playing.NowPlayingScreen
import com.sosauce.cutemusic.ui.screens.settings.SettingsScreen
import com.sosauce.cutemusic.ui.shared_components.MusicViewModel
import com.sosauce.cutemusic.ui.shared_components.PostViewModel
import com.sosauce.cutemusic.utils.ListToHandle
import org.koin.androidx.compose.koinViewModel

// https://stackoverflow.com/a/78771053
Expand All @@ -39,9 +38,9 @@ fun Nav() {
val viewModel = koinViewModel<MusicViewModel>()
val postViewModel = koinViewModel<PostViewModel>()
val metadataViewModel = koinViewModel<MetadataViewModel>()
val musics = postViewModel.musics
val musics by postViewModel.musics.collectAsStateWithLifecycle()
val musicState by viewModel.musicState.collectAsStateWithLifecycle()
val folders = postViewModel.folders
val albums by postViewModel.albums.collectAsStateWithLifecycle()


SharedTransitionLayout {
Expand All @@ -65,7 +64,6 @@ fun Nav() {
},
animatedVisibilityScope = this,
onLoadMetadata = { path, uri ->
metadataViewModel.onHandleMetadataActions(MetadataActions.ClearState)
metadataViewModel.onHandleMetadataActions(
MetadataActions.LoadSong(
path,
Expand All @@ -82,43 +80,20 @@ fun Nav() {
intentSender
)
},
onHandleSorting = { sortingType ->
postViewModel.handleFiltering(
listToHandle = ListToHandle.TRACKS,
sortingType = sortingType
)
},
onHandleSearching = { query ->
postViewModel.handleSearch(
listToHandle = ListToHandle.TRACKS,
query = query
)
},
onChargeAlbumSongs = postViewModel::albumSongs,
onChargeArtistLists = {
postViewModel.artistSongs(it)
postViewModel.artistAlbums(it)
},
musicState = musicState
}
)

}

composable<Screen.Albums> {

AlbumsScreen(
albums = postViewModel.albums,
albums = albums,
animatedVisibilityScope = this,
onHandleSorting = { sortingType ->
postViewModel.handleFiltering(
listToHandle = ListToHandle.ALBUMS,
sortingType = sortingType
)
},
onHandleSearching = { query ->
postViewModel.handleSearch(
listToHandle = ListToHandle.ALBUMS,
query = query
)
},
currentlyPlaying = musicState.currentlyPlaying,
chargePVMAlbumSongs = postViewModel::albumSongs,
isPlayerReady = musicState.isPlayerReady,
Expand All @@ -132,7 +107,6 @@ fun Nav() {
}
},
selectedIndex = viewModel.selectedItem,
musicState = musicState
)
}
composable<Screen.Artists> {
Expand All @@ -154,20 +128,7 @@ fun Nav() {
onHandlePlayerActions = viewModel::handlePlayerActions,
isPlaying = musicState.isCurrentlyPlaying,
animatedVisibilityScope = this,
isPlayerReady = musicState.isPlayerReady,
onHandleSorting = { sortingType ->
postViewModel.handleFiltering(
listToHandle = ListToHandle.ARTISTS,
sortingType = sortingType
)
},
onHandleSearching = { query ->
postViewModel.handleSearch(
listToHandle = ListToHandle.ARTISTS,
query = query
)
},
musicState = musicState
isPlayerReady = musicState.isPlayerReady
)
}

Expand All @@ -192,7 +153,7 @@ fun Nav() {
}
composable<Screen.AlbumsDetails> {
val index = it.toRoute<Screen.AlbumsDetails>()
postViewModel.albums.find { album -> album.id == index.id }?.let { album ->
albums.find { album -> album.id == index.id }?.let { album ->
AlbumDetailsScreen(
album = album,
viewModel = viewModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -48,7 +49,6 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImage
import com.sosauce.cutemusic.R
import com.sosauce.cutemusic.data.MusicState
import com.sosauce.cutemusic.data.actions.PlayerActions
import com.sosauce.cutemusic.data.datastore.rememberIsLandscape
import com.sosauce.cutemusic.domain.model.Album
Expand All @@ -58,7 +58,6 @@ import com.sosauce.cutemusic.ui.shared_components.CuteText
import com.sosauce.cutemusic.ui.shared_components.NavigationItem
import com.sosauce.cutemusic.ui.shared_components.ScreenSelection
import com.sosauce.cutemusic.utils.ImageUtils
import com.sosauce.cutemusic.utils.SortingType
import com.sosauce.cutemusic.utils.rememberSearchbarAlignment
import com.sosauce.cutemusic.utils.rememberSearchbarMaxFloatValue
import com.sosauce.cutemusic.utils.rememberSearchbarRightPadding
Expand All @@ -68,8 +67,6 @@ import com.sosauce.cutemusic.utils.thenIf
fun SharedTransitionScope.AlbumsScreen(
albums: List<Album>,
animatedVisibilityScope: AnimatedVisibilityScope,
onHandleSorting: (SortingType) -> Unit,
onHandleSearching: (String) -> Unit,
currentlyPlaying: String,
chargePVMAlbumSongs: (String) -> Unit,
onNavigate: (Screen) -> Unit,
Expand All @@ -78,7 +75,6 @@ fun SharedTransitionScope.AlbumsScreen(
onHandlePlayerActions: (PlayerActions) -> Unit,
isPlayerReady: Boolean,
onNavigationItemClicked: (Int, NavigationItem) -> Unit,
musicState: MusicState
) {
val isLandscape = rememberIsLandscape()
var query by remember { mutableStateOf("") }
Expand All @@ -92,8 +88,25 @@ fun SharedTransitionScope.AlbumsScreen(
if (isLandscape) 4 else 2
}

val displayAlbums by remember(isSortedByASC, albums, query) {
derivedStateOf {
if (query.isNotEmpty()) {
albums.filter {
it.name.contains(
other = query,
ignoreCase = true
) == true
}
} else {
if (isSortedByASC) albums
else albums.sortedByDescending { it.name }
}

}
}

Box {
if (albums.isEmpty()) {
if (displayAlbums.isEmpty()) {
Column(
modifier = Modifier
.fillMaxSize()
Expand All @@ -114,7 +127,7 @@ fun SharedTransitionScope.AlbumsScreen(
.fillMaxSize()
) {
itemsIndexed(
items = albums,
items = displayAlbums,
key = { _, album -> album.id }
) { index, album ->
AlbumCard(
Expand All @@ -138,10 +151,7 @@ fun SharedTransitionScope.AlbumsScreen(
}
CuteSearchbar(
query = query,
onQueryChange = {
query = it
onHandleSearching(query)
},
onQueryChange = { query = it },
modifier = Modifier
.navigationBarsPadding()
.fillMaxWidth(rememberSearchbarMaxFloatValue())
Expand Down Expand Up @@ -182,18 +192,7 @@ fun SharedTransitionScope.AlbumsScreen(
trailingIcon = {
Row {
IconButton(
onClick = {
isSortedByASC = !isSortedByASC
when (isSortedByASC) {
true -> {
onHandleSorting(SortingType.ASCENDING)
}

false -> {
onHandleSorting(SortingType.DESCENDING)
}
}
}
onClick = { isSortedByASC = !isSortedByASC }
) {
Icon(
imageVector = Icons.Rounded.ArrowUpward,
Expand Down
Loading

0 comments on commit a8e0b4e

Please sign in to comment.