Skip to content

Commit

Permalink
v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sosauce committed Sep 25, 2024
1 parent bf7cf7e commit 7f45ab2
Show file tree
Hide file tree
Showing 46 changed files with 1,513 additions and 1,028 deletions.
Binary file modified .DS_Store
Binary file not shown.
Empty file.
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 = 10
versionName = "2.0.0"
versionCode = 11
versionName = "2.1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
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": 9,
"versionName": "1.4.2",
"versionCode": 10,
"versionName": "2.0.0",
"outputFile": "app-release.apk"
}
],
Expand Down
Binary file modified app/src/main/java/com/sosauce/cutemusic/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ sealed interface PlayerActions {
data object PlayOrPause : PlayerActions
data object SeekToNextMusic : PlayerActions
data object SeekToPreviousMusic : PlayerActions
data object RestartSong : PlayerActions
data class SeekTo(val position: Long) : PlayerActions
data class SeekToSlider(val position: Long) : PlayerActions
data class RewindTo(val position: Long) : PlayerActions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import androidx.datastore.preferences.preferencesDataStore
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.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_DARK_MODE
import com.sosauce.cutemusic.data.datastore.PreferencesKeys.USE_SYSTEM_FONT
Expand All @@ -19,18 +22,30 @@ val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "se

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")
val USE_SYSTEM_FONT = booleanPreferencesKey("use_sys_font")
val BLACKLISTED_FOLDERS = stringSetPreferencesKey("blacklisted_folders")
val HAS_SEEN_TIP = booleanPreferencesKey("has_seen_tip")
val SNAP_SPEED_N_PITCH = booleanPreferencesKey("snap_peed_n_pitch")
val KILL_SERVICE = booleanPreferencesKey("kill_service")
}

@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 All @@ -55,3 +70,10 @@ fun rememberAllBlacklistedFolders() =
fun rememberHasSeenTip() =
rememberPreference(key = HAS_SEEN_TIP, defaultValue = false)

@Composable
fun rememberSnapSpeedAndPitch() =
rememberPreference(key = SNAP_SPEED_N_PITCH, defaultValue = false)

//fun rememberKillService(context: Context) =
// rememberNonComposablePreference(key = KILL_SERVICE, defaultValue = true, context = context)

Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
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.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 @@ -44,6 +48,38 @@ fun <T> rememberPreference(
}
}

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

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

