Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/team-yello/YELLO-Android
Browse files Browse the repository at this point in the history
…into add/#301-onboarding-highschool-amplitude
  • Loading branch information
minju1459 committed Oct 18, 2023
2 parents d3fa565 + a85ba96 commit f113cff
Show file tree
Hide file tree
Showing 10 changed files with 314 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class InviteFriendDialog :
binding.btnInviteKakao.setOnSingleClickListener {
AmplitudeUtils.trackEventWithProperties(
"click_invite_kakao",
JSONObject().put("invite_view", previousScreen)
JSONObject().put("invite_view", previousScreen),
)
startKakaoInvite(requireContext())
}
Expand All @@ -91,7 +91,7 @@ class InviteFriendDialog :
binding.btnInviteLink.setOnSingleClickListener {
AmplitudeUtils.trackEventWithProperties(
"click_invite_link",
JSONObject().put("invite_view", previousScreen)
JSONObject().put("invite_view", previousScreen),
)
val clipboardManager =
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
Expand Down Expand Up @@ -148,9 +148,9 @@ class InviteFriendDialog :
const val TEST_TEMPLATE_ID = 96906

const val LINK_TEXT = "추천인코드: %s\n" +
"우리 같이 YELL:O 해요!\n" +
"Android: https://play.google.com/store/apps/details?id=com.el.yello&hl=ko&gl=KR\n" +
"iOS: https://apps.apple.com/app/id6451451050"
"우리 같이 YELL:O 해요!\n" +
"Android: https://play.google.com/store/apps/details?id=com.el.yello&hl=ko&gl=KR\n" +
"iOS: https://apps.apple.com/app/id6451451050"

const val CLIP_LABEL = "RECOMMEND_LINK"
private const val KEY_YELLO_ID = "KEY"
Expand All @@ -159,7 +159,7 @@ class InviteFriendDialog :
fun newInstance(yelloId: String, previousScreen: String) = InviteFriendDialog().apply {
val args = bundleOf(
ARGS_YELLO_ID to yelloId,
ARGS_PREVIOUS_SCREEN to previousScreen
ARGS_PREVIOUS_SCREEN to previousScreen,
)
arguments = args
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.commit
import androidx.fragment.app.replace
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.el.yello.R
import com.el.yello.databinding.FragmentYelloBinding
import com.el.yello.presentation.main.yello.lock.YelloLockFragment
Expand All @@ -25,7 +27,8 @@ import com.example.ui.view.UiState.Failure
import com.example.ui.view.UiState.Loading
import com.example.ui.view.UiState.Success
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

@AndroidEntryPoint
class YelloFragment : BindingFragment<FragmentYelloBinding>(R.layout.fragment_yello) {
Expand All @@ -39,32 +42,31 @@ class YelloFragment : BindingFragment<FragmentYelloBinding>(R.layout.fragment_ye
}

private fun setupYelloState() {
viewModel.yelloState.observe(viewLifecycleOwner) { state ->
Timber.d("QATEST observe $state")
when (state) {
is Loading -> {}

is Success -> {
when (state.data) {
is Lock -> navigateTo<YelloLockFragment>()
is Valid -> navigateTo<YelloStartFragment>()
is Wait -> navigateTo<YelloWaitFragment>()
viewModel.yelloState.flowWithLifecycle(viewLifecycleOwner.lifecycle)
.onEach { state ->
when (state) {
is Loading -> {}
is Success -> {
when (state.data) {
is Lock -> navigateTo<YelloLockFragment>()
is Valid -> navigateTo<YelloStartFragment>()
is Wait -> navigateTo<YelloWaitFragment>()
}
}
}

is Empty -> {
yelloSnackbar(
binding.root,
getString(R.string.msg_failure),
)
}
is Empty -> {
yelloSnackbar(
binding.root,
getString(R.string.msg_failure),
)
}

is Failure -> {
toast(getString(R.string.msg_auto_login_error))
restartApp(requireContext())
is Failure -> {
toast(getString(R.string.msg_auto_login_error))
restartApp(requireContext())
}
}
}
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
}

private inline fun <reified T : Fragment> navigateTo() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.el.yello.presentation.main.yello

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.domain.entity.PayInfoModel
Expand All @@ -18,6 +16,9 @@ import com.example.ui.view.UiState.Failure
import com.example.ui.view.UiState.Success
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import retrofit2.HttpException
import timber.log.Timber
Expand All @@ -29,34 +30,35 @@ class YelloViewModel @Inject constructor(
private val authRepository: AuthRepository,
private val payRepository: PayRepository,
) : ViewModel() {
private val _yelloState = MutableLiveData<UiState<YelloState>>()
val yelloState: LiveData<UiState<YelloState>>
get() = _yelloState
private val _yelloState = MutableStateFlow<UiState<YelloState>>(UiState.Loading)
val yelloState: StateFlow<UiState<YelloState>>
get() = _yelloState.asStateFlow()

private val _leftTime = MutableLiveData<Long>()
val leftTime: LiveData<Long>
get() = _leftTime
private val _leftTime = MutableStateFlow<Long>(0)
val leftTime: StateFlow<Long>
get() = _leftTime.asStateFlow()

private val _point = MutableLiveData(0)
val point: LiveData<Int>
get() = _point
private val _point = MutableStateFlow(0)
val point: StateFlow<Int>
get() = _point.asStateFlow()

private val _isDecreasing = MutableLiveData(false)
private val _isDecreasing = MutableStateFlow(false)
private val isDecreasing: Boolean
get() = _isDecreasing.value ?: false
get() = _isDecreasing.value

private val _getPurchaseInfoState = MutableLiveData<UiState<PayInfoModel?>>()
val getPurchaseInfoState: LiveData<UiState<PayInfoModel?>> = _getPurchaseInfoState
private val _getPurchaseInfoState =
MutableStateFlow<UiState<PayInfoModel>>(UiState.Loading)
val getPurchaseInfoState: StateFlow<UiState<PayInfoModel>> =
_getPurchaseInfoState.asStateFlow()

private fun decreaseTime() {
leftTime.value ?: return
if (isDecreasing) return
viewModelScope.launch {
_isDecreasing.value = true
while (requireNotNull(leftTime.value) > 0) {
delay(1000L)
if (requireNotNull(leftTime.value) <= 0) return@launch
_leftTime.value = leftTime.value?.minus(1)
_leftTime.value = leftTime.value - 1
}

getVoteState()
Expand All @@ -65,11 +67,9 @@ class YelloViewModel @Inject constructor(
}

fun getVoteState() {
Timber.d("QATEST get vote state")
viewModelScope.launch {
voteRepository.getVoteAvailable()
.onSuccess { voteState ->
Timber.d("QATEST GET VOTE STATE SUCCESS : $voteState")
if (voteState == null) {
_yelloState.value = Empty
return@launch
Expand Down Expand Up @@ -110,11 +110,17 @@ class YelloViewModel @Inject constructor(
fun getPurchaseInfoFromServer() {
viewModelScope.launch {
payRepository.getPurchaseInfo()
.onSuccess {
_getPurchaseInfoState.value = Success(it)
.onSuccess { purchaseInfo ->
if (purchaseInfo == null) {
_getPurchaseInfoState.value = Empty
return@onSuccess
}
_getPurchaseInfoState.value = Success(purchaseInfo)
}
.onFailure {
_getPurchaseInfoState.value = Failure(it.message ?: "")
.onFailure { t ->
if (t is HttpException) {
_getPurchaseInfoState.value = Failure(t.code().toString())
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ package com.el.yello.presentation.main.yello.point

import android.os.Bundle
import android.view.View
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.el.yello.R
import com.el.yello.databinding.FragmentPointBinding
import com.el.yello.presentation.main.yello.YelloViewModel
import com.el.yello.presentation.main.yello.vote.VoteViewModel
import com.example.ui.base.BindingFragment
import com.example.ui.view.UiState
import com.example.ui.view.setOnSingleClickListener
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

class PointFragment : BindingFragment<FragmentPointBinding>(R.layout.fragment_point) {
private val yelloViewModel by activityViewModels<YelloViewModel>()
Expand All @@ -31,33 +36,31 @@ class PointFragment : BindingFragment<FragmentPointBinding>(R.layout.fragment_po
}
}

// 구독 여부 확인
private fun observeCheckIsSubscribed() {
yelloViewModel.getPurchaseInfoState.observe(viewLifecycleOwner) { state ->
when (state) {
is UiState.Success -> {
if (state.data?.isSubscribe == true) {
binding.tvPointPlusLabel.visibility = View.VISIBLE
binding.tvPointVotePoint.text =
voteViewModel.votePointSum.times(2).toString()
} else {
yelloViewModel.getPurchaseInfoState.flowWithLifecycle(viewLifecycleOwner.lifecycle)
.onEach { state ->
when (state) {
is UiState.Success -> {
binding.tvPointPlusLabel.isVisible = state.data.isSubscribe
if (state.data.isSubscribe) {
binding.tvPointVotePoint.text =
voteViewModel.votePointSum.times(2).toString()
}
}

is UiState.Failure -> {
binding.tvPointPlusLabel.visibility = View.GONE
binding.tvPointVotePoint.text = voteViewModel.votePointSum.toString()
}
}

is UiState.Failure -> {
binding.tvPointPlusLabel.visibility = View.GONE
}
is UiState.Loading -> {}

is UiState.Loading -> {}

is UiState.Empty -> {}
}
binding.tvPointVotePoint.visibility = View.VISIBLE
binding.tvPointVotePointPlus.visibility = View.VISIBLE
binding.tvPointVotePointLabel.visibility = View.VISIBLE
}
is UiState.Empty -> {}
}
binding.tvPointVotePoint.visibility = View.VISIBLE
binding.tvPointVotePointPlus.visibility = View.VISIBLE
binding.tvPointVotePointLabel.visibility = View.VISIBLE
}.launchIn(viewLifecycleOwner.lifecycleScope)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import android.os.Bundle
import android.view.View
import android.view.ViewGroup.MarginLayoutParams
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.el.yello.R
import com.el.yello.databinding.FragmentYelloStartBinding
import com.el.yello.presentation.main.yello.YelloViewModel
Expand All @@ -17,6 +19,8 @@ import com.example.ui.base.BindingFragment
import com.example.ui.view.UiState
import com.example.ui.view.setOnSingleClickListener
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

@AndroidEntryPoint
class YelloStartFragment :
Expand Down Expand Up @@ -49,6 +53,7 @@ class YelloStartFragment :
private fun initEntranceLottie() {
with(binding.lottieStartEntrance) {
val size = Point()
// TODO: getCompatibleRealSize 확장함수로 추출
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowMetrics = requireActivity().windowManager.currentWindowMetrics
size.x = windowMetrics.bounds.width()
Expand All @@ -60,18 +65,18 @@ class YelloStartFragment :
val displayHeight = size.y

layoutParams.width = (2.22 * displayWidth).toInt()
setMargins(this, 0, 0, 0, (-0.435 * displayHeight).toInt())
setMargins(this, (-0.435 * displayHeight).toInt())
}
}

private fun initShadowView() {
binding.shadowStart.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
}

private fun setMargins(v: View, l: Int, t: Int, r: Int, b: Int) {
private fun setMargins(v: View, b: Int) {
if (v.layoutParams is MarginLayoutParams) {
val p = v.layoutParams as MarginLayoutParams
p.setMargins(l, t, r, b)
p.setMargins(0, 0, 0, b)
v.requestLayout()
}
}
Expand All @@ -90,25 +95,26 @@ class YelloStartFragment :
}

private fun observeCheckIsSubscribed() {
viewModel.getPurchaseInfoState.observe(viewLifecycleOwner) { state ->
when (state) {
is UiState.Success -> {
if (state.data?.isSubscribe == true) {
binding.layoutSubsDouble.visibility = View.VISIBLE
} else {
binding.layoutSubsDouble.visibility = View.GONE
viewModel.getPurchaseInfoState.flowWithLifecycle(viewLifecycleOwner.lifecycle)
.onEach { state ->
when (state) {
is UiState.Success -> {
if (state.data?.isSubscribe == true) {
binding.layoutSubsDouble.visibility = View.VISIBLE
} else {
binding.layoutSubsDouble.visibility = View.GONE
}
}
}

is UiState.Failure -> {
binding.layoutSubsDouble.visibility = View.GONE
}
is UiState.Failure -> {
binding.layoutSubsDouble.visibility = View.GONE
}

is UiState.Loading -> {}
is UiState.Loading -> {}

is UiState.Empty -> {}
}
}
is UiState.Empty -> {}
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
}

companion object {
Expand Down
Loading

0 comments on commit f113cff

Please sign in to comment.