Skip to content

Commit 6dd9aaa

Browse files
committed
Migrate search dashboard to Compose
1 parent 74e63d4 commit 6dd9aaa

File tree

14 files changed

+191
-211
lines changed

14 files changed

+191
-211
lines changed

app/src/main/res/layout/fragment_search_dashboard.xml

Lines changed: 0 additions & 76 deletions
This file was deleted.

app/src/main/res/navigation/navigation.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<fragment
1212
android:id="@+id/searchDashboard"
13-
android:name="com.github.sikv.photos.ui.fragment.SearchDashboardFragment"
13+
android:name="com.github.sikv.photos.search.ui.SearchDashboardFragment"
1414
android:label="@string/search_dashboard" />
1515

1616
<fragment
@@ -25,7 +25,7 @@
2525

2626
<fragment
2727
android:id="@+id/search"
28-
android:name="com.github.sikv.photos.search.SearchFragment"
28+
android:name="com.github.sikv.photos.search.ui.SearchFragment"
2929
android:label="@string/search">
3030

3131
<argument

feature/recommendations/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ android {
1010

1111
buildFeatures {
1212
compose true
13-
viewBinding true
1413
}
1514

1615
composeOptions {
@@ -26,19 +25,18 @@ dependencies {
2625
implementation project(":common")
2726
implementation project(':common-ui')
2827

29-
implementation libs.androidx.fragment
3028
implementation libs.androidx.lifecycle.viewmodel
3129

3230
// Used for PullRefresh.
3331
implementation libs.androidx.compose.material
3432

3533
implementation libs.androidx.compose.material3
36-
implementation libs.accompanist.themeadapter.material3
3734
implementation libs.androidx.lifecycle.viewmodel.compose
3835

3936
implementation libs.inject
4037
kapt libs.hilt.compiler
4138
implementation libs.hilt.android
39+
implementation libs.androidx.hilt.navigation.compose
4240

4341
implementation libs.coroutines.core
4442

feature/recommendations/src/main/java/com/github/sikv/photos/recommendations/RecommendationsScreen.kt renamed to feature/recommendations/src/main/java/com/github/sikv/photos/recommendations/Recommendations.kt

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,79 @@ package com.github.sikv.photos.recommendations
22

33
import androidx.compose.foundation.background
44
import androidx.compose.foundation.clickable
5-
import androidx.compose.foundation.layout.*
5+
import androidx.compose.foundation.layout.Arrangement
6+
import androidx.compose.foundation.layout.Box
7+
import androidx.compose.foundation.layout.Column
8+
import androidx.compose.foundation.layout.Spacer
9+
import androidx.compose.foundation.layout.aspectRatio
10+
import androidx.compose.foundation.layout.height
11+
import androidx.compose.foundation.layout.padding
612
import androidx.compose.foundation.lazy.grid.GridCells
713
import androidx.compose.foundation.lazy.grid.GridItemSpan
814
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
915
import androidx.compose.material.ExperimentalMaterialApi
1016
import androidx.compose.material.pullrefresh.PullRefreshIndicator
1117
import androidx.compose.material.pullrefresh.pullRefresh
1218
import androidx.compose.material.pullrefresh.rememberPullRefreshState
13-
import androidx.compose.material3.*
19+
import androidx.compose.material3.Button
20+
import androidx.compose.material3.LinearProgressIndicator
21+
import androidx.compose.material3.MaterialTheme
22+
import androidx.compose.material3.Surface
23+
import androidx.compose.material3.Text
1424
import androidx.compose.runtime.Composable
25+
import androidx.compose.runtime.collectAsState
26+
import androidx.compose.runtime.getValue
1527
import androidx.compose.ui.Alignment
1628
import androidx.compose.ui.Modifier
1729
import androidx.compose.ui.input.nestedscroll.nestedScroll
1830
import androidx.compose.ui.res.colorResource
1931
import androidx.compose.ui.res.stringResource
2032
import androidx.compose.ui.text.style.TextAlign
2133
import androidx.compose.ui.unit.dp
34+
import androidx.hilt.navigation.compose.hiltViewModel
2235
import com.github.sikv.photos.common.ui.NetworkImage
2336
import com.github.sikv.photos.common.ui.rememberViewInteropNestedScrollConnection
2437
import com.github.sikv.photos.domain.Photo
2538

2639
@OptIn(ExperimentalMaterialApi::class)
2740
@Composable
28-
fun RecommendationsScreen(
29-
isRefreshing: Boolean,
30-
photos: List<Photo>,
31-
onPhotoPressed: (Photo) -> Unit,
32-
isNextPageLoading: Boolean,
33-
onLoadMore: () -> Unit,
34-
onRefresh: () -> Unit,
41+
fun Recommendations(
3542
modifier: Modifier = Modifier,
43+
viewModel: RecommendationsViewModel = hiltViewModel(),
44+
onPhotoClick: (Photo) -> Unit,
3645
) {
46+
val uiState by viewModel.uiState.collectAsState()
47+
3748
Surface(
3849
modifier = modifier,
3950
) {
40-
if (!isRefreshing && !isNextPageLoading && photos.isEmpty()) {
51+
if (!uiState.isLoading && !uiState.isNextPageLoading && uiState.photos.isEmpty()) {
4152
NoRecommendations(
42-
onRefreshPressed = onRefresh
53+
onRefreshPressed = {
54+
viewModel.loadRecommendations(refresh = true)
55+
}
4356
)
4457
} else {
4558
val pullRefreshState = rememberPullRefreshState(
46-
refreshing = isRefreshing,
47-
onRefresh = onRefresh
59+
refreshing = uiState.isLoading,
60+
onRefresh = {
61+
viewModel.loadRecommendations(refresh = true)
62+
}
4863
)
4964
Box(
5065
modifier = Modifier
5166
.pullRefresh(pullRefreshState)
5267
) {
5368
Recommendations(
54-
photos = photos,
55-
onPhotoPressed = onPhotoPressed,
56-
isNextPageLoading = isNextPageLoading,
57-
onLoadMore = onLoadMore,
69+
photos = uiState.photos,
70+
onPhotoClick = onPhotoClick,
71+
isNextPageLoading = uiState.isNextPageLoading,
72+
onLoadMore = {
73+
viewModel.loadRecommendations()
74+
},
5875
)
5976
PullRefreshIndicator(
60-
refreshing = isRefreshing,
77+
refreshing = uiState.isLoading,
6178
state = pullRefreshState,
6279
modifier = Modifier
6380
.align(Alignment.TopCenter),
@@ -98,7 +115,7 @@ private fun NoRecommendations(
98115
@Composable
99116
private fun Recommendations(
100117
photos: List<Photo>,
101-
onPhotoPressed: (Photo) -> Unit,
118+
onPhotoClick: (Photo) -> Unit,
102119
isNextPageLoading: Boolean,
103120
onLoadMore: () -> Unit,
104121
cellsCount: Int = 3,
@@ -127,7 +144,7 @@ private fun Recommendations(
127144
modifier = Modifier
128145
.aspectRatio(1f)
129146
.clickable {
130-
onPhotoPressed(photos[index])
147+
onPhotoClick(photos[index])
131148
}
132149
)
133150
}

feature/recommendations/src/main/java/com/github/sikv/photos/recommendations/RecommendationsFragment.kt

Lines changed: 0 additions & 61 deletions
This file was deleted.

feature/search/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ android {
99
namespace 'com.github.sikv.photos.search'
1010

1111
buildFeatures {
12+
compose true
1213
viewBinding true
1314
}
15+
16+
composeOptions {
17+
kotlinCompilerExtensionVersion libs.versions.composeCompiler.get()
18+
}
1419
}
1520

1621
dependencies {
@@ -19,15 +24,22 @@ dependencies {
1924
implementation project(':config')
2025
implementation project(':common')
2126
implementation project(':common-ui')
27+
implementation project(':compose-ui')
2228
implementation project(':navigation')
2329
implementation project(':photo-list-ui')
30+
implementation project(':feature:recommendations')
2431

2532
implementation libs.material
2633
implementation libs.androidx.fragment
2734

35+
implementation libs.androidx.compose.material3
36+
implementation libs.accompanist.themeadapter.material3
37+
implementation libs.androidx.lifecycle.viewmodel.compose
38+
2839
implementation libs.inject
2940
kapt libs.hilt.compiler
3041
implementation libs.hilt.android
42+
implementation libs.androidx.hilt.navigation.compose
3143

3244
implementation libs.androidx.paging.runtime
3345
}

0 commit comments

Comments
 (0)