Skip to content

Commit

Permalink
v2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sosauce committed Nov 26, 2024
1 parent 8683251 commit 92c2a3b
Show file tree
Hide file tree
Showing 73 changed files with 866 additions and 367 deletions.
Binary file modified app/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 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 = 16
versionName = "2.2.5"
versionCode = 17
versionName = "2.3.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
Expand Down
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": 15,
"versionName": "2.2.4",
"versionCode": 16,
"versionName": "2.2.5",
"outputFile": "app-release.apk"
}
],
Expand Down
Binary file modified app/src/.DS_Store
Binary file not shown.
Binary file modified app/src/main/.DS_Store
Binary file not shown.
Binary file modified app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/src/main/java/com/sosauce/cutemusic/data/MusicState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ data class MusicState(
val currentSize: Long = 0,
val currentLrcFile: File? = null,
val playbackParameters: PlaybackParameters = PlaybackParameters.DEFAULT,
val isPlayerReady: Boolean = false
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.sosauce.cutemusic.data.actions

import android.net.Uri

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

data object SaveChanges : MetadataActions
Expand Down
36 changes: 18 additions & 18 deletions app/src/main/java/com/sosauce/cutemusic/data/datastore/DataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import com.sosauce.cutemusic.data.datastore.PreferencesKeys.APPLY_LOOP
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.BLACKLISTED_FOLDERS
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.FOLLOW_SYS
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.HAS_SEEN_TIP
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.SHOW_ALBUMS_TAB
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.SHOW_ARTISTS_TAB
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.SHOW_FOLDERS_TAB
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.SHOW_X_BUTTON
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.SNAP_SPEED_N_PITCH
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.SORT_ORDER
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.SORT_ORDER_ALBUMS
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.SORT_ORDER_ARTISTS
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.USE_AMOLED_MODE
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.USE_ART_THEME
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.USE_CLASSIC_SLIDER
Expand All @@ -28,9 +28,6 @@ private const val PREFERENCES_NAME = "settings"
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(PREFERENCES_NAME)

private data object PreferencesKeys {
val SORT_ORDER = booleanPreferencesKey("sort_order")
val SORT_ORDER_ARTISTS = booleanPreferencesKey("sort_order_artists")
val SORT_ORDER_ALBUMS = booleanPreferencesKey("sort_order_albums")
val USE_DARK_MODE = booleanPreferencesKey("use_dark_mode")
val USE_AMOLED_MODE = booleanPreferencesKey("use_amoled_mode")
val FOLLOW_SYS = booleanPreferencesKey("follow_sys")
Expand All @@ -43,20 +40,11 @@ private data object PreferencesKeys {
val APPLY_LOOP = booleanPreferencesKey("apply_loop")
val USE_CLASSIC_SLIDER = booleanPreferencesKey("use_classic_slider")
val SHOW_X_BUTTON = booleanPreferencesKey("show_x_button")
val SHOW_ALBUMS_TAB = booleanPreferencesKey("show_albums_tab")
val SHOW_ARTISTS_TAB = booleanPreferencesKey("show_artists_tab")
val SHOW_FOLDERS_TAB = booleanPreferencesKey("show_folders_tab")
}

@Composable
fun rememberSortASC() =
rememberPreference(key = SORT_ORDER, defaultValue = true)

@Composable
fun rememberSortASCArtists() =
rememberPreference(key = SORT_ORDER_ARTISTS, defaultValue = true)

@Composable
fun rememberSortASCAlbums() =
rememberPreference(key = SORT_ORDER_ALBUMS, defaultValue = true)

@Composable
fun rememberUseDarkMode() =
rememberPreference(key = USE_DARK_MODE, defaultValue = false)
Expand Down Expand Up @@ -103,6 +91,18 @@ fun rememberUseClassicSlider() =
fun rememberShowXButton() =
rememberPreference(key = SHOW_X_BUTTON, defaultValue = true)

@Composable
fun rememberShowAlbumsTab() =
rememberPreference(key = SHOW_ALBUMS_TAB, defaultValue = true)

@Composable
fun rememberShowArtistsTab() =
rememberPreference(key = SHOW_ARTISTS_TAB, defaultValue = true)

@Composable
fun rememberShowFoldersTab() =
rememberPreference(key = SHOW_FOLDERS_TAB, defaultValue = true)


suspend fun getBlacklistedFolder(context: Context): Set<String> {
val preferences = context.dataStore.data.first()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ fun <T> rememberPreferenceNonComposable(
val coroutineScope = CoroutineScope(Dispatchers.Default)

val state = context.dataStore.data
.map { it[key] ?: defaultValue }.stateIn(coroutineScope, SharingStarted.WhileSubscribed(5000), defaultValue)
.map { it[key] ?: defaultValue }
.stateIn(coroutineScope, SharingStarted.WhileSubscribed(5000), defaultValue)

return object : MutableState<T> {
override var value: T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface MediaStoreHelper {
val musics: List<MediaItem>
val albums: List<Album>
val artists: List<Artist>
val folders: List<Folder>

fun fetchMusics(): List<MediaItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ 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 selectionArgs = blacklistedFolders.map { "$it%" }.toTypedArray()

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

var blacklistedFolders = getBlacklistedFoldersAsync()
val musics = mutableListOf<MediaItem>()

val projection = arrayOf(
Expand All @@ -43,14 +48,9 @@ class MediaStoreHelperImpl(
MediaStore.Audio.Media.ALBUM_ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.SIZE,
MediaStore.Audio.Media.DURATION,
//MediaStore.Audio.Media.IS_FAVORITE,
MediaStore.Audio.Media.DURATION
)

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



context.contentResolver.query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
Expand Down Expand Up @@ -153,7 +153,9 @@ class MediaStoreHelperImpl(
val albumInfo = Album(id, album, artist)

if (albums.none { it.name == albumInfo.name }) {
albums.add(albumInfo)
if (musics.map { it.mediaMetadata.extras?.getLong("album_id") }.contains(id)) {
albums.add(albumInfo)
}
}
}
}
Expand Down Expand Up @@ -187,7 +189,9 @@ class MediaStoreHelperImpl(
id = id,
name = artist
)
artists.add(artistInfo)
if (musics.map { it.mediaMetadata.extras?.getLong("artist_id") }.contains(id)) {
artists.add(artistInfo)
}
}
}

Expand Down Expand Up @@ -275,4 +279,5 @@ class MediaStoreHelperImpl(
override val musics: List<MediaItem> = fetchMusics()
override val albums: List<Album> = fetchAlbums()
override val artists: List<Artist> = fetchArtists()
override val folders: List<Folder> = fetchFoldersWithMusics()
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class PlaybackService : MediaLibraryService(),
.build()
setMediaNotificationProvider(
DefaultMediaNotificationProvider.Builder(this).build().apply {
setSmallIcon(R.drawable.round_music_note_24)
setSmallIcon(R.drawable.music_note_rounded)
}
)

Expand Down
38 changes: 27 additions & 11 deletions app/src/main/java/com/sosauce/cutemusic/ui/navigation/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import androidx.navigation.compose.rememberNavController
import androidx.navigation.toRoute
import com.sosauce.cutemusic.data.actions.MetadataActions
import com.sosauce.cutemusic.data.actions.PlayerActions
import com.sosauce.cutemusic.data.datastore.rememberAllBlacklistedFolders
import com.sosauce.cutemusic.ui.screens.album.AlbumDetailsScreen
import com.sosauce.cutemusic.ui.screens.album.AlbumsScreen
import com.sosauce.cutemusic.ui.screens.all_folders.AllFoldersScreen
import com.sosauce.cutemusic.ui.screens.artist.ArtistDetails
import com.sosauce.cutemusic.ui.screens.artist.ArtistsScreen
import com.sosauce.cutemusic.ui.screens.blacklisted.BlacklistedScreen
Expand All @@ -39,25 +39,21 @@ fun Nav() {
val viewModel = koinViewModel<MusicViewModel>()
val postViewModel = koinViewModel<PostViewModel>()
val metadataViewModel = koinViewModel<MetadataViewModel>()
val blacklistedFolders by rememberAllBlacklistedFolders()
val musics = postViewModel.musics
val musicState by viewModel.musicState.collectAsStateWithLifecycle()
val folders = postViewModel.folders


SharedTransitionLayout {

this
NavHost(
navController = navController,
startDestination = Screen.Main
) {

this@SharedTransitionLayout
composable<Screen.Main> {
MainScreen(
musics = musics,
selectedIndex = viewModel.selectedItem,
onNavigateTo = { navController.navigate(it) },
onNavigate = { navController.navigate(it) },
currentlyPlaying = musicState.currentlyPlaying,
isCurrentlyPlaying = musicState.isCurrentlyPlaying,
onShortClick = { viewModel.handlePlayerActions(PlayerActions.StartPlayback(it)) },
Expand All @@ -68,15 +64,16 @@ fun Nav() {
}
},
animatedVisibilityScope = this,
onLoadMetadata = { uri ->
onLoadMetadata = { path, uri ->
metadataViewModel.onHandleMetadataActions(MetadataActions.ClearState)
metadataViewModel.onHandleMetadataActions(
MetadataActions.LoadSong(
path,
uri
)
)
},
isPlayerReady = viewModel.isPlayerReady(),
isPlayerReady = musicState.isPlayerReady,
currentMusicUri = musicState.currentMusicUri,
onHandlePlayerAction = { viewModel.handlePlayerActions(it) },
onDeleteMusic = { uris, intentSender ->
Expand Down Expand Up @@ -124,7 +121,7 @@ fun Nav() {
},
currentlyPlaying = musicState.currentlyPlaying,
chargePVMAlbumSongs = postViewModel::albumSongs,
isPlayerReady = viewModel.isPlayerReady(),
isPlayerReady = musicState.isPlayerReady,
isPlaying = musicState.isCurrentlyPlaying,
onHandlePlayerActions = viewModel::handlePlayerActions,
onNavigate = { navController.navigate(it) },
Expand Down Expand Up @@ -157,7 +154,7 @@ fun Nav() {
onHandlePlayerActions = viewModel::handlePlayerActions,
isPlaying = musicState.isCurrentlyPlaying,
animatedVisibilityScope = this,
isPlayerReady = viewModel.isPlayerReady(),
isPlayerReady = musicState.isPlayerReady,
onHandleSorting = { sortingType ->
postViewModel.handleFiltering(
listToHandle = ListToHandle.ARTISTS,
Expand Down Expand Up @@ -245,6 +242,25 @@ fun Nav() {
)
}
}

composable<Screen.AllFolders> {
AllFoldersScreen(
musics = musics,
onNavigationItemClicked = { index, item ->
navController.navigate(item.navigateTo) {
viewModel.selectedItem = index
launchSingleTop = true
}
},
selectedIndex = viewModel.selectedItem,
onNavigate = { navController.navigate(it) },
currentlyPlaying = musicState.currentlyPlaying,
isCurrentlyPlaying = musicState.isCurrentlyPlaying,
onHandlePlayerActions = viewModel::handlePlayerActions,
isPlayerReady = musicState.isPlayerReady,
animatedVisibilityScope = this,
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ sealed class Screen {
@Serializable
data object Artists : Screen()

@Serializable
data object AllFolders : Screen()

@Serializable
data class AlbumsDetails(
val id: Long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fun AlbumDetailsLandscape(
)
)
},
isPlayerReady = viewModel.isPlayerReady()
isPlayerReady = musicState.isPlayerReady
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private fun SharedTransitionScope.AlbumDetailsContent(
)
},
currentMusicUri = musicState.currentMusicUri,
isPlayerReady = viewModel.isPlayerReady()
isPlayerReady = musicState.isPlayerReady
)
}
}
Expand All @@ -193,7 +193,7 @@ private fun SharedTransitionScope.AlbumDetailsContent(

CuteSearchbar(
currentlyPlaying = musicState.currentlyPlaying,
isPlayerReady = viewModel.isPlayerReady(),
isPlayerReady = musicState.isPlayerReady,
isPlaying = musicState.isCurrentlyPlaying,
onHandlePlayerActions = viewModel::handlePlayerActions,
animatedVisibilityScope = animatedVisibilityScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Album
import androidx.compose.material.icons.rounded.ArrowUpward
import androidx.compose.material.icons.rounded.Settings
import androidx.compose.material3.DropdownMenu
Expand All @@ -43,6 +42,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -160,7 +160,7 @@ fun SharedTransitionScope.AlbumsScreen(
leadingIcon = {
IconButton(onClick = { screenSelectionExpanded = true }) {
Icon(
imageVector = Icons.Rounded.Album,
painter = painterResource(androidx.media3.session.R.drawable.media3_icon_album),
contentDescription = null
)
}
Expand Down
Loading

0 comments on commit 92c2a3b

Please sign in to comment.