Skip to content

Commit

Permalink
Migrate search dashboard to Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
SIKV committed Jun 15, 2024
1 parent 74e63d4 commit 6dd9aaa
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 211 deletions.
76 changes: 0 additions & 76 deletions app/src/main/res/layout/fragment_search_dashboard.xml

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/res/navigation/navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

<fragment
Expand All @@ -25,7 +25,7 @@

<fragment
android:id="@+id/search"
android:name="com.github.sikv.photos.search.SearchFragment"
android:name="com.github.sikv.photos.search.ui.SearchFragment"
android:label="@string/search">

<argument
Expand Down
4 changes: 1 addition & 3 deletions feature/recommendations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ android {

buildFeatures {
compose true
viewBinding true
}

composeOptions {
Expand All @@ -26,19 +25,18 @@ dependencies {
implementation project(":common")
implementation project(':common-ui')

implementation libs.androidx.fragment
implementation libs.androidx.lifecycle.viewmodel

// Used for PullRefresh.
implementation libs.androidx.compose.material

implementation libs.androidx.compose.material3
implementation libs.accompanist.themeadapter.material3
implementation libs.androidx.lifecycle.viewmodel.compose

implementation libs.inject
kapt libs.hilt.compiler
implementation libs.hilt.android
implementation libs.androidx.hilt.navigation.compose

implementation libs.coroutines.core

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,79 @@ package com.github.sikv.photos.recommendations

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.*
import androidx.compose.material3.Button
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.github.sikv.photos.common.ui.NetworkImage
import com.github.sikv.photos.common.ui.rememberViewInteropNestedScrollConnection
import com.github.sikv.photos.domain.Photo

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun RecommendationsScreen(
isRefreshing: Boolean,
photos: List<Photo>,
onPhotoPressed: (Photo) -> Unit,
isNextPageLoading: Boolean,
onLoadMore: () -> Unit,
onRefresh: () -> Unit,
fun Recommendations(
modifier: Modifier = Modifier,
viewModel: RecommendationsViewModel = hiltViewModel(),
onPhotoClick: (Photo) -> Unit,
) {
val uiState by viewModel.uiState.collectAsState()

Surface(
modifier = modifier,
) {
if (!isRefreshing && !isNextPageLoading && photos.isEmpty()) {
if (!uiState.isLoading && !uiState.isNextPageLoading && uiState.photos.isEmpty()) {
NoRecommendations(
onRefreshPressed = onRefresh
onRefreshPressed = {
viewModel.loadRecommendations(refresh = true)
}
)
} else {
val pullRefreshState = rememberPullRefreshState(
refreshing = isRefreshing,
onRefresh = onRefresh
refreshing = uiState.isLoading,
onRefresh = {
viewModel.loadRecommendations(refresh = true)
}
)
Box(
modifier = Modifier
.pullRefresh(pullRefreshState)
) {
Recommendations(
photos = photos,
onPhotoPressed = onPhotoPressed,
isNextPageLoading = isNextPageLoading,
onLoadMore = onLoadMore,
photos = uiState.photos,
onPhotoClick = onPhotoClick,
isNextPageLoading = uiState.isNextPageLoading,
onLoadMore = {
viewModel.loadRecommendations()
},
)
PullRefreshIndicator(
refreshing = isRefreshing,
refreshing = uiState.isLoading,
state = pullRefreshState,
modifier = Modifier
.align(Alignment.TopCenter),
Expand Down Expand Up @@ -98,7 +115,7 @@ private fun NoRecommendations(
@Composable
private fun Recommendations(
photos: List<Photo>,
onPhotoPressed: (Photo) -> Unit,
onPhotoClick: (Photo) -> Unit,
isNextPageLoading: Boolean,
onLoadMore: () -> Unit,
cellsCount: Int = 3,
Expand Down Expand Up @@ -127,7 +144,7 @@ private fun Recommendations(
modifier = Modifier
.aspectRatio(1f)
.clickable {
onPhotoPressed(photos[index])
onPhotoClick(photos[index])
}
)
}
Expand Down

This file was deleted.

12 changes: 12 additions & 0 deletions feature/search/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ android {
namespace 'com.github.sikv.photos.search'

buildFeatures {
compose true
viewBinding true
}

composeOptions {
kotlinCompilerExtensionVersion libs.versions.composeCompiler.get()
}
}

dependencies {
Expand All @@ -19,15 +24,22 @@ dependencies {
implementation project(':config')
implementation project(':common')
implementation project(':common-ui')
implementation project(':compose-ui')
implementation project(':navigation')
implementation project(':photo-list-ui')
implementation project(':feature:recommendations')

implementation libs.material
implementation libs.androidx.fragment

implementation libs.androidx.compose.material3
implementation libs.accompanist.themeadapter.material3
implementation libs.androidx.lifecycle.viewmodel.compose

implementation libs.inject
kapt libs.hilt.compiler
implementation libs.hilt.android
implementation libs.androidx.hilt.navigation.compose

implementation libs.androidx.paging.runtime
}
Loading

0 comments on commit 6dd9aaa

Please sign in to comment.