This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 883
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converting 'Discover' to Jetpack Compose (#692)
* Add initial skeleton Compose setup to Discover * Hook up Compose discover to fragment * Show trending, popular and recommended shows * Re-use Carousel and PosterCard in ShowDetails.kt * Show next episode to watch * Fix app bar behavior * Add overflow actions to open grids * Change overflow buttons to secondary * Limit discover carousels to 10 items * Refactor Carousel and header logic * Add refresh app bar action * Stop passing actioner around * Move to using ComposeView * Add todo to investigate removing text from poster card * Address review comments
- Loading branch information
1 parent
80b8da5
commit 4330a30
Showing
22 changed files
with
669 additions
and
633 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
common-ui-compose/src/main/java/app/tivi/common/compose/Carousel.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,50 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package app.tivi.common.compose | ||
|
||
import androidx.compose.foundation.layout.InnerPadding | ||
import androidx.compose.foundation.lazy.LazyItemScope | ||
import androidx.compose.foundation.lazy.LazyRowFor | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun <T> Carousel( | ||
items: List<T>, | ||
modifier: Modifier = Modifier, | ||
contentPadding: InnerPadding = InnerPadding(0.dp), | ||
itemSpacing: Dp = 0.dp, | ||
verticalGravity: Alignment.Vertical = Alignment.Top, | ||
itemContent: @Composable LazyItemScope.(T, InnerPadding) -> Unit | ||
) { | ||
val halfSpacing = itemSpacing / 2 | ||
val spacingContent = InnerPadding(halfSpacing, 0.dp, halfSpacing, 0.dp) | ||
|
||
LazyRowFor( | ||
items = items, | ||
modifier = modifier, | ||
contentPadding = contentPadding.copy( | ||
start = (contentPadding.start - halfSpacing).coerceAtLeast(0.dp), | ||
end = (contentPadding.end - halfSpacing).coerceAtLeast(0.dp) | ||
), | ||
verticalGravity = verticalGravity, | ||
itemContent = { item -> itemContent(item, spacingContent) } | ||
) | ||
} |
63 changes: 63 additions & 0 deletions
63
common-ui-compose/src/main/java/app/tivi/common/compose/PosterCard.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,63 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package app.tivi.common.compose | ||
|
||
import androidx.compose.foundation.Text | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Stack | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Card | ||
import androidx.compose.material.EmphasisAmbient | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.ProvideEmphasis | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import app.tivi.data.entities.TiviShow | ||
import app.tivi.data.entities.TmdbImageEntity | ||
import dev.chrisbanes.accompanist.coil.CoilImageWithCrossfade | ||
|
||
@Composable | ||
fun PosterCard( | ||
show: TiviShow, | ||
poster: TmdbImageEntity? = null, | ||
onClick: (() -> Unit)? = null, | ||
modifier: Modifier = Modifier | ||
) { | ||
Card(modifier = modifier) { | ||
Stack( | ||
modifier = if (onClick != null) Modifier.clickable(onClick = onClick) else Modifier | ||
) { | ||
// TODO: remove text if the image has loaded (and animated in). | ||
// https://github.com/chrisbanes/accompanist/issues/76 | ||
ProvideEmphasis(EmphasisAmbient.current.medium) { | ||
Text( | ||
text = show.title ?: "No title", | ||
style = MaterialTheme.typography.caption, | ||
modifier = Modifier.padding(4.dp).gravity(Alignment.CenterStart) | ||
) | ||
} | ||
if (poster != null) { | ||
CoilImageWithCrossfade( | ||
data = poster, | ||
modifier = Modifier.matchParentSize() | ||
) | ||
} | ||
} | ||
} | ||
} |
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
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.