Skip to content

Commit

Permalink
Merge branch 'develop' into fix/#252-qa
Browse files Browse the repository at this point in the history
  • Loading branch information
chattymin committed Mar 14, 2024
2 parents e2d950d + 178af11 commit 50482fc
Show file tree
Hide file tree
Showing 26 changed files with 462 additions and 91 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 @@ -7,17 +7,17 @@ import com.going.domain.entity.response.TodoAllocatorModel
import com.going.presentation.databinding.ItemTodoCreateNameBinding
import com.going.ui.util.ItemDiffCallback

class TodoAllocatorAdapter(
class ChangeAllocatorAdapter(
private val itemClick: (Int) -> Unit
) : ListAdapter<TodoAllocatorModel, TodoAllocatorViewHolder>(diffUtil) {
) : ListAdapter<TodoAllocatorModel, ChangeAllocatorViewHolder>(diffUtil) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TodoAllocatorViewHolder {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChangeAllocatorViewHolder {
val binding: ItemTodoCreateNameBinding =
ItemTodoCreateNameBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return TodoAllocatorViewHolder(binding, itemClick)
return ChangeAllocatorViewHolder(binding, itemClick)
}

override fun onBindViewHolder(holder: TodoAllocatorViewHolder, position: Int) {
override fun onBindViewHolder(holder: ChangeAllocatorViewHolder, position: Int) {
holder.onBind(getItem(position), position)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.going.presentation.R
import com.going.presentation.databinding.ItemTodoCreateNameBinding
import com.going.ui.extension.colorOf

class TodoAllocatorViewHolder(
class ChangeAllocatorViewHolder(
val binding: ItemTodoCreateNameBinding,
private val itemClick: (Int) -> Unit
) : RecyclerView.ViewHolder(binding.root) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TodoChangeActivity : BaseActivity<ActivityTodoChangeBinding>(R.layout.acti

private val viewModel by viewModels<TodoChangeViewModel>()

private var _adapter: TodoAllocatorAdapter? = null
private var _adapter: ChangeAllocatorAdapter? = null
private val adapter
get() = requireNotNull(_adapter) { getString(R.string.adapter_not_initialized_error_msg) }

Expand Down Expand Up @@ -115,7 +115,7 @@ class TodoChangeActivity : BaseActivity<ActivityTodoChangeBinding>(R.layout.acti
}

private fun initOurTodoNameListAdapter() {
_adapter = TodoAllocatorAdapter { position ->
_adapter = ChangeAllocatorAdapter { position ->
viewModel.allocatorModelList[position].also { it.isAllocated = !it.isAllocated }
viewModel.checkIsFinishAvailable()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import com.going.domain.entity.response.TripParticipantModel
import com.going.presentation.databinding.ItemTodoCreateNameBinding
import com.going.ui.util.ItemDiffCallback

class TripParticipantAdapter(
class CreateParticipantAdapter(
private val isFixed: Boolean,
private val itemClick: (Int) -> Unit
) : ListAdapter<TripParticipantModel, TripParticipantViewHolder>(diffUtil) {
) : ListAdapter<TripParticipantModel, CreateParticipantViewHolder>(diffUtil) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TripParticipantViewHolder {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CreateParticipantViewHolder {
val binding: ItemTodoCreateNameBinding =
ItemTodoCreateNameBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return TripParticipantViewHolder(binding, isFixed, itemClick)
return CreateParticipantViewHolder(binding, isFixed, itemClick)
}

override fun onBindViewHolder(holder: TripParticipantViewHolder, position: Int) {
override fun onBindViewHolder(holder: CreateParticipantViewHolder, position: Int) {
holder.onBind(getItem(position), position)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.going.presentation.R
import com.going.presentation.databinding.ItemTodoCreateNameBinding
import com.going.ui.extension.colorOf

class TripParticipantViewHolder(
class CreateParticipantViewHolder(
val binding: ItemTodoCreateNameBinding,
private val isFixed: Boolean,
private val itemClick: (Int) -> Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TodoCreateActivity : BaseActivity<ActivityTodoCreateBinding>(R.layout.acti

private val viewModel by viewModels<TodoCreateViewModel>()

private var _adapter: TripParticipantAdapter? = null
private var _adapter: CreateParticipantAdapter? = null
private val adapter
get() = requireNotNull(_adapter) { getString(R.string.adapter_not_initialized_error_msg) }

Expand Down Expand Up @@ -104,7 +104,7 @@ class TodoCreateActivity : BaseActivity<ActivityTodoCreateBinding>(R.layout.acti
}

private fun initOurTodoNameListAdapter() {
_adapter = TripParticipantAdapter(false) { position ->
_adapter = CreateParticipantAdapter(false) { position ->
viewModel.participantModelList[position].also { it.isSelected = !it.isSelected }
viewModel.checkIsFinishAvailable()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import com.going.domain.entity.response.TodoAllocatorModel
import com.going.presentation.databinding.ItemTodoCreateNameBinding
import com.going.ui.util.ItemDiffCallback

class TripAllocatorAdapter : ListAdapter<TodoAllocatorModel, TripAllocatorViewHolder>(diffUtil) {
class DetailAllocatorAdapter : ListAdapter<TodoAllocatorModel, DetailAllocatorViewHolder>(diffUtil) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TripAllocatorViewHolder {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DetailAllocatorViewHolder {
val inflater by lazy { LayoutInflater.from(parent.context) }
val binding: ItemTodoCreateNameBinding =
ItemTodoCreateNameBinding.inflate(inflater, parent, false)
return TripAllocatorViewHolder(binding)
return DetailAllocatorViewHolder(binding)
}

override fun onBindViewHolder(holder: TripAllocatorViewHolder, position: Int) {
override fun onBindViewHolder(holder: DetailAllocatorViewHolder, position: Int) {
holder.onBind(getItem(position))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.going.presentation.R
import com.going.presentation.databinding.ItemTodoCreateNameBinding
import com.going.ui.extension.colorOf

class TripAllocatorViewHolder(
class DetailAllocatorViewHolder(
val binding: ItemTodoCreateNameBinding
) : RecyclerView.ViewHolder(binding.root) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TodoDetailActivity :

private val viewModel by viewModels<TodoDetailViewModel>()

private var _adapter: TripAllocatorAdapter? = null
private var _adapter: DetailAllocatorAdapter? = null
private val adapter
get() = requireNotNull(_adapter) { getString(R.string.adapter_not_initialized_error_msg) }

Expand Down Expand Up @@ -89,7 +89,7 @@ class TodoDetailActivity :

private fun initAllocatorListAdapter() {
if (viewModel.isPublic) {
_adapter = TripAllocatorAdapter()
_adapter = DetailAllocatorAdapter()
binding.rvOurTodoDetailPerson.adapter = adapter
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.going.presentation.todo.allocator
package com.going.presentation.todo.list

import android.view.LayoutInflater
import android.view.ViewGroup
Expand All @@ -7,18 +7,18 @@ import com.going.domain.entity.response.TodoListAllocatorModel
import com.going.presentation.databinding.ItemTodoNameBinding
import com.going.ui.util.ItemDiffCallback

class TodoAllocatorAdapter(
class ListAllocatorAdapter(
private val isCompleted: Boolean
) : ListAdapter<TodoListAllocatorModel, TodoAllocatorViewHolder>(diffUtil) {
) : ListAdapter<TodoListAllocatorModel, ListAllocatorViewHolder>(diffUtil) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TodoAllocatorViewHolder {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListAllocatorViewHolder {
val inflater by lazy { LayoutInflater.from(parent.context) }
val binding: ItemTodoNameBinding =
ItemTodoNameBinding.inflate(inflater, parent, false)
return TodoAllocatorViewHolder(binding, isCompleted)
return ListAllocatorViewHolder(binding, isCompleted)
}

override fun onBindViewHolder(holder: TodoAllocatorViewHolder, position: Int) {
override fun onBindViewHolder(holder: ListAllocatorViewHolder, position: Int) {
holder.onBind(getItem(position))
}

Expand Down
Loading

0 comments on commit 50482fc

Please sign in to comment.