Skip to content

Commit

Permalink
Merge pull request #353 from team-yello/feat/#346-notice-resubscribe
Browse files Browse the repository at this point in the history
[FEAT/#346]  재구독 연장 여부 공지 팝업 뷰 구현
  • Loading branch information
minju1459 authored Jan 27, 2024
2 parents f578265 + 7d10249 commit 7e3a76b
Show file tree
Hide file tree
Showing 28 changed files with 493 additions and 123 deletions.
55 changes: 52 additions & 3 deletions app/src/main/java/com/el/yello/presentation/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import androidx.fragment.app.commitNow
import androidx.fragment.app.replace
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
Expand All @@ -21,16 +22,21 @@ import com.el.yello.presentation.main.profile.ProfileViewModel
import com.el.yello.presentation.main.profile.info.ProfileFragment
import com.el.yello.presentation.main.recommend.RecommendFragment
import com.el.yello.presentation.main.yello.YelloFragment
import com.el.yello.presentation.pay.PayReSubsNoticeDialog
import com.el.yello.presentation.util.dp
import com.el.yello.util.amplitude.AmplitudeUtils
import com.el.yello.util.context.yelloSnackbar
import com.example.domain.enum.SubscribeType
import com.example.ui.base.BindingActivity
import com.example.ui.context.toast
import com.example.ui.intent.stringExtra
import com.example.ui.view.UiState
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.concurrent.TimeUnit

@AndroidEntryPoint
class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main) {
Expand All @@ -55,7 +61,8 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main

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

viewModel.getUserSubsInfoStateFromServer()
observeSubsNeededState()
initBnvItemIconTintList()
initBnvItemSelectedListener()
initBnvItemReselectedListener()
Expand All @@ -67,6 +74,48 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
this.onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}

