1
1
package com.vanced.store.ui.screen
2
2
3
- import androidx.compose.animation.AnimatedContent
4
- import androidx.compose.animation.AnimatedContentScope
5
- import androidx.compose.animation.ContentTransform
6
- import androidx.compose.animation.with
7
3
import androidx.compose.foundation.layout.fillMaxSize
8
4
import androidx.compose.foundation.layout.padding
9
5
import androidx.compose.foundation.lazy.grid.items
10
- import androidx.compose.foundation.lazy.items
11
6
import androidx.compose.material3.*
12
7
import androidx.compose.runtime.Composable
13
8
import androidx.compose.ui.Modifier
14
9
import androidx.compose.ui.res.painterResource
15
10
import androidx.compose.ui.res.stringResource
16
11
import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
17
12
import com.vanced.store.R
18
- import com.vanced.store.domain.manager.BrowseLayoutMode
19
13
import com.vanced.store.domain.model.DomainBrowseApp
20
14
import com.vanced.store.ui.component.VSSwipeRefresh
21
- import com.vanced.store.ui.theme.VSTheme
22
15
import com.vanced.store.ui.util.category
23
16
import com.vanced.store.ui.viewmodel.BrowseViewModel
24
17
import com.vanced.store.ui.widget.*
@@ -38,10 +31,6 @@ fun BrowseScreen(
38
31
searchButtonEnabled = state.isLoaded,
39
32
onSearchClick = onSearchClick,
40
33
scrollBehavior = scrollBehavior,
41
- layoutMode = viewModel.layoutMode,
42
- onChangeLayoutMode = { layoutMode ->
43
- viewModel.switchLayoutMode(layoutMode)
44
- }
45
34
)
46
35
}
47
36
) {
@@ -58,15 +47,12 @@ fun BrowseScreen(
58
47
is BrowseViewModel .State .Loading -> {
59
48
BrowseScreenLoading (
60
49
modifier = Modifier .fillMaxSize(),
61
- layoutMode = viewModel.layoutMode
62
50
)
63
51
}
64
52
is BrowseViewModel .State .Loaded -> {
65
53
BrowseScreenApps (
66
- modifier = Modifier .fillMaxSize(),
67
54
pinnedApps = state.pinnedApps,
68
55
repositoryApps = state.repoApps,
69
- layoutMode = viewModel.layoutMode
70
56
)
71
57
}
72
58
is BrowseViewModel .State .Error -> {
@@ -81,78 +67,39 @@ fun BrowseScreen(
81
67
fun BrowseScreenApps (
82
68
pinnedApps : List <DomainBrowseApp >,
83
69
repositoryApps : List <DomainBrowseApp >,
84
- layoutMode : BrowseLayoutMode ,
85
- modifier : Modifier = Modifier ,
86
70
) {
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 = {
104
83
105
- if (pinnedApps.isNotEmpty() && repositoryApps.isNotEmpty()) {
106
- item {
107
- Divider (
108
- modifier = Modifier
109
- .fillParentMaxWidth()
110
- .padding(horizontal = VSTheme .spacing.large)
111
- )
112
84
}
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
+ )
124
86
}
125
87
}
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
+
154
101
}
155
- }
102
+ )
156
103
}
157
104
}
158
105
}
@@ -162,71 +109,29 @@ fun BrowseScreenApps(
162
109
@Composable
163
110
fun BrowseScreenLoading (
164
111
modifier : Modifier = Modifier ,
165
- layoutMode : BrowseLayoutMode ,
166
112
) {
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 ()
189
119
}
190
120
}
191
121
}
192
122
193
123
@Composable
194
124
private fun AppBar (
195
125
onSearchClick : () -> Unit ,
196
- onChangeLayoutMode : (BrowseLayoutMode ) -> Unit ,
197
- layoutMode : BrowseLayoutMode ,
198
126
scrollBehavior : TopAppBarScrollBehavior ,
199
127
modifier : Modifier = Modifier ,
200
128
searchButtonEnabled : Boolean = true,
201
129
) {
202
130
SmallTopAppBar (
203
131
modifier = modifier,
204
- // scrollBehavior = scrollBehavior,
132
+ scrollBehavior = scrollBehavior,
205
133
title = { Text (stringResource(id = R .string.app_name)) },
206
134
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
- }
230
135
IconButton (
231
136
onClick = onSearchClick,
232
137
enabled = searchButtonEnabled
@@ -238,20 +143,4 @@ private fun AppBar(
238
143
}
239
144
}
240
145
)
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
- }
257
146
}
0 commit comments