Skip to content

Commit 256f74b

Browse files
committed
Better background color management and better favorite collections layout
1 parent c707e02 commit 256f74b

File tree

6 files changed

+156
-136
lines changed

6 files changed

+156
-136
lines changed

app/src/main/java/net/opatry/speedrun/emea/MainActivity.kt

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,24 @@
2222
package net.opatry.speedrun.emea
2323

2424
import android.os.Bundle
25-
import android.util.Config
2625
import androidx.activity.compose.setContent
2726
import androidx.appcompat.app.AppCompatActivity
2827
import androidx.compose.foundation.Canvas
2928
import androidx.compose.foundation.ExperimentalFoundationApi
3029
import androidx.compose.foundation.layout.fillMaxSize
31-
import androidx.compose.material.MaterialTheme
32-
import androidx.compose.material.Surface
3330
import androidx.compose.runtime.Composable
3431
import androidx.compose.runtime.mutableStateOf
3532
import androidx.compose.runtime.remember
3633
import androidx.compose.ui.Modifier
3734
import androidx.compose.ui.geometry.Offset
3835
import androidx.compose.ui.graphics.Color
39-
import androidx.compose.ui.res.booleanResource
4036
import androidx.compose.ui.unit.dp
4137
import androidx.core.view.WindowCompat
4238
import dev.chrisbanes.accompanist.insets.ProvideWindowInsets
4339
import net.opatry.speedrun.emea.ui.home.HomeScreen
40+
import net.opatry.speedrun.emea.ui.theme.MySootheTheme
4441
import net.opatry.speedrun.emea.ui.welcome.LoginScreen
4542
import net.opatry.speedrun.emea.ui.welcome.WelcomeScreen
46-
import net.opatry.speedrun.emea.ui.theme.MySootheTheme
4743

