Skip to content

Commit

Permalink
Merge branch 'compose/develop' into compose/community_ui_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yonghanJu committed Aug 26, 2024
2 parents 35e5875 + 8909658 commit e37086b
Show file tree
Hide file tree
Showing 36 changed files with 400 additions and 254 deletions.
2 changes: 1 addition & 1 deletion app/src/main/res/xml/path_provider.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-cache-path name="my_images" path="/"/>
<external-path name="my_images" path="/"/>
</paths>
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.whyranoid.data.datasource.account

import com.whyranoid.data.getResult
import com.whyranoid.data.model.account.ChangeMyInfoRequest
import com.whyranoid.data.model.account.SignUpRequest
import com.whyranoid.data.model.account.toLoginData
import com.whyranoid.data.model.account.toUserInfo
import com.whyranoid.domain.datasource.AccountDataSource
import com.whyranoid.domain.model.account.LoginData
import com.whyranoid.domain.model.account.UserInfo
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File

class AccountDataSourceImpl(private val accountService: AccountService) : AccountDataSource {
override suspend fun signUp(
Expand Down Expand Up @@ -54,12 +59,18 @@ class AccountDataSourceImpl(private val accountService: AccountService) : Accoun

override suspend fun changeMyInfo(walkieId: Long, nickName: String, profileUrl: String?): Result<Boolean> {
return kotlin.runCatching {
var imagePart: MultipartBody.Part? = null

if (profileUrl != null) {
val file = File(profileUrl)
val fileBody = RequestBody.create(MediaType.parse("image/*"), file)
imagePart = MultipartBody.Part.createFormData("profileImg", file.name, fileBody)
}

val response = accountService.changeMyInfo(
walkieId,
ChangeMyInfoRequest(
profileImg = profileUrl ?: "",
nickname = nickName
)
imagePart,
nickName
)
if (response.isSuccessful) {
return Result.success(true)
Expand All @@ -68,4 +79,10 @@ class AccountDataSourceImpl(private val accountService: AccountService) : Accoun
}
}
}

override suspend fun getUserInfo(walkieId: Long): Result<UserInfo> {
return kotlin.runCatching {
accountService.getMyInfo(walkieId).getResult { it.toUserInfo() }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.whyranoid.data.datasource.account

import com.whyranoid.data.API
import com.whyranoid.data.model.account.ChangeMyInfoRequest
import com.whyranoid.data.model.account.ChangeMyInfoResponse
import com.whyranoid.data.model.account.LoginDataResponse
import com.whyranoid.data.model.account.NickCheckResponse
import com.whyranoid.data.model.account.SignUpRequest
import com.whyranoid.data.model.account.SignUpResponse
import com.whyranoid.data.model.account.UserInfoResponse
import okhttp3.MultipartBody
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Query

interface AccountService {
Expand All @@ -31,7 +33,13 @@ interface AccountService {

@POST(API.WalkingControl.MY)
suspend fun changeMyInfo(
@Query("walkieId") id: Long,
@Body myInfoRequest: ChangeMyInfoRequest
@Part("walkieId") id: Long,
@Part profileImg: MultipartBody.Part?,
@Part("nickname") nickName: String,
): Response<ChangeMyInfoResponse>

@GET(API.WalkingControl.MY)
suspend fun getMyInfo(
@Query("walkieId") id: Long
): Response<UserInfoResponse>
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.whyranoid.data.model.account

import com.whyranoid.domain.model.account.UserInfo

data class UserInfoResponse (
val nickname: String,
val profileImg: String?
)

fun UserInfoResponse.toUserInfo() = UserInfo(
name = "", // TODO 수정
nickname = nickname,
profileImg = profileImg
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.util.Log
import com.whyranoid.data.AccountDataStore
import com.whyranoid.domain.datasource.AccountDataSource
import com.whyranoid.domain.model.account.Sex
import com.whyranoid.domain.model.account.UserInfo
import com.whyranoid.domain.repository.AccountRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
Expand All @@ -14,13 +15,13 @@ class AccountRepositoryImpl(
) : AccountRepository {

override val authId: Flow<String?> = accountDataStore.authId
override val uId: Flow<Long?> = accountDataStore.uId
override val walkieId: Flow<Long?> = accountDataStore.uId
override val userName: Flow<String?> = accountDataStore.userName
override val nickName: Flow<String?> = accountDataStore.nickName
override val profileUrl: Flow<String?> = accountDataStore.profileUrl

override suspend fun getUID(): Long {
return requireNotNull(uId.first())
return requireNotNull(walkieId.first())
}

override suspend fun signUp(
Expand Down Expand Up @@ -102,4 +103,8 @@ class AccountRepositoryImpl(
return Result.failure(Exception("마이페이지 정보 수정 실패"))
}
}

override suspend fun getUserInfo(walkieId: Long): Result<UserInfo> {
return accountDataSource.getUserInfo(walkieId)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.whyranoid.domain.datasource

import com.whyranoid.domain.model.account.LoginData
import com.whyranoid.domain.model.account.UserInfo

interface AccountDataSource {
suspend fun signUp(
Expand All @@ -16,4 +17,6 @@ interface AccountDataSource {
suspend fun signIn(authorId: String): Result<LoginData>

suspend fun changeMyInfo(walkieId: Long, nickName: String, profileUrl: String?): Result<Boolean>

suspend fun getUserInfo(walkieId: Long): Result<UserInfo>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.whyranoid.domain.model.account

data class UserInfo (
val name: String,
val profileImg: String?,
val nickname: String
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.whyranoid.domain.repository

import com.whyranoid.domain.model.account.Sex
import com.whyranoid.domain.model.account.UserInfo
import kotlinx.coroutines.flow.Flow

interface AccountRepository {

val authId: Flow<String?>
val uId: Flow<Long?>
val walkieId: Flow<Long?>
val userName: Flow<String?>
val nickName: Flow<String?>
val profileUrl: Flow<String?>
Expand All @@ -33,4 +34,6 @@ interface AccountRepository {
suspend fun checkNickName(nickName: String): Result<Pair<Boolean, String>>

suspend fun changeMyInfo(walkieId: Long, nickName: String, profileUrl: String?): Result<Boolean>

suspend fun getUserInfo(walkieId: Long): Result<UserInfo>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GetChallengePreviewsByTypeUseCase(
) {
suspend operator fun invoke(type: ChallengeType): List<ChallengePreview> {
return challengeRepository.getChallengePreviewsByType(
accountRepository.uId.first()?.toInt() ?: -1, type
accountRepository.walkieId.first()?.toInt() ?: -1, type
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GetFollowingsPostsUseCase(
private val postRepository: PostRepository,
) {
suspend operator fun invoke(): Result<List<Post>> {
val myUid = requireNotNull(accountRepository.uId.first())
val myUid = requireNotNull(accountRepository.walkieId.first())
return postRepository.getMyFollowingsPost(myUid)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class GetMyUidUseCase(
private val accountRepository: AccountRepository,
) {
suspend operator fun invoke(): Result<Long> {
return runCatching { requireNotNull(accountRepository.uId.firstOrNull()) }
return runCatching { requireNotNull(accountRepository.walkieId.firstOrNull()) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LikePostUseCase(
) {

suspend operator fun invoke(postId: Long): Result<Long> {
val uid = requireNotNull(accountRepository.uId.first())
val uid = requireNotNull(accountRepository.walkieId.first())
return communityRepository.likePost(postId, uid)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UploadPostUseCase @Inject constructor(
history: String,
imagePath: String,
): Result<String> {
return accountRepository.uId.first()?.let { uid ->
return accountRepository.walkieId.first()?.let { uid ->
postRepository.uploadPost(uid, content, colorMode, history, imagePath)
} ?: kotlin.run {
Result.failure(Exception("Account Error"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FollowUseCase(
) {
suspend operator fun invoke(otherUId: Long): Result<Long> {
return runCatching {
val uid = requireNotNull(accountRepository.uId.first())
val uid = requireNotNull(accountRepository.walkieId.first())
followRepository.follow(uid, otherUId).getOrThrow()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RemoveFollowerUseCase(
) {
suspend operator fun invoke(otherUId: Long): Result<Long> {
return runCatching {
val uid = requireNotNull(accountRepository.uId.first())
val uid = requireNotNull(accountRepository.walkieId.first())
followRepository.unfollow(otherUId, uid).getOrThrow()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SendCommentUseCase(
postId: Long,
content: String,
): Result<Unit> {
val commenterId = accountRepository.uId.first() ?: return Result.failure(Exception("uid is null"))
val commenterId = accountRepository.walkieId.first() ?: return Result.failure(Exception("uid is null"))
return postRepository.sendComment(
postId,
commenterId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UnFollowUseCase(
) {
suspend operator fun invoke(otherUId: Long): Result<Long> {
return runCatching {
val uid = requireNotNull(accountRepository.uId.first())
val uid = requireNotNull(accountRepository.walkieId.first())
followRepository.unfollow(uid, otherUId).getOrThrow()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GetRunningFollowerUseCase(
var followings = listOf<User>()
var runningFollowings = listOf<User>()
kotlin.runCatching {
id = requireNotNull(accountRepository.uId.first())
id = requireNotNull(accountRepository.walkieId.first())
}
return callbackFlow {
while (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RunningFinishUseCase(
private val runningRepository: RunningRepository,
) {
suspend operator fun invoke(): Result<Unit> {
accountRepository.uId.first()?.let { id ->
accountRepository.walkieId.first()?.let { id ->
return runningRepository.finishRunning(id)
}
return Result.failure(Exception("ID 정보 없음"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RunningStartUseCase(
private val runningRepository: RunningRepository,
) {
suspend operator fun invoke(): Result<Long> {
accountRepository.uId.first()?.let { id ->
accountRepository.walkieId.first()?.let { id ->
return runningRepository.startRunning(id)
}
return Result.failure(Exception("ID 정보 없음"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SendLikeUseCase(
) {
suspend operator fun invoke(receiverId: Long): Result<Unit> {
return kotlin.runCatching {
val uid = requireNotNull(accountRepository.uId.first())
val uid = requireNotNull(accountRepository.walkieId.first())
runningRepository.sendLike(uid, receiverId).onSuccess {
return Result.success(Unit)
}.onFailure {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ androidx-core = "1.13.1"
androidx-appcompat = "1.6.1"
androidx-constraintlayout = "2.1.4"
naver-maps-android-sdk = "3.16.2"
hilt = "2.44"
hilt = "2.48.1"
javax-inject = "1"

android-material = "1.8.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.whyranoid.presentation.reusable

import android.content.Context
import android.widget.Toast

object SingleToast {

private const val DEFAULT_DURATION = 2_000L
private var lastToastInfo: Pair<String, Long>? = null

fun show(
context: Context,
message: String,
duration: Int = Toast.LENGTH_SHORT
) {
if (lastToastInfo?.first != message) {
lastToastInfo = message to System.currentTimeMillis()
Toast.makeText(context, message, duration).show()
} else {
lastToastInfo?.second?.let {lastToastTime ->
if (System.currentTimeMillis() - lastToastTime > DEFAULT_DURATION) {
lastToastInfo = message to System.currentTimeMillis()
Toast.makeText(context, message, duration).show()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.whyranoid.presentation.screens.challenge

import android.widget.Toast
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -45,6 +44,7 @@ import com.whyranoid.presentation.component.ChallengeGoalContent
import com.whyranoid.presentation.component.UserIcon
import com.whyranoid.presentation.component.bottomsheet.ChallengeExitModalBottomSheetContainer
import com.whyranoid.presentation.component.button.WalkiePositiveButton
import com.whyranoid.presentation.reusable.SingleToast
import com.whyranoid.presentation.reusable.WalkieCircularProgressIndicator
import com.whyranoid.presentation.theme.SystemColor
import com.whyranoid.presentation.theme.WalkieTypography
Expand Down Expand Up @@ -75,12 +75,12 @@ fun ChallengeDetailScreen(
viewModel.collectSideEffect {
when (it) {
ChallengeDetailSideEffect.StartChallengeSuccess -> {
Toast.makeText(context, "챌린지를 성공적으로 시작하였습니다.", Toast.LENGTH_SHORT).show()
SingleToast.show(context, "챌린지를 성공적으로 시작하였습니다.")
navController.popBackStack()
}

ChallengeDetailSideEffect.StartChallengeFailure -> {
Toast.makeText(context, "챌린지를 시작할 수 없습니다.", Toast.LENGTH_SHORT).show()
SingleToast.show(context, "챌린지를 시작할 수 없습니다.")
}
}
}
Expand Down
Loading

0 comments on commit e37086b

Please sign in to comment.