Skip to content

Commit

Permalink
[del] #247 마이페이지 프래그먼트에서 사용하지 않는 코드 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeha committed Mar 2, 2024
1 parent d88111d commit 6579265
Showing 1 changed file with 32 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package org.go.sopt.winey.presentation.main.mypage

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.core.content.ContextCompat
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -49,17 +46,32 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
super.onViewCreated(view, savedInstanceState)
amplitudeUtils.logEvent("view_mypage")

initCheckNotificationPermission()
initUserData()
initNavigation()
addListener()
addObserver()
}

// 닉네임 액티비티 갔다가 다시 돌아왔을 때 유저 데이터 갱신하도록
override fun onStart() {
super.onStart()
mainViewModel.getUser()
}

private fun initUserData() {
viewLifeCycleScope.launch {
val userInfo = dataStoreRepository.getUserInfo().firstOrNull() ?: return@launch
updateUserInfo(userInfo)
}
}

private fun updateUserInfo(data: UserV2) {
binding.data = data
}

private fun addListener() {
initEditNicknameButtonClickListener()
initMyFeedButtonClickListener()
initSettingButtonClickListener()
initMyFeedButtonClickListener()
initGoalPathButtonClickListener()
registerBackPressedCallback()
}
Expand All @@ -68,31 +80,18 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
setupGetUserState()
}

private fun initCheckNotificationPermission() {
isNotificationPermissionAllowed =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.POST_NOTIFICATIONS
) == PackageManager.PERMISSION_GRANTED
} else {
true
}
}

// 닉네임 액티비티 갔다가 다시 돌아왔을 때 유저 데이터 갱신하도록
override fun onStart() {
super.onStart()
mainViewModel.getUser()
initCheckNotificationPermission()
}

private fun initEditNicknameButtonClickListener() {
binding.ivMypageEditNickname.setOnSingleClickListener {
navigateToNicknameScreen()
}
}

private fun initSettingButtonClickListener() {
binding.ivMypageSetting.setOnClickListener {
navigateToSettingScreen()
}
}

private fun initMyFeedButtonClickListener() {
binding.btnMypageMyfeed.setOnSingleClickListener {
navigateToMyFeedScreen()
Expand All @@ -101,19 +100,7 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_

private fun initGoalPathButtonClickListener() {
binding.btnMypageTrip.setOnClickListener {
navigateToGoalPath()
}
}

private fun navigateToGoalPath() {
Intent(requireContext(), GoalPathActivity::class.java).apply {
startActivity(this)
}
}

private fun initSettingButtonClickListener() {
binding.ivMypageSetting.setOnClickListener {
navigateToSettingScreen()
navigateToGoalPathScreen()
}
}

Expand All @@ -136,26 +123,6 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
}

private fun initUserData() {
viewLifeCycleScope.launch {
val data = dataStoreRepository.getUserInfo().first()
if (data != null) {
updateUserInfo(data)
}
}
}

private fun initNavigation() {
val receivedBundle = arguments
if (receivedBundle != null) {
val value = receivedBundle.getBoolean(KEY_TO_MYFEED)
if (value) {
navigateToMyFeedScreen()
arguments?.clear()
}
}
}

private fun navigateToNicknameScreen() {
Intent(requireContext(), NicknameActivity::class.java).apply {
putExtra(KEY_PREV_SCREEN_NAME, MY_PAGE_SCREEN)
Expand All @@ -175,6 +142,12 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
}
}

private fun navigateToGoalPathScreen() {
Intent(requireContext(), GoalPathActivity::class.java).apply {
startActivity(this)
}
}

private fun setupGetUserState() {
mainViewModel.getUserState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
Expand All @@ -192,14 +165,9 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
}.launchIn(lifecycleScope)
}

private fun updateUserInfo(data: UserV2) {
binding.data = data
}

companion object {
private const val KEY_PREV_SCREEN_NAME = "PREV_SCREEN_NAME"
private const val MY_PAGE_SCREEN = "MyPageFragment"
private const val KEY_FROM_NOTI = "fromNoti"
private const val KEY_TO_MYFEED = "toMyFeed"
}
}

0 comments on commit 6579265

Please sign in to comment.