From 6cf6ec9ac8e90e9118e8a933fff2178c0f5c3361 Mon Sep 17 00:00:00 2001 From: whitescent Date: Sat, 6 Jan 2024 16:17:14 +0800 Subject: [PATCH] fix: empty placeholder strings --- .../whitescent/mastify/screen/home/Home.kt | 4 +-- .../mastify/screen/profile/ProfilePager.kt | 5 +++ .../ui/component/status/StatusCommonList.kt | 5 +-- .../paging/EmptyStatusListPlaceholder.kt | 36 +++++++++++++------ .../mastify/viewModel/ProfileViewModel.kt | 2 +- app/src/main/res/values-zh-rCN/strings.xml | 3 ++ app/src/main/res/values/strings.xml | 3 ++ 7 files changed, 42 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/github/whitescent/mastify/screen/home/Home.kt b/app/src/main/java/com/github/whitescent/mastify/screen/home/Home.kt index ffc9a587..d909cd93 100644 --- a/app/src/main/java/com/github/whitescent/mastify/screen/home/Home.kt +++ b/app/src/main/java/com/github/whitescent/mastify/screen/home/Home.kt @@ -103,7 +103,7 @@ import com.github.whitescent.mastify.ui.component.drawVerticalScrollbar import com.github.whitescent.mastify.ui.component.status.StatusListItem import com.github.whitescent.mastify.ui.component.status.StatusSnackBar import com.github.whitescent.mastify.ui.component.status.paging.EmptyStatusListPlaceholder -import com.github.whitescent.mastify.ui.component.status.paging.PageType +import com.github.whitescent.mastify.ui.component.status.paging.PagePlaceholderType import com.github.whitescent.mastify.ui.component.status.paging.StatusListLoadError import com.github.whitescent.mastify.ui.component.status.paging.StatusListLoading import com.github.whitescent.mastify.ui.component.status.rememberStatusSnackBarState @@ -197,7 +197,7 @@ fun Home( StatusListLoadError { viewModel.refreshTimeline() } uiState.timelineLoadState == NotLoading && uiState.endReached -> EmptyStatusListPlaceholder( - pageType = PageType.Timeline, + pagePlaceholderType = PagePlaceholderType.Home, modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()) ) else -> StatusListLoading(Modifier.fillMaxSize()) diff --git a/app/src/main/java/com/github/whitescent/mastify/screen/profile/ProfilePager.kt b/app/src/main/java/com/github/whitescent/mastify/screen/profile/ProfilePager.kt index 498d25d0..9225a3e9 100644 --- a/app/src/main/java/com/github/whitescent/mastify/screen/profile/ProfilePager.kt +++ b/app/src/main/java/com/github/whitescent/mastify/screen/profile/ProfilePager.kt @@ -33,6 +33,7 @@ import com.github.whitescent.mastify.network.model.status.Status import com.github.whitescent.mastify.network.model.status.Status.Attachment import com.github.whitescent.mastify.paging.autoAppend import com.github.whitescent.mastify.ui.component.status.StatusCommonList +import com.github.whitescent.mastify.ui.component.status.paging.PagePlaceholderType import com.github.whitescent.mastify.viewModel.ExplorerViewModel import com.github.whitescent.mastify.viewModel.ProfileKind import com.github.whitescent.mastify.viewModel.ProfileViewModel @@ -65,6 +66,7 @@ fun ProfilePager( 0 -> StatusCommonList( statusCommonListData = statusList, statusListState = statusListState, + pagePlaceholderType = PagePlaceholderType.Profile(isSelf = viewModel.uiState.isSelf!!), action = { action, status -> viewModel.onStatusAction(action, context, status) }, @@ -74,9 +76,11 @@ fun ProfilePager( navigateToProfile = navigateToProfile, navigateToMedia = navigateToMedia, ) + 1 -> StatusCommonList( statusCommonListData = statusListWithReply, statusListState = statusListWithReplyState, + pagePlaceholderType = PagePlaceholderType.Profile(isSelf = viewModel.uiState.isSelf!!), action = { action, status -> viewModel.onStatusAction(action, context, status) }, @@ -89,6 +93,7 @@ fun ProfilePager( 2 -> StatusCommonList( statusCommonListData = statusListWithMedia, statusListState = statusListWithMediaState, + pagePlaceholderType = PagePlaceholderType.Profile(isSelf = viewModel.uiState.isSelf!!), action = { action, status -> viewModel.onStatusAction(action, context, status) }, diff --git a/app/src/main/java/com/github/whitescent/mastify/ui/component/status/StatusCommonList.kt b/app/src/main/java/com/github/whitescent/mastify/ui/component/status/StatusCommonList.kt index 4e507424..aec857e5 100644 --- a/app/src/main/java/com/github/whitescent/mastify/ui/component/status/StatusCommonList.kt +++ b/app/src/main/java/com/github/whitescent/mastify/ui/component/status/StatusCommonList.kt @@ -58,7 +58,7 @@ import com.github.whitescent.mastify.ui.component.StatusAppendingIndicator import com.github.whitescent.mastify.ui.component.StatusEndIndicator import com.github.whitescent.mastify.ui.component.drawVerticalScrollbar import com.github.whitescent.mastify.ui.component.status.paging.EmptyStatusListPlaceholder -import com.github.whitescent.mastify.ui.component.status.paging.PageType +import com.github.whitescent.mastify.ui.component.status.paging.PagePlaceholderType import com.github.whitescent.mastify.ui.component.status.paging.StatusListLoadError import com.github.whitescent.mastify.ui.component.status.paging.StatusListLoading import com.github.whitescent.mastify.utils.StatusAction @@ -71,6 +71,7 @@ import kotlinx.coroutines.launch fun StatusCommonList( statusCommonListData: StatusCommonListData, statusListState: LazyListState, + pagePlaceholderType: PagePlaceholderType, modifier: Modifier = Modifier, enablePullRefresh: Boolean = false, action: (StatusAction, Status) -> Unit, @@ -114,7 +115,7 @@ fun StatusCommonList( loadState == Error -> StatusListLoadError { refreshList() } loadState == NotLoading && statusCommonListData.endReached -> EmptyStatusListPlaceholder( - pageType = PageType.Timeline, + pagePlaceholderType = pagePlaceholderType, modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()) ) else -> StatusListLoading(Modifier.fillMaxSize()) diff --git a/app/src/main/java/com/github/whitescent/mastify/ui/component/status/paging/EmptyStatusListPlaceholder.kt b/app/src/main/java/com/github/whitescent/mastify/ui/component/status/paging/EmptyStatusListPlaceholder.kt index 8d694932..fd70a63e 100644 --- a/app/src/main/java/com/github/whitescent/mastify/ui/component/status/paging/EmptyStatusListPlaceholder.kt +++ b/app/src/main/java/com/github/whitescent/mastify/ui/component/status/paging/EmptyStatusListPlaceholder.kt @@ -17,9 +17,9 @@ package com.github.whitescent.mastify.ui.component.status.paging +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.size import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -37,10 +37,13 @@ import com.airbnb.lottie.compose.animateLottieCompositionAsState import com.airbnb.lottie.compose.rememberLottieComposition import com.github.whitescent.R import com.github.whitescent.mastify.ui.theme.AppTheme +import com.github.whitescent.mastify.viewModel.ExplorerKind +import com.github.whitescent.mastify.viewModel.ExplorerKind.PublicTimeline +import com.github.whitescent.mastify.viewModel.ExplorerKind.Trending @Composable fun EmptyStatusListPlaceholder( - pageType: PageType, + pagePlaceholderType: PagePlaceholderType, modifier: Modifier = Modifier, alignment: Alignment = Alignment.Center, ) { @@ -50,19 +53,28 @@ fun EmptyStatusListPlaceholder( modifier = modifier, contentAlignment = alignment ) { - Column(Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally) { + Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) { LottieAnimation( composition = composition, progress = { progress }, - contentScale = ContentScale.Fit, - modifier = Modifier - .size(360.dp) + contentScale = ContentScale.Crop, + modifier = Modifier.size(300.dp), + alignment = Alignment.TopCenter ) Text( text = stringResource( - id = when (pageType) { - PageType.Timeline -> R.string.empty_timeline - PageType.Profile -> R.string.empty_status + id = when (pagePlaceholderType) { + is PagePlaceholderType.Home -> R.string.empty_timeline + is PagePlaceholderType.Profile -> { + if (pagePlaceholderType.isSelf) R.string.empty_status_self + else R.string.empty_status + } + is PagePlaceholderType.Explore -> { + when (pagePlaceholderType.explorerKind) { + PublicTimeline, Trending -> R.string.timeline_is_empty + ExplorerKind.News -> R.string.news_is_empty + } + } } ), fontWeight = FontWeight.Medium, @@ -73,6 +85,8 @@ fun EmptyStatusListPlaceholder( } } -enum class PageType { - Timeline, Profile +sealed class PagePlaceholderType { + data object Home : PagePlaceholderType() + data class Profile(val isSelf: Boolean) : PagePlaceholderType() + data class Explore(val explorerKind: ExplorerKind) : PagePlaceholderType() } diff --git a/app/src/main/java/com/github/whitescent/mastify/viewModel/ProfileViewModel.kt b/app/src/main/java/com/github/whitescent/mastify/viewModel/ProfileViewModel.kt index ece0e5b9..2f9ef51c 100644 --- a/app/src/main/java/com/github/whitescent/mastify/viewModel/ProfileViewModel.kt +++ b/app/src/main/java/com/github/whitescent/mastify/viewModel/ProfileViewModel.kt @@ -226,10 +226,10 @@ class ProfileViewModel @Inject constructor( init { viewModelScope.launch { - statusPager.refresh() uiState = uiState.copy( isSelf = navArgs.account.id == accountDao.getActiveAccount()!!.accountId ) + statusPager.refresh() getRelationship(navArgs.account.id) fetchAccount(navArgs.account.id) launch { diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 6cc996fb..01037530 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -99,6 +99,7 @@ 媒体 编辑个人资料 "这个家伙还没有发布过任何嘟文" + 你还没有发布过嘟文哦 "你还没有关注其他人哦" @@ -133,4 +134,6 @@ 公共时间轴 新闻 搜索 + 这里现在还没有帖子 + 这个实例现在还没有新闻 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 99f9fec2..b725d796 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -102,6 +102,7 @@ Media Edit Profile This guy hasn\'t yet made a post + You haven\'t posted yet "You haven't followed anyone else yet" @@ -136,5 +137,7 @@ Public Timeline News Search + There are no posts here yet + There is no news about this instance yet