Skip to content

Commit

Permalink
Merge pull request #32 from musicorum-app/dev
Browse files Browse the repository at this point in the history
Update to 1.22-release
  • Loading branch information
MysteryMS authored Nov 19, 2023
2 parents cc889fd + db642f1 commit c23d4df
Show file tree
Hide file tree
Showing 53 changed files with 463 additions and 337 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ android {
applicationId "io.musicorum.mobile"
minSdk 28
targetSdk 34
versionCode 66
versionName "1.21-release"
versionCode 67
versionName "1.22-release"
//compileSdkPreview = "UpsideDownCake"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.setup.PLAY_SETUP_SERVICE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />

<!--<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" /> -->
Expand All @@ -32,8 +35,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Musicorum"
android:testOnly="false"
android:theme="@style/Theme.Musicorum"
tools:targetApi="31">

<meta-data
Expand Down Expand Up @@ -99,8 +102,8 @@
android:exported="true"
android:hardwareAccelerated="true"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.Musicorum.SplashScreenTheme">
android:theme="@style/Theme.Musicorum.SplashScreenTheme"
android:windowSoftInputMode="adjustResize">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
57 changes: 27 additions & 30 deletions app/src/main/java/io/musicorum/mobile/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
Expand All @@ -29,7 +30,6 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -63,11 +63,12 @@ import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings
import dagger.hilt.android.AndroidEntryPoint
import io.musicorum.mobile.datastore.ScrobblePreferences
import io.musicorum.mobile.datastore.UserData
import io.musicorum.mobile.ktor.endpoints.UserEndpoint
import io.musicorum.mobile.models.FetchPeriod
import io.musicorum.mobile.repositories.LocalUserRepository
import io.musicorum.mobile.router.BottomNavBar
import io.musicorum.mobile.serialization.User
import io.musicorum.mobile.ui.theme.KindaBlack
import io.musicorum.mobile.ui.theme.MusicorumMobileTheme
import io.musicorum.mobile.utils.CrowdinUtils
Expand Down Expand Up @@ -100,11 +101,9 @@ import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map
import kotlinx.serialization.json.Json

val Context.userData: DataStore<Preferences> by preferencesDataStore(name = "userdata")
val Context.scrobblePrefs by preferencesDataStore(name = "scrobblePrefs")
val LocalUser = compositionLocalOf<User?> { null }
val Context.userData: DataStore<Preferences> by preferencesDataStore(UserData.DataStoreName)
val Context.scrobblePrefs by preferencesDataStore(ScrobblePreferences.DataStoreName)
val LocalNavigation = compositionLocalOf<NavHostController?> { null }
val MutableUserState = mutableStateOf<User?>(null)
val LocalAnalytics = compositionLocalOf<FirebaseAnalytics?> { null }

@AndroidEntryPoint
Expand All @@ -130,6 +129,7 @@ class MainActivity : ComponentActivity() {
super.attachBaseContext(Crowdin.wrapContext(newBase))
}

@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -199,7 +199,9 @@ class MainActivity : ComponentActivity() {
}
if (!BuildConfig.DEBUG) {
try {
SentryAndroid.init(this)
SentryAndroid.init(this) { opts ->
opts.isAnrEnabled
}
} catch (_: Exception) {
}
}
Expand All @@ -214,27 +216,25 @@ class MainActivity : ComponentActivity() {
val systemUiController = rememberSystemUiController()

if (intent?.data == null) {
if (MutableUserState.value == null) {
LaunchedEffect(Unit) {
val sessionKey = ctx.applicationContext.userData.data.map { prefs ->
prefs[stringPreferencesKey("session_key")]
}.firstOrNull()
if (sessionKey == null) {
navController.navigate("login") {
popUpTo("home") {
inclusive = true
}
LaunchedEffect(Unit) {
val sessionKey = ctx.applicationContext.userData.data.map { prefs ->
prefs[stringPreferencesKey("session_key")]
}.firstOrNull()
if (sessionKey == null) {
navController.navigate("login") {
popUpTo("home") {
inclusive = true
}
} else {
}
} else {
val localUser = LocalUserRepository(applicationContext)
if (localUser.getUser().username.isEmpty()) {
val userReq = UserEndpoint.getSessionUser(sessionKey)
val localUser = LocalUserRepository(applicationContext)
if (localUser.getUser().username.isEmpty()) {
localUser.create(userReq?.user)
}
MutableUserState.value = userReq
localUser.create(userReq?.user)
}
}
}

}

DisposableEffect(systemUiController, useDarkIcons) {
Expand All @@ -255,7 +255,6 @@ class MainActivity : ComponentActivity() {
}

CompositionLocalProvider(
LocalUser provides MutableUserState.value,
LocalSnackbar provides LocalSnackbarContext(snackHostState),
LocalNavigation provides navController,
LocalAnalytics provides firebaseAnalytics
Expand Down Expand Up @@ -350,18 +349,16 @@ class MainActivity : ComponentActivity() {
}

composable("mostListened") {
MostListened(mostListenedViewModel = mostListenedViewModel)
MostListened(viewModel = mostListenedViewModel)
}

composable(
"user/{username}",
arguments = listOf(navArgument("username") {
"user/{usernameArg}",
arguments = listOf(navArgument("usernameArg") {
type = NavType.StringType
})
) {
User(
username = it.arguments?.getString("username")!!
)
User()
}

composable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import io.musicorum.mobile.database.daos.CachedScrobblesDao
import io.musicorum.mobile.models.CachedScrobble
import io.musicorum.mobile.repositories.daos.CachedScrobblesDao
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.internal.synchronized

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import io.musicorum.mobile.database.daos.PendingScrobblesDao
import io.musicorum.mobile.models.PendingScrobble
import io.musicorum.mobile.repositories.daos.PendingScrobblesDao
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.internal.synchronized

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.musicorum.mobile.datastore

import androidx.datastore.preferences.core.booleanPreferencesKey

object AnalyticsConsent {
const val DataStoreName = "analyticsConsent"
val CONSENT_KEY = booleanPreferencesKey("consent")
}
11 changes: 11 additions & 0 deletions app/src/main/java/io/musicorum/mobile/datastore/LocalUser.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.musicorum.mobile.datastore

import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey

object LocalUser {
const val DataStoreName = "partialUser"
val USERNAME_KEY = stringPreferencesKey("usernameArg")
val PROFILE_ICON_KEY = stringPreferencesKey("profilePictureUrl")
val EXPIRES_IN_KEY = longPreferencesKey("expires_in")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.musicorum.mobile.datastore

import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.floatPreferencesKey
import androidx.datastore.preferences.core.stringSetPreferencesKey

object ScrobblePreferences {
const val DataStoreName = "scrobblePrefs"
val SCROBBLE_POINT_KEY = floatPreferencesKey("scrobblePoint")
val ENABLED_KEY = booleanPreferencesKey("enabled")
val ALLOWED_APPS_KEY = stringSetPreferencesKey("enabledApps")
val UPDATED_NOWPLAYING_KEY = booleanPreferencesKey("updateNowPlaying")
}
8 changes: 8 additions & 0 deletions app/src/main/java/io/musicorum/mobile/datastore/UserData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.musicorum.mobile.datastore

import androidx.datastore.preferences.core.stringPreferencesKey

object UserData {
const val DataStoreName = "userdata"
val SESSION_KEY = stringPreferencesKey("session_key")
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object ArtistEndpoint {
parameter("method", "artist.getInfo")
parameter("name", artist)
parameter("artist", artist)
parameter("username", username)
parameter("usernameArg", username)
}
return if (res.status.isSuccess()) {
return res.body<InnerArtist>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object TrackEndpoint {
val autoCorrectValue = if (autoCorrect == true) 1 else 0
parameter("track", trackName)
parameter("method", "track.getInfo")
parameter("username", username)
parameter("usernameArg", username)
parameter("artist", artist)
parameter("autocorrect", autoCorrectValue)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object UserEndpoint {
val result = kotlin.runCatching {
val res = KtorConfiguration.lastFmClient.get {
parameter("method", "user.getFriends")
parameter("username", user)
parameter("user", user)
parameter("limit", limit)
headers.remove("Cache-Control")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object Generator {

/**
* Generates a grid collage
* @param username The last.fm username
* @param username The last.fm usernameArg
* @param rowCount Row count
* @param colCount Column count
* @param entity Entity, either artist, album or track
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.musicorum.mobile.repositories

import io.musicorum.mobile.database.daos.CachedScrobblesDao
import io.musicorum.mobile.models.CachedScrobble
import io.musicorum.mobile.repositories.daos.CachedScrobblesDao

class CachedScrobblesRepository(private val cachedScrobblesDao: CachedScrobblesDao) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.musicorum.mobile.repositories

import io.musicorum.mobile.models.PendingScrobble
import kotlinx.coroutines.flow.Flow

interface IPendingScrobbles {
suspend fun getAllScrobblesStream(): Flow<List<PendingScrobble>>

suspend fun deleteScrobble(scrobble: PendingScrobble)

suspend fun insertScrobble(scrobble: PendingScrobble)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import android.util.Log
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import io.musicorum.mobile.datastore.LocalUser
import io.musicorum.mobile.ktor.endpoints.UserEndpoint
import io.musicorum.mobile.models.PartialUser
import io.musicorum.mobile.serialization.User
Expand All @@ -22,9 +21,9 @@ val Context.localUser: DataStore<Preferences> by preferencesDataStore("partialUs
class LocalUserRepository(val context: Context) {
private val userFlow = context.localUser.data.map {
PartialUser(
it[usernameKey] ?: "",
it[pfpKey] ?: "",
it[expiresKey] ?: 0L
it[LocalUser.USERNAME_KEY] ?: "",
it[LocalUser.PROFILE_ICON_KEY] ?: "",
it[LocalUser.EXPIRES_IN_KEY] ?: 0L
)
}

Expand Down Expand Up @@ -71,14 +70,11 @@ class LocalUserRepository(val context: Context) {

suspend fun updateUser(partialUser: PartialUser) {
context.localUser.edit {
it[usernameKey] = partialUser.username
it[pfpKey] = partialUser.imageUrl
it[expiresKey] = partialUser.expiresIn
it[LocalUser.USERNAME_KEY] = partialUser.username
it[LocalUser.PROFILE_ICON_KEY] = partialUser.imageUrl
it[LocalUser.EXPIRES_IN_KEY] = partialUser.expiresIn
}
}

private val usernameKey = stringPreferencesKey("username")
private val pfpKey = stringPreferencesKey("profilePictureUrl")
private val expiresKey = longPreferencesKey("expires_in")
private val cacheTime = Date(Date().time + (1000 * 60 * 60 * 48)).time
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package io.musicorum.mobile.repositories

import io.musicorum.mobile.models.PendingScrobble
import io.musicorum.mobile.repositories.daos.PendingScrobblesDao
import kotlinx.coroutines.flow.Flow

interface PendingScrobblesRepository {
suspend fun getAllScrobblesStream(): Flow<List<PendingScrobble>>
class PendingScrobblesRepository(private val scrobblesDao: PendingScrobblesDao) :
IPendingScrobbles {
override suspend fun getAllScrobblesStream(): Flow<List<PendingScrobble>> =
scrobblesDao.getAll()

suspend fun deleteScrobble(scrobble: PendingScrobble)
override suspend fun deleteScrobble(scrobble: PendingScrobble) = scrobblesDao.delete(scrobble)

suspend fun insertScrobble(scrobble: PendingScrobble)
override suspend fun insertScrobble(scrobble: PendingScrobble) = scrobblesDao.insert(scrobble)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.musicorum.mobile.database.daos
package io.musicorum.mobile.repositories.daos

import androidx.room.Dao
import androidx.room.Delete
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.musicorum.mobile.database.daos
package io.musicorum.mobile.repositories.daos

import androidx.room.Dao
import androidx.room.Delete
Expand Down
Loading

0 comments on commit c23d4df

Please sign in to comment.