Skip to content

Commit

Permalink
Merge pull request #10 from azrael8576/feat/photo-search
Browse files Browse the repository at this point in the history
feat: Add PhotoSearchScreen
  • Loading branch information
azrael8576 authored Dec 2, 2023
2 parents b149591 + 4c5292e commit 465a1f1
Show file tree
Hide file tree
Showing 26 changed files with 280 additions and 99 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ android {

dependencies {
implementation(project(":feature:home"))
implementation(project(":feature:photolibrary"))
implementation(project(":feature:photo"))

// TODO Wei
// implementation(project(":feature:contactme"))
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/wei/picquest/navigation/PqNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import androidx.window.layout.DisplayFeature
import com.wei.picquest.core.designsystem.ui.DeviceOrientation
import com.wei.picquest.feature.home.home.navigation.homeGraph
import com.wei.picquest.feature.home.home.navigation.homeRoute
import com.wei.picquest.feature.photolibrary.photolibrary.navigation.photoLibraryGraph
import com.wei.picquest.feature.photo.photolibrary.navigation.navigateToPhotoLibrary
import com.wei.picquest.feature.photo.photolibrary.navigation.photoLibraryGraph
import com.wei.picquest.feature.photo.photosearch.navigation.photoSearchGraph
import com.wei.picquest.ui.PqAppState

/**
Expand Down Expand Up @@ -37,8 +39,12 @@ fun PqNavHost(
homeGraph(
navController = navController,
)
photoLibraryGraph(
photoSearchGraph(
navController = navController,
onSearchClick = navController::navigateToPhotoLibrary,
nestedGraphs = {
photoLibraryGraph(navController = navController)
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ enum class TopLevelDestination(
iconTextId = R.string.home,
titleTextId = R.string.home,
),
PHOTO_LIBRARY(
PHOTO(
selectedIcon = PqIcons.PhotoLibrary,
unselectedIcon = PqIcons.PhotoLibraryBorder,
iconTextId = R.string.photo_library,
titleTextId = R.string.photo_library,
iconTextId = R.string.photo,
titleTextId = R.string.photo,
),
CONTACT_ME(
selectedIcon = PqIcons.ContactMe,
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/wei/picquest/ui/PqApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import com.wei.picquest.core.manager.SnackbarState
import com.wei.picquest.core.utils.UiText
import com.wei.picquest.navigation.PqNavHost
import com.wei.picquest.navigation.TopLevelDestination
import timber.log.Timber

@OptIn(
ExperimentalMaterial3Api::class,
Expand Down Expand Up @@ -294,6 +295,8 @@ private fun PqBottomBar(

private fun NavDestination?.isTopLevelDestinationInHierarchy(destination: TopLevelDestination) =
this?.hierarchy?.any {
Timber.e("PQ isTopLevelDestinationInHierarchy " + it.route.toString())
Timber.e("PQ destination " + destination.name.toString())
it.route?.contains(destination.name, true) ?: false
} ?: false

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/wei/picquest/ui/PqAppState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import com.wei.picquest.core.designsystem.ui.isBookPosture
import com.wei.picquest.core.designsystem.ui.isSeparating
import com.wei.picquest.feature.home.home.navigation.homeRoute
import com.wei.picquest.feature.home.home.navigation.navigateToHome
import com.wei.picquest.feature.photolibrary.photolibrary.navigation.navigateToPhotoLibrary
import com.wei.picquest.feature.photolibrary.photolibrary.navigation.photoLibraryRoute
import com.wei.picquest.feature.photo.photosearch.navigation.navigateToPhotoSearch
import com.wei.picquest.feature.photo.photosearch.navigation.photoSearchRoute
import com.wei.picquest.navigation.TopLevelDestination
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
Expand Down Expand Up @@ -151,7 +151,7 @@ class PqAppState(
val currentTopLevelDestination: TopLevelDestination?
@Composable get() = when (currentDestination?.route) {
homeRoute -> TopLevelDestination.HOME
photoLibraryRoute -> TopLevelDestination.PHOTO_LIBRARY
photoSearchRoute -> TopLevelDestination.PHOTO
else -> null
}

Expand Down Expand Up @@ -199,7 +199,7 @@ class PqAppState(
topLevelNavOptions,
)

TopLevelDestination.PHOTO_LIBRARY -> navController.navigateToPhotoLibrary(
TopLevelDestination.PHOTO -> navController.navigateToPhotoSearch(
topLevelNavOptions,
)

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<resources>
<string name="app_name">PicQuest</string>
<string name="not_connected">⚠️ 您沒有網路連線</string>
<string name="photo_library">照片庫</string>
<string name="photo">照片</string>
<string name="home">首頁</string>
<string name="contact_me">聯絡我</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>
<string name="app_name">PicQuest</string>
<string name="not_connected">⚠️ You aren’t connected to the internet</string>
<string name="photo_library">Photo Library</string>
<string name="photo">Photo</string>
<string name="home">Home</string>
<string name="contact_me">Contact Me</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,14 @@ object PqNavigationDefaults {
fun navigationIndicatorColor() = MaterialTheme.colorScheme.primaryContainer
}

internal val previewItems = listOf("Schedule", "Home", "Contact Me")
internal val previewItems = listOf("Home", "Photo", "Contact Me")
internal val previewIcons = listOf(
PqIcons.ScheduleBorder,
PqIcons.HomeBorder,
PqIcons.PhotoLibraryBorder,
PqIcons.ContactMeBorder,
)
internal val previewSelectedIcons = listOf(
PqIcons.Schedule,
PqIcons.Home,
PqIcons.PhotoLibrary,
PqIcons.ContactMe,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.wei.picquest.core.designsystem.icon

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.CalendarMonth
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.outlined.PhotoLibrary
Expand All @@ -12,7 +11,6 @@ import androidx.compose.material.icons.rounded.ArrowBack
import androidx.compose.material.icons.rounded.ArrowBackIosNew
import androidx.compose.material.icons.rounded.ArrowForward
import androidx.compose.material.icons.rounded.ArrowForwardIos
import androidx.compose.material.icons.rounded.CalendarMonth
import androidx.compose.material.icons.rounded.Close
import androidx.compose.material.icons.rounded.GridView
import androidx.compose.material.icons.rounded.Home
Expand Down Expand Up @@ -44,8 +42,6 @@ object PqIcons {
val InfoBorder = Icons.Outlined.Info
val Home = Icons.Rounded.Home
val HomeBorder = Icons.Outlined.Home
val Schedule = Icons.Rounded.CalendarMonth
val ScheduleBorder = Icons.Outlined.CalendarMonth
val ContactMe = Icons.Rounded.SupportAgent
val ContactMeBorder = Icons.Outlined.SupportAgent
val PhotoLibrary = Icons.Rounded.PhotoLibrary
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

android {
namespace = "com.wei.picquest.feature.photolibrary"
namespace = "com.wei.picquest.feature.photo"
}

dependencies {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wei.picquest.feature.photolibrary.photolibrary
package com.wei.picquest.feature.photo.photolibrary

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
Expand Down Expand Up @@ -54,13 +54,12 @@ import coil.compose.AsyncImagePainter
import coil.compose.SubcomposeAsyncImage
import coil.compose.SubcomposeAsyncImageContent
import com.wei.picquest.core.data.model.ImageDetail
import com.wei.picquest.core.designsystem.component.FunctionalityNotAvailablePopup
import com.wei.picquest.core.designsystem.icon.PqIcons
import com.wei.picquest.core.designsystem.theme.SPACING_LARGE
import com.wei.picquest.core.designsystem.theme.SPACING_MEDIUM
import com.wei.picquest.core.designsystem.theme.SPACING_SMALL
import com.wei.picquest.feature.photolibrary.R
import com.wei.picquest.feature.photolibrary.photolibrary.component.LayoutSwitchWarningDialog
import com.wei.picquest.feature.photo.R
import com.wei.picquest.feature.photo.photolibrary.component.LayoutSwitchWarningDialog

/**
*
Expand Down Expand Up @@ -109,6 +108,7 @@ internal fun PhotoLibraryRoute(

TopBarActions(
layoutType = uiStates.layoutType,
onBackClick = navController::popBackStack,
onSwitchLayoutClick = {
viewModel.dispatch(PhotoLibraryViewAction.SwitchLayoutType)
},
Expand All @@ -120,12 +120,13 @@ internal fun PhotoLibraryRoute(
@Composable
fun TopBarActions(
layoutType: LayoutType,
onBackClick: () -> Unit,
onSwitchLayoutClick: () -> Unit,
) {
Column {
Spacer(Modifier.windowInsetsTopHeight(WindowInsets.safeDrawing))
Row(modifier = Modifier.padding(SPACING_MEDIUM.dp)) {
BackButton()
BackButton(onBackClick = onBackClick)
Spacer(modifier = Modifier.weight(1f))
SwitchLayoutButton(
layoutType = layoutType,
Expand All @@ -136,22 +137,11 @@ fun TopBarActions(
}

@Composable
fun BackButton() {
val showPopup = remember { mutableStateOf(false) }

if (showPopup.value) {
FunctionalityNotAvailablePopup(
onDismiss = {
showPopup.value = false
},
)
}

fun BackButton(
onBackClick: () -> Unit,
) {
IconButton(
onClick = {
/* TODO: Implement back button action */
showPopup.value = true
},
onClick = { onBackClick() },
modifier = Modifier
.clip(CircleShape)
.background(MaterialTheme.colorScheme.surfaceVariant)
Expand Down Expand Up @@ -208,12 +198,6 @@ fun PhotoLibraryListScreen(
Box(modifier = Modifier.fillMaxSize()) {
Column {
LazyColumn(modifier = Modifier.weight(1f)) {
if (withTopSpacer) {
item {
Spacer(Modifier.windowInsetsTopHeight(WindowInsets.safeDrawing))
}
}

items(lazyPagingItems.itemCount) { index ->
lazyPagingItems[index]?.let {
ImageDetailItem(
Expand All @@ -222,15 +206,11 @@ fun PhotoLibraryListScreen(
)
}
}

if (withBottomSpacer) {
item {
Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))
}
}
}

PagingStateHandling(lazyPagingItems)
if (withBottomSpacer) {
Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))
}
}
}
}
Expand All @@ -254,12 +234,6 @@ fun PhotoLibraryGridScreen(
verticalItemSpacing = 0.dp,
flingBehavior = ScrollableDefaults.flingBehavior(),
) {
if (withTopSpacer) {
item {
Spacer(Modifier.windowInsetsTopHeight(WindowInsets.safeDrawing))
}
}

items(lazyPagingItems.itemCount) { index ->
lazyPagingItems[index]?.let {
ImageDetailItem(
Expand All @@ -268,15 +242,12 @@ fun PhotoLibraryGridScreen(
)
}
}

if (withBottomSpacer) {
item {
Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))
}
}
}

