Skip to content

Commit

Permalink
[Fix] 마이페이지 페이징 적용 안되는 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ze-zeh committed Sep 29, 2024
1 parent 9751651 commit 318df34
Showing 1 changed file with 128 additions and 73 deletions.
201 changes: 128 additions & 73 deletions feature/mypage/src/main/java/team/ppac/mypage/MyPageScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package team.ppac.mypage
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand All @@ -14,8 +15,10 @@ import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpan
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Text
import androidx.compose.material.pullrefresh.pullRefresh
Expand All @@ -28,9 +31,11 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.collectAsLazyPagingItems
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import team.ppac.common.android.component.FarmemeMemeItem
import team.ppac.common.android.component.error.FarmemeErrorScreen
import team.ppac.common.android.util.showSkeleton
import team.ppac.common.android.util.visibility
Expand All @@ -41,15 +46,15 @@ import team.ppac.designsystem.component.scaffold.type.BackgroundColorType
import team.ppac.designsystem.component.tabbar.TabBarHeight
import team.ppac.designsystem.component.toolbar.FarmemeActionToolBar
import team.ppac.designsystem.foundation.FarmemeRadius
import team.ppac.domain.model.Meme
import team.ppac.domain.repository.SavedMemeEvent
import team.ppac.mypage.component.EmptyMemeContent
import team.ppac.mypage.component.MyPageLevelBox
import team.ppac.mypage.component.MyPageMemesTabBar
import team.ppac.mypage.component.MyPageProgressBar
import team.ppac.mypage.component.MyPagePullRefreshIndicator
import team.ppac.mypage.component.MyPageSpeechBubble
import team.ppac.mypage.component.RecentMemeContent
import team.ppac.mypage.component.RegisteredMemeContent
import team.ppac.mypage.component.SavedMemeContent
import team.ppac.mypage.model.LevelUiModel
import team.ppac.mypage.model.MyPageLevel
import team.ppac.mypage.mvi.MyPageIntent
Expand Down Expand Up @@ -103,83 +108,133 @@ internal fun MyPageScreen(
},
)
} else {
Column(
MyPageContent(
modifier = Modifier
.navigationBarsPadding()
.padding(bottom = TabBarHeight)
.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally,
) {
MyPageBody(
levelUiModel = uiState.levelUiModel,
isLoading = uiState.isLoading,
onSettingClick = {
onIntent(MyPageIntent.ClickSettingButton)
},
)
Spacer(
modifier = Modifier
.fillMaxWidth()
.height(10.dp)
.background(FarmemeTheme.skeletonColor.primary),
)
RecentMemeContent(
recentMemes = uiState.recentMemes,
onMemeClick = { memeId ->
onIntent(MyPageIntent.ClickRecentMemeItem(memeId = memeId))
},
isLoading = uiState.isLoading,
)
MyPageMemesTabBar(
currentTabType = uiState.currentTabType,
onClick = { tab ->
onIntent(MyPageIntent.ClickMemesTab(currentTabType = tab))
},
)
Spacer(
modifier = Modifier
.fillMaxWidth()
.height(1.dp)
.background(FarmemeTheme.borderColor.tertiary),
)
Spacer(modifier = Modifier.height(20.dp))
if (!uiState.isLoading) {
when (uiState.currentTabType) {
MyPageTabType.REGISTERED_MEMES -> {
RegisteredMemeContent(
registeredMemes = registeredMemes,
onMemeClick = { memeId ->
onIntent(MyPageIntent.ClickRegisteredMemeItem(memeId = memeId))
},
onCopyClick = {
onIntent(MyPageIntent.ClickCopy(it))
},
onRegisterClick = {
onIntent(MyPageIntent.ClickRegister)
},
)
}
.padding(bottom = TabBarHeight),
uiState = uiState,
onIntent = onIntent,
savedMemes = savedMemes,
registeredMemes = registeredMemes,
)
}
MyPagePullRefreshIndicator(
isRefreshing = uiState.isRefreshing,
pullRefreshState = pullRefreshState,
)
}
}
}

