Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT/#244] 여행 친구 조회 뷰 / 서버 통신 구현 #245

Merged
merged 8 commits into from
Mar 11, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,31 @@ import kotlinx.serialization.Serializable

@Serializable
data class CheckFriendsResponseDto(
@SerialName("bestPrefer")
val bestPrefer: List<String>,
@SerialName("participants")
val participants: List<TripParticipantResponseDto>,
@SerialName("styles")
val styles: List<StylesResponseDto>
) {

@Serializable
data class StylesResponseDto(
@SerialName("rate")
val rate: Int,
@SerialName("isLeft")
val isLeft: Boolean
@SerialName("rates")
val rates: List<Int>,
@SerialName("counts")
val counts: List<Int>
) {
fun toStyleModel() =
CheckFriendsModel.StylesModel(rate, isLeft)
CheckFriendsModel.StylesModel(rates, counts)
}

fun toCheckFriendsModel() =
CheckFriendsModel(participants.map {
it.toTripParticipantModel()
}, styles.map {
it.toStyleModel()
})
CheckFriendsModel(
bestPrefer,
participants.map {
it.toTripParticipantModel()
}, styles.map {
it.toStyleModel()
Comment on lines +30 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map 좋네욥~!

})

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.going.domain.entity.response

data class CheckFriendsModel(
val bestPrefer: List<String>,
val participants: List<TripParticipantModel>,
val styles: List<StylesModel>
) {
data class StylesModel(
val rate: Int,
val isLeft: Boolean
val rates: List<Int>,
val counts: List<Int>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class InviteFinishActivity :
startDate: String,
endDate: String,
day: Int,
): Intent = Intent(context, EnterTripActivity::class.java).apply {
): Intent = Intent(context, InviteFinishActivity::class.java).apply {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅎㅎ..수정 감ㅅㅏ합니도~...ㅎㅎ

putExtra(TRIP_ID, tripId)
putExtra(TITLE, title)
putExtra(START, startDate)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.going.presentation.todo.ourtodo

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
Expand Down Expand Up @@ -137,10 +136,10 @@ class OurTodoFragment() : BaseFragment<FragmentOurTodoBinding>(R.layout.fragment

private fun initTripFriendBtnClickListener() {
binding.btnOurTripFriend.setOnSingleClickListener {
Intent(requireActivity(), CheckFriendsActivity::class.java).apply {
putExtra(EXTRA_TRIP_ID, viewModel.tripId)
startActivity(this)
}
CheckFriendsActivity.createIntent(
requireContext(),
viewModel.tripId
).apply { startActivity(this) }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.going.presentation.todo.ourtodo.checkfriends

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import android.util.Log
import androidx.activity.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -37,10 +38,13 @@ class CheckFriendsActivity :

initBackClickListener()
initAdapterWithClickListener()
getTripId()
observeCheckFriendsListState()
setResultTextColor()
}

override fun onResume() {
super.onResume()

getTripId()
}

private fun initBackClickListener() {
Expand All @@ -54,7 +58,7 @@ class CheckFriendsActivity :
ParticipantProfileActivity.createIntent(
this,
participantId,
0
intent.getLongExtra(TRIP_ID, 0)
).apply { startActivity(this) }
}
binding.rvCheckFriendsMember.adapter = adapter
Expand All @@ -81,34 +85,117 @@ class CheckFriendsActivity :

private fun setFriendsData(data: CheckFriendsModel) {
adapter.submitList(data.participants)
val rate = data.styles.map { it.rate }
setProgressBarStatus(rate)

setProgressBarStatus(data.styles.map { it.rates })
setCountStatus(data.styles.map { it.counts })
setResultTextColor(data.bestPrefer)
}

private fun setProgressBarStatus(rate: List<Int>) {
private fun setProgressBarStatus(rates: List<List<Int>>) {
with(binding) {
val progressBars = listOf(
progressBarCheckFriends1,
progressBarCheckFriends2,
progressBarCheckFriends3,
progressBarCheckFriends4,
progressBarCheckFriends5
)

for (i in rates.indices) {
progressBars[i].progress = rates[i][0]
progressBars[i].secondaryProgress = rates[i][0] + rates[i][1]
}
}
}

val progressBars = listOf(
binding.progressBarCheckFriends1,
binding.progressBarCheckFriends2,
binding.progressBarCheckFriends3,
binding.progressBarCheckFriends4,
binding.progressBarCheckFriends5
)
private fun setCountStatus(counts: List<List<Int>>) {
with(binding) {
val countsLeftList = mutableListOf(
tvCheckFriendsPreferenceNumber1Left,
tvCheckFriendsPreferenceNumber2Left,
tvCheckFriendsPreferenceNumber3Left,
tvCheckFriendsPreferenceNumber4Left,
tvCheckFriendsPreferenceNumber5Left,
)

val countsCenterList = mutableListOf(
tvCheckFriendsPreferenceNumber1Center,
tvCheckFriendsPreferenceNumber2Center,
tvCheckFriendsPreferenceNumber3Center,
tvCheckFriendsPreferenceNumber4Center,
tvCheckFriendsPreferenceNumber5Center,
)

val countsRightList = mutableListOf(
tvCheckFriendsPreferenceNumber1Right,
tvCheckFriendsPreferenceNumber2Right,
tvCheckFriendsPreferenceNumber3Right,
tvCheckFriendsPreferenceNumber4Right,
tvCheckFriendsPreferenceNumber5Right
)

for (i in counts.indices) {
countsLeftList[i].text =
getString(R.string.check_friends_preference_number, counts[i][0])
countsCenterList[i].text =
getString(R.string.check_friends_preference_number, counts[i][1])
countsRightList[i].text =
getString(R.string.check_friends_preference_number, counts[i][2])
}

for (i in rate.indices) {
progressBars[i].progress = rate[i]
}

}

private fun setResultTextColor() {
binding.tvCheckFriendsResult.apply {
text = SpannableStringBuilder(text).apply {
setSpan(
ForegroundColorSpan(
colorOf(R.color.red_500)
), 0, 9, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
private fun setResultTextColor(bestPrefer: List<String>) {
binding.tvCheckFriendsResult.text = when {
bestPrefer.isEmpty() -> {
SpannableStringBuilder(getString(R.string.check_friends_result_no_match)).apply {
setSpan(
ForegroundColorSpan(
colorOf(R.color.red_500)
), 0, 11, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}

bestPrefer.size < 5 -> {
val bestPreferList = setBestPreferList(bestPrefer)
val bestPreferString = bestPreferList.joinToString(separator = ", ")
SpannableStringBuilder(
getString(
R.string.check_friends_result_match,
bestPreferString
)
).apply {
setSpan(
ForegroundColorSpan(colorOf(R.color.red_500)),
0,
bestPreferString.length,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}

else -> {
SpannableStringBuilder(getString(R.string.check_friends_result_perfect)).apply {
setSpan(
ForegroundColorSpan(
colorOf(R.color.red_500)
), 0, 11, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}
}
}

private fun setBestPreferList(bestPrefer: List<String>): List<String> {
return bestPrefer.map { prefer ->
when (prefer) {
getString(R.string.check_friends_preference_1_title) -> getString(R.string.check_friends_result_match_1)
getString(R.string.check_friends_preference_2_title) -> getString(R.string.check_friends_result_match_2)
getString(R.string.check_friends_preference_5_title) -> getString(R.string.check_friends_result_match_5)
else -> prefer
}
}
}
Expand All @@ -118,4 +205,16 @@ class CheckFriendsActivity :
_adapter = null
}

companion object {
private const val TRIP_ID = "TRIP_ID"

@JvmStatic
fun createIntent(
context: Context,
tripId: Long
): Intent = Intent(context, CheckFriendsActivity::class.java).apply {
putExtra(TRIP_ID, tripId)
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.going.presentation.todo.ourtodo.checkfriends

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.going.domain.entity.response.CheckFriendsModel
Expand All @@ -27,11 +26,9 @@ class CheckFriendsViewModel @Inject constructor(
viewModelScope.launch {
todoRepository.getFriendsList(tripId)
.onSuccess {
Log.e("TAG", "success", )
_checkFriendsListState.value = UiState.Success(it)
}
.onFailure {
Log.e("TAG", "fail", )
_checkFriendsListState.value = UiState.Failure(it.message.orEmpty())
}
}
Expand Down
14 changes: 7 additions & 7 deletions presentation/src/main/res/layout/activity_check_friends.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
android:background="@drawable/shape_rect_6_gray50_fill"
android:gravity="center"
android:paddingVertical="14dp"
android:text="식당, 여행 계획 취향이 잘 맞는 조합이네요!"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/check_friends_result_perfect" />

<TextView
android:id="@+id/tv_check_friends_check_member"
Expand Down Expand Up @@ -194,7 +194,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="@string/check_friends_preference_no_matter"
android:text="@string/check_friends_preference_1_center"
android:textColor="@color/gray_400" />

<TextView
Expand Down Expand Up @@ -344,7 +344,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="@string/check_friends_preference_no_matter"
android:text="@string/check_friends_preference_2_center"
android:textColor="@color/gray_400" />

<TextView
Expand Down Expand Up @@ -493,7 +493,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="@string/check_friends_preference_no_matter"
android:text="@string/check_friends_preference_3_center"
android:textColor="@color/gray_400" />

<TextView
Expand Down Expand Up @@ -642,7 +642,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="@string/check_friends_preference_no_matter"
android:text="@string/check_friends_preference_4_5_center"
android:textColor="@color/gray_400" />

<TextView
Expand Down Expand Up @@ -791,7 +791,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="@string/check_friends_preference_no_matter"
android:text="@string/check_friends_preference_4_5_center"
android:textColor="@color/gray_400" />

<TextView
Expand Down
11 changes: 10 additions & 1 deletion presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,31 @@
<string name="check_friends_tool_bar">우리의 여행 취향</string>
<string name="check_friends_check_member">프로필 사진을 눌러서 친구의 취향을 구경해보세요</string>
<string name="check_friends_preference_number">&#160;%d명</string>
<string name="check_friends_preference_no_matter">아무렇게</string>
<string name="check_friends_preference_1_title">여행 계획</string>
<string name="check_friends_preference_1_left">철저하게</string>
<string name="check_friends_preference_1_center">아무렇게</string>
<string name="check_friends_preference_1_right">즉흥으로</string>
<string name="check_friends_preference_2_title">여행 장소</string>
<string name="check_friends_preference_2_left">관광지</string>
<string name="check_friends_preference_2_center">어디든</string>
<string name="check_friends_preference_2_right">로컬장소</string>
<string name="check_friends_preference_3_title">식당</string>
<string name="check_friends_preference_3_left">유명 맛집</string>
<string name="check_friends_preference_3_center">아무데나</string>
<string name="check_friends_preference_3_right">가까운 곳</string>
<string name="check_friends_preference_4_title">사진</string>
<string name="check_friends_preference_4_left">사진필수</string>
<string name="check_friends_preference_4_5_center">상관없어</string>
<string name="check_friends_preference_4_right">눈에 담기</string>
<string name="check_friends_preference_5_title">여행 일정</string>
<string name="check_friends_preference_5_left">알차게</string>
<string name="check_friends_preference_5_right">여유롭게</string>
<string name="check_friends_result_match_1">계획</string>
<string name="check_friends_result_match_2">장소</string>
<string name="check_friends_result_match_5">일정</string>
<string name="check_friends_result_match">%s에 대한 여행 취향이 잘 맞네요!</string>
<string name="check_friends_result_no_match">달라서 즐거운 여행! 친구와 서로의 취향을 이야기해 봐요</string>
<string name="check_friends_result_perfect">최고의 여행 친구! 모든 여행 취향이 일치해요</string>

<!--kakao-link-share-->
<string name="invite_error_kakao"> 카카오톡 초대코드 오류 </string>
Expand Down
Loading