Skip to content

Commit

Permalink
```
Browse files Browse the repository at this point in the history
[FIX] Enhanced Stability and Addressed Build Issues

-   **Stability Configuration**: Added `com.android.billingclient.api.Purchase` and `com.android.billingclient.api.ProductDetails` to stability configuration.
-   **NowPlaying**: Removed `startForegroundService` from `NowPlaying` in favour of `startService`.
-   **Widget UI**: Added a new rounded corner drawable `rect_rounded_cornors_12dp.xml` for improved widget UI.
-   **Dependencies**: Updated Koin Compose to version `4.0.2`.
-   **Universal Widget**: Implemented backward compatibility for rounded corners in widgets using a drawable background.
-   **SystemFacade**: Changed `purchase` function to be non-inline. Added a check for session id to prevent duplicate sessions.
-   **App Insights**: Updated selected tab to `Firebase Crashlytics`. Added `FATAL` to failure types.
-   **Build**: Updated version code to 183 and version name to "3.3.0-rc01".
-  **Playback**: If session is not added, add the session.
- **Playback**: send broadcast when audio session id is updated.
  • Loading branch information
iZakirSheikh committed Jan 25, 2025
1 parent dcdf39c commit 073cab1
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .idea/appInsightsSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ android {
applicationId = "com.prime.player"
minSdk = 21
targetSdk = 35
versionCode = 182
versionName = "3.3.0-beta01"
versionCode = 183
versionName = "3.3.0-rc01"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables { useSupportLibrary = true }
// init different config fields.
Expand Down
30 changes: 27 additions & 3 deletions app/src/main/java/com/prime/media/common/SystemFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.util.Log
import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
import androidx.compose.runtime.NonRestartableComposable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
Expand All @@ -21,6 +22,7 @@ import com.google.android.play.core.splitinstall.SplitInstallRequest
import com.prime.media.BuildConfig
import com.prime.media.MainActivity
import com.primex.preferences.Key
import com.zs.core.paymaster.ProductInfo
import com.zs.core.paymaster.Purchase
import com.zs.core_ui.WindowStyle
import com.zs.core_ui.toast.Priority
Expand Down Expand Up @@ -264,7 +266,8 @@ val LocalSystemFacade =
* is called in preview mode.
*/
@Composable
inline fun purchase(id: String): State<Purchase?> {
@Stable
fun purchase(id: String): State<Purchase?> {
val activity = LocalSystemFacade.current as? MainActivity
if (activity == null) {
Log.i(
Expand All @@ -276,6 +279,28 @@ inline fun purchase(id: String): State<Purchase?> {
val manager = activity.paymaster
return produceState(remember { manager.purchases.value.find { it.id == id } }) {
manager.purchases.map { it.find { it.id == id } }.collect {
// updating purchase
value = it
}
}
}


@Composable
@Stable
fun SystemFacade.observeProductInfoAsState(id: String): State<ProductInfo?> {
val activity = LocalSystemFacade.current as? MainActivity
if (activity == null) {
Log.i(
"SystemFacade", "Purchase operation returned null in preview mode because " +
"the activity context is null. This is expected behavior in preview mode."
)
return remember { mutableStateOf(null) }
}
val manager = activity.paymaster
return produceState(remember { manager.details.value.find { it.id == id } }, id) {
manager.details.map { it.find { it.id == id } }.collect {
// updating
value = it
}
}
Expand All @@ -300,5 +325,4 @@ inline fun <S, O> preference(key: Key.Key1<S, O>): State<O?> {
inline fun <S, O> preference(key: Key.Key2<S, O>): State<O> {
val provider = LocalSystemFacade.current
return provider.observeAsState(key = key)
}

}
8 changes: 4 additions & 4 deletions app/src/main/java/com/prime/media/old/library/Promotions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import com.prime.media.BuildConfig
import com.prime.media.MainActivity
import com.prime.media.R
import com.prime.media.common.LocalSystemFacade
import com.prime.media.common.observeProductInfoAsState
import com.prime.media.common.preference
import com.prime.media.common.purchase
import com.prime.media.common.richDesc
Expand Down Expand Up @@ -317,14 +318,13 @@ private fun InAppPurchase(
// specific UI components. If in inspection mode, return to avoid executing the rest of the code.
if (purchase.purchased || LocalInspectionMode.current) return Spacer(modifier)
val facade = LocalSystemFacade.current
val details = remember(id) {
(facade as MainActivity).paymaster.details.value.find { it.id == id }
}
if (details == null) {
val info by facade.observeProductInfoAsState(id)
if (info == null) {
// This would never happen
Log.d(TAG, "InAppPurchase: details for $id not found")
return Spacer(modifier)
}
val details = info ?: return
Promotion(
expanded,
onValueChange,
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/zs/core/playback/NowPlaying.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ value class NowPlaying(private val value: Intent) {
inline fun trySend(ctx: Context, action: String? = null, args: Intent.() -> Unit = {}) {
try {
val intent = Intent(action, null, ctx, Playback::class.java).apply(args)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) ctx.startForegroundService(intent) else ctx.startService(intent)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) ctx.startService(intent) else ctx.startService(intent)
} catch (i: Exception) {
Log.d("NowPlaying", "trySend: ${i.message}")
}
Expand Down
22 changes: 13 additions & 9 deletions core/src/main/java/com/zs/core/playback/Playback.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ class Playback : MediaLibraryService(), Callback, Player.Listener {
private val LIST_ITEM_DELIMITER = ';'

/**
* Player events that trigger widget updates.
*
* The widget updates its state upon receiving any of these events,
* reflecting changes to playback, timeline, or other player properties.
*/
* Player events that trigger widget updates.
*
* The widget updates its state upon receiving any of these events,
* reflecting changes to playback, timeline, or other player properties.
*/
internal val UPDATE_EVENTS = intArrayOf(
Player.EVENT_TIMELINE_CHANGED,
Player.EVENT_PLAYBACK_STATE_CHANGED,
Expand Down Expand Up @@ -208,6 +208,7 @@ class Playback : MediaLibraryService(), Callback, Player.Listener {
private val session: MediaLibrarySession by lazy {
// Build and configure the MediaLibrarySession
MediaLibrarySession.Builder(this, player, this)
.setId("playback")
.setSessionActivity(activity)
.build()
}
Expand Down Expand Up @@ -270,6 +271,7 @@ class Playback : MediaLibraryService(), Callback, Player.Listener {
player.addListener(this@Playback)
// Initialize the audio effects;
onAudioSessionIdChanged(-1)
sendBroadcast(NowPlaying.from(this@Playback, player))
}
}

Expand All @@ -281,13 +283,15 @@ class Playback : MediaLibraryService(), Callback, Player.Listener {
sendBroadcast(NowPlaying.from(this, player))
return super.onStartCommand(intent, flags, startId)
}
if (player.playbackState != Player.STATE_READY) {
// FIX-ME Here we assume that session hasn't been added.

if (sessions.find { it.id == session.id } == null)
addSession(session)

if (player.playbackState != Player.STATE_READY)
player.prepare()
}

// if action is null; implies notification update requested
when(action){
when (action) {
NowPlaying.ACTION_TOGGLE_PLAY -> player.playWhenReady = !player.playWhenReady
NowPlaying.ACTION_NEXT -> player.seekToNextMediaItem()
NowPlaying.ACTION_PREVIOUS -> player.seekToPreviousMediaItem()
Expand Down
6 changes: 1 addition & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ toolkit = "v2.2.5"
material_icons = "1.7.6"
room = "2.6.1"
glance = "1.1.1"
junit = "4.13.2"
junitVersion = "1.2.1"
espressoCore = "3.6.1"
appcompat = "1.7.0"


[plugins]
Expand Down Expand Up @@ -45,7 +41,7 @@ material_view = { module = "com.google.android.material:material", version = "1.
androidx-biometric-ktx = { module = "androidx.biometric:biometric-ktx", version = "1.4.0-alpha02" }
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version = "1.15.0" }
navigation-compose = { module = "androidx.navigation:navigation-compose", version = "2.8.5" }
androidx-koin = { module = "io.insert-koin:koin-androidx-compose", version = "4.0.1" }
androidx-koin = { module = "io.insert-koin:koin-androidx-compose", version = "4.0.2" }
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version = "1.9.0" }
androidx-annotation-jvm = { group = "androidx.annotation", name = "annotation-jvm", version = "1.9.1" }

Expand Down
4 changes: 3 additions & 1 deletion stability_config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
// Consider NowPlaying stable;
// NowPlaying is inline class and hence need the internal to be declared as stable
com.zs.core.playback.NowPlaying
android.content.Intent
android.content.Intent
com.android.billingclient.api.Purchase
com.android.billingclient.api.ProductDetails
13 changes: 10 additions & 3 deletions widget/src/main/java/com/zs/widget/Universal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.glance.ColorFilter
import androidx.glance.GlanceTheme
import androidx.glance.Image
import androidx.glance.ImageProvider
Expand Down Expand Up @@ -67,9 +68,15 @@ private val ArtworkBg = Color.Gray.copy(0.7f)
@Composable
internal fun Universal(state: NowPlaying, type: ViewType) {
// Define a common top_modifier
val modifier =
Modifier.cornerRadius(ROUNDNESS)
.background(GlanceTheme.colors.surface)
val modifier = Modifier
// Rounded corners (cornerRadius) are not directly supported in Android API levels below 12.
// We're using a background drawable with rounded corners as a workaround for backward compatibility.
.background(
ImageProvider(R.drawable.rect_rounded_cornors_12dp),
colorFilter = ColorFilter.tint(GlanceTheme.colors.surface)
)
// cornerRadius(ROUNDNESS)
//.background(GlanceTheme.colors.surface)
.padding(8.dp)
.appWidgetBackground()
.launchApp()
Expand Down
18 changes: 18 additions & 0 deletions widget/src/main/res/drawable/rect_rounded_cornors_12dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<!-- <solid android:color="#00FF00" /> --><!-- Background color -->

<corners android:radius="12dp" /> <!-- Rounded corners -->

<!--<stroke
android:width="2dp"
android:color="#FF0000" />--> <!-- Border color and width -->

<!-- <padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" /> -->
</shape>

0 comments on commit 073cab1

Please sign in to comment.