-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Immutable collections for compose code (#364)
- Loading branch information
Showing
100 changed files
with
754 additions
and
770 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
core/ui/src/main/java/ru/stersh/youamp/core/ui/Playlist.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package ru.stersh.youamp.core.ui | ||
|
||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.rounded.Album | ||
import androidx.compose.material3.ElevatedCard | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.Layout | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.Constraints | ||
import androidx.compose.ui.unit.dp | ||
|
||
|
||
@Composable | ||
fun PlaylistItem( | ||
title: String, | ||
onClick: () -> Unit, | ||
artworkUrl: String? = null, | ||
playButton: @Composable () -> Unit = {}, | ||
modifier: Modifier = Modifier | ||
) { | ||
ElevatedCard( | ||
shape = MaterialTheme.shapes.large, | ||
onClick = onClick, | ||
modifier = modifier | ||
) { | ||
PlaylistLayout( | ||
title = { | ||
Text( | ||
text = title, | ||
modifier = Modifier.fillMaxWidth(), | ||
textAlign = TextAlign.Left, | ||
minLines = 1, | ||
maxLines = 1, | ||
style = MaterialTheme.typography.labelLarge | ||
) | ||
}, | ||
artwork = { | ||
Artwork( | ||
artworkUrl = artworkUrl, | ||
placeholder = Icons.Rounded.Album | ||
) | ||
}, | ||
playButton = playButton | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun PlaylistLayout( | ||
title: @Composable () -> Unit, | ||
artwork: @Composable () -> Unit, | ||
playButton: @Composable () -> Unit, | ||
modifier: Modifier = Modifier | ||
) { | ||
val density = LocalDensity.current | ||
val contentPadding = 12.dp.roundToPx(density) | ||
val titleTopPadding = 4.dp.roundToPx(density) | ||
Layout( | ||
contents = listOf( | ||
title, | ||
artwork, | ||
playButton | ||
), | ||
modifier = modifier | ||
) { measurables, constraints -> | ||
|
||
val titlePlaceable = measurables[0] | ||
.first() | ||
.measure(constraints) | ||
val artworkPlaceable = measurables[1] | ||
.first() | ||
.measure(Constraints.fixed(constraints.maxWidth, constraints.maxWidth)) | ||
val playButtonPlaceable = measurables | ||
.getOrNull(2) | ||
?.firstOrNull() | ||
?.measure(constraints) | ||
|
||
val maxHeight = | ||
titlePlaceable.height + artworkPlaceable.height + titleTopPadding + contentPadding + ((playButtonPlaceable?.height | ||
?: 0) / 2) | ||
|
||
layout(artworkPlaceable.width, maxHeight) { | ||
artworkPlaceable.placeRelative(0, 0) | ||
playButtonPlaceable?.placeRelative( | ||
(artworkPlaceable.width / 2) - (playButtonPlaceable.width / 2), | ||
artworkPlaceable.height - (playButtonPlaceable.height / 2) | ||
) | ||
val titleY = if (playButtonPlaceable != null) { | ||
artworkPlaceable.height + titleTopPadding + (playButtonPlaceable.height / 2) | ||
} else { | ||
artworkPlaceable.height + titleTopPadding | ||
} | ||
titlePlaceable.placeRelative(contentPadding, titleY) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@Preview | ||
private fun PlaylistItemPreview() { | ||
MaterialTheme { | ||
PlaylistItem( | ||
title = "Playlist", | ||
playButton = { | ||
PlayButtonOutlined( | ||
isPlaying = false, | ||
onClick = {}, | ||
) | ||
}, | ||
onClick = {} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
feature/album/favorites/src/main/java/ru/stresh/youamp/feature/album/favorites/ui/Mapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
feature/album/info/src/main/java/ru/stersh/youamp/feature/album/ui/AlbumInfoStateUi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
feature/album/list/src/main/java/ru/stersh/youamp/feature/albums/ui/AlbumUi.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
feature/album/list/src/main/java/ru/stersh/youamp/feature/albums/ui/AlbumsStateUi.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
feature/album/list/src/main/java/ru/stersh/youamp/feature/albums/ui/Mapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
feature/album/list/src/main/java/ru/stersh/youamp/feature/albums/ui/State.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ru.stersh.youamp.feature.albums.ui | ||
|
||
import kotlinx.collections.immutable.ImmutableList | ||
import kotlinx.collections.immutable.persistentListOf | ||
|
||
internal data class AlbumsStateUi( | ||
val progress: Boolean = true, | ||
val isRefreshing: Boolean = false, | ||
val error: Boolean = false, | ||
val items: ImmutableList<AlbumUi> = persistentListOf() | ||
) | ||
|
||
internal data class AlbumUi( | ||
val id: String, | ||
val title: String, | ||
val artist: String?, | ||
val artworkUrl: String? | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.