Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Update to Compose + UI v0.1.0-dev12 #621

Merged
merged 3 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ play-account.json

# Do not commit firebase config
google-services.json

# VS Code config
org.eclipse.buildship.core.prefs
.classpath
.project
bin/
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ dependencies {
implementation project(':ui-recommended')
implementation project(':ui-search')

implementation Libs.AndroidX.Lifecycle.extensions
implementation Libs.AndroidX.Lifecycle.viewmodelKtx
implementation Libs.AndroidX.Lifecycle.livedata
implementation Libs.AndroidX.Lifecycle.viewmodel

implementation Libs.AndroidX.appcompat
implementation Libs.AndroidX.browser
Expand Down
67 changes: 0 additions & 67 deletions base-android/src/main/java/app/tivi/util/Event.kt

This file was deleted.

7 changes: 4 additions & 3 deletions buildSrc/src/main/java/app/tivi/buildsrc/dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object Libs {
}

object Accompanist {
private const val version = "0.1.2"
private const val version = "0.1.3-SNAPSHOT"
const val mdcTheme = "dev.chrisbanes.accompanist:accompanist-mdc-theme:$version"
const val coil = "dev.chrisbanes.accompanist:accompanist-coil:$version"
}
Expand Down Expand Up @@ -134,7 +134,8 @@ object Libs {
object Lifecycle {
private const val version = "2.2.0"
const val extensions = "androidx.lifecycle:lifecycle-extensions:$version"
const val viewmodelKtx = "androidx.lifecycle:lifecycle-viewmodel-ktx:$version"
const val livedata = "androidx.lifecycle:lifecycle-livedata-ktx:$version"
const val viewmodel = "androidx.lifecycle:lifecycle-viewmodel-ktx:$version"
}

object Room {
Expand All @@ -152,7 +153,7 @@ object Libs {
}

object Compose {
const val version = "0.1.0-dev11"
const val version = "0.1.0-dev12"
const val kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424"

const val runtime = "androidx.compose:compose-runtime:$version"
Expand Down
4 changes: 2 additions & 2 deletions common-entrygrid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ dependencies {
implementation project(':common-layouts')
implementation project(':common-databinding')

implementation Libs.AndroidX.Lifecycle.extensions
implementation Libs.AndroidX.Lifecycle.viewmodelKtx
implementation Libs.AndroidX.Lifecycle.livedata
implementation Libs.AndroidX.Lifecycle.viewmodel

implementation Libs.AndroidX.Paging.runtime

Expand Down
1 change: 1 addition & 0 deletions common-ui-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
api project(':common-imageloading')

implementation Libs.AndroidX.coreKtx
implementation Libs.AndroidX.Lifecycle.livedata

implementation Libs.AndroidX.Compose.runtime
implementation Libs.AndroidX.UI.foundation
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@ import androidx.compose.setValue
import androidx.compose.state
import androidx.compose.stateFor
import androidx.ui.core.Modifier
import androidx.ui.foundation.Box
import androidx.ui.foundation.Clickable
import androidx.ui.foundation.Text
import androidx.ui.material.EmphasisAmbient
import androidx.ui.foundation.clickable
import androidx.ui.material.MaterialTheme
import androidx.ui.material.ProvideEmphasis
import androidx.ui.material.ripple.ripple
import androidx.ui.text.TextStyle
import androidx.ui.text.style.TextOverflow

@Composable
fun ExpandingSummary(
fun ExpandingText(
text: String,
textStyle: TextStyle = MaterialTheme.typography.body2,
expandable: Boolean = true,
Expand All @@ -42,25 +38,21 @@ fun ExpandingSummary(
modifier: Modifier = Modifier
) {
var canTextExpand by stateFor(text) { true }
var expanded by state { false }

Box(modifier = Modifier.ripple(bounded = true, enabled = expandable && canTextExpand)) {
var expanded by state { false }

Clickable(onClick = { expanded = !expanded }, enabled = expandable && canTextExpand) {
ProvideEmphasis(emphasis = EmphasisAmbient.current.high) {
Text(
text = text,
style = textStyle,
overflow = TextOverflow.Ellipsis,
maxLines = if (expanded) expandedMaxLines else collapsedMaxLines,
modifier = modifier,
onTextLayout = {
if (!expanded) {
canTextExpand = it.hasVisualOverflow
}
}
)
Text(
text = text,
style = textStyle,
overflow = TextOverflow.Ellipsis,
maxLines = if (expanded) expandedMaxLines else collapsedMaxLines,
modifier = Modifier.clickable(
onClick = { expanded = !expanded },
enabled = expandable && canTextExpand
).plus(modifier),
onTextLayout = {
if (!expanded) {
canTextExpand = it.hasVisualOverflow
}
}
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import androidx.ui.animation.Crossfade
import androidx.ui.core.Alignment
import androidx.ui.core.Modifier
import androidx.ui.core.Popup
import androidx.ui.core.PopupProperties
import androidx.ui.foundation.Clickable
import androidx.ui.foundation.Text
import androidx.ui.foundation.clickable
import androidx.ui.layout.Column
import androidx.ui.layout.padding
import androidx.ui.layout.preferredSizeIn
Expand All @@ -35,7 +34,6 @@ import androidx.ui.material.EmphasisAmbient
import androidx.ui.material.MaterialTheme
import androidx.ui.material.ProvideEmphasis
import androidx.ui.material.Surface
import androidx.ui.material.ripple.ripple
import androidx.ui.unit.IntPx
import androidx.ui.unit.IntPxPosition
import androidx.ui.unit.dp
Expand All @@ -51,10 +49,8 @@ fun PopupMenu(
Popup(
alignment = alignment,
offset = offset,
popupProperties = PopupProperties(
isFocusable = true,
onDismissRequest = { visible.value = false }
)
isFocusable = true,
onDismissRequest = { visible.value = false }
) {
Crossfade(current = visible.value) {
Surface(
Expand All @@ -67,25 +63,23 @@ fun PopupMenu(
.preferredSizeIn(minWidth = 96.dp, maxWidth = 192.dp)
) {
items.forEach { item ->
Clickable(
onClick = {
item.onClick?.invoke()
visible.value = false
},
enabled = item.enabled,
modifier = Modifier.ripple(enabled = item.enabled)
) {
val emphasis = when {
item.enabled -> EmphasisAmbient.current.high
else -> EmphasisAmbient.current.disabled
}
ProvideEmphasis(emphasis) {
Text(
text = item.title,
style = MaterialTheme.typography.body1,
modifier = Modifier.padding(16.dp)
)
}
val emphasis = when {
item.enabled -> EmphasisAmbient.current.high
else -> EmphasisAmbient.current.disabled
}
ProvideEmphasis(emphasis) {
Text(
text = item.title,
style = MaterialTheme.typography.body1,
modifier = Modifier.clickable(
onClick = {
item.onClick?.invoke()
visible.value = false
},
enabled = item.enabled
)
.padding(16.dp)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,7 @@

package app.tivi.common.compose

import androidx.compose.Composable
import androidx.compose.Providers
import androidx.compose.staticAmbientOf
import app.tivi.util.TiviDateFormatter

val TiviDateFormatterAmbient = staticAmbientOf<TiviDateFormatter>()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a whole file for an ambient? Consider creating a ProvideDateFormatter here similar to insets and renaming the file.

Copy link
Owner Author

@chrisbanes chrisbanes May 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've seen from Adam, we shouldn't hide the APIs around ambients too much. ProvideInsets is a bit special because it needs to observe a LiveData, so wrapping it up makes sense to me. TiviDateFormatterAmbient is a very simple static ambient though.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @adamp


@Composable
fun WrapWithAmbients(
tiviDateFormatter: TiviDateFormatter,
insetsHolder: InsetsHolder,
content: @Composable () -> Unit
) = Providers(
TiviDateFormatterAmbient provides tiviDateFormatter,
InsetsAmbient provides insetsHolder,
children = content
)
Loading