MyPageTabType.SAVED_MEMES -> {
SavedMemeContent(
savedMemes = savedMemes,
onMemeClick = { memeId ->
onIntent(MyPageIntent.ClickSavedMemeItem(memeId = memeId))
},
onCopyClick = {
onIntent(MyPageIntent.ClickCopy(it))
},
@Composable
private fun MyPageContent(
modifier: Modifier = Modifier,
uiState: MyPageUiState,
onIntent: (MyPageIntent) -> Unit,
savedMemes: LazyPagingItems<Meme>,
registeredMemes: LazyPagingItems<Meme>,
) {
LazyVerticalStaggeredGrid(
modifier = modifier.wrapContentHeight(),
columns = StaggeredGridCells.Fixed(2),
horizontalArrangement = Arrangement.spacedBy(space = (-28).dp),
) {
item(span = StaggeredGridItemSpan.FullLine) {
MyPageBody(
levelUiModel = uiState.levelUiModel,
isLoading = uiState.isLoading,
onSettingClick = {
onIntent(MyPageIntent.ClickSettingButton)
},
)
}
item(span = StaggeredGridItemSpan.FullLine) {
Spacer(
modifier = Modifier
.fillMaxWidth()
.height(10.dp)
.background(FarmemeTheme.skeletonColor.primary),
)
}
item(span = StaggeredGridItemSpan.FullLine) {
RecentMemeContent(
recentMemes = uiState.recentMemes,
onMemeClick = { memeId ->
onIntent(MyPageIntent.ClickRecentMemeItem(memeId = memeId))
},
isLoading = uiState.isLoading,
)
}
item(span = StaggeredGridItemSpan.FullLine) {
MyPageMemesTabBar(
currentTabType = uiState.currentTabType,
onClick = { tab ->
onIntent(MyPageIntent.ClickMemesTab(currentTabType = tab))
},
)
}
item(span = StaggeredGridItemSpan.FullLine) {
Spacer(
modifier = Modifier
.fillMaxWidth()
.height(1.dp)
.background(FarmemeTheme.borderColor.tertiary),
)
}
item(span = StaggeredGridItemSpan.FullLine) {
Spacer(modifier = Modifier.height(20.dp))
}
if (!uiState.isLoading) {
val memes = when (uiState.currentTabType) {
MyPageTabType.REGISTERED_MEMES -> registeredMemes
MyPageTabType.SAVED_MEMES -> savedMemes
}

if (memes.itemCount > 0) {
items(count = memes.itemCount) { index ->
val meme = memes[index]

if (meme != null) {
FarmemeMemeItem(
modifier = Modifier
.padding(
start = 20.dp,
end = 20.dp,
bottom = 20.dp,
),
memeId = meme.id,
memeTitle = meme.title,
lolCount = 0,
imageUrl = meme.imageUrl,
onMemeClick = { memeId ->
onIntent(
when (uiState.currentTabType) {
MyPageTabType.REGISTERED_MEMES -> MyPageIntent.ClickRegisteredMemeItem(
memeId = memeId
)

MyPageTabType.SAVED_MEMES -> MyPageIntent.ClickSavedMemeItem(
memeId = memeId
)
}
)
}
}
},
onCopyClick = { onIntent(MyPageIntent.ClickCopy(meme)) },
)
}
}
MyPagePullRefreshIndicator(
isRefreshing = uiState.isRefreshing,
pullRefreshState = pullRefreshState,
)
} else {
item(span = StaggeredGridItemSpan.FullLine) {
EmptyMemeContent(
tabType = uiState.currentTabType,
onUploadClick = { onIntent(MyPageIntent.ClickRegister) },
)
}
}
}
item(span = StaggeredGridItemSpan.FullLine) {
Spacer(modifier = Modifier.height(30.dp))
}
}
}

Expand Down

0 comments on commit 318df34

Please sign in to comment.