From 4d6dc10a5fa6f3f4d6052987923963bfbe5a9da0 Mon Sep 17 00:00:00 2001 From: yonghanJu Date: Tue, 13 Aug 2024 22:17:59 +0900 Subject: [PATCH 1/9] =?UTF-8?q?:bug:=20=ED=85=9D=20=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=95=84=EC=9B=83=20=EC=BB=A8=ED=85=90=ED=8A=B8=EA=B0=80=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=A1=A4=EC=9D=B4=20=EC=95=88=EB=90=98?= =?UTF-8?q?=EA=B3=A0=20=EA=B2=B9=EC=B3=90=EB=B3=B4=EC=9D=B4=EB=8A=94=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95(rememberScrollState=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../screens/mypage/MyPageScreen.kt | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/presentation/src/main/java/com/whyranoid/presentation/screens/mypage/MyPageScreen.kt b/presentation/src/main/java/com/whyranoid/presentation/screens/mypage/MyPageScreen.kt index 5e338ff..77a46a3 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/screens/mypage/MyPageScreen.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/screens/mypage/MyPageScreen.kt @@ -20,8 +20,10 @@ import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.rememberPagerState +import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.verticalScroll import androidx.compose.material.Scaffold import androidx.compose.material.Tab import androidx.compose.material.TabRow @@ -375,17 +377,25 @@ fun UserPageContent( verticalAlignment = Alignment.Top, ) { pagerNum -> when (pagerNum) { - 0 -> state.userPostPreviewsState.getDataOrNull()?.let { postPreviews -> - PostPage( - nickname == null, - postPreviews, - onPostPreviewClicked, - onPostCreateClicked, - ) + 0 -> { + Column( + modifier = Modifier.verticalScroll(rememberScrollState()) + ) { + state.userPostPreviewsState.getDataOrNull()?.let { postPreviews -> + PostPage( + nickname == null, + postPreviews, + onPostPreviewClicked, + onPostCreateClicked, + ) + } + } } 1 -> { - Column { + Column( + modifier = Modifier.verticalScroll(rememberScrollState()) + ) { HistoryPage(onDayClicked = onDateClicked) state.calendarPreviewsState.getDataOrNull() ?.let { postPreviews -> @@ -405,12 +415,16 @@ fun UserPageContent( 2 -> { val itemList = state.challengingPreviewsState.getDataOrNull() if (itemList != null) { - ChallengePage( - itemList, - onChallengePreviewClicked, - goChallengeMainScreen, - nickname == null - ) + Column( + modifier = Modifier.verticalScroll(rememberScrollState()) + ) { + ChallengePage( + itemList, + onChallengePreviewClicked, + goChallengeMainScreen, + nickname == null + ) + } } else { Box(Modifier.fillMaxSize()) { CircularProgressIndicator(Modifier.align(Alignment.Center)) From fb5dab0d5199a9393f37c3a59cadf9e155a639c6 Mon Sep 17 00:00:00 2001 From: yonghanJu Date: Thu, 15 Aug 2024 21:43:18 +0900 Subject: [PATCH 2/9] =?UTF-8?q?:sparkles:=20=EA=B2=8C=EC=8B=9C=EA=B8=80?= =?UTF-8?q?=EC=97=90=20=EB=8B=AC=EB=A6=B0=20=EB=8C=93=EA=B8=80=20=EC=88=98?= =?UTF-8?q?=20=EB=B3=80=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/whyranoid/data/model/post/PostResponse.kt | 3 +++ domain/src/main/java/com/whyranoid/domain/model/post/Post.kt | 1 + .../main/java/com/whyranoid/domain/model/post/PostPreview.kt | 1 + 3 files changed, 5 insertions(+) diff --git a/data/src/main/java/com/whyranoid/data/model/post/PostResponse.kt b/data/src/main/java/com/whyranoid/data/model/post/PostResponse.kt index 659f6ba..50927a3 100644 --- a/data/src/main/java/com/whyranoid/data/model/post/PostResponse.kt +++ b/data/src/main/java/com/whyranoid/data/model/post/PostResponse.kt @@ -18,6 +18,7 @@ data class PostResponse( @SerializedName("date") val date: String, @SerializedName("colorMode") val colorMode: Long, @SerializedName("historyContent") val historyContent: String, + @SerializedName("commentCount") val commentCount: Long, ) { fun toPostPreview(): PostPreview { val destructedHistoryContent = historyContent.split('_') @@ -33,6 +34,7 @@ data class PostResponse( timeText = destructedHistoryContent[3], paceText = destructedHistoryContent[4], address = destructedHistoryContent[1], + commentCount = commentCount, ) } @@ -52,6 +54,7 @@ data class PostResponse( timeText = destructedHistoryContent[3], paceText = destructedHistoryContent[4], address = destructedHistoryContent[1], + commentCount = commentCount, ) } diff --git a/domain/src/main/java/com/whyranoid/domain/model/post/Post.kt b/domain/src/main/java/com/whyranoid/domain/model/post/Post.kt index 1c4bc3c..e7e6b2e 100644 --- a/domain/src/main/java/com/whyranoid/domain/model/post/Post.kt +++ b/domain/src/main/java/com/whyranoid/domain/model/post/Post.kt @@ -18,6 +18,7 @@ data class Post( val timeText: String = "", val paceText: String = "", val address: String = "", + val commentCount: Long = 0, ) : Serializable { companion object { val DUMMY = diff --git a/domain/src/main/java/com/whyranoid/domain/model/post/PostPreview.kt b/domain/src/main/java/com/whyranoid/domain/model/post/PostPreview.kt index 6d07116..0f7737a 100644 --- a/domain/src/main/java/com/whyranoid/domain/model/post/PostPreview.kt +++ b/domain/src/main/java/com/whyranoid/domain/model/post/PostPreview.kt @@ -14,6 +14,7 @@ data class PostPreview( val timeText: String = "", val paceText: String = "", val address: String = "", + val commentCount: Long = 0, ) { companion object { val DUMMY_LIST = listOf( From 7feb914a3e5fb9519d9f1f48592723affdc947ad Mon Sep 17 00:00:00 2001 From: yonghanJu Date: Thu, 15 Aug 2024 21:43:37 +0900 Subject: [PATCH 3/9] =?UTF-8?q?:sparkles:=20=EA=B2=8C=EC=8B=9C=EA=B8=80?= =?UTF-8?q?=EC=97=90=20=EB=8B=AC=EB=A6=B0=20=EB=8C=93=EA=B8=80=20=EC=88=98?= =?UTF-8?q?=20=EB=B3=B4=EC=9D=B4=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/component/community/PostContentItem.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/presentation/src/main/java/com/whyranoid/presentation/component/community/PostContentItem.kt b/presentation/src/main/java/com/whyranoid/presentation/component/community/PostContentItem.kt index 1f67275..2f13333 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/component/community/PostContentItem.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/component/community/PostContentItem.kt @@ -94,7 +94,7 @@ fun PostContentItem( Text( modifier = Modifier.align(Alignment.CenterVertically), - text = "?", // todo replace real count + text = post.commentCount.toString(), style = WalkieTypography.Body1_Normal, color = WalkieColor.GrayBorder ) From a2b104b83b668007736f8141767ff2bfaee55ff1 Mon Sep 17 00:00:00 2001 From: yonghanJu Date: Thu, 15 Aug 2024 21:48:53 +0900 Subject: [PATCH 4/9] =?UTF-8?q?:sparkles:=20=EA=B2=8C=EC=8B=9C=EA=B8=80?= =?UTF-8?q?=EC=97=90=20=EB=8C=93=EA=B8=80=20=EC=95=84=EC=9D=B4=EC=BD=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/community/PostContentItem.kt | 3 +-- .../src/main/res/drawable/ic_comment_button.xml | 11 +++++++++++ .../main/res/drawable/ic_comment_outlined_button.xml | 5 ----- 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 presentation/src/main/res/drawable/ic_comment_button.xml delete mode 100644 presentation/src/main/res/drawable/ic_comment_outlined_button.xml diff --git a/presentation/src/main/java/com/whyranoid/presentation/component/community/PostContentItem.kt b/presentation/src/main/java/com/whyranoid/presentation/component/community/PostContentItem.kt index 2f13333..b47ec6b 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/component/community/PostContentItem.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/component/community/PostContentItem.kt @@ -78,14 +78,13 @@ fun PostContentItem( Icon( modifier = Modifier - .graphicsLayer(scaleX = -1f) .size(28.dp) .clip(CircleShape) .clickable { onCommentClicked(post) } .padding(3.dp), - painter = painterResource(id = R.drawable.ic_comment_outlined_button), + painter = painterResource(id = R.drawable.ic_comment_button), contentDescription = "댓글 버튼", tint = WalkieColor.GrayBorder ) diff --git a/presentation/src/main/res/drawable/ic_comment_button.xml b/presentation/src/main/res/drawable/ic_comment_button.xml new file mode 100644 index 0000000..e2b757c --- /dev/null +++ b/presentation/src/main/res/drawable/ic_comment_button.xml @@ -0,0 +1,11 @@ + + + diff --git a/presentation/src/main/res/drawable/ic_comment_outlined_button.xml b/presentation/src/main/res/drawable/ic_comment_outlined_button.xml deleted file mode 100644 index 91d5a01..0000000 --- a/presentation/src/main/res/drawable/ic_comment_outlined_button.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - From 003f93732f1e9b92afef5e26f6b50a3adb14f8bf Mon Sep 17 00:00:00 2001 From: yonghanJu Date: Thu, 15 Aug 2024 21:59:14 +0900 Subject: [PATCH 5/9] =?UTF-8?q?:sparkles:=20=EC=BB=A4=EB=AE=A4=EB=8B=88?= =?UTF-8?q?=ED=8B=B0=20=EC=9A=B0=EC=83=81=EB=8B=A8=20+=20=EB=B2=84?= =?UTF-8?q?=ED=8A=BC=EC=9C=BC=EB=A1=9C=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=93=B0=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/whyranoid/presentation/screens/CommunityScreen.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt b/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt index feecb16..2187693 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt @@ -61,6 +61,7 @@ fun CommunityScreen(navController: NavController) { modifier = Modifier .clickable { + navController.navigate(Screen.AddPostScreen.route) }, imageVector = Icons.Filled.Add, contentDescription = "추가 버튼", From e31050c9376ae1114d28601b039eb054d43004c0 Mon Sep 17 00:00:00 2001 From: yonghanJu Date: Mon, 26 Aug 2024 21:16:43 +0900 Subject: [PATCH 6/9] =?UTF-8?q?:sparkles:=20=EC=84=9C=EB=B2=84=20=EC=9D=B4?= =?UTF-8?q?=EC=A0=84=20baseURL=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/src/main/java/com/whyranoid/data/API.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/src/main/java/com/whyranoid/data/API.kt b/data/src/main/java/com/whyranoid/data/API.kt index 9a2061b..844951b 100644 --- a/data/src/main/java/com/whyranoid/data/API.kt +++ b/data/src/main/java/com/whyranoid/data/API.kt @@ -1,7 +1,7 @@ package com.whyranoid.data object API { - const val BASE_URL = "https://walkie-tsvdh.run.goorm.site/" + const val BASE_URL = "http://3.35.102.89:8080/" const val CHECK_NICKNAME = "api/walkies/signup/check" From 35e5875c6e4b84489fc24df3aab8677c7e452bec Mon Sep 17 00:00:00 2001 From: yonghanJu Date: Mon, 26 Aug 2024 21:45:43 +0900 Subject: [PATCH 7/9] =?UTF-8?q?:sparkles:=20=EC=BB=A4=EB=AE=A4=EB=8B=88?= =?UTF-8?q?=ED=8B=B0=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20pull=20refresh=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/screens/CommunityScreen.kt | 105 ++++++++++++------ .../screens/community/UserPostsScreen.kt | 101 +++++++++++++++++ .../viewmodel/CommunityScreenViewModel.kt | 3 + 3 files changed, 173 insertions(+), 36 deletions(-) create mode 100644 presentation/src/main/java/com/whyranoid/presentation/screens/community/UserPostsScreen.kt diff --git a/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt b/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt index 2187693..2c90df1 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt @@ -1,12 +1,16 @@ package com.whyranoid.presentation.screens import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyRow +import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.Icon import androidx.compose.material.Scaffold import androidx.compose.material.Text @@ -14,6 +18,9 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material.icons.filled.Search +import androidx.compose.material.pullrefresh.PullRefreshIndicator +import androidx.compose.material.pullrefresh.pullRefresh +import androidx.compose.material.pullrefresh.rememberPullRefreshState import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier @@ -28,6 +35,7 @@ import com.whyranoid.presentation.viewmodel.CommunityScreenViewModel import org.koin.androidx.compose.koinViewModel import org.orbitmvi.orbit.compose.collectAsState +@OptIn(ExperimentalMaterialApi::class) @Composable fun CommunityScreen(navController: NavController) { val viewModel = koinViewModel() @@ -47,9 +55,9 @@ fun CommunityScreen(navController: NavController) { Icon( modifier = - Modifier - .clickable { - }, + Modifier + .clickable { + }, imageVector = Icons.Filled.KeyboardArrowDown, contentDescription = "Down Arrow", ) @@ -59,10 +67,10 @@ fun CommunityScreen(navController: NavController) { Row { Icon( modifier = - Modifier - .clickable { - navController.navigate(Screen.AddPostScreen.route) - }, + Modifier + .clickable { + navController.navigate(Screen.AddPostScreen.route) + }, imageVector = Icons.Filled.Add, contentDescription = "추가 버튼", ) @@ -71,10 +79,10 @@ fun CommunityScreen(navController: NavController) { Icon( modifier = - Modifier - .clickable { - navController.navigate(Screen.SearchFriendScreen.route) - }, + Modifier + .clickable { + navController.navigate(Screen.SearchFriendScreen.route) + }, imageVector = Icons.Filled.Search, contentDescription = "검색 버튼", ) @@ -83,36 +91,61 @@ fun CommunityScreen(navController: NavController) { ) }, ) { - LazyColumn( - modifier = Modifier.padding(it), + + Column( + modifier = Modifier.padding(it) ) { - item { - LazyRow { - repeat(10) { - item { RunningFollowerItemWithLikable(isDisplayName = true) } - } + LazyRow { + repeat(10) { + item { RunningFollowerItemWithLikable(isDisplayName = true) } } } - state.posts.getDataOrNull()?.forEach { post -> - item { - PostItem( - post = post, - onLikeClicked = { postId -> - viewModel.likePost(postId) - }, - onProfileClicked = { user -> - state.following.getDataOrNull()?.let { followings -> - val isFollowing = followings.contains(user) - navController.navigate("userPage/${user.uid}/${user.nickname}/$isFollowing") - } - }, - onCommentClicked = { post -> - navController.currentBackStackEntry?.savedStateHandle?.set("post", post) - navController.navigate(Screen.CommentScreen.route) - }, - ) + val refreshing = state.posts.getDataOrNull() == null + + val pullRefreshState = rememberPullRefreshState( + refreshing = refreshing, + onRefresh = { + viewModel.getPosts() + } + ) + + Box( + modifier = Modifier + .fillMaxSize() + .pullRefresh(pullRefreshState) + ) { + LazyColumn { + state.posts.getDataOrNull()?.forEach { post -> + item { + PostItem( + post = post, + onLikeClicked = { postId -> + viewModel.likePost(postId) + }, + onProfileClicked = { user -> + state.following.getDataOrNull()?.let { followings -> + val isFollowing = followings.contains(user) + navController.navigate("userPage/${user.uid}/${user.nickname}/$isFollowing") + } + }, + onCommentClicked = { post -> + navController.currentBackStackEntry?.savedStateHandle?.set( + "post", + post + ) + navController.navigate(Screen.CommentScreen.route) + }, + ) + } + } } + + PullRefreshIndicator( + refreshing = refreshing, + state = pullRefreshState, + modifier = Modifier.align(androidx.compose.ui.Alignment.TopCenter) + ) } } } diff --git a/presentation/src/main/java/com/whyranoid/presentation/screens/community/UserPostsScreen.kt b/presentation/src/main/java/com/whyranoid/presentation/screens/community/UserPostsScreen.kt new file mode 100644 index 0000000..52f7978 --- /dev/null +++ b/presentation/src/main/java/com/whyranoid/presentation/screens/community/UserPostsScreen.kt @@ -0,0 +1,101 @@ +package com.whyranoid.presentation.screens.community + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.wrapContentHeight +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.whyranoid.domain.model.post.Post +import com.whyranoid.domain.model.user.User +import com.whyranoid.presentation.component.community.PostItem +import com.whyranoid.presentation.theme.WalkieTheme +import com.whyranoid.presentation.theme.WalkieTypography +import com.whyranoid.presentation.viewmodel.CommunityScreenViewModel +import org.koin.androidx.compose.koinViewModel + +@Composable +fun UserPostScreen( + user: User, + postPreviews: List, + startIndex: Int, + onBackPressed: () -> Unit = {}, + +) { + + val viewModel = koinViewModel() + + Column( + modifier = Modifier + .fillMaxWidth() + .wrapContentHeight(), + verticalArrangement = Arrangement.Top, + ) { + Column( + Modifier + .fillMaxWidth() + .padding(horizontal = 20.dp) + .padding(top = 20.dp), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Box( + contentAlignment = Alignment.CenterStart, + ) { + Column( + modifier = Modifier.align(Alignment.Center), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Text( + style = WalkieTypography.Body1_Normal, + text = user.nickname, + modifier = Modifier + .padding(bottom = 24.dp), + ) + Text( + style = WalkieTypography.Title, + text = "게시물", + modifier = Modifier + .padding(bottom = 24.dp), + ) + } + + } + + + Column { + postPreviews.forEach { post -> + PostItem( + post = post, + onLikeClicked = { postId -> + viewModel.likePost(postId) + }, + onProfileClicked = { user -> + // navController.back + }, + onCommentClicked = { post -> +// navController.currentBackStackEntry?.savedStateHandle?.set( +// "post", +// post +// ) +// navController.navigate(Screen.CommentScreen.route) + }, + ) + } + } + } + } +} + +@Composable +@Preview +fun UserPostsScreenPreview() { + WalkieTheme { + UserPostScreen(User.DUMMY, listOf(Post.DUMMY), 0) + } +} \ No newline at end of file diff --git a/presentation/src/main/java/com/whyranoid/presentation/viewmodel/CommunityScreenViewModel.kt b/presentation/src/main/java/com/whyranoid/presentation/viewmodel/CommunityScreenViewModel.kt index cb74f61..6406e29 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/viewmodel/CommunityScreenViewModel.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/viewmodel/CommunityScreenViewModel.kt @@ -43,6 +43,9 @@ class CommunityScreenViewModel( } fun getPosts() = intent { + reduce { + state.copy(posts = UiState.Loading) + } val result = getFollowingsPostsUseCase() result.onSuccess { posts -> reduce { From 0c72a90ba4b92ed3b9bbd6661f47ac65a2f35da4 Mon Sep 17 00:00:00 2001 From: yonghanJu Date: Mon, 26 Aug 2024 21:16:43 +0900 Subject: [PATCH 8/9] =?UTF-8?q?:sparkles:=20=EC=84=9C=EB=B2=84=20=EC=9D=B4?= =?UTF-8?q?=EC=A0=84=20baseURL=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/src/main/java/com/whyranoid/data/API.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/src/main/java/com/whyranoid/data/API.kt b/data/src/main/java/com/whyranoid/data/API.kt index 9a2061b..844951b 100644 --- a/data/src/main/java/com/whyranoid/data/API.kt +++ b/data/src/main/java/com/whyranoid/data/API.kt @@ -1,7 +1,7 @@ package com.whyranoid.data object API { - const val BASE_URL = "https://walkie-tsvdh.run.goorm.site/" + const val BASE_URL = "http://3.35.102.89:8080/" const val CHECK_NICKNAME = "api/walkies/signup/check" From 890965824260b0f501012af9b8619d2aaf08eb22 Mon Sep 17 00:00:00 2001 From: yonghanJu Date: Mon, 26 Aug 2024 21:45:43 +0900 Subject: [PATCH 9/9] =?UTF-8?q?:sparkles:=20=EC=BB=A4=EB=AE=A4=EB=8B=88?= =?UTF-8?q?=ED=8B=B0=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20pull=20refresh=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/screens/CommunityScreen.kt | 105 ++++++++++++------ .../screens/community/UserPostsScreen.kt | 101 +++++++++++++++++ .../viewmodel/CommunityScreenViewModel.kt | 3 + 3 files changed, 173 insertions(+), 36 deletions(-) create mode 100644 presentation/src/main/java/com/whyranoid/presentation/screens/community/UserPostsScreen.kt diff --git a/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt b/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt index 2187693..2c90df1 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/screens/CommunityScreen.kt @@ -1,12 +1,16 @@ package com.whyranoid.presentation.screens import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyRow +import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.Icon import androidx.compose.material.Scaffold import androidx.compose.material.Text @@ -14,6 +18,9 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.KeyboardArrowDown import androidx.compose.material.icons.filled.Search +import androidx.compose.material.pullrefresh.PullRefreshIndicator +import androidx.compose.material.pullrefresh.pullRefresh +import androidx.compose.material.pullrefresh.rememberPullRefreshState import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier @@ -28,6 +35,7 @@ import com.whyranoid.presentation.viewmodel.CommunityScreenViewModel import org.koin.androidx.compose.koinViewModel import org.orbitmvi.orbit.compose.collectAsState +@OptIn(ExperimentalMaterialApi::class) @Composable fun CommunityScreen(navController: NavController) { val viewModel = koinViewModel() @@ -47,9 +55,9 @@ fun CommunityScreen(navController: NavController) { Icon( modifier = - Modifier - .clickable { - }, + Modifier + .clickable { + }, imageVector = Icons.Filled.KeyboardArrowDown, contentDescription = "Down Arrow", ) @@ -59,10 +67,10 @@ fun CommunityScreen(navController: NavController) { Row { Icon( modifier = - Modifier - .clickable { - navController.navigate(Screen.AddPostScreen.route) - }, + Modifier + .clickable { + navController.navigate(Screen.AddPostScreen.route) + }, imageVector = Icons.Filled.Add, contentDescription = "추가 버튼", ) @@ -71,10 +79,10 @@ fun CommunityScreen(navController: NavController) { Icon( modifier = - Modifier - .clickable { - navController.navigate(Screen.SearchFriendScreen.route) - }, + Modifier + .clickable { + navController.navigate(Screen.SearchFriendScreen.route) + }, imageVector = Icons.Filled.Search, contentDescription = "검색 버튼", ) @@ -83,36 +91,61 @@ fun CommunityScreen(navController: NavController) { ) }, ) { - LazyColumn( - modifier = Modifier.padding(it), + + Column( + modifier = Modifier.padding(it) ) { - item { - LazyRow { - repeat(10) { - item { RunningFollowerItemWithLikable(isDisplayName = true) } - } + LazyRow { + repeat(10) { + item { RunningFollowerItemWithLikable(isDisplayName = true) } } } - state.posts.getDataOrNull()?.forEach { post -> - item { - PostItem( - post = post, - onLikeClicked = { postId -> - viewModel.likePost(postId) - }, - onProfileClicked = { user -> - state.following.getDataOrNull()?.let { followings -> - val isFollowing = followings.contains(user) - navController.navigate("userPage/${user.uid}/${user.nickname}/$isFollowing") - } - }, - onCommentClicked = { post -> - navController.currentBackStackEntry?.savedStateHandle?.set("post", post) - navController.navigate(Screen.CommentScreen.route) - }, - ) + val refreshing = state.posts.getDataOrNull() == null + + val pullRefreshState = rememberPullRefreshState( + refreshing = refreshing, + onRefresh = { + viewModel.getPosts() + } + ) + + Box( + modifier = Modifier + .fillMaxSize() + .pullRefresh(pullRefreshState) + ) { + LazyColumn { + state.posts.getDataOrNull()?.forEach { post -> + item { + PostItem( + post = post, + onLikeClicked = { postId -> + viewModel.likePost(postId) + }, + onProfileClicked = { user -> + state.following.getDataOrNull()?.let { followings -> + val isFollowing = followings.contains(user) + navController.navigate("userPage/${user.uid}/${user.nickname}/$isFollowing") + } + }, + onCommentClicked = { post -> + navController.currentBackStackEntry?.savedStateHandle?.set( + "post", + post + ) + navController.navigate(Screen.CommentScreen.route) + }, + ) + } + } } + + PullRefreshIndicator( + refreshing = refreshing, + state = pullRefreshState, + modifier = Modifier.align(androidx.compose.ui.Alignment.TopCenter) + ) } } } diff --git a/presentation/src/main/java/com/whyranoid/presentation/screens/community/UserPostsScreen.kt b/presentation/src/main/java/com/whyranoid/presentation/screens/community/UserPostsScreen.kt new file mode 100644 index 0000000..52f7978 --- /dev/null +++ b/presentation/src/main/java/com/whyranoid/presentation/screens/community/UserPostsScreen.kt @@ -0,0 +1,101 @@ +package com.whyranoid.presentation.screens.community + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.wrapContentHeight +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.whyranoid.domain.model.post.Post +import com.whyranoid.domain.model.user.User +import com.whyranoid.presentation.component.community.PostItem +import com.whyranoid.presentation.theme.WalkieTheme +import com.whyranoid.presentation.theme.WalkieTypography +import com.whyranoid.presentation.viewmodel.CommunityScreenViewModel +import org.koin.androidx.compose.koinViewModel + +@Composable +fun UserPostScreen( + user: User, + postPreviews: List, + startIndex: Int, + onBackPressed: () -> Unit = {}, + +) { + + val viewModel = koinViewModel() + + Column( + modifier = Modifier + .fillMaxWidth() + .wrapContentHeight(), + verticalArrangement = Arrangement.Top, + ) { + Column( + Modifier + .fillMaxWidth() + .padding(horizontal = 20.dp) + .padding(top = 20.dp), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Box( + contentAlignment = Alignment.CenterStart, + ) { + Column( + modifier = Modifier.align(Alignment.Center), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Text( + style = WalkieTypography.Body1_Normal, + text = user.nickname, + modifier = Modifier + .padding(bottom = 24.dp), + ) + Text( + style = WalkieTypography.Title, + text = "게시물", + modifier = Modifier + .padding(bottom = 24.dp), + ) + } + + } + + + Column { + postPreviews.forEach { post -> + PostItem( + post = post, + onLikeClicked = { postId -> + viewModel.likePost(postId) + }, + onProfileClicked = { user -> + // navController.back + }, + onCommentClicked = { post -> +// navController.currentBackStackEntry?.savedStateHandle?.set( +// "post", +// post +// ) +// navController.navigate(Screen.CommentScreen.route) + }, + ) + } + } + } + } +} + +@Composable +@Preview +fun UserPostsScreenPreview() { + WalkieTheme { + UserPostScreen(User.DUMMY, listOf(Post.DUMMY), 0) + } +} \ No newline at end of file diff --git a/presentation/src/main/java/com/whyranoid/presentation/viewmodel/CommunityScreenViewModel.kt b/presentation/src/main/java/com/whyranoid/presentation/viewmodel/CommunityScreenViewModel.kt index cb74f61..6406e29 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/viewmodel/CommunityScreenViewModel.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/viewmodel/CommunityScreenViewModel.kt @@ -43,6 +43,9 @@ class CommunityScreenViewModel( } fun getPosts() = intent { + reduce { + state.copy(posts = UiState.Loading) + } val result = getFollowingsPostsUseCase() result.onSuccess { posts -> reduce {