return object : MutableState<T> {
override var value: T
get() = state.value
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 {
val config = LocalConfiguration.current
Expand Down
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 @@ -10,7 +10,7 @@ import com.sosauce.cutemusic.ui.shared_components.MusicViewModel
import com.sosauce.cutemusic.ui.shared_components.PostViewModel
import org.koin.android.ext.koin.androidApplication
import org.koin.android.ext.koin.androidContext
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.module.dsl.viewModel
import org.koin.dsl.module

val appModule = module {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.sosauce.cutemusic.domain.model

data class Lyrics(
val timestamp: Long = 0L,
val lineLyrics: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import android.content.ContentUris
import android.content.Context
import android.os.Bundle
import android.provider.MediaStore
import android.util.Log
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
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.queryAsFlow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow

class MediaStoreHelper(
private val context: Context
) {
fun getMusics(): List<MediaItem> {
fun getMusics():List<MediaItem> {

val musics = mutableListOf<MediaItem>()

Expand All @@ -33,7 +37,6 @@ class MediaStoreHelper(
projection,
null,
null,
null
)?.use { cursor ->
val idColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID)
val titleColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE)
Expand All @@ -58,8 +61,7 @@ class MediaStoreHelper(
)
val artUri = ContentUris.appendId(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.buildUpon(), id
)
.appendPath("albumart").build()
).appendPath("albumart").build()

musics.add(
MediaItem
Expand All @@ -86,6 +88,7 @@ class MediaStoreHelper(
)
}
}

return musics
}

Expand All @@ -104,7 +107,7 @@ class MediaStoreHelper(
projection,
null,
null,
"${MediaStore.Audio.Albums.ALBUM} ASC"
null
)?.use { cursor ->
val idColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID)
val albumColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM)
Expand Down Expand Up @@ -163,7 +166,7 @@ class MediaStoreHelper(
val folders = mutableListOf<Folder>()

val projection = arrayOf(
MediaStore.Audio.Media.DATA
MediaStore.Audio.Media.DATA,
)

context.contentResolver.query(
Expand All @@ -186,7 +189,7 @@ class MediaStoreHelper(
folders.add(
Folder(
name = folderName,
path = path
path = path,
)
)
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/sosauce/cutemusic/main/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ package com.sosauce.cutemusic.main
import android.app.Application
import com.sosauce.cutemusic.di.appModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.java.KoinAndroidApplication
import org.koin.core.Koin
import org.koin.core.KoinApplication
import org.koin.core.context.startKoin

class App : Application() {

override fun onCreate() {
super.onCreate()
startKoin {
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/sosauce/cutemusic/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
Expand Down Expand Up @@ -39,8 +38,7 @@ class MainActivity : ComponentActivity() {
Scaffold(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
) { innerPadding ->
) { _ ->
MaterialTheme {
Nav()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class PlaybackService : MediaLibraryService() {
.setUsage(C.USAGE_MEDIA)
.build()

//private val shouldKill = rememberKillService(this)

override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaLibrarySession? =
mediaLibrarySession

Expand All @@ -42,11 +44,13 @@ class PlaybackService : MediaLibraryService() {

override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent)
//if (shouldKill.value) {
mediaLibrarySession?.run {
player.release()
release()
mediaLibrarySession = null
stopSelf()
}
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class QuickPlayActivity : ComponentActivity() {
) {
FloatingActionButton(
onClick = {
if (!vm.isPlaylistEmpty()) vm.quickPlay(uri) else vm.handlePlayerActions(
if (!vm.isPlaylistEmptyAndDataNotNull()) vm.quickPlay(uri) else vm.handlePlayerActions(
PlayerActions.PlayOrPause
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
package com.sosauce.cutemusic.ui.navigation

import android.annotation.SuppressLint
import android.util.Log
import androidx.compose.animation.ExperimentalSharedTransitionApi
import androidx.compose.animation.SharedTransitionLayout
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
Expand All @@ -25,6 +28,7 @@ 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 kotlinx.coroutines.Dispatchers
import org.koin.androidx.compose.koinViewModel

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter", "SuspiciousIndentation")
Expand All @@ -36,8 +40,13 @@ fun Nav() {
val postViewModel = koinViewModel<PostViewModel>()
val metadataViewModel = koinViewModel<MetadataViewModel>()
val blacklistedFolders by rememberAllBlacklistedFolders()
val musics =
postViewModel.musics.filter { it.mediaMetadata.extras?.getString("folder") !in blacklistedFolders }
val musics = postViewModel.musics
.filter { it.mediaMetadata.extras?.getString("folder") !in blacklistedFolders }

LaunchedEffect(musics) {
Log.d("new musics", musics.toString())
}



SharedTransitionLayout {
Expand Down Expand Up @@ -113,7 +122,8 @@ fun Nav() {
artist = artist,
navController = navController,
viewModel = viewModel,
postViewModel = postViewModel
postViewModel = postViewModel,
onNavigate = { screen -> navController.navigate(screen) }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.ui.unit.sp
import coil3.compose.AsyncImage
import com.sosauce.cutemusic.R
import com.sosauce.cutemusic.domain.model.Album
import com.sosauce.cutemusic.ui.screens.main.MusicListItem
import com.sosauce.cutemusic.ui.shared_components.CuteText
import com.sosauce.cutemusic.ui.shared_components.MusicViewModel
import com.sosauce.cutemusic.ui.shared_components.PostViewModel
Expand Down Expand Up @@ -97,14 +98,14 @@ fun AlbumDetailsLandscape(
Spacer(modifier = Modifier.width(5.dp))
LazyColumn {
items(albumSongs, key = { it.mediaId }) { music ->
AlbumSong(
MusicListItem(
music = music,
onShortClick = { viewModel.itemClicked(music.mediaId, listOf()) },
currentMusicUri = viewModel.currentMusicUri,
onShortClick = { viewModel.itemClicked(it, listOf()) }
)
}
}
}
}
}

}
Loading

0 comments on commit 7f45ab2

Please sign in to comment.