Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/Team-Going/Going-Android
Browse files Browse the repository at this point in the history
…into fix/#255-todo-2nd-qa
  • Loading branch information
Marchbreeze committed Mar 13, 2024
2 parents 10f5093 + 178af11 commit 6fd33e4
Show file tree
Hide file tree
Showing 13 changed files with 427 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ class DashBoardActivity :
checkIsFirstEntered()
setTabLayout()
setViewPager()
setTravelerName()
initSettingBtnClickListener()
initCreateTripBtnClickListener()
initOnBackPressedListener(binding.root)
}

override fun onResume() {
super.onResume()

setTravelerName()
}

private fun checkIsFirstEntered() {
if (intent.getBooleanExtra(IS_FIRST_ENTERED, false)) {
val tripId = intent.getLongExtra(TRIP_ID, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class ChangeTagActivity :
private var _adapter: ChangeTagAdapter? = null
private val adapter get() = requireNotNull(_adapter) { getString(R.string.adapter_not_initialized_error_msg) }

private val preferenceAnswers = MutableList(5) { 0 }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

initAdapter()
setTripId()
initPreferenceList()
observeIsButtonValid()
initItemDecoration()
initChangeClickListener()
initBackClickListener()
Expand All @@ -46,6 +46,10 @@ class ChangeTagActivity :
binding.rvChangeTag.adapter = adapter
}

private fun setTripId() {
tagViewModel.tripId = intent.getLongExtra(TRIP_ID, 0)
}

private fun initPreferenceList() {
if (intent != null) {
val styleA = intent.getIntExtra(STYLE_A, 0)
Expand All @@ -64,34 +68,28 @@ class ChangeTagActivity :
)
)

preferenceAnswers[0] = styleA
preferenceAnswers[1] = styleB
preferenceAnswers[2] = styleC
preferenceAnswers[3] = styleD
preferenceAnswers[4] = styleE
tagViewModel.setDefaultPreference(styleA, styleB, styleC, styleD, styleE)
}
}

private fun preferenceTagClickListener(item: ProfilePreferenceData, checkedIndex: Int) {
preferenceAnswers[item.number.toInt() - 1] = checkedIndex
setButtonValid()
sendPreferenceInfo()
}

private fun setButtonValid() {
binding.btnChangeStart.isEnabled = true
binding.btnChangeStart.setTextColor(
colorOf(R.color.white_000)
)
tagViewModel.checkIsPreferenceChange(item.number.toInt(), checkedIndex)
}

