Skip to content

Commit

Permalink
Update AndroidX Compose (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 authored Sep 11, 2024
1 parent 1847355 commit fd46ee1
Show file tree
Hide file tree
Showing 39 changed files with 200 additions and 186 deletions.
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[versions]
accompanist = "0.34.0"
android-gradle-plugin = "8.6.0"
androidx-activity = "1.9.2"
androidx-annotation = "1.8.2"
androidx-compose = "2024.08.00"
androidx-compose = "2024.09.01"
androidx-compose-material-navigation = "1.7.0-beta01" # TODO Remove this once https://issuetracker.google.com/issues/347719428 is resolved
androidx-core = "1.13.1"
androidx-fragment = "1.8.3"
androidx-lifecycle = "2.8.5"
Expand Down Expand Up @@ -37,7 +37,6 @@ tag-commander-server-side = "5.5.2"
turbine = "1.1.0"

[libraries]
accompanist-navigation-material = { module = "com.google.accompanist:accompanist-navigation-material", version.ref = "accompanist" }
android-gradle-api = { module = "com.android.tools.build:gradle-api", version.ref = "android-gradle-plugin" }
androidx-activity = { module = "androidx.activity:activity", version.ref = "androidx-activity" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
Expand Down Expand Up @@ -123,6 +122,7 @@ androidx-compose-ui-util = { module = "androidx.compose.ui:ui-util" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-compose-material-icons-core = { module = "androidx.compose.material:material-icons-core" }
androidx-compose-material-icons-extended = { module = "androidx.compose.material:material-icons-extended" }
androidx-compose-material-navigation = { module = "androidx.compose.material:material-navigation", version.ref = "androidx-compose-material-navigation" }
androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" }
androidx-compose-runtime-saveable = { module = "androidx.compose.runtime:runtime-saveable" }
androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import kotlin.time.Duration.Companion.seconds
class BlockedTimeRangeAssetLoader(context: Context) : AssetLoader(DefaultMediaSourceFactory(context)) {

override fun canLoadAsset(mediaItem: MediaItem): Boolean {
return mediaItem.localConfiguration?.uri?.toString()?.startsWith("blocked:") ?: false
return mediaItem.localConfiguration?.uri?.toString()?.startsWith("blocked:") == true
}

override suspend fun loadAsset(mediaItem: MediaItem): Asset {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ch.srgssr.pillarbox.player.asset.Asset
import ch.srgssr.pillarbox.player.asset.AssetLoader

/**
* Custom asset loader that always load the same url and the content is not seekable.
* Custom asset loader that always loads the same url and the content is not seekable.
*
* @param context The context.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sealed class HomeDestination(
val imageVector: ImageVector
) {
/**
* Examples home page containing all kind of streams
* Examples home page containing all kinds of streams
*/
data object Examples : HomeDestination(NavigationRoutes.homeSamples, R.string.examples, Icons.Default.Home)

Expand Down Expand Up @@ -62,9 +62,9 @@ fun NavController.navigate(destination: HomeDestination) {
saveState = true
}
// Avoid multiple copies of the same destination when
// reselecting the same item
// re-selecting the same item
launchSingleTop = true
// Restore state when reselecting a previously selected item
// Restore state when re-selecting a previously selected item
restoreState = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fun PillarboxSlider(
inactiveTrackColorDisabled: Color,
secondaryTrackColorEnabled: Color = Color.Unspecified,
secondaryTrackColorDisabled: Color = Color.Unspecified,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
interactionSource: MutableInteractionSource? = null,
onValueChange: (value: Long) -> Unit = {},
onValueChangeFinished: () -> Unit = {},
onSeekBack: () -> Unit = {},
Expand All @@ -109,7 +109,7 @@ fun PillarboxSlider(
secondaryTrackColorDisabled = secondaryTrackColorDisabled,
interactionSource = interactionSource,
onSliderValueChange = { ratio ->
onValueChange((ratio * (range.last - range.start)).toLong())
onValueChange((ratio * (range.last - range.first)).toLong())
},
onSliderValueChangeFinished = onValueChangeFinished,
onSeekBack = onSeekBack,
Expand Down Expand Up @@ -157,7 +157,7 @@ fun PillarboxSlider(
inactiveTrackColorDisabled: Color,
secondaryTrackColorEnabled: Color = Color.Unspecified,
secondaryTrackColorDisabled: Color = Color.Unspecified,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
interactionSource: MutableInteractionSource? = null,
onValueChange: (value: Float) -> Unit = {},
onValueChangeFinished: () -> Unit = {},
onSeekBack: () -> Unit = {},
Expand Down Expand Up @@ -202,7 +202,7 @@ private fun PillarboxSliderInternal(
inactiveTrackColorDisabled: Color,
secondaryTrackColorEnabled: Color,
secondaryTrackColorDisabled: Color,
interactionSource: MutableInteractionSource,
interactionSource: MutableInteractionSource?,
onSliderValueChange: (ratio: Float) -> Unit,
onSliderValueChangeFinished: () -> Unit,
onSeekBack: () -> Unit,
Expand Down Expand Up @@ -231,15 +231,22 @@ private fun PillarboxSliderInternal(
Row(
modifier = modifier
.height(seekBarHeight)
.clickToSlide(
interactionSource = interactionSource,
onSliderValueChange = onSliderValueChange,
onSliderValueChangeFinished = onSliderValueChangeFinished,
)
.dragThumb(
interactionSource = interactionSource,
onSliderValueChange = onSliderValueChange,
onSliderValueChangeFinished = onSliderValueChangeFinished,
.then(
if (interactionSource != null) {
Modifier
.clickToSlide(
interactionSource = interactionSource,
onSliderValueChange = onSliderValueChange,
onSliderValueChangeFinished = onSliderValueChangeFinished,
)
.dragThumb(
interactionSource = interactionSource,
onSliderValueChange = onSliderValueChange,
onSliderValueChangeFinished = onSliderValueChangeFinished,
)
} else {
Modifier
}
),
horizontalArrangement = Arrangement.spacedBy(6.dp),
) {
Expand Down Expand Up @@ -291,12 +298,12 @@ private fun Modifier.clickToSlide(
}
}

return this then pointerInput(Unit) {
return this then Modifier.pointerInput(Unit) {
detectTapGestures(
onPress = { offset ->
initPressInteraction(offset)

val nextInteraction = if (tryAwaitRelease()) {
val nextInteraction: (PressInteraction.Press) -> PressInteraction = if (tryAwaitRelease()) {
PressInteraction::Release
} else {
PressInteraction::Cancel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sealed interface Content {
val duration = media.duration.toDuration(DurationUnit.MILLISECONDS).inWholeMinutes.coerceAtLeast(1)

/**
* @property imageTitle The image image of the media.
* @property imageTitle The image title of the media.
*/
val imageTitle = media.imageTitle

Expand Down Expand Up @@ -71,7 +71,7 @@ sealed interface Content {
*/
data class Show(private val show: ch.srg.dataProvider.integrationlayer.data.remote.Show) : Content {
/**
* @property imageTitle The image image of the show.
* @property imageTitle The image title of the show.
*/
val imageTitle = show.imageTitle

Expand All @@ -98,7 +98,7 @@ sealed interface Content {
*/
data class Topic(private val topic: ch.srg.dataProvider.integrationlayer.data.remote.Topic) : Content {
/**
* @property imageTitle The image image of the topic.
* @property imageTitle The image title of the topic.
*/
val imageTitle = topic.imageTitle

Expand Down Expand Up @@ -135,7 +135,7 @@ sealed interface Content {
val id = channel.id

/**
* @property imageTitle The image image of the channel.
* @property imageTitle The image title of the channel.
*/
val imageTitle = channel.imageTitle

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ILRepository(
}

/**
* Get tv topics
* Get TV topics
*
* @param bu
*/
Expand All @@ -94,7 +94,7 @@ class ILRepository(
}

/**
* Get latest media by show urn
* Get the latest media by show urn
*
* @param urn
*/
Expand All @@ -103,7 +103,7 @@ class ILRepository(
}

/**
* Get latest media by show urn
* Get the latest media by show urn
*
* @param urn
* @param pageSize
Expand All @@ -114,7 +114,7 @@ class ILRepository(
}

/**
* Get latest media by topic urn
* Get the latest media by topic urn
*
* @param urn
*/
Expand All @@ -123,7 +123,7 @@ class ILRepository(
}

/**
* Get tv live stream
* Get TV live stream
*
* @param bu
*/
Expand Down Expand Up @@ -151,7 +151,7 @@ class ILRepository(
}

/**
* Get tv live web
* Get TV live web
*
* @param bu
*/
Expand All @@ -160,7 +160,7 @@ class ILRepository(
}

/**
* Get tv live center
* Get TV live center
*
* @param bu
*/
Expand All @@ -169,7 +169,7 @@ class ILRepository(
}

/**
* Get tv live center
* Get TV live center
*
* @param bu
* @param pageSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import kotlinx.coroutines.flow.stateIn
/**
* Player settings view model
*
* @constructor Create empty Player settings view model
* @constructor Create an empty Player settings view model
*/
class PlayerSettingsViewModel(
private val player: Player,
Expand Down Expand Up @@ -274,7 +274,7 @@ class PlayerSettingsViewModel(
*
* @param player
* @param application
* @constructor Create empty Factory
* @constructor Create an empty Factory
*/
@Suppress("UndocumentedPublicClass")
class Factory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import ch.srgssr.pillarbox.demo.tv.ui.theme.paddings
* Top bar displayed in the demo app on TV.
*
* @param destinations The list of destinations to display.
* @param currentNavDestination The currently destination selected.
* @param currentNavDestination The currently selected destination.
* @param modifier The [Modifier] to apply to the top bar.
* @param onDestinationClick The action to perform the selected a destination.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.text.input.TextFieldLineLimits
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Block
import androidx.compose.material.icons.filled.Search
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -158,24 +161,29 @@ private fun SearchInput(
modifier: Modifier = Modifier,
onQueryChange: (query: String) -> Unit
) {
val textFieldState = rememberTextFieldState(query)

LaunchedEffect(textFieldState.text) {
onQueryChange(textFieldState.text.toString())
}

BasicTextField(
value = query,
onValueChange = onQueryChange,
state = textFieldState,
modifier = modifier.background(
color = MaterialTheme.colorScheme.surfaceVariant,
shape = MaterialTheme.shapes.small
),
textStyle = MaterialTheme.typography.titleSmall
.copy(color = MaterialTheme.colorScheme.onSurface),
keyboardOptions = KeyboardOptions(
autoCorrect = false,
autoCorrectEnabled = false,
imeAction = ImeAction.Search
),
singleLine = true,
lineLimits = TextFieldLineLimits.SingleLine,
cursorBrush = Brush.verticalGradient(
colors = listOf(LocalContentColor.current, LocalContentColor.current)
),
decorationBox = { innerTextField ->
decorator = { innerTextField ->
Box(modifier = Modifier.padding(MaterialTheme.paddings.baseline)) {
innerTextField()

Expand Down
2 changes: 1 addition & 1 deletion pillarbox-demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ dependencies {
implementation(project(":pillarbox-player"))
implementation(project(":pillarbox-ui"))

implementation(libs.accompanist.navigation.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.annotation)
Expand All @@ -59,6 +58,7 @@ dependencies {
implementation(libs.androidx.compose.foundation.layout)
implementation(libs.androidx.compose.material.icons.core)
implementation(libs.androidx.compose.material.icons.extended)
implementation(libs.androidx.compose.material.navigation)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.compose.runtime)
implementation(libs.androidx.compose.ui)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import okhttp3.internal.toImmutableList
/**
* The only way to handle an Android Auto application.
*
* Hints for testing : https://developer.android.com/training/cars/testing
* Hints for testing: https://developer.android.com/training/cars/testing
*/
class DemoMediaLibraryService : PillarboxMediaLibraryService() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ch.srgssr.pillarbox.player.utils.PendingIntentUtils
* Demo media session service to handle background playback has Media3 would us to use.
* Can be still useful when using with MediaLibrary for android auto.
*
* Limitations :
* Limitations:
* - No custom data access from MediaController so no MediaComposition or other custom attributes integrator wants.
*
* @constructor Create empty Demo media session service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ch.srgssr.pillarbox.player.utils.PendingIntentUtils
/**
* Demo playback service
*
* It doesn't stop playback after 1min while in background and maintain a MediaNotification.
* It doesn't stop playback after 1min while in the background and maintains a MediaNotification.
*
* @constructor Create empty Demo playback service
*/
Expand Down
Loading

0 comments on commit fd46ee1

Please sign in to comment.