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

[QA] #180 / 커플이 생성되었으나 아직 연결이 안되었을 때 처리 #182

Merged
merged 9 commits into from
Dec 20, 2023
10 changes: 10 additions & 0 deletions app/src/main/java/sopt/uni/data/datasource/local/SparkleStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ object SparkleStorage {
get() = pref.getInt(PARTNER_ID, -1)
set(value) = pref.edit { putInt(PARTNER_ID, value ?: -1).apply() }

var coupleId: Int?
get() = pref.getInt(COUPLE_ID, -1)
set(value) = pref.edit { putInt(COUPLE_ID, value ?: -1).apply() }

var inviteCode: String?
get() = pref.getString(INVITE_CODE, EMPTY_TEXT)
set(value) = pref.edit { putString(INVITE_CODE, value).apply() }

var isActive: Boolean
get() = prefTimer.getBoolean(ACTIVEKEY, false)
set(value) = prefTimer.edit { putBoolean(ACTIVEKEY, value).apply() }
Expand Down Expand Up @@ -93,6 +101,8 @@ const val REFRESH_TOKEN = "refreshToken"
const val AUTH = "auth"
const val USER_ID = "userId"
const val PARTNER_ID = "partnerId"
const val COUPLE_ID = "coupleId"
const val INVITE_CODE = "inviteCode"
const val NAME = "timer_prefs"
const val ACTIVEKEY = "isTimerActive"
const val TOTALTIMEKEY = "totalTime"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package sopt.uni.data.repository.onboarding

import retrofit2.Response
import sopt.uni.data.source.remote.response.ResponseStartDateDto

interface OnBoardingRepository {

suspend fun patchNickName(nickname: String)

suspend fun postStartDate(startDate: String): String
suspend fun postStartDate(startDate: String): Response<ResponseStartDateDto>

suspend fun checkCoupleConnection(): Boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import sopt.uni.data.service.OnBoardingService
import sopt.uni.data.source.remote.request.RequestNickNameDto
import sopt.uni.data.source.remote.request.RequestPostCheckConnectionDto
import sopt.uni.data.source.remote.request.RequestStartDateDto
import sopt.uni.data.source.remote.response.ResponseStartDateDto
import javax.inject.Inject

class OnBoardingRepositoryImpl @Inject constructor(
Expand All @@ -15,8 +16,8 @@ class OnBoardingRepositoryImpl @Inject constructor(
onBoardingService.patchNickName(RequestNickNameDto(nickname))
}

override suspend fun postStartDate(startDate: String): String {
return onBoardingService.postStartDate(RequestStartDateDto(startDate)).inviteCode
override suspend fun postStartDate(startDate: String): Response<ResponseStartDateDto> {
return onBoardingService.postStartDate(RequestStartDateDto(startDate))
}

override suspend fun checkCoupleConnection(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface OnBoardingService {
@POST("api/couple")
suspend fun postStartDate(
@Body request: RequestStartDateDto,
): ResponseStartDateDto
): Response<ResponseStartDateDto>

@GET("api/couple/join")
suspend fun checkConnection(): ResponseCheckConnectionDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class ResponseStartDateDto(
@SerialName("heartToken")
val heartToken: Int,
@SerialName("id")
val id: Int,
val coupleId: Int,
@SerialName("inviteCode")
val inviteCode: String,
@SerialName("startDate")
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/sopt/uni/presentation/IntroActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import sopt.uni.data.datasource.local.SparkleStorage
import sopt.uni.data.repository.shortgame.ShortGameRepository
import sopt.uni.presentation.home.HomeActivity
import sopt.uni.presentation.invite.NickNameActivity
import sopt.uni.presentation.invite.ShareInviteCodeActivity
import sopt.uni.presentation.onboarding.OnBoardingActivity
import sopt.uni.util.extension.startActivity
import javax.inject.Inject
Expand All @@ -32,9 +33,12 @@ class IntroActivity : AppCompatActivity() {
if (SparkleStorage.accessToken != null) {
Log.e("accessToken", SparkleStorage.accessToken.toString())
Log.e("partnerId", SparkleStorage.partnerId.toString())
if (SparkleStorage.partnerId != -1) {
if (SparkleStorage.partnerId != -1 && SparkleStorage.coupleId != -1) {
startActivity<HomeActivity>()
Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
} else if (SparkleStorage.partnerId == -1 && SparkleStorage.coupleId != -1) {
startActivity<ShareInviteCodeActivity>()
Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
} else {
startActivity<NickNameActivity>()
Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
Expand Down
20 changes: 19 additions & 1 deletion app/src/main/java/sopt/uni/presentation/invite/DdayActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sopt.uni.presentation.invite

import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -12,6 +13,7 @@ import sopt.uni.presentation.common.content.INVITECODE
import sopt.uni.util.DateUtil
import sopt.uni.util.binding.BindingActivity
import sopt.uni.util.extension.setOnSingleClickListener
import sopt.uni.util.extension.startActivity
import java.util.Calendar

@AndroidEntryPoint
Expand All @@ -24,6 +26,7 @@ class DdayActivity : BindingActivity<ActivityDDayBinding>(R.layout.activity_d_da
setMaxDate()
moveToShareInviteCode()
moveToPrevPage()
initOnBackPressedListener()
}

private fun moveToShareInviteCode() {
Expand All @@ -48,12 +51,27 @@ class DdayActivity : BindingActivity<ActivityDDayBinding>(R.layout.activity_d_da

private fun moveToPrevPage() {
binding.ivBackArrow.setOnSingleClickListener {
finish()
backToInviteHub()
}
}

private fun setMaxDate() {
val calendar = Calendar.getInstance()
binding.dpDDay.maxDate = calendar.timeInMillis
}

private fun initOnBackPressedListener() {
val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
backToInviteHub()
}
}
this.onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}

private fun backToInviteHub() {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity<InviteHubActivity>()
finish()
}
}
15 changes: 12 additions & 3 deletions app/src/main/java/sopt/uni/presentation/invite/DdayViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import sopt.uni.data.datasource.local.SparkleStorage
import sopt.uni.data.repository.onboarding.OnBoardingRepository
import timber.log.Timber
import javax.inject.Inject
Expand All @@ -14,15 +16,22 @@ class DdayViewModel @Inject constructor(
private val onBoardingRepository: OnBoardingRepository,
) : ViewModel() {

var inviteCode = MutableStateFlow("")
private val _inviteCode = MutableStateFlow<String>("")
val inviteCode get() = _inviteCode.asStateFlow()

fun postStartDate(startDate: String) {
viewModelScope.launch {
kotlin.runCatching {
onBoardingRepository.postStartDate(startDate = startDate)
}.fold({
inviteCode.emit(it)
Timber.d("기념일 갱신이 완료되었습니다.")
it.body()?.let { response ->
Timber.d("기념일 갱신이 성공했습니다.")
_inviteCode.value = response.inviteCode
SparkleStorage.inviteCode = response.inviteCode
SparkleStorage.coupleId = response.coupleId
} ?: run {
Timber.d("기념일 갱신에서 null이 반환되었습니다.")
}
}, {
Timber.d("기념일 갱신이 실패했습니다.")
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sopt.uni.presentation.invite

import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import dagger.hilt.android.AndroidEntryPoint
import sopt.uni.R
import sopt.uni.databinding.ActivityInviteHubBinding
Expand All @@ -17,6 +19,7 @@ class InviteHubActivity : BindingActivity<ActivityInviteHubBinding>(R.layout.act
moveToEnterDday()
moveToEnterInviteCode()
moveToPrevPage()
initOnBackPressedListener()
}

private fun moveToEnterDday() {
Expand All @@ -33,7 +36,22 @@ class InviteHubActivity : BindingActivity<ActivityInviteHubBinding>(R.layout.act

private fun moveToPrevPage() {
binding.ivBackArrow.setOnSingleClickListener {
finish()
backToNickNameActivity()
}
}

private fun initOnBackPressedListener() {
val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
backToNickNameActivity()
}
}
this.onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}

private fun backToNickNameActivity() {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity<NickNameActivity>()
finish()
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package sopt.uni.presentation.invite

import android.content.Context
import android.content.Intent
import android.graphics.Rect
import android.os.Bundle
import android.view.MotionEvent
import android.view.MotionEvent.ACTION_DOWN
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import androidx.activity.OnBackPressedCallback
import androidx.activity.viewModels
import dagger.hilt.android.AndroidEntryPoint
import sopt.uni.R
import sopt.uni.databinding.ActivityNicknameBinding
import sopt.uni.presentation.login.LoginActivity
import sopt.uni.presentation.mypage.MypageAccountLogoutDialogFragment
import sopt.uni.util.binding.BindingActivity
import sopt.uni.util.extension.setOnSingleClickListener
Expand All @@ -28,6 +31,7 @@ class NickNameActivity : BindingActivity<ActivityNicknameBinding>(R.layout.activ
moveToPrevPage()
moveToAskPage()
logoutOnNickNamePage()
initOnBackPressedListener()
}

private fun moveToInviteHub() {
Expand All @@ -39,7 +43,7 @@ class NickNameActivity : BindingActivity<ActivityNicknameBinding>(R.layout.activ

private fun moveToPrevPage() {
binding.ivBackArrow.setOnSingleClickListener {
finish()
backToLogin()
}
}

Expand Down Expand Up @@ -74,4 +78,19 @@ class NickNameActivity : BindingActivity<ActivityNicknameBinding>(R.layout.activ
)
}
}

private fun initOnBackPressedListener() {
val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
backToLogin()
}
}
this.onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}

private fun backToLogin() {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity<LoginActivity>()
finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ package sopt.uni.presentation.invite

import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import androidx.activity.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import sopt.uni.R
import sopt.uni.data.datasource.local.SparkleStorage
import sopt.uni.databinding.ActivityShareInviteCodeBinding
import sopt.uni.presentation.common.content.INVITECODE
import sopt.uni.presentation.home.HomeActivity
import sopt.uni.util.UiState
import sopt.uni.util.binding.BindingActivity
import sopt.uni.util.extension.setOnSingleClickListener
import sopt.uni.util.extension.showToast
import sopt.uni.util.extension.startActivity
import timber.log.Timber

@AndroidEntryPoint
class ShareInviteCodeActivity :
Expand All @@ -31,16 +31,16 @@ class ShareInviteCodeActivity :
getInviteCode()
checkCoupleConnection()
copyInviteCode()
initOnBackPressedListener()
}

private fun getInviteCode() {
Timber.e(intent.getStringExtra(INVITECODE))
binding.tvInviteCode.text = intent.getStringExtra(INVITECODE)
binding.tvInviteCode.text = SparkleStorage.inviteCode
}

private fun moveToPrevPage() {
binding.ivBackArrow.setOnSingleClickListener {
finish()
backToDdayActivity()
}
}

Expand Down Expand Up @@ -81,4 +81,19 @@ class ShareInviteCodeActivity :
startActivity(shareIntent)
}
}

private fun initOnBackPressedListener() {
val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
backToDdayActivity()
}
}
this.onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}

private fun backToDdayActivity() {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity<DdayActivity>()
finish()
}
}
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:visibility="invisible"
android:background="@drawable/bg_heart_btn"
android:elevation="2dp"
android:paddingHorizontal="12dp"
Expand Down
Loading