Skip to content

Commit

Permalink
Merge branch 'develop' into fix/#156-list-scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
chattymin committed Jan 17, 2024
2 parents fc48adb + 7e182c9 commit c6907a6
Show file tree
Hide file tree
Showing 23 changed files with 409 additions and 288 deletions.
2 changes: 1 addition & 1 deletion core-ui/src/main/java/com/going/ui/base/BaseBottomSheet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ abstract class BaseBottomSheet<T : ViewDataBinding>(
super.onDestroyView()
_binding = null
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.going.presentation.entertrip.createtrip.choosedate

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import com.going.presentation.R
import com.going.presentation.databinding.FragmentBottomSheetDateContentBinding
Expand All @@ -16,20 +14,47 @@ class BottomSheetDateContentFragment(val viewModel: CreateTripViewModel, val isS
override fun onStart() {
super.onStart()
dialog?.window?.setBackgroundDrawableResource(R.color.transparent)
customStartDate()
customEndDate()
}

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

destroyToast()
binding.lifecycleOwner = viewLifecycleOwner
initFinishBtnClickListener()
}

private fun customStartDate() {
val datePicker = binding.dpCreateTripDate
val calendar = Calendar.getInstance()

private fun destroyToast() {
dialog?.setOnDismissListener {
binding.tvErrorToast.visibility = View.GONE
}
val currentStartYear = calendar.get(Calendar.YEAR)
val currentStartMonth = calendar.get(Calendar.MONTH)
val currentStartDay = calendar.get(Calendar.DAY_OF_MONTH)

calendar.set(2000, 0, 1)
datePicker.minDate = calendar.timeInMillis

calendar.set(2100, 0, 1)
datePicker.maxDate = calendar.timeInMillis

datePicker.updateDate(currentStartYear, currentStartMonth, currentStartDay)
}


private fun customEndDate() {
val datePicker = binding.dpCreateTripDate
val calendar = Calendar.getInstance()

val currentEndYear = viewModel.startYear.value ?: 0
val currentEndMonth = viewModel.startMonth.value ?: 0
val currentEndDay = viewModel.startDay.value ?: 0

calendar.set(currentEndYear, currentEndMonth - 1, currentEndDay)
datePicker.minDate = calendar.timeInMillis

calendar.set(2100, 0, 1)
datePicker.maxDate = calendar.timeInMillis
}

private fun sendDateInfo() {
Expand All @@ -39,6 +64,7 @@ class BottomSheetDateContentFragment(val viewModel: CreateTripViewModel, val isS
viewModel.startDay.value = binding.dpCreateTripDate.dayOfMonth
viewModel.checkStartDateAvailable()
} else {
customEndDate()
viewModel.endYear.value = binding.dpCreateTripDate.year
viewModel.endMonth.value = binding.dpCreateTripDate.month + 1
viewModel.endDay.value = binding.dpCreateTripDate.dayOfMonth
Expand Down Expand Up @@ -67,21 +93,9 @@ class BottomSheetDateContentFragment(val viewModel: CreateTripViewModel, val isS
viewModel.checkStartDateAvailable()
viewModel.checkEndDateAvailable()
dismiss()
} else {
viewModel.startYear.value = null
viewModel.endYear.value = null
viewModel.checkStartDateAvailable()
viewModel.checkEndDateAvailable()

binding.viewBlank.visibility = View.VISIBLE
binding.tvErrorToast.visibility = View.VISIBLE
Handler(Looper.getMainLooper()).postDelayed({
binding.tvErrorToast.visibility = View.GONE
}, 2000)
}
} else {
} else
dismiss()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FinishTripActivity :
}

private fun initCopyCodetvClickListener() {
binding.tvFinishTripTermsText.setOnSingleClickListener {
binding.clCopyCode.setOnSingleClickListener {
val clipboardManager =
this.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clipData = ClipData.newPlainText("INVITE_CODE_LABEL", inviteCode)
Expand All @@ -62,16 +62,16 @@ class FinishTripActivity :

private fun startKakaoInvite(context: Context) {
val test = HashMap<String, String>()
test.put("KEY", inviteCode)
test.put("NAME", title)
test.put(KEY, inviteCode)
test.put(NAME, title)

if (ShareClient.instance.isKakaoTalkSharingAvailable(context)) {
ShareClient.instance.shareCustom(
context,
TEMPLATE_ID.toLong(),
hashMapOf(
"KEY" to inviteCode,
"NAME" to title
KEY to inviteCode,
NAME to title
)
) { sharingResult, error ->
if (error != null) {
Expand All @@ -85,8 +85,8 @@ class FinishTripActivity :
WebSharerClient.instance.makeCustomUrl(
TEMPLATE_ID.toLong(),
hashMapOf(
"KEY" to inviteCode,
"NAME" to title
KEY to inviteCode,
NAME to title
)
)
try {
Expand Down Expand Up @@ -140,6 +140,9 @@ class FinishTripActivity :
companion object {
const val TAG_SHARE = "recommendInvite"
const val TEMPLATE_ID = 102829
const val KEY = "KEY"
const val NAME = "NAME"

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class InviteFinishActivity :

companion object {
const val DATE_FORMAT = "%s - %s"
const val D_DAY_FORMAT = "D - %d"
const val D_DAY_FORMAT = "D-%d"
const val TRIP_FORMAT = "여행중"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class EnterTripActivity : BaseActivity<ActivityEnterTripBinding>(R.layout.activi

is UiState.Failure -> {
when (state.msg) {
ERROR_NO_EXIST -> toast(getString(R.string.enter_trip_invite_code_exist_error))
ERROR_NO_EXIST -> toast(getString(R.string.enter_trip_invite_code_exist_toast))

ERROR_OVER_SIX -> toast(getString(R.string.enter_trip_invite_code_over_error))
ERROR_OVER_SIX -> toast(getString(R.string.enter_trip_invite_code_over_toast))

else -> toast(getString(R.string.server_error))
}
Expand All @@ -113,6 +113,7 @@ class EnterTripActivity : BaseActivity<ActivityEnterTripBinding>(R.layout.activi
}.launchIn(lifecycleScope)
}


private fun initNextBtnClickListener() {
binding.btnEnterTripNext.setOnSingleClickListener {
viewModel.checkInviteCodeFromServer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,32 @@ class EnterTripViewModel @Inject constructor(
var codeLength = MutableLiveData(0)

val isCodeAvailable = MutableLiveData(CodeState.Empty)
var isCheckEnterAvailable = MutableLiveData(false)
val isInviteCodeAvailable = MutableLiveData(false)

fun checkCodeAvailable() {
codeLength.value = getCodeLength(inviteCode.value)
isCodeAvailable.value = when {
codeLength.value == 0 -> CodeState.Empty
inviteCode.value.isNullOrBlank() -> CodeState.Blank
!isCodeValid(inviteCode.value) -> CodeState.Invalid
else -> CodeState.Success.also { checkEnterAvailable() }
else -> CodeState.Success
}

val isLengthAvailable = codeLength.value in 1..MAX_INVITE_LEN

isInviteCodeAvailable.value =
(isCodeAvailable.value == CodeState.Success) && isLengthAvailable

checkEnterAvailable()
}

private fun getCodeLength(value: String?) = value?.length ?: 0

private fun isCodeValid(code: String?) = code?.matches(ENG_NUM_REGEX.toRegex()) ?: false
private fun isCodeValid(code: String?) =
code?.matches(ENG_NUM_REGEX.toRegex()) == true && code.length == 6

fun checkEnterAvailable() {
isCheckEnterAvailable.value = isCodeAvailable.value == CodeState.Success
isInviteCodeAvailable.value = isCodeAvailable.value == CodeState.Success
}

fun checkInviteCodeFromServer() {
Expand All @@ -73,5 +81,6 @@ class EnterTripViewModel @Inject constructor(
const val MAX_INVITE_LEN = 6
const val ERROR_NO_EXIST = "e4043"
const val ERROR_OVER_SIX = "e4006"
const val ERROR_ALREADY_EXIST = "e4092"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import com.going.presentation.dashboard.DashBoardActivity
import com.going.presentation.dashboard.DashBoardActivity.Companion.IS_FIRST_ENTERED
import com.going.presentation.databinding.ActivityFinishPreferenceBinding
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripActivity.Companion.TRIP_ID
import com.going.presentation.entertrip.invitetrip.invitecode.EnterTripViewModel.Companion.ERROR_ALREADY_EXIST
import com.going.presentation.entertrip.preferencetag.PreferenceTagAdapter
import com.going.presentation.entertrip.preferencetag.PreferenceTagDecoration
import com.going.presentation.util.initOnBackPressedListener
import com.going.ui.base.BaseActivity
import com.going.ui.extension.UiState
import com.going.ui.extension.setOnSingleClickListener
Expand Down Expand Up @@ -79,7 +79,11 @@ class FinishPreferenceActivity :
is UiState.Success -> navigateToDashBoard(state.data.tripId)

is UiState.Failure -> {
toast(getString(R.string.server_error))
when (state.msg) {
ERROR_ALREADY_EXIST -> toast(getString(R.string.enter_trip_my_code_toast))

else -> toast(getString(R.string.server_error))
}
}

is UiState.Loading -> return@onEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import org.json.JSONObject
import retrofit2.HttpException
import javax.inject.Inject

@HiltViewModel
Expand All @@ -34,18 +36,24 @@ class FinishPreferenceViewModel @Inject constructor(
_finishInviteState.value = UiState.Loading
viewModelScope.launch {
enterTripRepository.postStartInviteTrip(
tripId, StartInviteTripRequestModel(
tripId,
StartInviteTripRequestModel(
styleA.value ?: 0,
styleB.value ?: 0,
styleC.value ?: 0,
styleD.value ?: 0,
styleE.value ?: 0,
),
).onSuccess {
_finishInviteState.value = UiState.Success(it)
}.onFailure {
_finishInviteState.value = UiState.Failure(it.message.orEmpty())
_finishInviteState.value = UiState.Success(it)
}.onFailure { throwable ->
if (throwable is HttpException) {
val errorResponse = throwable.response()?.errorBody()?.string()
val jsonObject = JSONObject(errorResponse)
val errorCode = jsonObject.getString("code")
_finishInviteState.value = UiState.Failure(errorCode)
}
}
}
}

Expand Down Expand Up @@ -81,5 +89,4 @@ class FinishPreferenceViewModel @Inject constructor(
rightPrefer = "여유롭게",
),
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.going.presentation.entertrip.preferencetag

import androidx.recyclerview.widget.RecyclerView
import com.going.domain.entity.PreferenceData
import com.going.presentation.R
import com.going.presentation.databinding.ItemPreferenceTagBinding

class PreferenceTagViewHolder(
Expand All @@ -17,20 +16,36 @@ class PreferenceTagViewHolder(
tvPreferenceTag1.text = item.leftPrefer
tvPreferenceTag3.text = item.rightPrefer

rgPreferenceTag.setOnCheckedChangeListener { _, checkedId ->
val selectedButtonIdList = listOf(
R.id.rb_preference_1,
R.id.rb_preference_2,
R.id.rb_preference_3,
R.id.rb_preference_4,
R.id.rb_preference_5
)
val selectedButtonList = listOf(
rbPreference1,
rbPreference2,
rbPreference3,
rbPreference4,
rbPreference5
)

val checkedIndex = selectedButtonIdList.indexOf(checkedId)
if (checkedIndex != -1) {
listener.onPreferenceSelected(item, checkedIndex)
val selectedViewList = listOf(
viewPreferenceRadio1,
viewPreferenceRadio2,
viewPreferenceRadio3,
viewPreferenceRadio4,
viewPreferenceRadio5
)

selectedButtonList.forEachIndexed { index, radioButton ->
radioButton.setOnClickListener {
if (radioButton.isChecked) {
listener.onPreferenceSelected(item, index)
}
}
}

selectedViewList.forEachIndexed { index, view ->
view.setOnClickListener {
selectedButtonList[index].isChecked = true
listener.onPreferenceSelected(item, index)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ val UserTendencyResultList = listOf(
profileTitle = "배려심 넘치는, 든든잉",
profileSubTitle = "꼼꼼하고 세심하게 여행을 준비해요",
tags = listOf(
"친구와 함께",
"친구와함께",
"꼼꼼함",
"세심함",
),
Expand Down Expand Up @@ -173,7 +173,7 @@ val UserTendencyResultList = listOf(
tags = listOf(
"낙천적",
"낭만추구",
"남는건 사",
"남는건사진",
),
profileBoxInfo = listOf(
ProfileMock.BoxInfo(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dp" />
<stroke android:color="@color/gray_100" />
<corners android:radius="6dp" />
</shape>
Loading

0 comments on commit c6907a6

Please sign in to comment.