Skip to content

Commit

Permalink
[MERGE] #339 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#339] OnBoarding / 이름 변경 뷰플로우 추가
  • Loading branch information
Marchbreeze authored Dec 12, 2023
2 parents 104d041 + 16ed9c2 commit 009719f
Show file tree
Hide file tree
Showing 13 changed files with 584 additions and 57 deletions.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
</intent-filter>
</activity>

<activity
android:name=".presentation.onboarding.activity.EditNameActivity"
android:exported="true"
android:screenOrientation="portrait"/>

<activity
android:name=".presentation.onboarding.activity.OnBoardingActivity"
android:exported="true"
Expand Down
47 changes: 39 additions & 8 deletions app/src/main/java/com/el/yello/presentation/auth/SignInActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package com.el.yello.presentation.auth

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.el.yello.R
import com.el.yello.databinding.ActivitySignInBinding
import com.el.yello.presentation.auth.SignInViewModel.Companion.FRIEND_LIST
import com.el.yello.presentation.main.MainActivity
import com.el.yello.presentation.onboarding.activity.EditNameActivity
import com.el.yello.presentation.onboarding.activity.GetAlarmActivity
import com.el.yello.presentation.onboarding.activity.OnBoardingActivity
import com.el.yello.presentation.onboarding.fragment.checkName.CheckNameDialog
import com.el.yello.presentation.tutorial.TutorialAActivity
import com.el.yello.util.amplitude.AmplitudeUtils
import com.el.yello.util.context.yelloSnackbar
Expand All @@ -27,6 +29,8 @@ class SignInActivity : BindingActivity<ActivitySignInBinding>(R.layout.activity_

private val viewModel by viewModels<SignInViewModel>()

private var checkNameDialog: CheckNameDialog? = null

private var userKakaoId: Long = 0
private var userName: String = String()
private var userGender: String = String()
Expand Down Expand Up @@ -122,7 +126,7 @@ class SignInActivity : BindingActivity<ActivitySignInBinding>(R.layout.activity_
is UiState.Success -> {
val friendScope = state.data.find { it.id == FRIEND_LIST }
if (friendScope?.agreed == true) {
startOnBoardingActivity()
startCheckNameDialog()
} else {
startSocialSyncActivity()
}
Expand Down Expand Up @@ -179,13 +183,25 @@ class SignInActivity : BindingActivity<ActivitySignInBinding>(R.layout.activity_
finish()
}

private fun startOnBoardingActivity() {
Intent(this, OnBoardingActivity::class.java).apply {
addPutExtra()
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
private fun startCheckNameDialog() {
val bundle = Bundle().apply { addPutExtra() }
if (userName.isBlank() || userName.isEmpty()) {
Intent(SignInActivity(), EditNameActivity::class.java).apply {
putExtras(bundle)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
finish()
} else {
checkNameDialog = CheckNameDialog()
binding.btnSignIn.visibility = View.GONE
binding.ivSignIn.visibility = View.GONE
binding.ivSignInKakao.visibility = View.GONE
binding.tvSignInTitle.visibility = View.GONE
binding.tvSignInSubtitle.visibility = View.GONE
checkNameDialog?.arguments = bundle
checkNameDialog?.show(supportFragmentManager, CHECK_NAME_DIALOG)
}
finish()
}

private fun Intent.addPutExtra() {
Expand All @@ -197,6 +213,20 @@ class SignInActivity : BindingActivity<ActivitySignInBinding>(R.layout.activity_
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}


private fun Bundle.addPutExtra() {
putLong(EXTRA_KAKAO_ID, userKakaoId)
putString(EXTRA_NAME, userName)
putString(EXTRA_GENDER, userGender)
putString(EXTRA_EMAIL, userEmail)
putString(EXTRA_PROFILE_IMAGE, userImage)
}

override fun onDestroy() {
super.onDestroy()
checkNameDialog?.dismiss()
}

companion object {
const val EXTRA_KAKAO_ID = "KAKAO_ID"
const val EXTRA_EMAIL = "KAKAO_EMAIL"
Expand All @@ -205,5 +235,6 @@ class SignInActivity : BindingActivity<ActivitySignInBinding>(R.layout.activity_
const val EXTRA_GENDER = "GENDER"
const val CODE_NOT_SIGNED_IN = "403"
const val CODE_NO_UUID = "404"
const val CHECK_NAME_DIALOG = "CHECK_NAME_DIALOG"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package com.el.yello.presentation.auth

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.el.yello.R
import com.el.yello.databinding.ActivitySocialSyncBinding
import com.el.yello.presentation.auth.SignInActivity.Companion.CHECK_NAME_DIALOG
import com.el.yello.presentation.auth.SignInActivity.Companion.EXTRA_EMAIL
import com.el.yello.presentation.auth.SignInActivity.Companion.EXTRA_GENDER
import com.el.yello.presentation.auth.SignInActivity.Companion.EXTRA_KAKAO_ID
import com.el.yello.presentation.auth.SignInActivity.Companion.EXTRA_NAME
import com.el.yello.presentation.auth.SignInActivity.Companion.EXTRA_PROFILE_IMAGE
import com.el.yello.presentation.onboarding.activity.OnBoardingActivity
import com.el.yello.presentation.onboarding.activity.EditNameActivity
import com.el.yello.presentation.onboarding.fragment.checkName.CheckNameDialog
import com.el.yello.util.amplitude.AmplitudeUtils
import com.el.yello.util.context.yelloSnackbar
import com.example.ui.base.BindingActivity
Expand All @@ -28,6 +31,8 @@ class SocialSyncActivity :

private val viewModel by viewModels<SocialSyncViewModel>()

private var checkNameDialog: CheckNameDialog? = null

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

Expand All @@ -46,35 +51,49 @@ class SocialSyncActivity :
private fun observeFriendsAccessState() {
viewModel.getFriendListState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
is UiState.Success -> startOnBoardingActivity()

is UiState.Success -> startCheckNameDialog()
is UiState.Failure -> yelloSnackbar(binding.root, getString(R.string.msg_error))

is UiState.Empty -> return@onEach

is UiState.Loading -> return@onEach
}
}.launchIn(lifecycleScope)
}

private fun startOnBoardingActivity() {
private fun startCheckNameDialog() {
intent.apply {
val kakaoId = getLongExtra(EXTRA_KAKAO_ID, -1)
val email = getStringExtra(EXTRA_EMAIL)
val profileImage = getStringExtra(EXTRA_PROFILE_IMAGE)
val name = getStringExtra(EXTRA_NAME)
val gender = getStringExtra(EXTRA_GENDER)

Intent(this@SocialSyncActivity, OnBoardingActivity::class.java).apply {
putExtra(EXTRA_KAKAO_ID, kakaoId)
putExtra(EXTRA_EMAIL, email)
putExtra(EXTRA_PROFILE_IMAGE, profileImage)
putExtra(EXTRA_NAME, name)
putExtra(EXTRA_GENDER, gender)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
val userKakaoId = getLongExtra(EXTRA_KAKAO_ID, -1)
val userEmail = getStringExtra(EXTRA_EMAIL)
val userImage = getStringExtra(EXTRA_PROFILE_IMAGE)
val userName = getStringExtra(EXTRA_NAME)
val userGender = getStringExtra(EXTRA_GENDER)
val bundle = Bundle().apply {
putLong(EXTRA_KAKAO_ID, userKakaoId)
putString(EXTRA_NAME, userName)
putString(EXTRA_GENDER, userGender)
putString(EXTRA_EMAIL, userEmail)
putString(EXTRA_PROFILE_IMAGE, userImage)
}
if (userName?.isBlank() == true || userName?.isEmpty() == true) {
Intent(SocialSyncActivity(), EditNameActivity::class.java).apply {
putExtras(bundle)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
finish()
} else {
checkNameDialog = CheckNameDialog()
binding.tvSocialSyncTitle.visibility = View.GONE
binding.tvSocialSyncSubtitle.visibility = View.GONE
binding.ivSocialSync.visibility = View.GONE
binding.btnSocialSync.visibility = View.GONE
checkNameDialog?.arguments = bundle
checkNameDialog?.show(supportFragmentManager, CHECK_NAME_DIALOG)
}
finish()
}
}

override fun onDestroy() {
super.onDestroy()
checkNameDialog?.dismiss()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.el.yello.presentation.onboarding.activity

import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import androidx.activity.viewModels
import com.el.yello.R
import com.el.yello.databinding.ActivityNameEditBinding
import com.el.yello.presentation.auth.SignInActivity.Companion.EXTRA_EMAIL
import com.el.yello.presentation.auth.SignInActivity.Companion.EXTRA_GENDER
import com.el.yello.presentation.auth.SignInActivity.Companion.EXTRA_KAKAO_ID
import com.el.yello.presentation.auth.SignInActivity.Companion.EXTRA_NAME
import com.el.yello.presentation.auth.SignInActivity.Companion.EXTRA_PROFILE_IMAGE
import com.example.ui.base.BindingActivity
import com.example.ui.context.toast
import com.example.ui.view.setOnSingleClickListener
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class EditNameActivity :
BindingActivity<ActivityNameEditBinding>(R.layout.activity_name_edit) {

private val viewModel by viewModels<OnBoardingViewModel>()

private var backPressedTime: Long = 0

private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (System.currentTimeMillis() - backPressedTime >= BACK_PRESSED_INTERVAL) {
backPressedTime = System.currentTimeMillis()
toast(getString(R.string.main_toast_back_pressed))
} else {
finish()
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.vm = viewModel
setConfirmBtnClickListener()
setDeleteBtnClickListener()
this.onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}

private fun setConfirmBtnClickListener() {
getIntentExtraData()
binding.btnNameNext.setOnSingleClickListener {
val bundle = Bundle().apply {
putLong(EXTRA_KAKAO_ID, viewModel.kakaoId.toLong())
putString(EXTRA_NAME, viewModel.nameText.value.toString())
putString(EXTRA_GENDER, viewModel.gender)
putString(EXTRA_EMAIL, viewModel.email)
putString(EXTRA_PROFILE_IMAGE, viewModel.profileImg)
}
Intent(this, OnBoardingActivity::class.java).apply {
putExtras(bundle)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(this)
}
finish()
}
}

private fun setDeleteBtnClickListener() {
binding.btnNameDelete.setOnSingleClickListener {
binding.etName.text.clear()
}
}

private fun getIntentExtraData() {
val bundle: Bundle? = intent.extras
intent.apply {
if (bundle != null) {
viewModel.kakaoId = bundle.getLong(EXTRA_KAKAO_ID, 0).toString()
viewModel.nameText.value = bundle.getString(EXTRA_NAME, "")
viewModel.gender = bundle.getString(EXTRA_GENDER, "")
viewModel.email = bundle.getString(EXTRA_EMAIL, "")
viewModel.profileImg = bundle.getString(EXTRA_PROFILE_IMAGE, "")
}
}
// 받아온 이름 값이 비었거나 null -> clear
if (viewModel.nameText.value.isNullOrEmpty() || viewModel.nameText.value.isNullOrBlank()) {
binding.etName.text.clear()
}
}

companion object {
private const val BACK_PRESSED_INTERVAL = 2000
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class OnBoardingActivity :
finish()
}
}

R.id.codeFragment -> {
if (System.currentTimeMillis() - backPressedTime >= BACK_PRESSED_INTERVAL) {
backPressedTime = System.currentTimeMillis()
Expand All @@ -46,6 +47,7 @@ class OnBoardingActivity :
finish()
}
}

else -> {
navController.popBackStack()
progressBarMinus()
Expand All @@ -65,6 +67,7 @@ class OnBoardingActivity :
when (navController.currentDestination?.id) {
R.id.selectStudentFragment -> {
}

else -> {
navController.popBackStack()
progressBarMinus()
Expand All @@ -73,12 +76,15 @@ class OnBoardingActivity :
}

private fun getIntentExtraData() {
val bundle: Bundle? = intent.extras
intent.apply {
viewModel.kakaoId = getLongExtra(EXTRA_KAKAO_ID, -1).toString()
viewModel.email = getStringExtra(EXTRA_EMAIL) ?: ""
viewModel.profileImg = getStringExtra(EXTRA_PROFILE_IMAGE) ?: ""
viewModel.name = getStringExtra(EXTRA_NAME) ?: ""
viewModel.gender = getStringExtra(EXTRA_GENDER) ?: ""
if (bundle != null) {
viewModel.kakaoId = bundle.getLong(EXTRA_KAKAO_ID, 0).toString()
viewModel.nameText.value = bundle.getString(EXTRA_NAME, "")
viewModel.gender = bundle.getString(EXTRA_GENDER, "")
viewModel.email = bundle.getString(EXTRA_EMAIL, "")
viewModel.profileImg = bundle.getString(EXTRA_PROFILE_IMAGE, "")
}
}
}

Expand Down Expand Up @@ -114,6 +120,7 @@ class OnBoardingActivity :
animator.interpolator = LinearInterpolator()
animator.start()
}

fun hideBackBtn() {
binding.backBtn.visibility = View.INVISIBLE
}
Expand Down
Loading

0 comments on commit 009719f

Please sign in to comment.