private fun sendPreferenceInfo() {
tagViewModel.tripId = intent.getLongExtra(TRIP_ID, 0)
tagViewModel.styleA.value = preferenceAnswers[0]
tagViewModel.styleB.value = preferenceAnswers[1]
tagViewModel.styleC.value = preferenceAnswers[2]
tagViewModel.styleD.value = preferenceAnswers[3]
tagViewModel.styleE.value = preferenceAnswers[4]
private fun observeIsButtonValid() {
tagViewModel.isButtonValid.flowWithLifecycle(lifecycle).onEach { state ->
if (state) {
binding.btnChangeStart.isEnabled = true
binding.btnChangeStart.setTextColor(
colorOf(R.color.white_000)
)
} else {
binding.btnChangeStart.isEnabled = false
binding.btnChangeStart.setTextColor(
colorOf(R.color.gray_200)
)
}
}.launchIn(lifecycleScope)
}

private fun initItemDecoration() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.going.presentation.profile.participant.profiletag.changetag

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.going.domain.entity.ProfilePreferenceData
import com.going.domain.entity.request.PreferenceChangeRequestModel
import com.going.domain.repository.ProfileRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand All @@ -20,24 +21,91 @@ class ChangeTagViewModel @Inject constructor(
private val _preferencePatchState = MutableSharedFlow<Boolean>()
val preferencePatchState: SharedFlow<Boolean> = _preferencePatchState

private val _isButtonValid = MutableStateFlow(false)
val isButtonValid: StateFlow<Boolean> = _isButtonValid

var tripId: Long = 0

val styleA = MutableLiveData(0)
val styleB = MutableLiveData(0)
val styleC = MutableLiveData(0)
val styleD = MutableLiveData(0)
val styleE = MutableLiveData(0)
private var defaultStyleA: Int? = 0
private var defaultStyleB: Int? = 0
private var defaultStyleC: Int? = 0
private var defaultStyleD: Int? = 0
private var defaultStyleE: Int? = 0

private var styleA: Int? = 0
private var styleB: Int? = 0
private var styleC: Int? = 0
private var styleD: Int? = 0
private var styleE: Int? = 0

private var isStyleAChanged: Boolean = false
private var isStyleBChanged: Boolean = false
private var isStyleCChanged: Boolean = false
private var isStyleDChanged: Boolean = false
private var isStyleEChanged: Boolean = false

fun setDefaultPreference(styleA: Int, styleB: Int, styleC: Int, styleD: Int, styleE: Int) {
defaultStyleA = styleA
this.styleA = styleA

defaultStyleB = styleB
this.styleB = styleB

defaultStyleC = styleC
this.styleC = styleC

defaultStyleD = styleD
this.styleD = styleD

defaultStyleE = styleE
this.styleE = styleE
}

fun checkIsPreferenceChange(number: Int, index: Int) {
when (number) {
1 -> {
styleA = index
isStyleAChanged = index != defaultStyleA
}

2 -> {
styleB = index
isStyleBChanged = index != defaultStyleB
}

3 -> {
styleC = index
isStyleCChanged = index != defaultStyleC
}

4 -> {
styleD = index
isStyleDChanged = index != defaultStyleD
}

5 -> {
styleE = index
isStyleEChanged = index != defaultStyleE
}
}
checkIsButtonValid()
}

private fun checkIsButtonValid() {
_isButtonValid.value =
isStyleAChanged || isStyleBChanged || isStyleCChanged || isStyleDChanged || isStyleEChanged
}

fun patchPreferenceTagToServer() {
viewModelScope.launch {
profileRepository.patchPreferenceTag(
tripId,
PreferenceChangeRequestModel(
styleA.value ?: 0,
styleB.value ?: 0,
styleC.value ?: 0,
styleD.value ?: 0,
styleE.value ?: 0
styleA ?: 0,
styleB ?: 0,
styleC ?: 0,
styleD ?: 0,
styleE ?: 0
)
)
.onSuccess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ class OurTodoFragment() : BaseFragment<FragmentOurTodoBinding>(R.layout.fragment
binding.btnOurTripFriend.setOnSingleClickListener {
CheckFriendsActivity.createIntent(
requireContext(),
viewModel.tripId
viewModel.tripId,
viewModel.inviteCode
).apply { startActivity(this) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import androidx.activity.viewModels
import androidx.core.view.isVisible
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.going.domain.entity.response.CheckFriendsModel
import com.going.presentation.R
import com.going.presentation.databinding.ActivityCheckFriendsBinding
import com.going.presentation.profile.participant.ParticipantProfileActivity
import com.going.presentation.todo.TodoActivity.Companion.EXTRA_TRIP_ID
import com.going.presentation.todo.ourtodo.invite.FriendInviteEmptyDialog
import com.going.ui.base.BaseActivity
import com.going.ui.extension.colorOf
import com.going.ui.extension.setOnSingleClickListener
Expand All @@ -33,6 +35,8 @@ class CheckFriendsActivity :

private val viewModel by viewModels<CheckFriendsViewModel>()

private var friendInviteDialog: FriendInviteEmptyDialog? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand Down Expand Up @@ -84,11 +88,28 @@ class CheckFriendsActivity :
}

private fun setFriendsData(data: CheckFriendsModel) {
adapter.submitList(data.participants)
if (data.participants.size == 1) {
binding.layoutCheckFriendsEmpty.isVisible = true
setInviteCode()
initInviteBtnListener()
} else {
binding.svCheckFriends.isVisible = true
adapter.submitList(data.participants)
setProgressBarStatus(data.styles.map { it.rates })
setCountStatus(data.styles.map { it.counts })
setResultTextColor(data.bestPrefer)
}
}

setProgressBarStatus(data.styles.map { it.rates })
setCountStatus(data.styles.map { it.counts })
setResultTextColor(data.bestPrefer)
private fun setInviteCode() {
viewModel.inviteCode = intent.getStringExtra(INVITE_CODE)
}

private fun initInviteBtnListener() {
binding.btnCheckFriendsInvite.setOnSingleClickListener {
friendInviteDialog = FriendInviteEmptyDialog()
friendInviteDialog?.show(supportFragmentManager, INVITE_DIALOG)
}
}

private fun setProgressBarStatus(rates: List<List<Int>>) {
Expand Down Expand Up @@ -203,17 +224,22 @@ class CheckFriendsActivity :
override fun onDestroy() {
super.onDestroy()
_adapter = null
if (friendInviteDialog?.isAdded == true) friendInviteDialog?.dismiss()
}

companion object {
private const val TRIP_ID = "TRIP_ID"
private const val INVITE_CODE = "INVITE_CODE"
private const val INVITE_DIALOG = "INVITE_DIALOG"

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class CheckFriendsViewModel @Inject constructor(
private val _checkFriendsListState = MutableStateFlow<UiState<CheckFriendsModel>>(UiState.Empty)
val checkFriendsListState: StateFlow<UiState<CheckFriendsModel>> get() = _checkFriendsListState

var inviteCode: String? = ""

fun getFriendsListFromServer(
tripId: Long
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.going.presentation.todo.ourtodo.invite

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import androidx.fragment.app.activityViewModels
import com.going.presentation.R
import com.going.presentation.databinding.FragmentFriendInviteDialogBinding
import com.going.presentation.todo.ourtodo.checkfriends.CheckFriendsViewModel
import com.going.ui.base.BaseDialog
import com.going.ui.extension.setOnSingleClickListener
import com.going.ui.extension.toast

class FriendInviteEmptyDialog :
BaseDialog<FragmentFriendInviteDialogBinding>(R.layout.fragment_friend_invite_dialog) {

private val viewModel by activityViewModels<CheckFriendsViewModel>()

override fun onStart() {
super.onStart()
dialog?.window?.apply {
setLayout(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
)
setBackgroundDrawableResource(R.color.transparent)
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

setInviteCode()
initExitBtnListener()
initLinkInviteBtnListener()
}

private fun setInviteCode() {
binding.tvTodoInviteCode.text = viewModel.inviteCode
}

private fun initExitBtnListener() {
binding.btnTodoInviteFinish.setOnSingleClickListener {
dismiss()
}
}

private fun initLinkInviteBtnListener() {
binding.tvTodoInviteTermsText.setOnSingleClickListener {
val clipboardManager =
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText(CLIP_LABEL, viewModel.inviteCode)
clipboardManager.setPrimaryClip(clipData)
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) toast(getString(R.string.finish_trip_tv_copy_code_complete))
}
}

companion object {
const val CLIP_LABEL = "RECOMMEND_LINK"
}
}
Loading

0 comments on commit 6fd33e4

Please sign in to comment.