Skip to content

Commit

Permalink
Merge pull request #256 from team-winey/feature/feat-mypage-goal-path
Browse files Browse the repository at this point in the history
[feat] ๋ชฉํ‘œ์—ฌ์ • / ์„œ๋ฒ„ ์—ฐ๊ฒฐ
  • Loading branch information
leeeha authored Mar 2, 2024
2 parents b2630a5 + 631b635 commit f58802b
Show file tree
Hide file tree
Showing 29 changed files with 511 additions and 278 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ data class ResponsePostWineyFeedDto(
@SerialName("feedId")
val feedId: Int,
@SerialName("createdAt")
val createdAt: LocalDateTime
val createdAt: LocalDateTime,
@SerialName("levelUpgraded")
val levelUpgraded: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ import org.go.sopt.winey.util.view.snackbar.SnackbarType

@AndroidEntryPoint
class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main) {
private val mainViewModel by viewModels<MainViewModel>()
private val viewModel by viewModels<MainViewModel>()

private val isUploadSuccess by lazy { intent.extras?.getBoolean(KEY_FEED_UPLOAD, false) }
private val isDeleteSuccess by lazy { intent.extras?.getBoolean(KEY_FEED_DELETE, false) }
private val levelUpFromUpload by lazy { intent.getBooleanExtra(WineyFeedFragment.KEY_LEVEL_UP, false) }
private val isUploadSuccess by lazy { intent.getBooleanExtra(KEY_FEED_UPLOAD, false) }
private val isDeleteSuccess by lazy { intent.getBooleanExtra(KEY_FEED_DELETE, false) }

private val prevScreenName by lazy { intent.extras?.getString(KEY_PREV_SCREEN, "") }
private val notiType by lazy { intent.extras?.getString(KEY_NOTI_TYPE, "") }
private val feedId by lazy { intent.extras?.getString(KEY_FEED_ID) }
private val notiType by lazy { intent.getStringExtra(KEY_NOTI_TYPE) }
private val feedId by lazy { intent.getStringExtra(KEY_FEED_ID) }

private val notificationPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
Expand All @@ -59,12 +59,13 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main

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

requestNotificationPermission()

// ์œ„๋‹ˆํ”ผ๋“œ, ๋งˆ์ดํŽ˜์ด์ง€ ํ”„๋ž˜๊ทธ๋จผํŠธ์—์„œ getUserState ๊ด€์ฐฐ
mainViewModel.getUser()
mainViewModel.patchFcmToken()
viewModel.apply {
getUser() // ์œ„๋‹ˆํ”ผ๋“œ, ๋งˆ์ดํŽ˜์ด์ง€ ํ”„๋ž˜๊ทธ๋จผํŠธ์—์„œ ๊ด€์ฐฐ
patchFcmToken()
saveLevelUpState(levelUpFromUpload)
}

initNotiTypeHandler()
initFragment()
Expand Down Expand Up @@ -100,41 +101,43 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
NotificationType.RANK_UP_TO_2, NotificationType.RANK_UP_TO_3,
NotificationType.RANK_UP_TO_4, NotificationType.RANK_DOWN_TO_1,
NotificationType.RANK_DOWN_TO_2, NotificationType.RANK_DOWN_TO_3,
NotificationType.GOAL_FAILED -> navigateToMyPageWithBundle(
KEY_FROM_NOTI,
true
)
NotificationType.GOAL_FAILED -> {
navigateToMyPageFragment(KEY_FROM_NOTI, true)
}

NotificationType.LIKE_NOTIFICATION, NotificationType.COMMENT_NOTIFICATION
-> navigateToDetail(feedId?.toInt())
NotificationType.LIKE_NOTIFICATION, NotificationType.COMMENT_NOTIFICATION -> {
navigateToDetailScreen(feedId?.toInt())
}

NotificationType.HOW_TO_LEVEL_UP -> navigateToLevelupHelp()
NotificationType.HOW_TO_LEVEL_UP -> navigateToLevelUpGuideScreen()
else -> {}
}
}

