Skip to content

Commit

Permalink
v2.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
sosauce committed Dec 21, 2024
1 parent 4ec0f4e commit 9c5a694
Show file tree
Hide file tree
Showing 40 changed files with 1,038 additions and 482 deletions.
Binary file modified app/.DS_Store
Binary file not shown.
20 changes: 10 additions & 10 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId = "com.sosauce.cutemusic"
minSdk = 26
targetSdk = 35
versionCode = 20
versionName = "2.3.3"
versionCode = 21
versionName = "2.3.4"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
Expand Down Expand Up @@ -54,14 +54,14 @@ android {
}


// splits {
// abi {
// isEnable = true
// reset()
// include("armeabi-v7a", "arm64-v8a")
// isUniversalApk = false
// }
// }
splits {
abi {
isEnable = true
reset()
include("armeabi-v7a", "arm64-v8a")
isUniversalApk = true
}
}
}

dependencies {
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": 19,
"versionName": "2.3.2",
"versionCode": 20,
"versionName": "2.3.3",
"outputFile": "app-release.apk"
}
],
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<application
android:name=".main.App"
android:appCategory="audio"
android:enableOnBackInvokedCallback="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand All @@ -40,6 +41,16 @@
</intent-filter>
</service>

<service
android:name=".main.AutoPlaybackService"
android:exported="true"
android:enabled="true"
tools:ignore="ExportedService">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService"/>
</intent-filter>
</service>

<activity
android:name=".main.MainActivity"
android:launchMode="singleTask"
Expand Down Expand Up @@ -96,9 +107,11 @@

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

</application>





</manifest>
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.sosauce.cutemusic.data.datastore

import android.content.Context
import android.util.Log
import androidx.compose.runtime.Composable
import androidx.datastore.core.DataStore
import androidx.datastore.core.IOException
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.stringSetPreferencesKey
Expand All @@ -11,6 +13,7 @@ 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.SAF_TRACKS
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
Expand All @@ -21,7 +24,10 @@ 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
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map

private const val PREFERENCES_NAME = "settings"

Expand All @@ -43,6 +49,7 @@ private data object PreferencesKeys {
val SHOW_ALBUMS_TAB = booleanPreferencesKey("show_albums_tab")
val SHOW_ARTISTS_TAB = booleanPreferencesKey("show_artists_tab")
val SHOW_FOLDERS_TAB = booleanPreferencesKey("show_folders_tab")
val SAF_TRACKS = stringSetPreferencesKey("saf_tracks")
}

@Composable
Expand Down Expand Up @@ -103,9 +110,25 @@ fun rememberShowArtistsTab() =
fun rememberShowFoldersTab() =
rememberPreference(key = SHOW_FOLDERS_TAB, defaultValue = true)

@Composable
fun rememberAllSafTracks() =
rememberPreference(key = SAF_TRACKS, defaultValue = emptySet())


suspend fun getBlacklistedFolder(context: Context): Set<String> {
val preferences = context.dataStore.data.first()
return preferences[BLACKLISTED_FOLDERS] ?: emptySet()
}

fun getSafTracks(context: Context): Flow<Set<String>> =

context.dataStore.data
.catch { exception ->
if (exception is IOException) {
Log.d("CuteError", "getSafTracks: ${exception.message}")
} else throw exception
}
.map { preference ->
preference[SAF_TRACKS] ?: emptySet()
}

10 changes: 8 additions & 2 deletions app/src/main/java/com/sosauce/cutemusic/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.sosauce.cutemusic.di

import com.sosauce.cutemusic.domain.repository.MediaStoreHelper
import com.sosauce.cutemusic.domain.repository.MediaStoreHelperImpl
import com.sosauce.cutemusic.domain.repository.SafManager
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 @@ -14,11 +15,16 @@ val appModule = module {
single<MediaStoreHelper> {
MediaStoreHelperImpl(androidContext())
}

single {
SafManager(androidContext())
}

viewModel {
PostViewModel(get())
PostViewModel(get(), get())
}
viewModel {
MusicViewModel(androidApplication(), get())
MusicViewModel(androidApplication(), get(), get())
}
viewModel {
MetadataViewModel(androidApplication())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +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
import kotlinx.coroutines.flow.StateFlow

interface MediaStoreHelper {

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

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

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

fun fetchArtists(): List<Artist>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,55 @@ 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.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.runBlocking

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


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()


override fun fetchLatestMusics(): Flow<List<MediaItem>> =
override fun fetchLatestMusics(): StateFlow<List<MediaItem>> =
context.contentResolver.observe(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI)
.map { fetchMusics() }
.map {
fetchMusics()
}
.stateIn(
CoroutineScope(Dispatchers.IO),
SharingStarted.WhileSubscribed(5000),
listOf()
)

override fun fetchLatestAlbums(): Flow<List<Album>> =
override fun fetchLatestAlbums(): StateFlow<List<Album>> =
context.contentResolver.observe(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI)
.map { fetchAlbums() }
.stateIn(
CoroutineScope(Dispatchers.IO),
SharingStarted.WhileSubscribed(5000),
listOf()
)

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


val musics = mutableListOf<MediaItem>()

val projection = arrayOf(
Expand All @@ -62,7 +81,8 @@ class MediaStoreHelperImpl(
MediaStore.Audio.Media.ALBUM_ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.SIZE,
MediaStore.Audio.Media.DURATION
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.TRACK,
)


Expand All @@ -82,6 +102,7 @@ class MediaStoreHelperImpl(
val folderColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)
val sizeColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE)
val durationColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION)
val trackNbColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TRACK)
//val isFavColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.IS_FAVORITE)

while (cursor.moveToNext()) {
Expand All @@ -95,6 +116,7 @@ class MediaStoreHelperImpl(
val folder = filePath.substring(0, filePath.lastIndexOf('/'))
val size = cursor.getLong(sizeColumn)
val duration = cursor.getLong(durationColumn)
val trackNumber = cursor.getInt(trackNbColumn)
//val isFavorite = cursor.getInt(isFavColumn) // 1 = is favorite, 0 = no
val uri = ContentUris.withAppendedId(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
Expand All @@ -119,6 +141,7 @@ class MediaStoreHelperImpl(
.setAlbumTitle(album)
.setArtworkUri(artUri)
.setDurationMs(duration)
.setTrackNumber(trackNumber)
.setExtras(
Bundle()
.apply {
Expand All @@ -128,6 +151,7 @@ class MediaStoreHelperImpl(
putString("uri", uri.toString())
putLong("album_id", albumId)
putLong("artist_id", artistId)
putBoolean("is_saf", false)
// putInt("isFavorite", isFavorite)
}).build()
)
Expand Down
Loading

0 comments on commit 9c5a694

Please sign in to comment.