Skip to content

Commit

Permalink
Merge pull request #67 from Team-Walkie/compose/community
Browse files Browse the repository at this point in the history
유저 프로필 세부 구현 및 네비게이션 연결
  • Loading branch information
yonghanJu authored Jan 25, 2024
2 parents 5e22969 + 7f82a78 commit f9a868d
Show file tree
Hide file tree
Showing 24 changed files with 312 additions and 146 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {
minSdk = 26
targetSdk = 33
versionCode = 1
versionName = "1.0.8"
versionName = "1.0.9"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/whyranoid/walkie/KoinModules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ val viewModelModule = module {
single { ChallengeMainViewModel(get(), get(), get()) }
single { ChallengeDetailViewModel(get()) }
single { ChallengeExitViewModel(get()) }
factory { UserPageViewModel(get(), get(), get(), get(), get(), get()) }
factory { UserPageViewModel(get(), get(), get(), get(), get(), get(), get(), get()) }
factory { RunningViewModel(get(), get(), get(), get(), get(), get()) }
factory { RunningEditViewModel() }
factory { SplashViewModel(get()) }
Expand Down Expand Up @@ -148,7 +148,7 @@ val useCaseModule = module {
single { GetPostUseCase(get()) }
single { GetUserPostPreviewsUseCase(get(), get()) }
single { GetUserBadgesUseCase(get()) }
single { GetUserDetailUseCase(get()) }
single { GetUserDetailUseCase(get(), get()) }
single { GetRunningFollowerUseCase(get(), get()) }
single { RunningFinishUseCase(get(), get()) }
single { RunningStartUseCase(get(), get()) }
Expand Down
2 changes: 2 additions & 0 deletions data/src/main/java/com/whyranoid/data/API.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ object API {
const val LIKE_TOTAL = "api/walk/count-total"

const val LIKE_COUNT = "api/walk/count-like"

const val MY = "/api/walkies/my"
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
package com.whyranoid.data.datasource

import com.whyranoid.data.AccountDataStore
import android.util.Log
import com.whyranoid.data.datasource.community.CommunityService
import com.whyranoid.domain.datasource.UserDataSource
import com.whyranoid.domain.model.user.User
import com.whyranoid.domain.model.user.UserDetail
import kotlinx.coroutines.flow.first

class UserDataSourceImpl(private val dataStore: AccountDataStore) : UserDataSource {
// TODO: change to api call
class UserDataSourceImpl(
private val communityService: CommunityService,
) : UserDataSource {
override suspend fun getUser(uid: Long): Result<User> {
val savedUId = dataStore.uId.first()
return if (savedUId == uid) {
kotlin.runCatching {
val name = dataStore.userName.first()
val nickName = dataStore.nickName.first()
val imageUrl = dataStore.profileUrl.first()
User(
savedUId,
requireNotNull(name),
requireNotNull(nickName),
requireNotNull(imageUrl),
) // TODO uid 변경 사항 적용
}
} else {
Result.success(User.DUMMY)
return kotlin.runCatching {
val response = requireNotNull(communityService.getUserNickProfile(uid).body())
User(
uid,
requireNotNull(response.nickname),
requireNotNull(response.nickname),
requireNotNull(response.profileImg),
)
}.onFailure {
Log.d("UserDataSourceImpl", it.message.toString())
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package com.whyranoid.data.datasource.community

import com.whyranoid.data.API
import com.whyranoid.data.model.account.NickProfileResponse
import com.whyranoid.data.model.community.request.PostLikeRequest
import com.whyranoid.data.model.community.response.PostLikeResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Query

interface CommunityService {

@POST(API.SEND_LIKE)
suspend fun likePost(@Body postLikeRequest: PostLikeRequest): Response<PostLikeResponse>

}
@GET(API.WalkingControl.MY)
suspend fun getUserNickProfile(
@Query("walkieId") id: Long,
): Response<NickProfileResponse>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.whyranoid.data.datasource.running

import com.whyranoid.data.API
import com.whyranoid.data.model.account.NickProfileResponse
import com.whyranoid.data.model.running.LikeTotalResponse
import com.whyranoid.data.model.running.RunningFinishRequest
import com.whyranoid.data.model.running.RunningStartRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.whyranoid.data.model.account

import com.google.gson.annotations.SerializedName

data class NickProfileResponse(
@SerializedName("profileImg") val profileImg: String?,
@SerializedName("nickname") val nickname: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class UserDetail(
val postCount: Int,
val followerCount: Int,
val followingCount: Int,
val isFollowing: Boolean,
val isFollowing: Boolean? = null,
) {
companion object {
val DUMMY = UserDetail(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.whyranoid.domain.usecase

import com.whyranoid.domain.model.user.UserDetail
import com.whyranoid.domain.repository.FollowRepository
import com.whyranoid.domain.repository.UserRepository

class GetUserDetailUseCase(
private val userRepository: UserRepository,
private val followRepository: FollowRepository,
) {
suspend operator fun invoke(uid: Long): Result<UserDetail> {
return kotlin.runCatching {
val user = userRepository.getUser(uid).getOrThrow()
UserDetail(user, 0, 0, 0, true)
val followingCount = followRepository.getFollowings(user.uid).getOrThrow().size
val followerCount = followRepository.getFollowers(user.uid).getOrThrow().size
UserDetail(user, 0, followerCount, followingCount, true)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.whyranoid.domain.usecase.community

import com.whyranoid.domain.model.user.User
import com.whyranoid.domain.repository.AccountRepository
import com.whyranoid.domain.repository.FollowRepository
import kotlinx.coroutines.flow.first
Expand All @@ -9,10 +8,10 @@ class FollowUseCase(
private val accountRepository: AccountRepository,
private val followRepository: FollowRepository,
) {
suspend operator fun invoke(other: User) {
runCatching {
suspend operator fun invoke(otherUId: Long): Result<Long> {
return runCatching {
val uid = requireNotNull(accountRepository.uId.first())
followRepository.follow(uid, other.uid)
followRepository.follow(uid, otherUId).getOrThrow()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.whyranoid.domain.usecase.community

import com.whyranoid.domain.model.user.User
import com.whyranoid.domain.repository.AccountRepository
import com.whyranoid.domain.repository.FollowRepository
import kotlinx.coroutines.flow.first
Expand All @@ -9,10 +8,10 @@ class UnFollowUseCase(
private val accountRepository: AccountRepository,
private val followRepository: FollowRepository,
) {
suspend operator fun invoke(other: User) {
runCatching {
suspend operator fun invoke(otherUId: Long): Result<Long> {
return runCatching {
val uid = requireNotNull(accountRepository.uId.first())
followRepository.unfollow(uid, other.uid)
followRepository.unfollow(uid, otherUId).getOrThrow()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,39 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.whyranoid.domain.model.post.Post
import com.whyranoid.domain.model.user.User

@Composable
fun PostItem(
post: Post,
onLikeClicked: (Long) -> Unit = {},
onProfileClicked: (User) -> Unit = {},
) {
Column(
modifier = Modifier
.fillMaxHeight()
Modifier.fillMaxHeight(),
) {

Divider(
modifier = Modifier
.fillMaxWidth()
.height(1.dp)
.height(1.dp),
)

PostProfileItem(post.author)
PostProfileItem(
post.author,
onProfileClicked,
)

AsyncImage(
model = post.imageUrl, contentDescription = "게시글 사진",
model = post.imageUrl,
contentDescription = "게시글 사진",
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f),
contentScale = ContentScale.Crop
contentScale = ContentScale.Crop,
)

PostContentItem(post) {
onLikeClicked(it)
}

}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.whyranoid.presentation.component.community

import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -22,40 +23,43 @@ import com.whyranoid.presentation.theme.WalkieColor
import com.whyranoid.presentation.theme.WalkieTypography

@Composable
fun PostProfileItem(user: User) {
fun PostProfileItem(
user: User,
onProfileClicked: (User) -> Unit = {},
) {
Row(
modifier = Modifier
Modifier.clickable { onProfileClicked(user) }
.fillMaxWidth()
.padding(horizontal = 12.dp, vertical = 10.dp),
verticalAlignment = Alignment.CenterVertically
verticalAlignment = Alignment.CenterVertically,
) {

Box(
modifier = Modifier
.size(27.dp)
.border(1.dp, WalkieColor.Primary, CircleShape)
.clip(CircleShape),
contentAlignment = Alignment.Center
contentAlignment = Alignment.Center,
) {
AsyncImage(
model = user.imageUrl, contentDescription = "내 프로필 이미지",
model = user.imageUrl,
contentDescription = "내 프로필 이미지",
modifier = Modifier
.size(24.dp)
.border(0.5.dp, WalkieColor.GrayBorder, CircleShape)
.clip(CircleShape),
contentScale = ContentScale.Crop
contentScale = ContentScale.Crop,
)
}
Spacer(modifier = Modifier.size(11.dp))
Column {
Text(
user.nickname,
style = WalkieTypography.Body1
style = WalkieTypography.Body1,
)
Text(
"Seoul, park",
style = WalkieTypography.Body2
style = WalkieTypography.Body2,
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import com.whyranoid.presentation.theme.WalkieColor

@Composable
fun CheckableCustomTextField(
Expand All @@ -37,7 +38,7 @@ fun CheckableCustomTextField(
onTextChanged?.invoke(it)
},
singleLine = true,
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
cursorBrush = SolidColor(WalkieColor.Primary),
textStyle = textStyle,
decorationBox = { innerTextField ->
Row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fun AppScreenContent(
val arguments = requireNotNull(backStackEntry.arguments)
val uid = arguments.getLong(Screen.UID_ARGUMENT)
val nickname = requireNotNull(arguments.getString(Screen.NICKNAME_ARGUMENT))
val isFollowing = arguments.getBoolean(Screen.NICKNAME_ARGUMENT)
val isFollowing = arguments.getBoolean(Screen.IS_FOLLOWING_ARGUMENT)
UserPageScreen(navController, uid, nickname, isFollowing)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,18 @@ fun CommunityScreen(

state.posts.getDataOrNull()?.forEach { post ->
item {
PostItem(post = post) { postId ->
viewModel.likePost(postId)
}
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")
}
},
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fun SearchFriendScreen(
},
cursorBrush = SolidColor(WalkieColor.Primary),
singleLine = true,
) {
) { innerTextField ->
if (query.value.isEmpty()) {
Text(
text = "워키 아이디로 친구찾기",
Expand All @@ -130,6 +130,7 @@ fun SearchFriendScreen(
style = WalkieTypography.Body1_Normal,
)
}
innerTextField()
}
}
}
Expand Down
Loading

0 comments on commit f9a868d

Please sign in to comment.