private fun observeSubsNeededState() {
viewModel.getUserSubsInfoState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
is UiState.Success -> {
if (state.data?.subscribe == SubscribeType.CANCELED) {
val expiredDateString = state.data?.expiredDate.toString()
val expiredDate =
SimpleDateFormat(EXPIRED_DATE_FORMAT).parse(expiredDateString)
val currentDate = Calendar.getInstance().time
val daysDifference = TimeUnit.DAYS.convert(
expiredDate.time - currentDate.time,
TimeUnit.MILLISECONDS,
)
if (daysDifference >= 1) {
val expiredDateString = state.data?.expiredDate.toString()
val payResubsNoticeFragment =
PayReSubsNoticeDialog.newInstance(expiredDateString)
supportFragmentManager.commitNow {
add(
payResubsNoticeFragment,
PAY_RESUBS_DIALOG,
)
}
}
}
}

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 initBnvItemIconTintList() {
binding.bnvMain.itemIconTintList = null
binding.bnvMain.selectedItemId = R.id.menu_yello
Expand Down Expand Up @@ -209,9 +258,9 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
const val NEW_FRIEND = "NEW_FRIEND"
const val VOTE_AVAILABLE = "VOTE_AVAILABLE"
const val RECOMMEND = "RECOMMEND"

const val BACK_PRESSED_INTERVAL = 2000

const val EXPIRED_DATE_FORMAT = "yyyy-MM-dd"
const val PAY_RESUBS_DIALOG = "PayResubsNoticeDialog"
private const val EVENT_CLICK_RECOMMEND_NAVIGATION = "click_recommend_navigation"

fun getIntent(context: Context, type: String? = null, path: String? = null) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.el.yello.R
import com.el.yello.databinding.ItemMyYelloBinding
import com.el.yello.util.Utils
import com.example.domain.entity.Yello
import com.example.domain.enum.GenderEnum
import com.example.domain.enum.Gender
import com.example.ui.view.setOnSingleClickListener

class MyYelloAdapter(private val itemClick: (Yello, Int) -> (Unit)) :
Expand Down Expand Up @@ -73,7 +73,7 @@ class MyYelloAdapter(private val itemClick: (Yello, Int) -> (Unit)) :
)
)
binding.tvTime.setTextColor(ContextCompat.getColor(itemView.context, R.color.grayscales_600))
if (item.gender == GenderEnum.M) {
if (item.gender == Gender.M) {
if ((item.isHintUsed || item.nameHint != -1) && item.isRead) {
binding.cardMyYello.setCardBackgroundColor(
ContextCompat.getColor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.el.yello.util.amplitude.AmplitudeUtils
import com.example.domain.entity.PayInfoModel
import com.example.domain.entity.PayUserSubsInfoModel
import com.example.domain.entity.ProfileFriendsListModel
import com.example.domain.entity.ProfileUserModel
import com.example.domain.entity.vote.VoteCount
Expand Down Expand Up @@ -60,6 +61,10 @@ class ProfileViewModel @Inject constructor(
private val _voteCount = MutableStateFlow<UiState<VoteCount>>(UiState.Loading)
val voteCount: StateFlow<UiState<VoteCount>> = _voteCount

private val _getUserSubsInfoState =
MutableStateFlow<UiState<PayUserSubsInfoModel?>>(UiState.Empty)
val getUserSubsInfoState: StateFlow<UiState<PayUserSubsInfoModel?>> = _getUserSubsInfoState

var isItemBottomSheetRunning: Boolean = false

var isFirstScroll: Boolean = true
Expand Down Expand Up @@ -240,4 +245,19 @@ class ProfileViewModel @Inject constructor(
}.onFailure(Timber::e)
}
}
fun getUserSubsInfoStateFromServer() {
viewModelScope.launch {
payRepository.getUserSubsInfo()
.onSuccess { userInfo ->
if (userInfo == null) {
_getUserSubsInfoState.value = UiState.Empty
} else {
_getUserSubsInfoState.value = UiState.Success(userInfo)
}
}
.onFailure {
_getUserSubsInfoState.value = UiState.Failure(it.message.toString())
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.el.yello.presentation.onboarding.fragment.highschoolinfo.group.GroupD
import com.el.yello.presentation.onboarding.fragment.highschoolinfo.school.SearchDialogHighSchoolFragment
import com.el.yello.util.amplitude.AmplitudeUtils
import com.el.yello.util.context.yelloSnackbar
import com.example.domain.enum.GradeEnum
import com.example.domain.enum.Grade
import com.example.ui.base.BindingFragment
import com.example.ui.view.setOnSingleClickListener
import org.json.JSONObject
Expand All @@ -24,9 +24,9 @@ class HighSchoolInfoFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.vm = viewModel
binding.first = GradeEnum.A.toInt()
binding.second = GradeEnum.B.toInt()
binding.third = GradeEnum.C.toInt()
binding.first = Grade.A.toInt()
binding.second = Grade.B.toInt()
binding.third = Grade.C.toInt()
setupHighSchool()
setupGrade()
setupHighSchoolGroup()
Expand Down Expand Up @@ -61,7 +61,7 @@ class HighSchoolInfoFragment :
private fun setupGrade() {
viewModel.studentIdText.observe(viewLifecycleOwner) { grade ->
when (grade) {
GradeEnum.A.toInt() -> {
Grade.A.toInt() -> {
binding.tvGradeFirst.setBackgroundResource(R.drawable.shape_grayscales900_fill_yello_main600_line_8_leftrect)
binding.tvGradeFirst.setTextColor(resources.getColor(R.color.yello_main_600))
binding.tvGradeSecond.setBackgroundResource(R.drawable.shape_grayscales900_fill_grayscales700_line_8_square)
Expand All @@ -70,7 +70,7 @@ class HighSchoolInfoFragment :
binding.tvGradeThird.setTextColor(resources.getColor(R.color.grayscales_700))
}

GradeEnum.B.toInt() -> {
Grade.B.toInt() -> {
binding.tvGradeFirst.setBackgroundResource(R.drawable.shape_grayscales900_fill_grayscales700_line_8_leftrect)
binding.tvGradeFirst.setTextColor(resources.getColor(R.color.grayscales_700))
binding.tvGradeSecond.setBackgroundResource(R.drawable.shape_grayscales900_fill_yello_main600_line_8_square)
Expand All @@ -79,7 +79,7 @@ class HighSchoolInfoFragment :
binding.tvGradeThird.setTextColor(resources.getColor(R.color.grayscales_700))
}

GradeEnum.C.toInt() -> {
Grade.C.toInt() -> {
binding.tvGradeFirst.setBackgroundResource(R.drawable.shape_grayscales900_fill_grayscales700_line_8_leftrect)
binding.tvGradeFirst.setTextColor(resources.getColor(R.color.grayscales_700))
binding.tvGradeSecond.setBackgroundResource(R.drawable.shape_grayscales900_fill_grayscales700_line_8_square)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.el.yello.databinding.FragmentSelectStudentTypeBinding
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.example.domain.enum.StudentTypeEnum
import com.example.domain.enum.StudentType
import com.example.ui.base.BindingFragment
import com.example.ui.view.setOnSingleClickListener
import org.json.JSONObject
Expand All @@ -21,8 +21,8 @@ class SelectStudentFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.vm = viewModel
binding.highschool = StudentTypeEnum.H.toString()
binding.university = StudentTypeEnum.U.toString()
binding.highschool = StudentType.H.toString()
binding.university = StudentType.U.toString()
setupStudentType()
}

Expand All @@ -33,7 +33,7 @@ class SelectStudentFragment :
private fun setupStudentType() {
viewModel.studentType.observe(viewLifecycleOwner) { studentType ->
when (studentType) {
StudentTypeEnum.H.toString() -> {
StudentType.H.toString() -> {
binding.btnSchoolHighschool.setBackgroundResource(R.drawable.shape_black_fill_yello_main_500_line_8_rect)
binding.btnSchoolUniversity.setBackgroundResource(R.drawable.shape_black_fill_grayscales700_line_8_rect)
binding.ivStudentHighschool.setImageResource(R.drawable.ic_student_highschool_face_select)
Expand All @@ -48,7 +48,7 @@ class SelectStudentFragment :
activity.progressBarPlus()
}
}
StudentTypeEnum.U.toString() -> {
StudentType.U.toString() -> {
binding.btnSchoolUniversity.setBackgroundResource(R.drawable.shape_black_fill_yello_main_500_line_8_rect)
binding.btnSchoolHighschool.setBackgroundResource(R.drawable.shape_black_fill_grayscales700_line_8_rect)
binding.ivStudentUniversity.setImageResource(R.drawable.ic_student_university_face_select)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.el.yello.presentation.pay

import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import com.el.yello.R
import com.el.yello.databinding.FragmentNoticeResubscribeBinding
import com.example.ui.base.BindingDialogFragment
import com.example.ui.view.setOnSingleClickListener

class PayReSubsNoticeDialog :
BindingDialogFragment<FragmentNoticeResubscribeBinding>(R.layout.fragment_notice_resubscribe) {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setNoticeBtnClickListener()
getArgExpiredDate()
}

override fun onStart() {
super.onStart()
showDialogFullScreen()
}

private fun showDialogFullScreen() {
dialog?.window?.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
)
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
}

private fun setNoticeBtnClickListener() {
binding.btnNoticeQuit.setOnSingleClickListener {
dismiss()
}
binding.btnYelloplusSubscribe.setOnSingleClickListener {
Intent(requireContext(), PayActivity::class.java).apply {
startActivity(this)
}
dismiss()
}
}

private fun setExpiredDate(expiredDate: String) {
if (isAdded) {
binding.tvResubscribeExpiredDate.text = expiredDate
}
}

private fun getArgExpiredDate() {
val expiredDate = arguments?.getString(ARG_EXPIRED_DATE)
expiredDate?.let {
setExpiredDate(it)
}
}

companion object {
private const val ARG_EXPIRED_DATE = "arg_expired_date"

@JvmStatic
fun newInstance(expiredDate: String): PayReSubsNoticeDialog {
return PayReSubsNoticeDialog().apply {
arguments = Bundle().apply {
putString(ARG_EXPIRED_DATE, expiredDate)
}
}
}
}
}
20 changes: 1 addition & 19 deletions app/src/main/java/com/el/yello/presentation/pay/PayViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.example.domain.entity.PayInAppModel
import com.example.domain.entity.PayInfoModel
import com.example.domain.entity.PayRequestModel
import com.example.domain.entity.PaySubsModel
import com.example.domain.entity.PaySubsNeededModel
import com.example.domain.repository.PayRepository
import com.example.ui.view.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -17,7 +16,7 @@ import javax.inject.Inject

@HiltViewModel
class PayViewModel @Inject constructor(
private val payRepository: PayRepository
private val payRepository: PayRepository,
) : ViewModel() {

var currentInAppItem = String()
Expand All @@ -28,9 +27,6 @@ class PayViewModel @Inject constructor(
private val _postInAppCheckState = MutableStateFlow<UiState<PayInAppModel?>>(UiState.Empty)
val postInAppCheckState: StateFlow<UiState<PayInAppModel?>> = _postInAppCheckState

private val _getSubsNeededState = MutableStateFlow<UiState<PaySubsNeededModel?>>(UiState.Empty)
val getSubsNeededState: StateFlow<UiState<PaySubsNeededModel?>> = _getSubsNeededState

private val _getPurchaseInfoState = MutableStateFlow<UiState<PayInfoModel?>>(UiState.Empty)
val getPurchaseInfoState: StateFlow<UiState<PayInfoModel?>> = _getPurchaseInfoState

Expand Down Expand Up @@ -71,20 +67,6 @@ class PayViewModel @Inject constructor(
}
}

// 서버 통신 - (아직 사용 X) 구독 재촉 알림 필요 여부 확인
fun getSubsNeededFromServer() {
viewModelScope.launch {
payRepository.getSubsNeeded()
.onSuccess {
it ?: return@launch
_getSubsNeededState.value = UiState.Success(it)
}
.onFailure {
_getSubsNeededState.value = UiState.Failure(it.message.toString())
}
}
}

fun getPurchaseInfoFromServer() {
viewModelScope.launch {
payRepository.getPurchaseInfo()
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_notice_subscribe_one.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12,12m12,0a12,12 0,1 0,-24 0a12,12 0,1 0,24 0"
android:fillColor="#FBFF3E"/>
<path
android:pathData="M14.034,6.818V17H12.493V8.359H12.433L9.997,9.95V8.479L12.537,6.818H14.034Z"
android:fillColor="#191919"/>
</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_notice_subscribe_three.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12,12m12,0a12,12 0,1 0,-24 0a12,12 0,1 0,24 0"
android:fillColor="#FBFF3E"/>
<path
android:pathData="M12.012,17.139C11.33,17.139 10.72,17.021 10.183,16.786C9.649,16.551 9.227,16.224 8.915,15.807C8.607,15.386 8.441,14.899 8.418,14.345H9.979C9.999,14.647 10.1,14.909 10.282,15.131C10.468,15.349 10.71,15.519 11.008,15.638C11.307,15.757 11.638,15.817 12.002,15.817C12.403,15.817 12.758,15.747 13.066,15.608C13.378,15.469 13.622,15.275 13.797,15.026C13.973,14.774 14.061,14.484 14.061,14.156C14.061,13.815 13.973,13.515 13.797,13.256C13.625,12.995 13.371,12.789 13.037,12.64C12.705,12.491 12.304,12.416 11.833,12.416H10.973V11.163H11.833C12.211,11.163 12.543,11.095 12.828,10.96C13.116,10.824 13.342,10.635 13.504,10.393C13.666,10.148 13.748,9.861 13.748,9.533C13.748,9.218 13.676,8.944 13.534,8.712C13.394,8.477 13.196,8.293 12.937,8.161C12.682,8.028 12.38,7.962 12.032,7.962C11.701,7.962 11.391,8.023 11.103,8.146C10.818,8.265 10.586,8.437 10.407,8.663C10.228,8.885 10.132,9.152 10.118,9.463H8.632C8.648,8.913 8.811,8.429 9.119,8.011C9.431,7.594 9.842,7.267 10.352,7.032C10.862,6.797 11.429,6.679 12.052,6.679C12.705,6.679 13.269,6.807 13.743,7.062C14.22,7.314 14.588,7.65 14.846,8.071C15.108,8.492 15.237,8.953 15.234,9.453C15.237,10.023 15.078,10.507 14.757,10.905C14.439,11.303 14.014,11.569 13.484,11.705V11.785C14.16,11.887 14.684,12.156 15.055,12.59C15.43,13.024 15.615,13.563 15.612,14.206C15.615,14.766 15.459,15.268 15.144,15.712C14.833,16.156 14.407,16.506 13.867,16.761C13.327,17.013 12.708,17.139 12.012,17.139Z"
android:fillColor="#191919"/>
</vector>
Loading

0 comments on commit 7e3a76b

Please sign in to comment.