Skip to content

Commit

Permalink
[MERGE] : develop -> #368
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed Feb 5, 2024
2 parents 36f0739 + 9ac7604 commit 0597561
Show file tree
Hide file tree
Showing 65 changed files with 812 additions and 152 deletions.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@
android:exported="false"
android:screenOrientation="portrait" />

<activity
android:name=".presentation.main.profile.manage.ProfileQuitReasonActivity"
android:exported="false"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="portrait" />
<activity
android:name=".presentation.main.myyello.read.MyYelloReadActivity"
android:exported="false"
Expand Down
35 changes: 27 additions & 8 deletions app/src/main/java/com/el/yello/presentation/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ 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 kotlinx.coroutines.Job
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import java.text.SimpleDateFormat
Expand All @@ -48,6 +49,7 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
private val type by stringExtra()

private var backPressedTime: Long = 0
private var userSubsStateJob: Job? = null

private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
Expand Down Expand Up @@ -82,12 +84,15 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
}

private fun initBnvItemSelectedListener() {
supportFragmentManager.findFragmentById(R.id.fcv_main) ?: navigateTo<YelloFragment>()
supportFragmentManager.findFragmentById(R.id.fcv_main)
?: navigateTo<YelloFragment>()

binding.bnvMain.setOnItemSelectedListener { menu ->
when (menu.itemId) {
R.id.menu_recommend -> {
AmplitudeUtils.trackEventWithProperties(EVENT_CLICK_RECOMMEND_NAVIGATION)
AmplitudeUtils.trackEventWithProperties(
EVENT_CLICK_RECOMMEND_NAVIGATION,
)
navigateTo<RecommendFragment>()
}

Expand Down Expand Up @@ -185,7 +190,7 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
}

private fun setupGetUserSubsState() {
viewModel.getUserSubsState.flowWithLifecycle(lifecycle)
userSubsStateJob = viewModel.getUserSubsState.flowWithLifecycle(lifecycle)
.onEach { state ->
when (state) {
is Empty -> return@onEach
Expand All @@ -195,20 +200,25 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
// TODO : 도메인 모델에 변환된 날짜로 파싱되도록 보완
val expiredDateString = state.data?.expiredDate.toString()
val expiredDate =
SimpleDateFormat(EXPIRED_DATE_FORMAT).parse(expiredDateString)
SimpleDateFormat(EXPIRED_DATE_FORMAT).parse(
expiredDateString,
)
?: return@onEach
val currentDate = Calendar.getInstance().time
val daysDifference = TimeUnit.DAYS.convert(
expiredDate.time - currentDate.time,
TimeUnit.MILLISECONDS,
)
if (daysDifference >= 1) {
if (daysDifference <= 1) {
PayReSubsNoticeDialog.newInstance(expiredDateString)
.show(supportFragmentManager, PAY_RESUBS_DIALOG)
}
}

is Failure -> yelloSnackbar(binding.root, getString(R.string.msg_error))
is Failure -> yelloSnackbar(
binding.root,
getString(R.string.msg_error),
)
}
}.launchIn(lifecycleScope)
}
Expand All @@ -217,7 +227,11 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
viewModel.getNoticeState.flowWithLifecycle(lifecycle)
.onEach { state ->
when (state) {
is Empty -> yelloSnackbar(binding.root, getString(R.string.msg_error))
is Empty -> yelloSnackbar(
binding.root,
getString(R.string.msg_error),
)

is Loading -> return@onEach
is Success -> {
if (!state.data.isAvailable) return@onEach
Expand Down Expand Up @@ -262,6 +276,10 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
badgeDrawable.isVisible = count != 0
}

fun resetUserSubsStateFlow() {
userSubsStateJob?.cancel()
}

companion object {
private const val EXTRA_TYPE = "type"
private const val EXTRA_PATH = "path"
Expand All @@ -274,7 +292,8 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
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"
private const val EVENT_CLICK_RECOMMEND_NAVIGATION =
"click_recommend_navigation"

private const val TAG_NOTICE_DIALOG = "NOTICE_DIALOG"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ class LookFragment : BindingFragment<FragmentLookBinding>(R.layout.fragment_look
private var isScrolled: Boolean = false
private var isNoFriend: Boolean = false

private var isFilterSelected: Boolean = false

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

initAdapter()
initInviteBtnListener()
initFilterBtnListener()
setListBottomPadding()
observeTimelinePagingList()
observeTimelinePagingList(isFilterSelected)
setPullToScrollListener()
observePagingLoadingState()
catchScrollForAmplitude()
Expand All @@ -59,6 +62,7 @@ class LookFragment : BindingFragment<FragmentLookBinding>(R.layout.fragment_look
adapter.addLoadStateListener { combinedLoadStates ->
if (combinedLoadStates.prepend.endOfPaginationReached) {
binding.layoutLookNoFriendsList.isVisible = adapter.itemCount < 1
binding.layoutLookListInfo.isGone = adapter.itemCount < 1
binding.rvLook.isGone = adapter.itemCount < 1
isNoFriend = adapter.itemCount < 1
}
Expand All @@ -77,6 +81,16 @@ class LookFragment : BindingFragment<FragmentLookBinding>(R.layout.fragment_look
}
}

private fun initFilterBtnListener() {
binding.btnLookFilter.setOnSingleClickListener {
isFilterSelected = !isFilterSelected
adapter.refresh()
viewModel.setFirstLoading(true)
observeTimelinePagingList(isFilterSelected)
binding.tvLookFilterType.text = if(isFilterSelected) TYPE_MINE else TYPE_ALL
}
}

private fun setListBottomPadding() {
binding.rvLook.addItemDecoration(BaseLinearRcvItemDeco(bottomPadding = 14))
}
Expand All @@ -96,11 +110,10 @@ class LookFragment : BindingFragment<FragmentLookBinding>(R.layout.fragment_look
}.launchIn(lifecycleScope)
}

private fun observeTimelinePagingList() {
viewModel.getLookListWithPaging().flowWithLifecycle(lifecycle)
.onEach { pagingData ->
adapter.submitData(lifecycle, pagingData)
}.launchIn(lifecycleScope)
private fun observeTimelinePagingList(onlyMine: Boolean) {
viewModel.getLookListWithPaging(onlyMine).flowWithLifecycle(lifecycle).onEach { pagingData ->
adapter.submitData(lifecycle, pagingData)
}.launchIn(lifecycleScope)
}


Expand Down Expand Up @@ -166,5 +179,8 @@ class LookFragment : BindingFragment<FragmentLookBinding>(R.layout.fragment_look
companion object {
const val INVITE_DIALOG = "inviteDialog"
const val TIMELINE_NO_FRIEND = "timeline_0friend"

const val TYPE_ALL = "모든 쪽지"
const val TYPE_MINE = "내가 보낸 쪽지"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class LookViewHolder(
setTextColor(itemView.context.colorOf(R.color.semantic_gender_f_500))
FROM_FEMALE
}
if (item.isUserSenderVote) text = FROM_ME
}
}
}
Expand All @@ -58,5 +59,6 @@ class LookViewHolder(
const val MALE = "MALE"
const val FROM_MALE = "남학생에게 받음"
const val FROM_FEMALE = "여학생에게 받음"
const val FROM_ME = "나에게 받음"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class LookViewModel @Inject constructor(
_isFirstLoading.value = boolean
}

fun getLookListWithPaging(): Flow<PagingData<LookModel>> =
fun getLookListWithPaging(onlyMine: Boolean): Flow<PagingData<LookModel>> =
Pager(
config = PagingConfig(LookPagingSource.LOOK_PAGE_SIZE),
pagingSourceFactory = { LookPagingSource(lookService) }
pagingSourceFactory = { LookPagingSource(lookService, onlyMine) }
).flow.cachedIn(viewModelScope)

fun getYelloId() = authRepository.getYelloId()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.el.yello.presentation.main.profile

import android.content.Context
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.el.yello.R
import com.el.yello.util.amplitude.AmplitudeUtils
import com.example.domain.entity.PayInfoModel
import com.example.domain.entity.ProfileFriendsListModel
import com.example.domain.entity.ProfileQuitReasonModel
import com.example.domain.entity.ProfileUserModel
import com.example.domain.repository.AuthRepository
import com.example.domain.repository.PayRepository
Expand All @@ -30,14 +36,12 @@ class ProfileViewModel @Inject constructor(

init {
resetPageVariable()
// resetStateVariable()
}

private val _getUserDataResult = MutableSharedFlow<Boolean>()
val getUserDataResult: SharedFlow<Boolean> = _getUserDataResult

private val _getFriendListState =
MutableStateFlow<UiState<ProfileFriendsListModel>>(UiState.Empty)
private val _getFriendListState = MutableStateFlow<UiState<ProfileFriendsListModel>>(UiState.Empty)
val getFriendListState: StateFlow<UiState<ProfileFriendsListModel>> = _getFriendListState

private val _deleteUserState = MutableStateFlow<UiState<Unit>>(UiState.Empty)
Expand Down Expand Up @@ -71,6 +75,21 @@ class ProfileViewModel @Inject constructor(
var clickedUserData = ProfileUserModel()
var clickedItemPosition: Int? = null

private val quitReasonText = MutableLiveData<String>()
val etcText = MutableLiveData("")
private val _quitReasonData: MutableLiveData<List<String>> = MutableLiveData()
val quitReasonData: LiveData<List<String>> = _quitReasonData
fun setEtcText(etc: String) {
etcText.value = etc
}
fun setQuitReason(reason: String) {
quitReasonText.value = reason
}
fun addQuitReasonList(context: Context) {
val quitReasonArray = context.resources.getStringArray(R.array.quit_reasons)
_quitReasonData.value = quitReasonArray.toList()
}

fun setItemPosition(position: Int) {
clickedItemPosition = position
}
Expand All @@ -92,6 +111,7 @@ class ProfileViewModel @Inject constructor(
_kakaoQuitState.value = UiState.Empty
_getFriendListState.value = UiState.Empty
_getPurchaseInfoState.value = UiState.Empty
_getUserDataResult.resetReplayCache()
}

fun getUserDataFromServer() {
Expand Down Expand Up @@ -136,7 +156,16 @@ class ProfileViewModel @Inject constructor(
fun deleteUserDataToServer() {
viewModelScope.launch {
_deleteUserState.value = UiState.Loading
profileRepository.deleteUserData()
val quitReason = if (quitReasonText.value.toString().equals("기타")) {
etcText.value.toString()
} else {
quitReasonText.value.toString()
}
profileRepository.deleteUserData(
ProfileQuitReasonModel(
quitReason,
),
)
.onSuccess {
clearLocalInfo()
delay(300)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ class ProfileFragment : BindingFragment<FragmentProfileBinding>(R.layout.fragmen
AmplitudeUtils.trackEventWithProperties("view_profile")
}

override fun onResume() {
super.onResume()

resetProfileData()
}

private fun initProfileSetting() {
initProfileManageBtnListener()
initUpwardBtnListener()
initUpwardBtnVisibility()
initAdapter()
setItemDivider()
viewModel.getUserDataFromServer()
viewModel.getFriendsListFromServer()
viewModel.getPurchaseInfoFromServer()
}

private fun setItemDivider() {
Expand Down Expand Up @@ -156,14 +159,7 @@ class ProfileFragment : BindingFragment<FragmentProfileBinding>(R.layout.fragmen
binding.layoutProfileSwipe.apply {
setOnRefreshListener {
lifecycleScope.launch {
adapter.setItemList(listOf())
viewModel.run {
resetPageVariable()
resetStateVariable()
getPurchaseInfoFromServer()
getUserDataFromServer()
getFriendsListFromServer()
}
resetProfileData()
delay(200)
binding.layoutProfileSwipe.isRefreshing = false
}
Expand All @@ -172,6 +168,17 @@ class ProfileFragment : BindingFragment<FragmentProfileBinding>(R.layout.fragmen
}
}

private fun resetProfileData() {
adapter.setItemList(listOf())
viewModel.run {
resetPageVariable()
resetStateVariable()
getPurchaseInfoFromServer()
getUserDataFromServer()
getFriendsListFromServer()
}
}

private fun observeUserDataResult() {
viewModel.getUserDataResult.flowWithLifecycle(lifecycle).onEach { result ->
if (!result) yelloSnackbar(requireView(), getString(R.string.profile_error_user_data))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ class ProfileQuitDialog :
viewModel.deleteUserDataToServer()
}
}

// 유저 탈퇴 서버 통신 성공 시 카카오 연결 해제 진행
private fun observeUserDeleteState() {
viewModel.deleteUserState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
Expand Down
Loading

0 comments on commit 0597561

Please sign in to comment.