Skip to content

Commit

Permalink
Merge pull request #22 from musicorum-app/dev
Browse files Browse the repository at this point in the history
hotfix for plural resources
  • Loading branch information
MysteryMS authored Sep 16, 2023
2 parents 2ad8a79 + 5300de1 commit 7875afd
Show file tree
Hide file tree
Showing 24 changed files with 320 additions and 104 deletions.
16 changes: 7 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ plugins {
id 'dagger.hilt.android.plugin'
id 'com.github.triplet.play' version '3.7.0'
id 'com.google.devtools.ksp'
id "io.sentry.android.gradle" version "3.12.0"
}

def appKeyStoreFile = "../upload_key.jks"
//def appKeyStorePassword = System.env.KEY_STORE_PASSWORD
//def appKeyAlias = System.env.KEY_ALIAS
//def appKeyPassword = System.env.KEY_PASSWORD
def appKeyStorePassword = System.env.KEY_STORE_PASSWORD
def appKeyAlias = System.env.KEY_ALIAS
def appKeyPassword = System.env.KEY_PASSWORD

/*sentry {
sentry {
includeProguardMapping = true
autoUploadProguardMapping = true
experimentalGuardsquareSupport = true
}*/
}

android {
namespace 'io.musicorum.mobile'
Expand All @@ -51,8 +49,8 @@ android {
applicationId "io.musicorum.mobile"
minSdk 28
targetSdk 34
versionCode 60
versionName "1.18.0-pre-release"
versionCode 61
versionName "1.18.1-pre-release"
//compileSdkPreview = "UpsideDownCake"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -127,8 +125,8 @@ dependencies {
implementation 'com.google.android.play:app-update-ktx:2.1.0'
implementation 'org.jsoup:jsoup:1.15.3'

//implementation 'io.sentry:sentry-android:6.14.0'
//implementation 'io.sentry:sentry-compose-android:6.14.0'
implementation 'io.sentry:sentry-android:6.27.0'
implementation 'io.sentry:sentry-compose-android:6.27.0'

def room_version = "2.5.2"
implementation "androidx.room:room-runtime:$room_version"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@
android:value="androidx.startup" />
</provider>
</application>
</manifest>
</manifest>
8 changes: 4 additions & 4 deletions app/src/main/java/io/musicorum/mobile/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import com.google.android.gms.common.GoogleApiAvailability
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
import com.google.android.play.core.install.model.AppUpdateType.IMMEDIATE
import com.google.android.play.core.install.model.UpdateAvailability
import com.google.android.play.core.ktx.startUpdateFlowForResult
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.ktx.Firebase
Expand Down Expand Up @@ -92,6 +91,8 @@ import io.musicorum.mobile.views.login.loginGraph
import io.musicorum.mobile.views.mostListened.MostListened
import io.musicorum.mobile.views.settings.ScrobbleSettings
import io.musicorum.mobile.views.settings.Settings
import io.sentry.android.core.SentryAndroid
import io.sentry.compose.withSentryObservableEffect
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map
import kotlinx.serialization.decodeFromString
Expand Down Expand Up @@ -196,14 +197,14 @@ class MainActivity : ComponentActivity() {
}
if (!BuildConfig.DEBUG) {
try {
//SentryAndroid.init(this)
SentryAndroid.init(this)
} catch (_: Exception) {
}
}

setContent {
val useDarkIcons = !isSystemInDarkTheme()
navController = rememberNavController()//.withSentryObservableEffect()
navController = rememberNavController().withSentryObservableEffect()

val mostListenedViewModel: MostListenedViewModel = viewModel()
val ctx = LocalContext.current
Expand All @@ -229,7 +230,6 @@ class MainActivity : ComponentActivity() {
localUser.create(userReq?.user)
}
MutableUserState.value = userReq

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.musicorum.mobile.models.CachedScrobble
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.internal.synchronized

@Database(entities = [CachedScrobble::class], version = 2, exportSchema = false)
@Database(entities = [CachedScrobble::class], version = 3, exportSchema = false)
abstract class CachedScrobblesDb : RoomDatabase() {
abstract fun cachedScrobblesDao(): CachedScrobblesDao

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ interface CachedScrobblesDao {
@Delete
suspend fun delete(data: CachedScrobble)

@Query("SELECT * FROM cachedScrobbles")
@Query("SELECT * FROM cachedScrobbles WHERE isTopTrack is 0")
fun getAll(): Flow<List<CachedScrobble>>

@Query("SELECT * FROM cachedScrobbles WHERE isTopTrack is 1")
fun getAllTops(): Flow<List<CachedScrobble>>

@Query("DELETE FROM cachedScrobbles")
suspend fun clearAll()
}
12 changes: 8 additions & 4 deletions app/src/main/java/io/musicorum/mobile/ktor/KtorConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package io.musicorum.mobile.ktor

import android.util.Log
import io.ktor.client.HttpClient
import io.ktor.client.plugins.ClientRequestException
import io.ktor.client.plugins.HttpResponseValidator
import io.ktor.client.plugins.HttpSend
import io.ktor.client.plugins.ServerResponseException
import io.ktor.client.plugins.cache.HttpCache
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.defaultRequest
Expand All @@ -14,13 +16,15 @@ import io.ktor.client.plugins.plugin
import io.ktor.client.request.header
import io.ktor.client.request.headers
import io.ktor.client.request.parameter
import io.ktor.client.statement.bodyAsText
import io.ktor.http.URLProtocol
import io.ktor.http.isSuccess
import io.ktor.http.path
import io.ktor.serialization.kotlinx.json.json
import io.musicorum.mobile.BuildConfig
import io.musicorum.mobile.utils.CustomCacheControl
import io.musicorum.mobile.utils.md5Hash
import io.sentry.Sentry
import kotlinx.serialization.json.Json

object KtorConfiguration {
Expand All @@ -41,9 +45,9 @@ object KtorConfiguration {
validateResponse { res ->
if (!res.status.isSuccess()) {
if (res.status.value >= 500) {
//Sentry.captureException(ServerResponseException(res, res.bodyAsText()))
Sentry.captureException(ServerResponseException(res, res.bodyAsText()))
} else {
//Sentry.captureException(ClientRequestException(res, res.bodyAsText()))
Sentry.captureException(ClientRequestException(res, res.bodyAsText()))
}
}
}
Expand Down Expand Up @@ -98,9 +102,9 @@ object KtorConfiguration {
validateResponse { res ->
if (!res.status.isSuccess()) {
if (res.status.value >= 500) {
//Sentry.captureException(ServerResponseException(res, res.bodyAsText()))
Sentry.captureException(ServerResponseException(res, res.bodyAsText()))
} else {
//Sentry.captureException(ClientRequestException(res, res.bodyAsText()))
Sentry.captureException(ClientRequestException(res, res.bodyAsText()))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,17 @@ object UserEndpoint {
}

suspend fun getTopTracks(user: String, period: FetchPeriod?, limit: Int?): TopTracks? {
return kotlin.runCatching {
val res = KtorConfiguration.lastFmClient.get {
parameter("method", "user.getTopTracks")
parameter("user", user)
parameter("period", period?.value)
parameter("limit", limit)
}
return@runCatching if (res.status.isSuccess()) {
return if (res.status.isSuccess()) {
res.body<TopTracks>()
} else {
null
}
}.getOrNull()
}

suspend fun getTopAlbums(user: String, period: FetchPeriod?, limit: Int?): TopAlbumsResponse? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ data class CachedScrobble(
val trackName: String,
val artistName: String,
val scrobbleDate: Long,
val imageUrl: String
val imageUrl: String,
val isTopTrack: Boolean
) {
fun toTrack(): Track {
return Track(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import io.musicorum.mobile.models.CachedScrobble

class CachedScrobblesRepository(private val cachedScrobblesDao: CachedScrobblesDao) {

fun getAll() = cachedScrobblesDao.getAll()
/**
* Get all scrobbles from cache
*/
fun getAllFromCache() = cachedScrobblesDao.getAll()

suspend fun delete(data: CachedScrobble) = cachedScrobblesDao.delete(data)

suspend fun insert(data: CachedScrobble) = cachedScrobblesDao.insert(data)

suspend fun deleteAll() = cachedScrobblesDao.clearAll()

fun getAllTopsFromCache() = cachedScrobblesDao.getAllTops()
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import io.musicorum.mobile.serialization.User
import io.musicorum.mobile.serialization.UserData
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import java.net.UnknownHostException
import java.util.Date

val Context.localUser: DataStore<Preferences> by preferencesDataStore("partialUser")

class LocalUserRepository(val context: Context) {
val prefUser = context.localUser.data.map {
private val userFlow = context.localUser.data.map {
PartialUser(
it[usernameKey] ?: "",
it[pfpKey] ?: "",
Expand All @@ -28,17 +29,21 @@ class LocalUserRepository(val context: Context) {
}

suspend fun getUser(): PartialUser {
val user = prefUser.first()
val user = userFlow.first()
return if (Date().time > user.expiresIn) {
Log.d("user repository", "fetching online")
val fetchedUser = fetch()
val updatedUser = PartialUser(
fetchedUser?.user?.name ?: "",
fetchedUser?.user?.bestImageUrl ?: "",
cacheTime
)
updateUser(updatedUser)
updatedUser
if (fetchedUser != null) {
val updatedUser = PartialUser(
fetchedUser.user.name,
fetchedUser.user.bestImageUrl,
cacheTime
)
updateUser(updatedUser)
return updatedUser
} else {
return user
}
} else {
Log.d("user repository", "skipping fetch")
user
Expand All @@ -55,9 +60,13 @@ class LocalUserRepository(val context: Context) {
}

suspend fun fetch(): User? {
val user = prefUser.first()
val user = userFlow.first()
if (user.username.isEmpty()) return null
return UserEndpoint.getUser(user.username)
return try {
UserEndpoint.getUser(user.username)
} catch(e: UnknownHostException) {
null
}
}

suspend fun updateUser(partialUser: PartialUser) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class NotificationListener : NotificationListenerService() {

if (artist == null || track == null) {
val bundle = Bundle()
bundle.putString("reason", "track os artist is null")
bundle.putString("reason", "track or artist is null")
bundle.putString("artist", artist)
bundle.putString("track", track)
analytics.logEvent("device_scrobble_failed", bundle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import androidx.lifecycle.viewModelScope
import io.musicorum.mobile.ktor.endpoints.musicorum.Generator
import io.musicorum.mobile.models.PartialUser
import io.musicorum.mobile.repositories.LocalUserRepository
import io.sentry.Sentry
import io.sentry.SpanStatus
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -36,9 +38,9 @@ class ChartCollageViewModel(application: Application) : AndroidViewModel(applica
period: String,
showNames: Boolean
) {
//val transaction = Sentry.startTransaction("generate", "task")
//transaction.setTag("entity", entity)
//transaction.setTag("collageType", "grid")
val transaction = Sentry.startTransaction("generate", "task")
transaction.setTag("entity", entity)
transaction.setTag("collageType", "grid")
ready.value = false
isGenerating.value = true
viewModelScope.launch {
Expand All @@ -48,11 +50,11 @@ class ChartCollageViewModel(application: Application) : AndroidViewModel(applica
ready.value = true
isGenerating.value = false
if (url == null) {
//transaction.status = SpanStatus.INTERNAL_ERROR
transaction.status = SpanStatus.INTERNAL_ERROR
} else {
//transaction.status = SpanStatus.OK
transaction.status = SpanStatus.OK
}
//transaction.finish()
transaction.finish()
}
}

Expand Down
Loading

0 comments on commit 7875afd

Please sign in to comment.