4844
@ExperimentalFoundationApi
4945
class MainActivity : AppCompatActivity() {
@@ -70,21 +66,19 @@ enum class AppState {
7066
fun MySootheApp() {
7167
ProvideWindowInsets {
7268
MySootheTheme {
73-
Surface(color = MaterialTheme.colors.background) {
74-
val (appState, setAppState) = remember { mutableStateOf(AppState.OnBoarding) }
75-
when (appState) {
76-
AppState.OnBoarding -> WelcomeScreen {
77-
setAppState(AppState.Login)
78-
}
79-
AppState.Login -> LoginScreen {
80-
setAppState(AppState.Home)
81-
}
82-
AppState.Home -> HomeScreen()
69+
val (appState, setAppState) = remember { mutableStateOf(AppState.OnBoarding) }
70+
when (appState) {
71+
AppState.OnBoarding -> WelcomeScreen {
72+
setAppState(AppState.Login)
8373
}
84-
val showGrid = true // TODO booleanResource(id = R.bool.is_debug)
85-
if (showGrid) {
86-
GridLayer()
74+
AppState.Login -> LoginScreen {
75+
setAppState(AppState.Home)
8776
}
77+
AppState.Home -> HomeScreen()
78+
}
79+
val showGrid = true // TODO booleanResource(id = R.bool.is_debug)
80+
if (showGrid) {
81+
GridLayer()
8882
}
8983
}
9084
}

app/src/main/java/net/opatry/speedrun/emea/ui/home/HomeScreen.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ import net.opatry.speedrun.emea.data.mySootheBodyActivities
5555
import net.opatry.speedrun.emea.data.mySootheCollections
5656
import net.opatry.speedrun.emea.data.mySootheMindActivities
5757
import net.opatry.speedrun.emea.ui.component.SearchComponent
58-
import net.opatry.speedrun.emea.ui.home.component.FavoriteCollections
5958
import net.opatry.speedrun.emea.ui.home.component.Activities
59+
import net.opatry.speedrun.emea.ui.home.component.FavoriteCollections
6060
import net.opatry.speedrun.emea.ui.theme.MySootheTheme
6161

6262
private enum class HomeTabs(
@@ -70,10 +70,11 @@ private enum class HomeTabs(
7070
@ExperimentalFoundationApi
7171
@Composable
7272
fun HomeScreen() {
73-
7473
val (selectedTab, setSelectedTab) = remember { mutableStateOf(HomeTabs.Home) }
7574
val tabs = HomeTabs.values()
75+
7676
Scaffold(
77+
backgroundColor = MaterialTheme.colors.background,
7778
topBar = {},
7879
floatingActionButton = {
7980
FloatingActionButton(

app/src/main/java/net/opatry/speedrun/emea/ui/home/component/ActivityComponent.kt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,29 @@ package net.opatry.speedrun.emea.ui.home.component
2424

2525
import androidx.compose.foundation.Image
2626
import androidx.compose.foundation.clickable
27+
import androidx.compose.foundation.interaction.MutableInteractionSource
2728
import androidx.compose.foundation.layout.Column
29+
import androidx.compose.foundation.layout.PaddingValues
30+
import androidx.compose.foundation.layout.Spacer
2831
import androidx.compose.foundation.layout.aspectRatio
2932
import androidx.compose.foundation.layout.fillMaxWidth
30-
import androidx.compose.foundation.layout.padding
3133
import androidx.compose.foundation.layout.paddingFromBaseline
3234
import androidx.compose.foundation.layout.width
3335
import androidx.compose.foundation.lazy.LazyRow
3436
import androidx.compose.foundation.lazy.items
3537
import androidx.compose.foundation.shape.CircleShape
3638
import androidx.compose.material.Text
39+
import androidx.compose.material.ripple.rememberRipple
3740
import androidx.compose.runtime.Composable
41+
import androidx.compose.runtime.remember
3842
import androidx.compose.ui.Alignment
3943
import androidx.compose.ui.Modifier
4044
import androidx.compose.ui.draw.clip
4145
import androidx.compose.ui.graphics.painter.Painter
4246
import androidx.compose.ui.layout.ContentScale
4347
import androidx.compose.ui.res.painterResource
4448
import androidx.compose.ui.res.stringResource
49+
import androidx.compose.ui.semantics.Role
4550
import androidx.compose.ui.text.style.TextAlign
4651
import androidx.compose.ui.tooling.preview.Preview
4752
import androidx.compose.ui.unit.dp
@@ -59,12 +64,16 @@ fun Activities(
5964
) {
6065
Column(Modifier.fillMaxWidth()) {
6166
SectionTitle(title, modifier)
62-
LazyRow(Modifier.fillMaxWidth().padding(horizontal = 8.dp)) {
67+
LazyRow(
68+
Modifier.fillMaxWidth(),
69+
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 0.dp)
70+
) {
6371
items(activities) { activity ->
6472
ActivityComponent(
6573
stringResource(activity.name),
6674
painterResource(activity.picture)
6775
)
76+
Spacer(Modifier.width(8.dp))
6877
}
6978
}
7079
}
@@ -74,13 +83,18 @@ fun Activities(
7483
fun ActivityComponent(name: String, picture: Painter) {
7584
Column(
7685
// TODO circle ripple
77-
Modifier.clickable { },
86+
Modifier
87+
.clickable(
88+
enabled = true,
89+
role = Role.Button,
90+
interactionSource = remember { MutableInteractionSource() },
91+
indication = rememberRipple(bounded = false)
92+
) { },
7893
horizontalAlignment = Alignment.CenterHorizontally) {
7994
Image(
8095
picture,
8196
null,
8297
Modifier
83-
.padding(horizontal = 4.dp)
8498
.width(88.dp)
8599
.aspectRatio(1f)
86100
.clip(CircleShape),

app/src/main/java/net/opatry/speedrun/emea/ui/home/component/FavoriteCollectionComponent.kt

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import androidx.compose.foundation.clickable
2828
import androidx.compose.foundation.layout.Column
2929
import androidx.compose.foundation.layout.PaddingValues
3030
import androidx.compose.foundation.layout.Row
31+
import androidx.compose.foundation.layout.Spacer
3132
import androidx.compose.foundation.layout.aspectRatio
3233
import androidx.compose.foundation.layout.fillMaxHeight
3334
import androidx.compose.foundation.layout.fillMaxWidth
@@ -59,37 +60,42 @@ import net.opatry.speedrun.emea.ui.theme.typography
5960
fun FavoriteCollections(collections: List<MySootheCollection>, modifier: Modifier = Modifier) {
6061
Column(Modifier.fillMaxWidth()) {
6162
SectionTitle(stringResource(R.string.favorite_collections), modifier)
62-
// FIXME is it a single horizontal list or 2 separate list
63-
// FIXME is it a 3x2 or 2x3?
64-
// FIXME grid 3 cols
65-
// LazyVerticalGrid(GridCells.Adaptive(200.dp),Modifier.fillMaxWidth()) {
63+
// FIXME Using a grid?
64+
// LazyVerticalGrid(GridCells.Adaptive(192.dp),Modifier.fillMaxWidth()) {
6665
// items(collections) { collection ->
6766
// CollectionCard(stringResource(collection.name), painterResource(collection.picture))
6867
// }
6968
// }
70-
val firstRow = collections.subList(0, collections.size / 2)
71-
val secondRow = collections.subList(collections.size / 2, collections.size)
72-
73-
listOf(firstRow, secondRow).forEach { row ->
74-
LazyRow(
75-
Modifier.fillMaxWidth(),
76-
contentPadding = PaddingValues(8.dp)
77-
) {
78-
items(row) { collection ->
79-
CollectionCard(stringResource(collection.name), painterResource(collection.picture))
69+
LazyRow(
70+
Modifier.fillMaxWidth(),
71+
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 0.dp)
72+
) {
73+
items(collections.chunked(2)) { column ->
74+
val first = column.first()
75+
val second = column.last()
76+
Column {
77+
CollectionCard(
78+
stringResource(first.name),
79+
painterResource(first.picture),
80+
Modifier.width(192.dp).height(56.dp)
81+
)
82+
Spacer(Modifier.height(8.dp))
83+
CollectionCard(
84+
stringResource(second.name),
85+
painterResource(second.picture),
86+
Modifier.width(192.dp).height(56.dp)
87+
)
8088
}
89+
Spacer(Modifier.width(8.dp))
8190
}
8291
}
8392
}
8493
}
8594

8695
@Composable
87-
private fun CollectionCard(name: String, picture: Painter) {
96+
private fun CollectionCard(name: String, picture: Painter, modifier: Modifier = Modifier) {
8897
Card(
89-
Modifier
90-
.padding(end = 8.dp)
91-
.width(192.dp)
92-
.height(56.dp),
98+
modifier,
9399
shape = MaterialTheme.shapes.small
94100
) {
95101
Row(
@@ -107,7 +113,8 @@ private fun CollectionCard(name: String, picture: Painter) {
107113
Text(
108114
name,
109115
Modifier.padding(4.dp),
110-
style = typography.h3
116+
style = typography.h3,
117+
color = MaterialTheme.colors.onSurface
111118
)
112119
}
113120
}
@@ -118,7 +125,7 @@ private fun CollectionCard(name: String, picture: Painter) {
118125
@Composable
119126
fun CollectionsLightPreview() {
120127
MySootheTheme {
121-
FavoriteCollections(mySootheCollections)
128+
FavoriteCollections(mySootheCollections, Modifier.padding(horizontal = 16.dp))
122129
}
123130
}
124131

@@ -127,6 +134,6 @@ fun CollectionsLightPreview() {
127134
@Composable
128135
fun CollectionsDarkPreview() {
129136
MySootheTheme(darkTheme = true) {
130-
FavoriteCollections(mySootheCollections)
137+
FavoriteCollections(mySootheCollections, Modifier.padding(horizontal = 16.dp))
131138
}
132139
}

0 commit comments

Comments
 (0)