-
Notifications
You must be signed in to change notification settings - Fork 4
GT-2990 Localization Settings Box (Tools Layout) #4422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
cc91d14
Add Surface box to end of tools layout for personalization
tjohnson009 cf69aa8
Create and insert localizations settings box for tools and lessons pa…
tjohnson009 fc99ef8
Add string resources for lessons layout personalization
tjohnson009 42a0af0
Add UiEvent for going to localization settings from lesson layout
tjohnson009 5ccbf15
Add locationSettingsBox to lessons layout; Make padding similar to to…
tjohnson009 87a4eb8
Remove unused imports
tjohnson009 963815e
Remove unnecessary Row composable for center alignment; Remove unused…
tjohnson009 b3e1396
Remove unused imports
tjohnson009 1a2bc22
Gate the localization settings banner based on the isPersonalizationE…
tjohnson009 5112561
Minor lint fix
tjohnson009 210a55d
Make localizationSettingsBox internal following lessons and tools lay…
tjohnson009 63f45a8
Revert erroneous padding changes and correct personalization if state…
tjohnson009 91e8186
Correct personalization if statement for personalization settings box
tjohnson009 91983dd
Add snapshot tests for lessons and tools localization settings box
tjohnson009 8603cfb
Record updated snapshots
tjohnson009 a02e9fd
Retrigger CI
tjohnson009 eddeda0
Update modifier line to single line
tjohnson009 88f340b
Add a custom vertical arrangement to LazyColumn to pin localization t…
tjohnson009 d4f475e
Record updated snapshots
tjohnson009 24a5326
Retrigger CI
tjohnson009 9cdeb78
Bring in rememberPinLastArrangement composable to both tools and lessons
tjohnson009 f4c0a1b
Create rememberPinLastItemBottomArrangement composable for reuse in t…
tjohnson009 b5647d1
Adjust the rememberlastItem call to reflect changes
tjohnson009 6cb5543
Remove unnecessary key from remember and params
tjohnson009 d8e3e97
Rename and generalize PinLastItemBottomArrangement to FloatLastItemsT…
frett 089ff26
Update LocalizationSettingsBox typography to titleMedium and bodyMedium
frett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
app/src/main/kotlin/org/cru/godtools/ui/dashboard/LocalizationSettingsBox.kt
This file contains hidden or 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,49 @@ | ||
| package org.cru.godtools.ui.dashboard | ||
|
|
||
| import androidx.annotation.StringRes | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.material3.Button | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Surface | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| import androidx.compose.ui.unit.dp | ||
| import org.cru.godtools.R | ||
|
|
||
| @Composable | ||
| internal fun LocalizationSettingsBox( | ||
| @StringRes title: Int, | ||
| @StringRes description: Int, | ||
| onClickSettings: () -> Unit, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| Surface( | ||
| color = MaterialTheme.colorScheme.primaryContainer, | ||
| modifier = modifier.fillMaxWidth(), | ||
| ) { | ||
| Column(modifier = Modifier.padding(16.dp)) { | ||
| Text( | ||
| text = stringResource(title), | ||
| style = MaterialTheme.typography.titleMedium | ||
| ) | ||
| Text( | ||
| text = stringResource(description), | ||
| style = MaterialTheme.typography.bodyMedium | ||
| ) | ||
| Button( | ||
| onClick = onClickSettings, | ||
| modifier = Modifier | ||
| .align(Alignment.CenterHorizontally) | ||
| .padding(top = 8.dp) | ||
| ) { | ||
| Text(stringResource(R.string.dashboard_section_localization_box_button)) | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
28 changes: 28 additions & 0 deletions
28
...kotlin/org/cru/godtools/ui/dashboard/personalization/FloatLastItemsToBottomArrangement.kt
This file contains hidden or 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,28 @@ | ||
| package org.cru.godtools.ui.dashboard.personalization | ||
|
|
||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.ui.unit.Density | ||
|
|
||
| @Composable | ||
| internal fun rememberFloatLastItemsToBottomArrangement(numToFloat: Int) = | ||
| remember(numToFloat) { FloatLastItemsToBottomArrangement(numToFloat) } | ||
|
|
||
| internal class FloatLastItemsToBottomArrangement(val numToFloat: Int) : Arrangement.Vertical { | ||
| override fun Density.arrange(totalSize: Int, sizes: IntArray, outPositions: IntArray) { | ||
| var currentOffset = 0 | ||
| sizes.forEachIndexed { index, size -> | ||
| outPositions[index] = currentOffset | ||
| currentOffset += size | ||
| } | ||
|
|
||
| if (currentOffset < totalSize && numToFloat > 0) { | ||
| currentOffset = totalSize | ||
| sizes.takeLast(numToFloat).reversed().forEachIndexed { index, size -> | ||
| currentOffset -= size | ||
| outPositions[sizes.lastIndex - index] = currentOffset | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
80 changes: 80 additions & 0 deletions
80
...in/org/cru/godtools/ui/dashboard/personalization/FloatLastItemsToBottomArrangementTest.kt
This file contains hidden or 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,80 @@ | ||
| package org.cru.godtools.ui.dashboard.personalization | ||
|
|
||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.ui.unit.Density | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertContentEquals | ||
|
|
||
| class FloatLastItemsToBottomArrangementTest { | ||
| private val density = Density(1f) | ||
|
|
||
| private fun Arrangement.Vertical.testArrange(totalSize: Int, vararg sizes: Int): IntArray { | ||
| val outPositions = IntArray(sizes.size) | ||
| with(density) { arrange(totalSize, sizes, outPositions) } | ||
| return outPositions | ||
| } | ||
|
|
||
| // region numToFloat = 0 | ||
| @Test | ||
| fun `numToFloat=0 - items positioned sequentially from top`() { | ||
| val arrangement = FloatLastItemsToBottomArrangement(numToFloat = 0) | ||
| assertContentEquals(intArrayOf(0, 100, 200), arrangement.testArrange(500, 100, 100, 100)) | ||
| } | ||
| // endregion numToFloat = 0 | ||
|
|
||
| // region numToFloat = 1 | ||
| @Test | ||
| fun `numToFloat=1 - last item floats to bottom when content fits`() { | ||
| val arrangement = FloatLastItemsToBottomArrangement(numToFloat = 1) | ||
| assertContentEquals(intArrayOf(0, 100, 400), arrangement.testArrange(500, 100, 100, 100)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `numToFloat=1 - no floating when content overflows container`() { | ||
| val arrangement = FloatLastItemsToBottomArrangement(numToFloat = 1) | ||
| assertContentEquals(intArrayOf(0, 100, 200), arrangement.testArrange(200, 100, 100, 100)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `numToFloat=1 - single item floats to bottom`() { | ||
| val arrangement = FloatLastItemsToBottomArrangement(numToFloat = 1) | ||
| assertContentEquals(intArrayOf(400), arrangement.testArrange(500, 100)) | ||
| } | ||
| // endregion numToFloat = 1 | ||
|
|
||
| // region numToFloat = 2 | ||
| @Test | ||
| fun `numToFloat=2 - last 2 items float to bottom when content fits`() { | ||
| val arrangement = FloatLastItemsToBottomArrangement(numToFloat = 2) | ||
| assertContentEquals(intArrayOf(0, 300, 400), arrangement.testArrange(500, 100, 100, 100)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `numToFloat=2 - no floating when content exactly fills container`() { | ||
| val arrangement = FloatLastItemsToBottomArrangement(numToFloat = 2) | ||
| assertContentEquals(intArrayOf(0, 100, 200), arrangement.testArrange(300, 100, 100, 100)) | ||
| } | ||
| // endregion numToFloat = 2 | ||
|
|
||
| // region numToFloat exceeds item count | ||
| @Test | ||
| fun `numToFloat exceeds item count - all items float to bottom`() { | ||
| val arrangement = FloatLastItemsToBottomArrangement(numToFloat = 5) | ||
| assertContentEquals(intArrayOf(200, 300, 400), arrangement.testArrange(500, 100, 100, 100)) | ||
| } | ||
| // endregion numToFloat exceeds item count | ||
|
|
||
| // region edge cases | ||
| @Test | ||
| fun `empty item list`() { | ||
| val arrangement = FloatLastItemsToBottomArrangement(numToFloat = 1) | ||
| assertContentEquals(intArrayOf(), arrangement.testArrange(500)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `variable item sizes - floating item positioned correctly`() { | ||
| val arrangement = FloatLastItemsToBottomArrangement(numToFloat = 1) | ||
| assertContentEquals(intArrayOf(0, 50, 350), arrangement.testArrange(500, 50, 200, 150)) | ||
| } | ||
| // endregion edge cases | ||
| } |
3 changes: 3 additions & 0 deletions
3
...ion_-_Localization_Settings_Box[Nexus_5,locale=null,NIGHT,NO_ACCESSIBILITY].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
...ion_-_Localization_Settings_Box[Nexus_5,locale=null,NOTNIGHT,ACCESSIBILITY].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
..._-_Localization_Settings_Box[Nexus_5,locale=null,NOTNIGHT,NO_ACCESSIBILITY].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
...-_Localization_Settings_Box[Pixel_6_Pro,locale=null,NIGHT,NO_ACCESSIBILITY].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
...ocalization_Settings_Box[Pixel_6_Pro,locale=null,NOTNIGHT,NO_ACCESSIBILITY].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
...ion_-_Localization_Settings_Box[Nexus_5,locale=null,NIGHT,NO_ACCESSIBILITY].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
...ion_-_Localization_Settings_Box[Nexus_5,locale=null,NOTNIGHT,ACCESSIBILITY].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
..._-_Localization_Settings_Box[Nexus_5,locale=null,NOTNIGHT,NO_ACCESSIBILITY].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
...-_Localization_Settings_Box[Pixel_6_Pro,locale=null,NIGHT,NO_ACCESSIBILITY].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
...ocalization_Settings_Box[Pixel_6_Pro,locale=null,NOTNIGHT,NO_ACCESSIBILITY].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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.