Skip to content

Commit

Permalink
Merge pull request #293 from team-yello/mod/#288-onboarding-flow
Browse files Browse the repository at this point in the history
[MOD/#288] OnBoarding / Stateflow & Refactoring
  • Loading branch information
minju1459 authored Oct 12, 2023
2 parents 2a4425c + ca082f8 commit 0d1ba60
Show file tree
Hide file tree
Showing 31 changed files with 232 additions and 346 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
android:screenOrientation="portrait" />

<activity
android:name=".presentation.onboarding.GetAlarmActivity"
android:name=".presentation.onboarding.activity.GetAlarmActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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.GetAlarmActivity
import com.el.yello.presentation.onboarding.activity.GetAlarmActivity
import com.el.yello.presentation.onboarding.activity.OnBoardingActivity
import com.el.yello.presentation.tutorial.TutorialAActivity
import com.el.yello.util.amplitude.AmplitudeUtils
Expand Down Expand Up @@ -129,9 +129,7 @@ class SignInActivity : BindingActivity<ActivitySignInBinding>(R.layout.activity_
is UiState.Failure -> {
yelloSnackbar(binding.root, getString(R.string.msg_error))
}

is UiState.Empty -> {}

is UiState.Loading -> {}
}
}
Expand Down Expand Up @@ -207,7 +205,6 @@ class SignInActivity : BindingActivity<ActivitySignInBinding>(R.layout.activity_
const val EXTRA_PROFILE_IMAGE = "PROFILE_IMAGE"
const val EXTRA_NAME = "NAME"
const val EXTRA_GENDER = "GENDER"

const val CODE_NOT_SIGNED_IN = "403"
const val CODE_NO_UUID = "404"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.el.yello.presentation.onboarding
package com.el.yello.presentation.onboarding.activity

import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
Expand All @@ -12,11 +13,13 @@ import com.el.yello.databinding.ActivityGetAlarmBinding
import com.el.yello.presentation.tutorial.TutorialAActivity
import com.el.yello.util.amplitude.AmplitudeUtils
import com.example.ui.base.BindingActivity
import com.example.ui.intent.boolExtra
import com.example.ui.view.setOnSingleClickListener

class GetAlarmActivity :
BindingActivity<ActivityGetAlarmBinding>(R.layout.activity_get_alarm) {

private val isFromOnBoarding by boolExtra()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
askNotificationPermission()
Expand All @@ -34,12 +37,17 @@ class GetAlarmActivity :
}

private fun startTutorialActivity() {
val isCodeTextEmpty =
intent.getBooleanExtra(OnBoardingActivity.EXTRA_CODE_TEXT_EMPTY, false)
val intent = TutorialAActivity.newIntent(this, false).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra(OnBoardingActivity.EXTRA_CODE_TEXT_EMPTY, isCodeTextEmpty)
putExtra(TutorialAActivity.EXTRA_FROM_ONBOARDING, isFromOnBoarding)
}
startActivity(intent)
finish()
}

private fun askNotificationPermission() {
binding.btnStartYello.setOnSingleClickListener {
AmplitudeUtils.trackEventWithProperties("click_onboarding_notification")
Expand All @@ -60,4 +68,18 @@ class GetAlarmActivity :
}
}
}

override fun onPause() {
super.onPause()
overridePendingTransition(NONE_ANIMATION, NONE_ANIMATION)
}

companion object {
@JvmStatic
fun newIntent(context: Context, isFromOnBoarding: Boolean) =
Intent(context, GetAlarmActivity::class.java).apply {
putExtra("isFromOnBoarding", isFromOnBoarding)
}
private const val NONE_ANIMATION = 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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.tutorial.TutorialAActivity
import com.example.ui.base.BindingActivity
import com.example.ui.context.toast
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -39,7 +38,6 @@ class OnBoardingActivity :
finish()
}
}

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

else -> {
navController.popBackStack()
progressBarMinus()
Expand All @@ -59,7 +56,6 @@ class OnBoardingActivity :

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

getIntentExtraData()
this.onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}
Expand All @@ -86,6 +82,13 @@ class OnBoardingActivity :
}
}

fun endTutorialActivity() {
val intent = GetAlarmActivity.newIntent(this, true)
intent.putExtra(EXTRA_CODE_TEXT_EMPTY, viewModel.isCodeTextEmpty())
startActivity(intent)
finish()
}

fun progressBarPlus() {
viewModel.plusCurrentPercent()
val animator = ObjectAnimator.ofInt(
Expand All @@ -111,12 +114,6 @@ class OnBoardingActivity :
animator.interpolator = LinearInterpolator()
animator.start()
}

fun hideViews() {
binding.backBtn.visibility = View.INVISIBLE
binding.onboardingProgressbar.visibility = View.INVISIBLE
}

fun hideBackBtn() {
binding.backBtn.visibility = View.INVISIBLE
}
Expand All @@ -125,21 +122,14 @@ class OnBoardingActivity :
binding.backBtn.visibility = View.VISIBLE
}

fun endTutorialActivity() {
val intent = TutorialAActivity.newIntent(this, true)
intent.putExtra(EXTRA_CODE_TEXT_EMPTY, viewModel.isCodeTextEmpty())
startActivity(intent)
finish()
}

override fun onPause() {
super.onPause()
overridePendingTransition(0, 0)
overridePendingTransition(NONE_ANIMATION, NONE_ANIMATION)
}

