Skip to content

Commit

Permalink
feat(photo): Add no data found message
Browse files Browse the repository at this point in the history
  • Loading branch information
azrael8576 committed Dec 2, 2023
1 parent 0cd31a1 commit 4d567b1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -303,6 +302,37 @@ fun PagingStateHandling(lazyPagingItems: LazyPagingItems<ImageDetail>) {
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,
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = "",
Expand All @@ -38,7 +39,6 @@ class PhotoSearchViewModel @Inject constructor() : BaseViewModel<
recentSearchQueries = recentSearchManager.recentSearchQueries,
)
}
Timber.e("clearRecentSearchQueries " + recentSearchManager.recentSearchQueries.toString())
}

override fun dispatch(action: PhotoSearchViewAction) {
Expand Down
1 change: 1 addition & 0 deletions feature/photo/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<string name="clear_search_text_content_desc">清除搜尋文字</string>
<string name="recent_searches">最近的搜尋</string>
<string name="clear_recent_searches_content_desc">清除搜尋</string>
<string name="no_data_found">沒有找到數據</string>
</resources>
1 change: 1 addition & 0 deletions feature/photo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<string name="clear_search_text_content_desc">Clear search text</string>
<string name="recent_searches">Recent searches</string>
<string name="clear_recent_searches_content_desc">Clear searches</string>
<string name="no_data_found">No Data Found</string>
</resources>

0 comments on commit 4d567b1

Please sign in to comment.