private fun initFragment() {
if (intent.getBooleanExtra(KEY_FROM_GOAL_PATH, false)) {
navigateTo<MyPageFragment>()
return
}

if (intent.getBooleanExtra(KEY_TO_MYPAGE, false)) {
navigateToMyPageWithBundle(KEY_FROM_NOTI, true)
} else {
if (prevScreenName == VAL_MY_FEED_SCREEN) {
navigateToMyPageWithBundle(KEY_TO_MYFEED, true)
} else {
navigateTo<WineyFeedFragment>()
}
navigateToMyPageFragment(KEY_FROM_NOTI, true)
return
}

navigateTo<WineyFeedFragment>()
}

private fun showWineyFeedResultSnackBar() {
if (isUploadSuccess == true) {
if (isUploadSuccess) {
wineySnackbar(
anchorView = binding.root,
message = stringOf(R.string.snackbar_upload_success),
type = SnackbarType.WineyFeedResult(isSuccess = true)
)
}

if (isDeleteSuccess == true) {
if (isDeleteSuccess) {
wineySnackbar(
anchorView = binding.root,
message = stringOf(R.string.snackbar_feed_delete_success),
Expand Down Expand Up @@ -170,7 +173,7 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
}

private fun setupLogoutState() {
mainViewModel.logoutState.flowWithLifecycle(lifecycle).onEach { state ->
viewModel.logoutState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
is UiState.Loading -> {
}
Expand All @@ -197,13 +200,7 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
}
}

private inline fun <reified T : Fragment> navigateTo() {
supportFragmentManager.commit {
replace<T>(R.id.fcv_main, T::class.simpleName)
}
}

private fun navigateToMyPageWithBundle(key: String, value: Boolean) {
private fun navigateToMyPageFragment(key: String, value: Boolean) {
supportFragmentManager.commit {
val bundle = Bundle()
bundle.putBoolean(key, value)
Expand All @@ -214,28 +211,32 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
}
}

private fun navigateToDetail(feedId: Int?) {
private fun navigateToDetailScreen(feedId: Int?) {
val intent = Intent(this, DetailActivity::class.java)
intent.putExtra(KEY_FEED_ID, feedId)
startActivity(intent)
}

private fun navigateToLevelupHelp() {
// todo: ๋ ˆ๋ฒจ์—… ๊ฐ€์ด๋“œ ํ™”๋ฉด ๋ฐ”๊ฟ”์•ผ ํ• ํ…๋ฐ!
private fun navigateToLevelUpGuideScreen() {
val intent = Intent(this, MypageHelpActivity::class.java)
startActivity(intent)
}

private inline fun <reified T : Fragment> navigateTo() {
supportFragmentManager.commit {
replace<T>(R.id.fcv_main, T::class.simpleName)
}
}

companion object {
private const val KEY_FEED_UPLOAD = "upload"
private const val KEY_FEED_DELETE = "delete"

private const val KEY_FEED_ID = "feedId"
private const val KEY_NOTI_TYPE = "notiType"
private const val KEY_PREV_SCREEN = "PREV_SCREEN_NAME"
private const val KEY_FROM_NOTI = "fromNoti"
private const val KEY_TO_MYFEED = "toMyFeed"
private const val KEY_TO_MYPAGE = "navigateMypage"

private const val VAL_MY_FEED_SCREEN = "MyFeedFragment"
const val KEY_FEED_ID = "feedId"
const val KEY_TO_MYPAGE = "navigateMypage"
const val KEY_FROM_GOAL_PATH = "fromGoalPath"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class MainViewModel @Inject constructor(
private val _notiState = MutableStateFlow(true)
val notiState: LiveData<Boolean> = _notiState.asLiveData()

private val _levelUpState = MutableStateFlow(false)
val levelUpState: StateFlow<Boolean> = _levelUpState.asStateFlow()

fun getUser() {
viewModelScope.launch {
_getUserState.value = UiState.Loading
Expand Down Expand Up @@ -131,6 +134,10 @@ class MainViewModel @Inject constructor(
}
}

fun saveLevelUpState(currentState: Boolean) {
_levelUpState.value = currentState
}

companion object {
private const val CODE_TOKEN_EXPIRED = 401
private const val CODE_INVALID_USER = 404
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import android.os.Bundle
import android.view.View
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.commit
import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.paging.LoadState
import androidx.paging.PagingData
import androidx.recyclerview.widget.ConcatAdapter
import androidx.recyclerview.widget.SimpleItemAnimator
import com.google.android.material.bottomnavigation.BottomNavigationView
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.launchIn
Expand All @@ -28,7 +26,7 @@ import org.go.sopt.winey.domain.repository.DataStoreRepository
import org.go.sopt.winey.presentation.main.MainViewModel
import org.go.sopt.winey.presentation.main.feed.detail.DetailActivity
import org.go.sopt.winey.presentation.main.feed.upload.UploadActivity
import org.go.sopt.winey.presentation.main.mypage.MyPageFragment
import org.go.sopt.winey.presentation.main.mypage.goal.GoalPathActivity
import org.go.sopt.winey.presentation.main.notification.NotificationActivity
import org.go.sopt.winey.presentation.model.WineyDialogLabel
import org.go.sopt.winey.util.activity.showReportGoogleForm
Expand Down Expand Up @@ -103,6 +101,7 @@ class WineyFeedFragment :
initGetDetailFeedStateObserver()
initPostLikeStateObserver()
initDeleteFeedStateObserver()
initLevelUpStateObserver()
}

/** Adapter */
Expand Down Expand Up @@ -416,6 +415,30 @@ class WineyFeedFragment :
}
}

private fun initLevelUpStateObserver() {
mainViewModel.levelUpState.flowWithLifecycle(viewLifeCycle)
.onEach { nowLevelUp ->
if (nowLevelUp) {
showCongratulationDialog()
}
}.launchIn(viewLifeCycleScope)
}

private fun showCongratulationDialog() {
val dialog = WineyDialogFragment.newInstance(
wineyDialogLabel = WineyDialogLabel(
title = stringOf(R.string.wineyfeed_congratulation_dialog_title),
subTitle = stringOf(R.string.wineyfeed_congratulation_dialog_subtitle),
positiveButtonLabel = stringOf(R.string.wineyfeed_congratulation_dialog_positive_button)
),
handleNegativeButton = {},
handlePositiveButton = {
navigateToGoalPath()
}
)
activity?.supportFragmentManager?.let { dialog.show(it, TAG_CONGRATULATION_DIALOG) }
}

/** Navigation */
private fun navigateToUpload(feedType: WineyFeedType) {
Intent(requireContext(), UploadActivity::class.java).apply {
Expand All @@ -428,7 +451,14 @@ class WineyFeedFragment :
Intent(requireContext(), DetailActivity::class.java).apply {
putExtra(KEY_FEED_ID, wineyFeed.feedId)
putExtra(KEY_FEED_WRITER_ID, wineyFeed.userId)
putExtra(KEY_PREV_SCREEN_NAME, VAL_WINEY_FEED_SCREEN)
putExtra(KEY_PREV_SCREEN_NAME, WINEY_FEED_SCREEN)
startActivity(this)
}
}

private fun navigateToGoalPath() {
Intent(requireContext(), GoalPathActivity::class.java).apply {
putExtra(KEY_LEVEL_UP, true)
startActivity(this)
}
}
Expand All @@ -442,23 +472,6 @@ class WineyFeedFragment :
}

/** Amplitude Event Tagging */
private fun sendDialogClickEvent(isNavigate: Boolean) {
val eventProperties = JSONObject()

try {
if (isNavigate) {
eventProperties.put("method", "yes")
} else {
eventProperties.put("method", "no")
}
} catch (e: JSONException) {
System.err.println("Invalid JSON")
e.printStackTrace()
}

amplitudeUtils.logEvent("click_goalsetting", eventProperties)
}

private fun sendWineyFeedEvent(type: EventType, feed: WineyFeed) {
val eventProperties = JSONObject()

Expand Down Expand Up @@ -488,78 +501,22 @@ class WineyFeedFragment :
}
}

private fun showDefaultGoalSettingDialog() {
amplitudeUtils.logEvent("view_goalsetting_popup")

val dialog = WineyDialogFragment.newInstance(
WineyDialogLabel(
stringOf(R.string.wineyfeed_goal_dialog_title),
stringOf(R.string.wineyfeed_goal_dialog_subtitle),
stringOf(R.string.wineyfeed_goal_dialog_negative_button),
stringOf(R.string.wineyfeed_goal_dialog_positive_button)
),
handleNegativeButton = {
sendDialogClickEvent(false)
},
handlePositiveButton = {
sendDialogClickEvent(true)
navigateToMyPageWithBundle()
}
)

activity?.supportFragmentManager?.let { dialog.show(it, TAG_DEFAULT_GOAL_SETTING_DIALOG) }
}

private fun showCongratulationDialog() {
amplitudeUtils.logEvent("view_goalsetting_popup")

val dialog = WineyDialogFragment.newInstance(
WineyDialogLabel(
stringOf(R.string.wineyfeed_congratulation_dialog_title),
stringOf(R.string.wineyfeed_congratulation_dialog_subtitle),
stringOf(R.string.wineyfeed_goal_dialog_negative_button),
stringOf(R.string.wineyfeed_goal_dialog_positive_button)
),
handleNegativeButton = {
sendDialogClickEvent(false)
},
handlePositiveButton = {
sendDialogClickEvent(true)
navigateToMyPageWithBundle()
}
)

activity?.supportFragmentManager?.let { dialog.show(it, TAG_CONGRATULATION_DIALOG) }
}

private fun navigateToMyPageWithBundle() {
activity?.supportFragmentManager?.commit {
replace(R.id.fcv_main, MyPageFragment())
}
syncBnvSelectedItem()
}

private fun syncBnvSelectedItem() {
val bottomNav: BottomNavigationView = requireActivity().findViewById(R.id.bnv_main)
bottomNav.selectedItemId = R.id.menu_mypage
}

companion object {
private const val INSTAGRAM_URL =
"https://instagram.com/winey__official?igshid=MzRlODBiNWFlZA=="
private const val MSG_WINEYFEED_ERROR = "ERROR"
private const val TAG_DEFAULT_GOAL_SETTING_DIALOG = "DEFAULT_GOAL_SETTING_DIALOG"
private const val TAG_CONGRATULATION_DIALOG = "CONGRATULATION_DIALOG"

private const val TAG_FEED_DELETE_DIALOG = "FEED_DELETE_DIALOG"
private const val TAG_FEED_REPORT_DIALOG = "FEED_REPORT_DIALOG"
private const val TAG_UPLOAD_DIALOG = "UPLOAD_DIALOG"
private const val TAG_CONGRATULATION_DIALOG = "CONGRATULATION_DIALOG"

private const val KEY_PREV_SCREEN_NAME = "PREV_SCREEN_NAME"
private const val WINEY_FEED_SCREEN = "WineyFeedFragment"
private const val KEY_FEED_ID = "feedId"
private const val KEY_FEED_WRITER_ID = "feedWriterId"
const val KEY_FEED_TYPE = "feedType"

private const val KEY_PREV_SCREEN_NAME = "PREV_SCREEN_NAME"
private const val VAL_WINEY_FEED_SCREEN = "WineyFeedFragment"

private const val INSTAGRAM_URL =
"https://instagram.com/winey__official?igshid=MzRlODBiNWFlZA=="
const val KEY_FEED_TYPE = "feedType"
const val KEY_LEVEL_UP = "LEVEL_UP_MOMENT"
}
}
Loading

0 comments on commit f58802b

Please sign in to comment.