Skip to content

Commit

Permalink
v2.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
sosauce committed Oct 18, 2024
1 parent af5bca8 commit ba58845
Show file tree
Hide file tree
Showing 54 changed files with 1,853 additions and 1,350 deletions.
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 = 13
versionName = "2.2.2"
versionCode = 14
versionName = "2.2.3"
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": 12,
"versionName": "2.2.1",
"versionCode": 13,
"versionName": "2.2.2",
"outputFile": "app-release.apk"
}
],
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<data android:mimeType="audio/*" />
</intent-filter>
</activity>

<meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
</application>

</manifest>
24 changes: 24 additions & 0 deletions app/src/main/java/com/sosauce/cutemusic/data/MusicState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.sosauce.cutemusic.data

import android.net.Uri
import com.sosauce.cutemusic.domain.model.Lyrics
import java.io.File

data class MusicState(
var currentlyPlaying: String = "",
var currentArtist: String = "",
val currentArtistId: Long = 0,
var currentArt: Uri? = null,
var isCurrentlyPlaying: Boolean = false,
var currentPosition: Long = 0L,
var currentMusicDuration: Long = 0L,
var currentMusicUri: String = "",
var currentLyrics: List<Lyrics> = listOf(),
var isLooping: Boolean = false,
var isShuffling: Boolean = false,
var currentPath: String = "",
val currentAlbum: String = "",
val currentAlbumId: Long = 0,
val currentSize: Long = 0,
val currentLrcFile: File? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,25 @@ sealed interface PlayerActions {
data object SeekToNextMusic : PlayerActions
data object SeekToPreviousMusic : PlayerActions
data object RestartSong : PlayerActions
data object PlayRandom : PlayerActions
data object ApplyLoop : PlayerActions
data object ApplyShuffle : PlayerActions
data class SeekTo(val position: Long) : PlayerActions
data class SeekToSlider(val position: Long) : PlayerActions
data class RewindTo(val position: Long) : PlayerActions
data class StartPlayback(val mediaId: String) : PlayerActions
data class StartAlbumPlayback(
val albumName: String,
val mediaId: String?
) : PlayerActions

data class StartArtistPlayback(
val artistName: String,
val mediaId: String?
) : PlayerActions

data class ApplyPlaybackSpeed(
val speed: Float,
val pitch: Float
) : PlayerActions
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.stringSetPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
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.KILL_SERVICE
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
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.USE_DARK_MODE
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.USE_SYSTEM_FONT

Expand All @@ -37,6 +38,8 @@ private data object PreferencesKeys {
val SNAP_SPEED_N_PITCH = booleanPreferencesKey("snap_peed_n_pitch")
val KILL_SERVICE = booleanPreferencesKey("kill_service")
val USE_ART_THEME = booleanPreferencesKey("use_art_theme")
val APPLY_LOOP = booleanPreferencesKey("apply_loop")
val USE_CLASSIC_SLIDER = booleanPreferencesKey("use_classic_slider")
}

@Composable
Expand Down Expand Up @@ -83,6 +86,12 @@ fun rememberSnapSpeedAndPitch() =
fun rememberUseArtTheme() =
rememberPreference(key = USE_ART_THEME, defaultValue = false)

fun rememberKillService(context: Context) =
rememberNonComposablePreference(key = KILL_SERVICE, defaultValue = true, context = context)
//fun rememberKillService(context: Context) =
// rememberNonComposablePreference(key = KILL_SERVICE, defaultValue = true, context = context)
@Composable
fun rememberShouldApplyLoop() =
rememberPreference(key = APPLY_LOOP, defaultValue = false)

@Composable
fun rememberUseClassicSlider() =
rememberPreference(key = USE_CLASSIC_SLIDER, defaultValue = false)
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
package com.sosauce.cutemusic.data.datastore

import android.content.Context
import android.content.res.Configuration
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -49,37 +44,6 @@ fun <T> rememberPreference(
}
}

fun <T> rememberNonComposablePreference(
key: Preferences.Key<T>,
defaultValue: T,
context: Context
): MutableState<T> {
val coroutineScope = CoroutineScope(Dispatchers.Main)
var state by mutableStateOf(defaultValue)

coroutineScope.launch {
context.dataStore.data
.map { preferences -> preferences[key] ?: defaultValue }
.collect { newValue ->
state = newValue
}
}

return object : MutableState<T> {
override var value: T
get() = state
set(value) {
coroutineScope.launch {
context.dataStore.edit {
it[key] = value
}
}
}

override fun component1() = value
override fun component2(): (T) -> Unit = { value = it }
}
}

@Composable
fun rememberIsLandscape(): Boolean {
Expand Down
15 changes: 1 addition & 14 deletions app/src/main/java/com/sosauce/cutemusic/di/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.sosauce.cutemusic.di

import android.content.ComponentName
import androidx.media3.session.MediaController
import androidx.media3.session.SessionToken
import com.sosauce.cutemusic.domain.repository.MediaStoreHelper
import com.sosauce.cutemusic.domain.repository.MediaStoreHelperImpl
import com.sosauce.cutemusic.main.PlaybackService
import com.sosauce.cutemusic.ui.screens.metadata.MetadataViewModel
import com.sosauce.cutemusic.ui.shared_components.MusicViewModel
import com.sosauce.cutemusic.ui.shared_components.PostViewModel
Expand All @@ -18,20 +14,11 @@ val appModule = module {
single<MediaStoreHelper> {
MediaStoreHelperImpl(androidContext())
}
single {
MediaController.Builder(
androidContext(),
SessionToken(
androidContext(),
ComponentName(androidContext(), PlaybackService::class.java)
)
).buildAsync()
}
viewModel {
PostViewModel(get(), androidApplication())
}
viewModel {
MusicViewModel(get(), androidApplication())
MusicViewModel(androidApplication(), get())
}
viewModel {
MetadataViewModel(androidApplication())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ import com.sosauce.cutemusic.domain.model.Folder

interface MediaStoreHelper {

fun getMusics() : List<MediaItem>
val musics: List<MediaItem>
val albums: List<Album>
val artists: List<Artist>

fun getAlbums(): List<Album>
fun fetchMusics(): List<MediaItem>

fun getArtists(): List<Artist>
fun fetchAlbums(): List<Album>

fun getFoldersWithMusics(): List<Folder>
fun fetchArtists(): List<Artist>

fun fetchFoldersWithMusics(): List<Folder>

suspend fun deleteMusics(
uris: List<Uri>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ import com.sosauce.cutemusic.domain.model.Folder

class MediaStoreHelperImpl(
private val context: Context
): MediaStoreHelper {
) : MediaStoreHelper {

override fun getMusics(): List<MediaItem> {
override fun fetchMusics(): List<MediaItem> {
val musics = mutableListOf<MediaItem>()

val projection = arrayOf(
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ARTIST_ID,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.ALBUM_ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.SIZE,
//MediaStore.Audio.Media.IS_FAVORITE,
Expand All @@ -45,7 +47,9 @@ class MediaStoreHelperImpl(
val idColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID)
val titleColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE)
val artistColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST)
val artistIdColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST_ID)
val albumColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM)
val albumIdColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID)
val folderColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)
val sizeColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE)
//val isFavColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.IS_FAVORITE)
Expand All @@ -54,7 +58,9 @@ class MediaStoreHelperImpl(
val id = cursor.getLong(idColumn)
val title = cursor.getString(titleColumn)
val artist = cursor.getString(artistColumn)
val artistId = cursor.getLong(artistIdColumn)
val album = cursor.getString(albumColumn)
val albumId = cursor.getLong(albumIdColumn)
val filePath = cursor.getString(folderColumn)
val folder = filePath.substring(0, filePath.lastIndexOf('/'))
val size = cursor.getLong(sizeColumn)
Expand All @@ -63,36 +69,37 @@ class MediaStoreHelperImpl(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
id
)
val artUri = ContentUris.appendId(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.buildUpon(), id
).appendPath("albumart").build()

val artUri = Uri.parse("$uri/albumart")


musics.add(
MediaItem
.Builder()
.setUri(uri)
.setMediaId(id.toString())
.setMediaMetadata(
MediaMetadata
.Builder()
.setIsBrowsable(false)
.setIsPlayable(true)
.setTitle(title)
.setArtist(artist)
.setAlbumTitle(album)
.setArtworkUri(artUri)
.setExtras(
Bundle()
.apply {
putString("folder", folder)
putLong("size", size)
putString("path", filePath)
putString("uri", uri.toString())
// putInt("isFavorite", isFavorite)
}).build()
)
.build()
MediaItem
.Builder()
.setUri(uri)
.setMediaId(id.toString())
.setMediaMetadata(
MediaMetadata
.Builder()
.setIsBrowsable(false)
.setIsPlayable(true)
.setTitle(title)
.setArtist(artist)
.setAlbumTitle(album)
.setArtworkUri(artUri)
.setExtras(
Bundle()
.apply {
putString("folder", folder)
putLong("size", size)
putString("path", filePath)
putString("uri", uri.toString())
putLong("album_id", albumId)
putLong("artist_id", artistId)
// putInt("isFavorite", isFavorite)
}).build()
)
.build()
)
}
}
Expand All @@ -101,7 +108,7 @@ class MediaStoreHelperImpl(
}


override fun getAlbums(): List<Album> {
override fun fetchAlbums(): List<Album> {
val albums = mutableListOf<Album>()

val projection = arrayOf(
Expand Down Expand Up @@ -136,7 +143,7 @@ class MediaStoreHelperImpl(
return albums
}

override fun getArtists(): List<Artist> {
override fun fetchArtists(): List<Artist> {
val artists = mutableListOf<Artist>()

val projection = arrayOf(
Expand Down Expand Up @@ -171,7 +178,7 @@ class MediaStoreHelperImpl(


// Only gets folder with musics in them
override fun getFoldersWithMusics(): List<Folder> {
override fun fetchFoldersWithMusics(): List<Folder> {

val folders = mutableListOf<Folder>()

Expand Down Expand Up @@ -245,4 +252,9 @@ class MediaStoreHelperImpl(
intentSenderLauncher.launch(IntentSenderRequest.Builder(intentSender).build())
}
}

// Caching music to not re-query them in Music and Post ViewModels
override val musics: List<MediaItem> = fetchMusics()
override val albums: List<Album> = fetchAlbums()
override val artists: List<Artist> = fetchArtists()
}
12 changes: 0 additions & 12 deletions app/src/main/java/com/sosauce/cutemusic/main/AppContainer.kt

This file was deleted.

Loading

0 comments on commit ba58845

Please sign in to comment.