From 4d567b1e8b7bac05cf2b63513e9a51342d60e1de Mon Sep 17 00:00:00 2001 From: WeiHe Date: Sun, 3 Dec 2023 06:59:08 +0800 Subject: [PATCH] feat(photo): Add no data found message --- .../picquest/feature/home/home/HomeScreen.kt | 5 --- .../photo/photolibrary/PhotoLibraryScreen.kt | 32 ++++++++++++++++++- .../photo/photosearch/PhotoSearchViewModel.kt | 6 ++-- .../src/main/res/values-zh-rTW/strings.xml | 1 + feature/photo/src/main/res/values/strings.xml | 1 + 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/feature/home/src/main/java/com/wei/picquest/feature/home/home/HomeScreen.kt b/feature/home/src/main/java/com/wei/picquest/feature/home/home/HomeScreen.kt index 1ed4645..ce7d5a1 100644 --- a/feature/home/src/main/java/com/wei/picquest/feature/home/home/HomeScreen.kt +++ b/feature/home/src/main/java/com/wei/picquest/feature/home/home/HomeScreen.kt @@ -4,7 +4,6 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.safeDrawing import androidx.compose.foundation.layout.windowInsetsBottomHeight @@ -26,7 +25,6 @@ import androidx.navigation.NavController import com.wei.picquest.core.designsystem.component.FunctionalityNotAvailablePopup import com.wei.picquest.core.designsystem.component.ThemePreviews import com.wei.picquest.core.designsystem.theme.PqTheme -import com.wei.picquest.core.designsystem.theme.SPACING_EXTRA_LARGE import com.wei.picquest.core.designsystem.theme.SPACING_MEDIUM import com.wei.picquest.feature.home.R @@ -92,9 +90,6 @@ internal fun HomeScreen( Spacer(Modifier.windowInsetsTopHeight(WindowInsets.safeDrawing)) } LazyColumn { - item { - Spacer(modifier = Modifier.height(SPACING_EXTRA_LARGE.dp)) - } item { val importantNotes = stringResource(id = R.string.important_notes) Text( diff --git a/feature/photo/src/main/java/com/wei/picquest/feature/photo/photolibrary/PhotoLibraryScreen.kt b/feature/photo/src/main/java/com/wei/picquest/feature/photo/photolibrary/PhotoLibraryScreen.kt index 9b333de..3115120 100644 --- a/feature/photo/src/main/java/com/wei/picquest/feature/photo/photolibrary/PhotoLibraryScreen.kt +++ b/feature/photo/src/main/java/com/wei/picquest/feature/photo/photolibrary/PhotoLibraryScreen.kt @@ -95,7 +95,6 @@ internal fun PhotoLibraryRoute( navController: NavController, viewModel: PhotoLibraryViewModel = hiltViewModel(), ) { - val query = "your_search_query" // 這應該是動態查詢字串 val lazyPagingItems = viewModel.imagesState.collectAsLazyPagingItems() val uiStates: PhotoLibraryViewState by viewModel.states.collectAsStateWithLifecycle() @@ -303,6 +302,37 @@ fun PagingStateHandling(lazyPagingItems: LazyPagingItems) { loadState.append is LoadState.Loading -> LoadingNextPageItem() loadState.append is LoadState.Error -> ErrorMessage { retry() } } + if (itemCount == 0 && + loadState.append is LoadState.NotLoading && + loadState.append.endOfPaginationReached + ) { + NoDataMessage() + } + } +} + +@Composable +fun NoDataMessage() { + val noDataFound = stringResource(R.string.no_data_found) + Box( + modifier = Modifier + .fillMaxSize() + .semantics { + contentDescription = noDataFound + }, + contentAlignment = Alignment.Center, + ) { + Column(horizontalAlignment = Alignment.CenterHorizontally) { + Text( + text = "(´・ω・`)", + style = MaterialTheme.typography.displayMedium, + ) + Spacer(modifier = Modifier.height(SPACING_SMALL.dp)) + Text( + text = noDataFound, + style = MaterialTheme.typography.bodyLarge, + ) + } } } diff --git a/feature/photo/src/main/java/com/wei/picquest/feature/photo/photosearch/PhotoSearchViewModel.kt b/feature/photo/src/main/java/com/wei/picquest/feature/photo/photosearch/PhotoSearchViewModel.kt index c4918a4..7d226f2 100644 --- a/feature/photo/src/main/java/com/wei/picquest/feature/photo/photosearch/PhotoSearchViewModel.kt +++ b/feature/photo/src/main/java/com/wei/picquest/feature/photo/photosearch/PhotoSearchViewModel.kt @@ -3,7 +3,6 @@ package com.wei.picquest.feature.photo.photosearch import com.wei.picquest.core.base.BaseViewModel import com.wei.picquest.feature.photo.photosearch.manager.RecentSearchManager import dagger.hilt.android.lifecycle.HiltViewModel -import timber.log.Timber import javax.inject.Inject @HiltViewModel @@ -22,7 +21,9 @@ class PhotoSearchViewModel @Inject constructor() : BaseViewModel< } private fun searchTriggered(query: String) { - recentSearchManager.addSearchQuery(query) + if (query.isNotBlank()) { + recentSearchManager.addSearchQuery(query) + } updateState { copy( searchQuery = "", @@ -38,7 +39,6 @@ class PhotoSearchViewModel @Inject constructor() : BaseViewModel< recentSearchQueries = recentSearchManager.recentSearchQueries, ) } - Timber.e("clearRecentSearchQueries " + recentSearchManager.recentSearchQueries.toString()) } override fun dispatch(action: PhotoSearchViewAction) { diff --git a/feature/photo/src/main/res/values-zh-rTW/strings.xml b/feature/photo/src/main/res/values-zh-rTW/strings.xml index 801c762..b173324 100644 --- a/feature/photo/src/main/res/values-zh-rTW/strings.xml +++ b/feature/photo/src/main/res/values-zh-rTW/strings.xml @@ -8,4 +8,5 @@ 清除搜尋文字 最近的搜尋 清除搜尋 + 沒有找到數據 \ No newline at end of file diff --git a/feature/photo/src/main/res/values/strings.xml b/feature/photo/src/main/res/values/strings.xml index 6de29e5..7fb8893 100644 --- a/feature/photo/src/main/res/values/strings.xml +++ b/feature/photo/src/main/res/values/strings.xml @@ -8,4 +8,5 @@ Clear search text Recent searches Clear searches + No Data Found \ No newline at end of file