Skip to content

Commit

Permalink
[M
Browse files Browse the repository at this point in the history
[FIX/#144] 세연 담당 뷰 / QA 이슈 해결
  • Loading branch information
crownjoe authored Jan 17, 2024
2 parents cfa6c99 + 7775000 commit 7e182c9
Show file tree
Hide file tree
Showing 17 changed files with 310 additions and 262 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 @@ -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>
6 changes: 3 additions & 3 deletions presentation/src/main/res/layout/activity_create_trip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
android:hint="@string/create_trip_et_name_hint"
android:imeOptions="actionNext"
android:inputType="text"
android:maxLines="1"
android:maxLines="3"
android:text="@={viewModel.name}"
android:textAppearance="@style/TextAppearance.Doorip.Detail1.Regular"
app:layout_constraintEnd_toEndOf="parent"
Expand Down Expand Up @@ -131,7 +131,7 @@
android:layout_weight="1"
android:background="@drawable/shape_rect_4_gray200_line"
android:hint="@string/create_trip_start_date"
android:maxLines="1"
android:maxLines="2"
android:paddingHorizontal="12dp"
android:paddingVertical="16dp"
android:text="@{viewModel.isStartDateAvailable() == true ? @string/create_trip_date(viewModel.startYear, viewModel.startMonth, viewModel.startDay) : @string/create_trip_start_date}" />
Expand All @@ -152,7 +152,7 @@
android:layout_weight="1"
android:background="@drawable/shape_rect_4_gray200_line"
android:hint="@string/create_trip_end_date"
android:maxLines="1"
android:maxLines="2"
android:paddingHorizontal="12dp"
android:paddingVertical="16dp"
android:text="@{viewModel.isEndDateAvailable() == true ? @string/create_trip_date(viewModel.endYear, viewModel.endMonth, viewModel.endDay) : @string/create_trip_end_date}" />
Expand Down
8 changes: 4 additions & 4 deletions presentation/src/main/res/layout/activity_enter_trip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white_000"
tools:context=".entertrip.createtrip.choosedate.CreateTripActivity">
tools:context=".entertrip.invitetrip.invitecode.EnterTripActivity">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_enter_trip"
Expand Down Expand Up @@ -77,7 +77,7 @@
android:imeOptions="actionNext"
android:inputType="text"
android:maxLength="6"
android:maxLines="1"
android:maxLines="3"
android:text="@={viewModel.inviteCode}"
android:textAppearance="@style/TextAppearance.Doorip.Detail1.Regular"
app:layout_constraintEnd_toEndOf="parent"
Expand Down Expand Up @@ -115,11 +115,11 @@
android:layout_marginHorizontal="24dp"
android:layout_marginBottom="22dp"
android:background="@drawable/sel_rounded_corner_button"
android:enabled="@{viewModel.isCheckEnterAvailable}"
android:enabled="@{viewModel.isInviteCodeAvailable}"
android:outlineProvider="none"
android:paddingVertical="10dp"
android:text="@string/enter_trip_tv_next_button"
android:textColor="@{viewModel.isCheckEnterAvailable() == true ? @color/white_000 : @color/gray_200}"
android:textColor="@{viewModel.isInviteCodeAvailable() == true ? @color/white_000 : @color/gray_200}"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
Loading

0 comments on commit 7e182c9

Please sign in to comment.