Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 마이페이지 / 설정 #252

Merged
merged 11 commits into from
Mar 1, 2024
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
android:name=".presentation.main.notification.NotificationActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".presentation.main.mypage.setting.SettingActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".presentation.main.mypage.goal.GoalPathActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class MainViewModel @Inject constructor(
}
}

private fun postLogout() {
fun postLogout() {
viewModelScope.launch {
_logoutState.value = UiState.Loading

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package org.go.sopt.winey.presentation.main.mypage

import android.Manifest
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.core.content.ContextCompat
Expand All @@ -29,13 +26,13 @@ import org.go.sopt.winey.domain.entity.UserV2
import org.go.sopt.winey.domain.repository.DataStoreRepository
import org.go.sopt.winey.presentation.main.MainViewModel
import org.go.sopt.winey.presentation.main.mypage.myfeed.MyFeedActivity
import org.go.sopt.winey.presentation.main.mypage.setting.SettingActivity
import org.go.sopt.winey.presentation.main.notification.NotificationActivity
import org.go.sopt.winey.presentation.nickname.NicknameActivity
import org.go.sopt.winey.presentation.onboarding.guide.GuideActivity
import org.go.sopt.winey.util.amplitude.AmplitudeUtils
import org.go.sopt.winey.util.binding.BindingFragment
import org.go.sopt.winey.util.fragment.snackBar
import org.go.sopt.winey.util.fragment.viewLifeCycle
import org.go.sopt.winey.util.fragment.viewLifeCycleScope
import org.go.sopt.winey.util.view.UiState
import org.go.sopt.winey.util.view.setOnSingleClickListener
Expand Down Expand Up @@ -70,12 +67,14 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
private fun addListener() {
initEditNicknameButtonClickListener()
initMyFeedButtonClickListener()
initSettingButtonClickListener()
registerBackPressedCallback()
}

private fun addObserver() {
setupGetUserState()
setupDeleteUserState()

checkFromWineyFeed()
}

private fun initCheckNotificationPermission() {
Expand All @@ -90,44 +89,6 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
}
}

private fun navigateToNotificationSetting(context: Context) {
val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setNotificationIntentActionOreo(context)
} else {
setNorificationIntentActionOreoLess(context)
}
try {
context.startActivity(intent)
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
}
}

private fun setNotificationIntentActionOreo(context: Context): Intent {
return Intent().also { intent ->
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
}

private fun setNorificationIntentActionOreoLess(context: Context): Intent {
return Intent().also { intent ->
intent.action = "android.settings.APP_NOTIFICATION_SETTINGS"
intent.putExtra("app_package", context.packageName)
intent.putExtra("app_uid", context.applicationInfo?.uid)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
}

private fun patchUserInfo() {
lifecycleScope.launch {
val data = dataStoreRepository.getUserInfo().first()
val newData = data?.copy(fcmIsAllowed = false)
dataStoreRepository.saveUserInfo(newData)
}
}

// 닉네임 액티비티 갔다가 다시 돌아왔을 때 유저 데이터 갱신하도록
override fun onStart() {
super.onStart()
Expand All @@ -154,6 +115,12 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
}
}

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

// 마이페이지 왔다가 다시 알림 화면으로 돌아가도록
private fun registerBackPressedCallback() {
val callback = object : OnBackPressedCallback(true) {
Expand Down Expand Up @@ -193,25 +160,6 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
}
}

private fun setupDeleteUserState() {
myPageViewModel.deleteUserState.flowWithLifecycle(viewLifeCycle)
.onEach { state ->
when (state) {
is UiState.Success -> {
myPageViewModel.clearDataStore()
navigateToGuideScreen()
}

is UiState.Failure -> {
snackBar(binding.root) { state.msg }
}

else -> {
}
}
}.launchIn(viewLifeCycleScope)
}

private fun navigateToGuideScreen() {
Intent(requireContext(), GuideActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
Expand All @@ -226,6 +174,12 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
}
}

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

private fun navigateToMyFeedScreen() {
Intent(requireContext(), MyFeedActivity::class.java).apply {
startActivity(this)
Expand Down Expand Up @@ -259,11 +213,6 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
amplitudeUtils.logEvent("view_goalsetting")
}

private fun showTargetNotOverDialog() {
val dialog = MyPageNotOverDialogFragment()
dialog.show(parentFragmentManager, dialog.tag)
}

private inline fun <reified T : Fragment> navigateAndBackStack() {
parentFragmentManager.commit {
replace<T>(R.id.fcv_main, T::class.simpleName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class MyPageViewModel @Inject constructor(
private val _deleteUserState = MutableStateFlow<UiState<Unit>>(UiState.Empty)
val deleteUserState: StateFlow<UiState<Unit>> = _deleteUserState.asStateFlow()

private val _patchAllowedNotificationState = MutableStateFlow<UiState<Boolean?>>(UiState.Empty)
val patchAllowedNotificationState: StateFlow<UiState<Boolean?>> = _patchAllowedNotificationState.asStateFlow()

fun deleteUser() {
viewModelScope.launch {
authRepository.deleteUser()
Expand All @@ -44,30 +41,4 @@ class MyPageViewModel @Inject constructor(
}
}
}

fun patchAllowedNotification(isAllowed: Boolean) {
viewModelScope.launch {
authRepository.patchAllowedNotification(!isAllowed)
.onSuccess { response ->
Timber.d("SUCCESS PATCH ALLOWED NOTI")
_patchAllowedNotificationState.value = UiState.Success(response)
}
.onFailure { t ->
_patchAllowedNotificationState.value = UiState.Failure(t.message.toString())

if (t is HttpException) {
Timber.e("HTTP FAIL ALLOWED NOTI : ${t.code()} ${t.message}")
return@onFailure
}

Timber.e("FAIL ALLOWED NOTI : ${t.message}")
}
}
}

fun clearDataStore() {
viewModelScope.launch {
dataStoreRepository.clearDataStore()
}
}
}
Loading
Loading