PagingStateHandling(lazyPagingItems)
if (withBottomSpacer) {
Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.safeDrawing))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.wei.picquest.feature.photolibrary.photolibrary
package com.wei.picquest.feature.photo.photolibrary

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.wei.picquest.core.base.BaseViewModel
import com.wei.picquest.core.data.model.ImageDetail
import com.wei.picquest.core.data.repository.SearchImagesRepository
import com.wei.picquest.feature.photo.photolibrary.navigation.PhotoLibraryArgs
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
Expand All @@ -14,19 +16,23 @@ import javax.inject.Inject

@HiltViewModel
class PhotoLibraryViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val searchImagesRepository: SearchImagesRepository,
) : BaseViewModel<
PhotoLibraryViewAction,
PhotoLibraryViewState,
>(PhotoLibraryViewState()) {

private val photoLibraryArgs: PhotoLibraryArgs = PhotoLibraryArgs(savedStateHandle)

val photoSearchKeyword = photoLibraryArgs.photoSearchKeyword

private val _imagesState: MutableStateFlow<PagingData<ImageDetail>> =
MutableStateFlow(value = PagingData.empty())
val imagesState: MutableStateFlow<PagingData<ImageDetail>> get() = _imagesState

init {
// TODO Wei
searchImages("")
searchImages(photoSearchKeyword)
}

private fun searchImages(query: String) {
Expand All @@ -50,7 +56,6 @@ class PhotoLibraryViewModel @Inject constructor(

override fun dispatch(action: PhotoLibraryViewAction) {
when (action) {
is PhotoLibraryViewAction.SearchImages -> searchImages(action.query)
is PhotoLibraryViewAction.SwitchLayoutType -> switchLayoutType()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wei.picquest.feature.photolibrary.photolibrary
package com.wei.picquest.feature.photo.photolibrary

import com.wei.picquest.core.base.Action
import com.wei.picquest.core.base.State
Expand All @@ -8,9 +8,6 @@ enum class LayoutType {
}

sealed class PhotoLibraryViewAction : Action {
data class SearchImages(
val query: String,
) : PhotoLibraryViewAction()

object SwitchLayoutType : PhotoLibraryViewAction()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.wei.picquest.feature.photolibrary.photolibrary.component
package com.wei.picquest.feature.photo.photolibrary.component

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme
Expand All @@ -9,7 +9,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import com.wei.picquest.feature.photolibrary.R
import com.wei.picquest.feature.photo.R

@Composable
fun LayoutSwitchWarningDialog(onDismiss: () -> Unit) {
Expand Down
Loading

0 comments on commit 465a1f1

Please sign in to comment.