Skip to content

Commit 67ffc93

Browse files
committed
update home screen ui
1 parent 6f1c66b commit 67ffc93

File tree

6 files changed

+170
-394
lines changed

6 files changed

+170
-394
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.vanced.store.ui.component
2+
3+
import androidx.compose.foundation.layout.*
4+
import androidx.compose.material3.ProvideTextStyle
5+
import androidx.compose.runtime.Composable
6+
import androidx.compose.ui.Alignment
7+
import androidx.compose.ui.Modifier
8+
import androidx.compose.ui.draw.clip
9+
import com.vanced.store.ui.theme.VSTheme
10+
11+
@Composable
12+
fun BrowseAppCard(
13+
icon: @Composable () -> Unit,
14+
title: @Composable () -> Unit,
15+
description: @Composable () -> Unit,
16+
labels: @Composable () -> Unit,
17+
actions: @Composable () -> Unit,
18+
modifier: Modifier = Modifier,
19+
) {
20+
VSElevatedCard(
21+
modifier = modifier,
22+
shape = VSTheme.shapes.large
23+
) {
24+
Box(
25+
modifier = Modifier
26+
.fillMaxSize()
27+
.padding(VSTheme.spacing.extraLarge)
28+
) {
29+
Row(
30+
modifier = Modifier.align(Alignment.TopEnd),
31+
horizontalArrangement = Arrangement.spacedBy(VSTheme.spacing.extraSmall),
32+
verticalAlignment = Alignment.CenterVertically
33+
) {
34+
labels()
35+
}
36+
Row(
37+
modifier = Modifier
38+
.fillMaxSize()
39+
.align(Alignment.Center),
40+
horizontalArrangement = Arrangement.spacedBy(VSTheme.spacing.large)
41+
) {
42+
Box(modifier = Modifier.clip(VSTheme.shapes.medium)) {
43+
icon()
44+
}
45+
Column(
46+
modifier = Modifier
47+
.fillMaxWidth()
48+
.padding(top = VSTheme.spacing.extraSmall),
49+
verticalArrangement = Arrangement.spacedBy(VSTheme.spacing.medium)
50+
) {
51+
ProvideTextStyle(VSTheme.typography.titleMedium) {
52+
title()
53+
}
54+
ProvideTextStyle(VSTheme.typography.bodySmall) {
55+
description()
56+
}
57+
Row(
58+
modifier = Modifier.align(Alignment.End),
59+
horizontalArrangement = Arrangement.spacedBy(VSTheme.spacing.small)
60+
) {
61+
actions()
62+
}
63+
}
64+
}
65+
}
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
package com.vanced.store.ui.screen
22

3-
import androidx.compose.animation.AnimatedContent
4-
import androidx.compose.animation.AnimatedContentScope
5-
import androidx.compose.animation.ContentTransform
6-
import androidx.compose.animation.with
73
import androidx.compose.foundation.layout.fillMaxSize
84
import androidx.compose.foundation.layout.padding
95
import androidx.compose.foundation.lazy.grid.items
10-
import androidx.compose.foundation.lazy.items
116
import androidx.compose.material3.*
127
import androidx.compose.runtime.Composable
138
import androidx.compose.ui.Modifier
149
import androidx.compose.ui.res.painterResource
1510
import androidx.compose.ui.res.stringResource
1611
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
1712
import com.vanced.store.R
18-
import com.vanced.store.domain.manager.BrowseLayoutMode
1913
import com.vanced.store.domain.model.DomainBrowseApp
2014
import com.vanced.store.ui.component.VSSwipeRefresh
21-
import com.vanced.store.ui.theme.VSTheme
2215
import com.vanced.store.ui.util.category
2316
import com.vanced.store.ui.viewmodel.BrowseViewModel
2417
import com.vanced.store.ui.widget.*
@@ -38,10 +31,6 @@ fun BrowseScreen(
3831
searchButtonEnabled = state.isLoaded,
3932
onSearchClick = onSearchClick,
4033
scrollBehavior = scrollBehavior,
41-
layoutMode = viewModel.layoutMode,
42-
onChangeLayoutMode = { layoutMode ->
43-
viewModel.switchLayoutMode(layoutMode)
44-
}
4534
)
4635
}
4736
) {
@@ -58,15 +47,12 @@ fun BrowseScreen(
5847
is BrowseViewModel.State.Loading -> {
5948
BrowseScreenLoading(
6049
modifier = Modifier.fillMaxSize(),
61-
layoutMode = viewModel.layoutMode
6250
)
6351
}
6452
is BrowseViewModel.State.Loaded -> {
6553
BrowseScreenApps(
66-
modifier = Modifier.fillMaxSize(),
6754
pinnedApps = state.pinnedApps,
6855
repositoryApps = state.repoApps,
69-
layoutMode = viewModel.layoutMode
7056
)
7157
}
7258
is BrowseViewModel.State.Error -> {
@@ -81,78 +67,39 @@ fun BrowseScreen(
8167
fun BrowseScreenApps(
8268
pinnedApps: List<DomainBrowseApp>,
8369
repositoryApps: List<DomainBrowseApp>,
84-
layoutMode: BrowseLayoutMode,
85-
modifier: Modifier = Modifier,
8670
) {
87-
AnimatedContent(
88-
modifier = modifier,
89-
targetState = layoutMode,
90-
transitionSpec = { layoutModeAnimationSpec() }
91-
) { animatedLayoutMode ->
92-
when (animatedLayoutMode) {
93-
BrowseLayoutMode.LIST -> {
94-
CardLazyColumn(modifier = Modifier.fillMaxSize()) {
95-
items(pinnedApps) { app ->
96-
LoadedListBrowseAppCard(
97-
modifier = Modifier.fillParentMaxWidth(),
98-
appName = app.appName,
99-
appDescription = app.appDescription,
100-
supportsNonroot = app.supportsNonroot,
101-
supportsRoot = app.supportsRoot
102-
)
103-
}
71+
CardLazyVerticalGrid(modifier = Modifier.fillMaxSize()) {
72+
if (pinnedApps.isNotEmpty()) {
73+
category(title = {
74+
Text(stringResource(id = R.string.browse_category_vanced))
75+
}) {
76+
items(pinnedApps) { app ->
77+
BrowseAppCardLoaded(
78+
appName = app.appName,
79+
appDescription = app.appDescription,
80+
supportsNonroot = app.supportsNonroot,
81+
supportsRoot = app.supportsRoot,
82+
onDetailsClick = {
10483

105-
if (pinnedApps.isNotEmpty() && repositoryApps.isNotEmpty()) {
106-
item {
107-
Divider(
108-
modifier = Modifier
109-
.fillParentMaxWidth()
110-
.padding(horizontal = VSTheme.spacing.large)
111-
)
11284
}
113-
}
114-
115-
items(repositoryApps) { app ->
116-
LoadedListBrowseAppCard(
117-
modifier = Modifier.fillParentMaxWidth(),
118-
appName = app.appName,
119-
appDescription = app.appDescription,
120-
supportsNonroot = app.supportsNonroot,
121-
supportsRoot = app.supportsRoot
122-
)
123-
}
85+
)
12486
}
12587
}
126-
BrowseLayoutMode.GRID -> {
127-
CardLazyVerticalGrid(modifier = Modifier.fillMaxSize()) {
128-
if (pinnedApps.isNotEmpty()) {
129-
category(title = {
130-
Text(stringResource(id = R.string.browse_category_vanced))
131-
}) {
132-
items(pinnedApps) { app ->
133-
LoadedGridBrowseAppCard(
134-
appName = app.appName,
135-
appDescription = app.appDescription,
136-
supportsNonroot = app.supportsNonroot,
137-
supportsRoot = app.supportsRoot
138-
)
139-
}
140-
}
141-
}
142-
if (repositoryApps.isNotEmpty()) {
143-
category(title = {
144-
Text(stringResource(id = R.string.browse_category_apps))
145-
}) {
146-
items(repositoryApps) { app ->
147-
LoadedGridBrowseAppCard(
148-
appName = app.appName,
149-
appDescription = app.appDescription,
150-
supportsNonroot = app.supportsNonroot,
151-
supportsRoot = app.supportsRoot
152-
)
153-
}
88+
}
89+
if (repositoryApps.isNotEmpty()) {
90+
category(title = {
91+
Text(stringResource(id = R.string.browse_category_apps))
92+
}) {
93+
items(repositoryApps) { app ->
94+
BrowseAppCardLoaded(
95+
appName = app.appName,
96+
appDescription = app.appDescription,
97+
supportsNonroot = app.supportsNonroot,
98+
supportsRoot = app.supportsRoot,
99+
onDetailsClick = {
100+
154101
}
155-
}
102+
)
156103
}
157104
}
158105
}
@@ -162,71 +109,29 @@ fun BrowseScreenApps(
162109
@Composable
163110
fun BrowseScreenLoading(
164111
modifier: Modifier = Modifier,
165-
layoutMode: BrowseLayoutMode,
166112
) {
167-
when (layoutMode) {
168-
BrowseLayoutMode.LIST -> {
169-
CardLazyColumn(
170-
modifier = modifier,
171-
scrollEnabled = false
172-
) {
173-
items(10) {
174-
LoadingListBrowseAppCard(
175-
modifier = Modifier.fillParentMaxWidth()
176-
)
177-
}
178-
}
179-
}
180-
BrowseLayoutMode.GRID -> {
181-
CardLazyVerticalGrid(
182-
modifier = modifier,
183-
scrollEnabled = false
184-
) {
185-
items(10) {
186-
LoadingGridBrowseAppCard()
187-
}
188-
}
113+
CardLazyVerticalGrid(
114+
modifier = modifier,
115+
scrollEnabled = false
116+
) {
117+
items(10) {
118+
BrowseAppCardLoading()
189119
}
190120
}
191121
}
192122

193123
@Composable
194124
private fun AppBar(
195125
onSearchClick: () -> Unit,
196-
onChangeLayoutMode: (BrowseLayoutMode) -> Unit,
197-
layoutMode: BrowseLayoutMode,
198126
scrollBehavior: TopAppBarScrollBehavior,
199127
modifier: Modifier = Modifier,
200128
searchButtonEnabled: Boolean = true,
201129
) {
202130
SmallTopAppBar(
203131
modifier = modifier,
204-
// scrollBehavior = scrollBehavior,
132+
scrollBehavior = scrollBehavior,
205133
title = { Text(stringResource(id = R.string.app_name)) },
206134
actions = {
207-
IconButton(onClick = {
208-
onChangeLayoutMode(layoutMode.opposite())
209-
}) {
210-
AnimatedContent(
211-
targetState = layoutMode,
212-
transitionSpec = { layoutModeAnimationSpec() }
213-
) { animatedLayoutMode ->
214-
when (animatedLayoutMode) {
215-
BrowseLayoutMode.LIST -> {
216-
Icon(
217-
painter = painterResource(id = R.drawable.ic_list),
218-
contentDescription = null
219-
)
220-
}
221-
BrowseLayoutMode.GRID -> {
222-
Icon(
223-
painter = painterResource(id = R.drawable.ic_grid),
224-
contentDescription = null
225-
)
226-
}
227-
}
228-
}
229-
}
230135
IconButton(
231136
onClick = onSearchClick,
232137
enabled = searchButtonEnabled
@@ -238,20 +143,4 @@ private fun AppBar(
238143
}
239144
}
240145
)
241-
}
242-
243-
private fun AnimatedContentScope<BrowseLayoutMode>.layoutModeAnimationSpec(): ContentTransform {
244-
return if (BrowseLayoutMode.LIST isTransitioningTo BrowseLayoutMode.GRID) {
245-
slideIntoContainer(
246-
towards = AnimatedContentScope.SlideDirection.Start
247-
) with slideOutOfContainer(
248-
towards = AnimatedContentScope.SlideDirection.Start
249-
)
250-
} else {
251-
slideIntoContainer(
252-
towards = AnimatedContentScope.SlideDirection.End
253-
) with slideOutOfContainer(
254-
towards = AnimatedContentScope.SlideDirection.End
255-
)
256-
}
257146
}

app/src/main/java/com/vanced/store/ui/viewmodel/BrowseViewModel.kt

-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ class BrowseViewModel(
3131
var state by mutableStateOf<State>(State.Loading)
3232
private set
3333

34-
var layoutMode by mutableStateOf(preferenceManager.browseLayoutMode)
35-
private set
36-
3734
fun loadApps() {
3835
viewModelScope.launch {
3936
try {
@@ -52,7 +49,6 @@ class BrowseViewModel(
5249
}
5350

5451
fun switchLayoutMode(newMode: BrowseLayoutMode) {
55-
layoutMode = newMode
5652
preferenceManager.browseLayoutMode = newMode
5753
}
5854

0 commit comments

Comments
 (0)