-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
280 additions
and
19 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
45 changes: 45 additions & 0 deletions
45
...src/debug/java/com/google/android/horologist/auth/composables/chips/AccountChipPreview.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,45 @@ | ||
/* | ||
* Copyright 2022 The Android Open Source Project | ||
* | ||
* 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 | ||
* | ||
* https://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 com.google.android.horologist.auth.composables.chips | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.tooling.preview.Preview | ||
|
||
@Preview( | ||
backgroundColor = 0xff000000, | ||
showBackground = true | ||
) | ||
@Composable | ||
fun AccountChipPreview() { | ||
AccountChip( | ||
email = "[email protected]", | ||
onClick = {} | ||
) | ||
} | ||
|
||
@Preview( | ||
backgroundColor = 0xff000000, | ||
showBackground = true | ||
) | ||
@Composable | ||
fun AccountChipPreviewNoAvatar() { | ||
AccountChip( | ||
email = "[email protected]", | ||
onClick = {}, | ||
defaultAvatar = null | ||
) | ||
} |
99 changes: 99 additions & 0 deletions
99
...osables/src/main/java/com/google/android/horologist/auth/composables/chips/AccountChip.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,99 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* 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 | ||
* | ||
* https://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 com.google.android.horologist.auth.composables.chips | ||
|
||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.AccountCircle | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import androidx.compose.ui.text.style.LineBreak | ||
import androidx.wear.compose.material.ChipColors | ||
import androidx.wear.compose.material.ChipDefaults | ||
import androidx.wear.compose.material.MaterialTheme | ||
import com.google.android.horologist.auth.composables.model.AccountUiModel | ||
import com.google.android.horologist.compose.material.Chip | ||
|
||
/** | ||
* A [Chip] to display the [AccountUiModel]'s email address and avatar. | ||
* | ||
* The email text has optimised line break parameters, in order to display as much text as it can. | ||
*/ | ||
@Composable | ||
public fun AccountChip( | ||
account: AccountUiModel, | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
defaultAvatar: Any? = Icons.Default.AccountCircle, | ||
largeAvatar: Boolean = true, | ||
placeholder: Painter? = null, | ||
colors: ChipColors = ChipDefaults.primaryChipColors(), | ||
enabled: Boolean = true | ||
) { | ||
AccountChip( | ||
email = account.email, | ||
onClick = onClick, | ||
modifier = modifier, | ||
avatar = account.avatar, | ||
defaultAvatar = defaultAvatar, | ||
largeAvatar = largeAvatar, | ||
placeholder = placeholder, | ||
colors = colors, | ||
enabled = enabled | ||
) | ||
} | ||
|
||
/** | ||
* A [Chip] to display an email address and avatar. | ||
* | ||
* The email text has optimised line break parameters, in order to display as much text as it can. | ||
*/ | ||
@Composable | ||
public fun AccountChip( | ||
email: String, | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
avatar: Any? = null, | ||
defaultAvatar: Any? = Icons.Default.AccountCircle, | ||
largeAvatar: Boolean = true, | ||
placeholder: Painter? = null, | ||
colors: ChipColors = ChipDefaults.primaryChipColors(), | ||
enabled: Boolean = true | ||
) { | ||
MaterialTheme( | ||
typography = MaterialTheme.typography.copy( | ||
button = MaterialTheme.typography.button.copy( | ||
lineBreak = LineBreak( | ||
strategy = LineBreak.Strategy.Balanced, | ||
strictness = LineBreak.Strictness.Normal, | ||
wordBreak = LineBreak.WordBreak.Default | ||
) | ||
) | ||
) | ||
) { | ||
Chip( | ||
label = email, | ||
onClick = onClick, | ||
modifier = modifier, | ||
icon = avatar ?: defaultAvatar, | ||
largeIcon = largeAvatar, | ||
placeholder = placeholder, | ||
colors = colors, | ||
enabled = enabled | ||
) | ||
} | ||
} |
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
87 changes: 87 additions & 0 deletions
87
...les/src/test/java/com/google/android/horologist/auth/composables/chips/AccountChipTest.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,87 @@ | ||
/* | ||
* Copyright 2022 The Android Open Source Project | ||
* | ||
* 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 | ||
* | ||
* https://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 com.google.android.horologist.auth.composables.chips | ||
|
||
import androidx.wear.compose.material.ChipDefaults | ||
import com.google.android.horologist.screenshots.ScreenshotBaseTest | ||
import org.junit.Test | ||
|
||
class AccountChipTest : ScreenshotBaseTest() { | ||
|
||
@Test | ||
fun default() { | ||
screenshotTestRule.setContent(isComponent = true, takeScreenshot = true) { | ||
AccountChip( | ||
email = "[email protected]", | ||
onClick = {} | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun disabled() { | ||
screenshotTestRule.setContent(isComponent = true, takeScreenshot = true) { | ||
AccountChip( | ||
email = "[email protected]", | ||
onClick = {}, | ||
enabled = false | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun withSmallAvatar() { | ||
screenshotTestRule.setContent(isComponent = true, takeScreenshot = true) { | ||
AccountChip( | ||
email = "[email protected]", | ||
onClick = {}, | ||
largeAvatar = false | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun withSecondaryChipType() { | ||
screenshotTestRule.setContent(isComponent = true, takeScreenshot = true) { | ||
AccountChip( | ||
email = "[email protected]", | ||
onClick = {}, | ||
colors = ChipDefaults.secondaryChipColors() | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun withLongEmailAddress() { | ||
screenshotTestRule.setContent(isComponent = true, takeScreenshot = true) { | ||
AccountChip( | ||
email = "[email protected]", | ||
onClick = {} | ||
) | ||
} | ||
} | ||
|
||
@Test | ||
fun withEmailAddressStartingWithSingleLetterAndDot() { | ||
screenshotTestRule.setContent(isComponent = true, takeScreenshot = true) { | ||
AccountChip( | ||
email = "[email protected]", | ||
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
3 changes: 3 additions & 0 deletions
3
...om.google.android.horologist.auth.composables.chips_AccountChipTest_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...m.google.android.horologist.auth.composables.chips_AccountChipTest_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...sables.chips_AccountChipTest_withEmailAddressStartingWithSingleLetterAndDot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...roid.horologist.auth.composables.chips_AccountChipTest_withLongEmailAddress.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...oid.horologist.auth.composables.chips_AccountChipTest_withSecondaryChipType.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...e.android.horologist.auth.composables.chips_AccountChipTest_withSmallAvatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
....horologist.auth.composables.chips_CreateAccountChipTest_withLargeIconSpace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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