companion object {
private const val BACK_PRESSED_INTERVAL = 2000

const val EXTRA_CODE_TEXT_EMPTY = "codeTextEmpty"
private const val NONE_ANIMATION = 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import com.example.domain.repository.OnboardingRepository
import com.example.ui.view.UiState
import com.kakao.sdk.talk.TalkApiClient
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import retrofit2.HttpException
import timber.log.Timber
Expand Down Expand Up @@ -63,15 +65,16 @@ class OnBoardingViewModel @Inject constructor(
val id: String get() = idText.value?.trim() ?: ""
val isValidId: LiveData<Boolean> = idText.map { id -> checkId(id) }
val codeText = MutableLiveData("")
val isValidCode: LiveData<Boolean> = codeText.map { id -> checkId(id) }

private val _universityState = MutableLiveData<UiState<SchoolList>>()
val universityState: MutableLiveData<UiState<SchoolList>> = _universityState
private val _universityState = MutableStateFlow<UiState<SchoolList>>(UiState.Empty)
val universityState: StateFlow<UiState<SchoolList>> = _universityState

private val _highSchoolState = MutableLiveData<UiState<HighSchoolList>>()
val highSchoolState: MutableLiveData<UiState<HighSchoolList>> = _highSchoolState
private val _highSchoolState = MutableStateFlow<UiState<HighSchoolList>>(UiState.Empty)
val highSchoolState: StateFlow<UiState<HighSchoolList>> = _highSchoolState

private val _departmentState = MutableLiveData<UiState<GroupList>>()
val departmentState: MutableLiveData<UiState<GroupList>> = _departmentState
private val _departmentState = MutableStateFlow<UiState<GroupList>>(UiState.Empty)
val departmentState: StateFlow<UiState<GroupList>> = _departmentState

private val _highSchoolGroupState = MutableLiveData<UiState<GroupHighSchool?>>()

Expand All @@ -88,8 +91,8 @@ class OnBoardingViewModel @Inject constructor(
val studentIdResult: LiveData<List<Int>> = _studentIdResult

private val _friendListState =
MutableLiveData<UiState<List<AddFriendListModel.FriendModel>>>(UiState.Loading)
val friendListState: LiveData<UiState<List<AddFriendListModel.FriendModel>>> = _friendListState
MutableStateFlow<UiState<List<AddFriendListModel.FriendModel>>>(UiState.Loading)
val friendListState: StateFlow<UiState<List<AddFriendListModel.FriendModel>>> = _friendListState

var selectedFriendIdList: List<Long> = listOf()
var selectedFriendCount: MutableLiveData<Int> = MutableLiveData(0)
Expand Down Expand Up @@ -246,7 +249,7 @@ class OnBoardingViewModel @Inject constructor(
}
}
}
fun getHighSchoolGroupId(group: String) {
private fun getHighSchoolGroupId(group: String) {
viewModelScope.launch {
onboardingRepository.getGroupHighSchool(
highSchool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.el.yello.presentation.onboarding.fragment.addfriend
import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -11,18 +12,19 @@ import com.el.yello.databinding.FragmentAddFriendBinding
import com.el.yello.presentation.onboarding.activity.OnBoardingActivity
import com.el.yello.presentation.onboarding.activity.OnBoardingViewModel
import com.el.yello.util.amplitude.AmplitudeUtils
import com.el.yello.util.context.yelloSnackbar
import com.example.domain.entity.onboarding.AddFriendListModel.FriendModel
import com.example.ui.base.BindingFragment
import com.example.ui.fragment.toast
import com.example.ui.view.UiState
import com.example.ui.view.setOnSingleClickListener
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.json.JSONObject

@AndroidEntryPoint
class AddFriendFragment : BindingFragment<FragmentAddFriendBinding>(R.layout.fragment_add_friend) {
private val viewModel by activityViewModels<OnBoardingViewModel>()

private var _adapter: AddFriendAdapter? = null
private val adapter
get() = requireNotNull(_adapter) { getString(R.string.adapter_not_initialized_error_msg) }
Expand Down Expand Up @@ -76,8 +78,6 @@ class AddFriendFragment : BindingFragment<FragmentAddFriendBinding>(R.layout.fra
viewModel.initFriendPagingVariable()
viewModel.addListWithKakaoIdList()
}

// 무한 스크롤 구현
private fun setInfinityScroll() {
binding.rvFriendList.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
Expand All @@ -98,26 +98,25 @@ class AddFriendFragment : BindingFragment<FragmentAddFriendBinding>(R.layout.fra

// 리스트 추가 서버 통신 성공 시 어댑터에 리스트 추가
private fun observeAddListState() {
viewModel.friendListState.observe(viewLifecycleOwner) { state ->
when (state) {
is UiState.Success -> {
stopShimmerView()
friendsList = state.data
adapter.submitList(friendsList)
selectedItemIdList.addAll(friendsList.map { friend -> friend.id })
viewModel.selectedFriendCount.value = friendsList.size
}

is UiState.Failure -> {
stopShimmerView()
toast(getString(R.string.onboarding_add_friend_error))
}

is UiState.Loading -> {
startShimmerView()
lifecycleScope.launch {
viewModel.friendListState.collectLatest { state ->
when (state) {
is UiState.Success -> {
stopShimmerView()
friendsList = state.data
adapter.submitList(friendsList)
selectedItemIdList.addAll(friendsList.map { friend -> friend.id })
viewModel.selectedFriendCount.value = friendsList.size
}
is UiState.Failure -> {
stopShimmerView()
yelloSnackbar(binding.root, getString(R.string.onboarding_add_friend_error))
}
is UiState.Loading -> {
startShimmerView()
}
is UiState.Empty -> {}
}

is UiState.Empty -> {}
}
}
}
Expand Down
Loading

0 comments on commit 0d1ba60

Please sign in to comment.