-
Notifications
You must be signed in to change notification settings - Fork 90
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
289 additions
and
18 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
51 changes: 51 additions & 0 deletions
51
...java/com/google/android/horologist/auth/composables/screens/SelectAccountScreenPreview.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,51 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
@file:OptIn(ExperimentalHorologistAuthComposablesApi::class) | ||
|
||
package com.google.android.horologist.auth.composables.screens | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.google.android.horologist.auth.composables.ExperimentalHorologistAuthComposablesApi | ||
import com.google.android.horologist.compose.layout.belowTimeTextPreview | ||
import com.google.android.horologist.compose.tools.WearPreviewDevices | ||
|
||
@WearPreviewDevices | ||
@Composable | ||
fun SelectAccountScreenPreview() { | ||
SelectAccountScreen( | ||
accounts = listOf( | ||
AccountUiModel(email = "maggie@example.com"), | ||
AccountUiModel(email = "thisisaverylongemail@example.com") | ||
), | ||
onAccountClicked = { _, _ -> }, | ||
columnState = belowTimeTextPreview() | ||
) | ||
} | ||
|
||
@WearPreviewDevices | ||
@Composable | ||
fun SelectAccountScreenPreviewNoAvatar() { | ||
SelectAccountScreen( | ||
accounts = listOf( | ||
AccountUiModel(email = "maggie@example.com"), | ||
AccountUiModel(email = "thisisaverylongemailaccountsample@example.com") | ||
), | ||
onAccountClicked = { _, _ -> }, | ||
columnState = belowTimeTextPreview(), | ||
defaultAvatar = null | ||
) | ||
} |
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
77 changes: 77 additions & 0 deletions
77
...c/main/java/com/google/android/horologist/auth/composables/screens/SelectAccountScreen.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,77 @@ | ||
/* | ||
* 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.screens | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
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.platform.LocalConfiguration | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.google.android.horologist.auth.composables.ExperimentalHorologistAuthComposablesApi | ||
import com.google.android.horologist.auth.composables.R | ||
import com.google.android.horologist.base.ui.components.StandardChip | ||
import com.google.android.horologist.base.ui.components.StandardChipType | ||
import com.google.android.horologist.base.ui.components.Title | ||
import com.google.android.horologist.compose.layout.ScalingLazyColumn | ||
import com.google.android.horologist.compose.layout.ScalingLazyColumnState | ||
|
||
private const val HORIZONTAL_PADDING_SCREEN_PERCENTAGE = 0.052 | ||
|
||
@ExperimentalHorologistAuthComposablesApi | ||
@Composable | ||
public fun SelectAccountScreen( | ||
accounts: List<AccountUiModel>, | ||
onAccountClicked: (index: Int, account: AccountUiModel) -> Unit, | ||
columnState: ScalingLazyColumnState, | ||
modifier: Modifier = Modifier, | ||
title: String = stringResource(id = R.string.horologist_select_account_title), | ||
defaultAvatar: Any? = Icons.Default.AccountCircle | ||
) { | ||
val configuration = LocalConfiguration.current | ||
val horizontalPadding = (configuration.screenWidthDp * HORIZONTAL_PADDING_SCREEN_PERCENTAGE).dp | ||
|
||
ScalingLazyColumn( | ||
modifier = modifier | ||
.fillMaxSize() | ||
.padding(horizontal = horizontalPadding), | ||
columnState = columnState | ||
) { | ||
item { Title(text = title, modifier = Modifier.padding(bottom = 8.dp)) } | ||
|
||
items(accounts.size) { index -> | ||
val account = accounts[index] | ||
|
||
StandardChip( | ||
label = account.email, | ||
icon = account.avatar ?: defaultAvatar, | ||
largeIcon = true, | ||
onClick = { onAccountClicked(index, account) }, | ||
chipType = StandardChipType.Secondary | ||
) | ||
} | ||
} | ||
} | ||
|
||
@ExperimentalHorologistAuthComposablesApi | ||
public data class AccountUiModel( | ||
val email: String, | ||
val avatar: Any? = null | ||
) |
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
89 changes: 89 additions & 0 deletions
89
...st/java/com/google/android/horologist/auth/composables/screens/SelectAccountScreenTest.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,89 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
@file:OptIn( | ||
ExperimentalHorologistPaparazziApi::class, | ||
ExperimentalHorologistAuthComposablesApi::class | ||
) | ||
|
||
package com.google.android.horologist.auth.composables.screens | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Face | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import com.google.android.horologist.auth.composables.ExperimentalHorologistAuthComposablesApi | ||
import com.google.android.horologist.compose.tools.coil.FakeImageLoader | ||
import com.google.android.horologist.paparazzi.ExperimentalHorologistPaparazziApi | ||
import com.google.android.horologist.paparazzi.WearPaparazzi | ||
import com.google.android.horologist.test.toolbox.positionedState | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class SelectAccountScreenTest { | ||
|
||
@get:Rule | ||
val paparazzi = WearPaparazzi() | ||
|
||
@Test | ||
fun selectAccountScreen() { | ||
paparazzi.snapshot { | ||
FakeImageLoader.Resources.override { | ||
Box( | ||
modifier = Modifier.background(Color.Black), | ||
contentAlignment = Alignment.Center | ||
) { | ||
SelectAccountScreen( | ||
accounts = listOf( | ||
AccountUiModel( | ||
email = "maggie@example.com", | ||
avatar = Icons.Default.Face | ||
), | ||
AccountUiModel(email = "thisisaverylongemail@example.com") | ||
), | ||
onAccountClicked = { _, _ -> }, | ||
columnState = positionedState(0, 0) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun selectAccountScreenNoAvatar() { | ||
paparazzi.snapshot { | ||
FakeImageLoader.Resources.override { | ||
Box( | ||
modifier = Modifier.background(Color.Black), | ||
contentAlignment = Alignment.Center | ||
) { | ||
SelectAccountScreen( | ||
accounts = listOf( | ||
AccountUiModel(email = "maggie@example.com"), | ||
AccountUiModel(email = "thisisaverylongemailaccountsample@example.com") | ||
), | ||
onAccountClicked = { _, _ -> }, | ||
columnState = positionedState(0, 0), | ||
defaultAvatar = null | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
auth-composables/src/test/java/com/google/android/horologist/test/toolbox/PositionedState.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,32 @@ | ||
/* | ||
* 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.test.toolbox | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.google.android.horologist.compose.layout.ScalingLazyColumnDefaults | ||
import com.google.android.horologist.compose.layout.ScalingLazyColumnState | ||
import com.google.android.horologist.compose.tools.a11y.forceState | ||
|
||
@Composable | ||
fun positionedState( | ||
topIndex: Int, | ||
topScrollOffset: Int | ||
): ScalingLazyColumnState { | ||
return ScalingLazyColumnDefaults.belowTimeText().create().apply { | ||
state.forceState(topIndex, topScrollOffset) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...logist.auth.composables.screens_SelectAccountScreenTest_selectAccountScreen.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
...uth.composables.screens_SelectAccountScreenTest_selectAccountScreenNoAvatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.