diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/MainActivity.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/MainActivity.kt index 5b308aaa..cf64e383 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/MainActivity.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/MainActivity.kt @@ -29,6 +29,7 @@ class MainActivity : BindingActivity(R.layout.activity_main private val isUploadSuccess by lazy { intent.extras?.getBoolean(EXTRA_UPLOAD_KEY, false) } private val isDeleteSuccess by lazy { intent.extras?.getBoolean(EXTRA_DELETE_KEY, false) } private val isReportSuccess by lazy { intent.extras?.getBoolean(EXTRA_REPORT_KEY, false) } + private val prevScreenName by lazy { intent.extras?.getString(KEY_PREV_SCREEN, "") } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -45,17 +46,14 @@ class MainActivity : BindingActivity(R.layout.activity_main } private fun initFragment() { - if (intent.getBooleanExtra("navigateMypage", false)) { - val bundle = Bundle() - bundle.putString("fromNoti", "true") - val myPageFragment = MyPageFragment() - myPageFragment.arguments = bundle - val transaction = supportFragmentManager.beginTransaction() - transaction.replace(R.id.fcv_main, myPageFragment) - transaction.commit() - binding.bnvMain.selectedItemId = R.id.menu_mypage + if (intent.getBooleanExtra(KEY_TO_MYPAGE, false)) { + navigateToMyPageWithBundle(KEY_FROM_NOTI, true) } else { - navigateTo() + if (prevScreenName == MY_FEED_SCREEN) { + navigateToMyPageWithBundle(KEY_TO_MYFEED, true) + } else { + navigateTo() + } } } @@ -131,9 +129,27 @@ class MainActivity : BindingActivity(R.layout.activity_main } } + private fun navigateToMyPageWithBundle(key: String, value: Boolean) { + supportFragmentManager.commit { + val bundle = Bundle() + bundle.putBoolean(key, value) + val myPageFragment = MyPageFragment() + myPageFragment.arguments = bundle + replace(R.id.fcv_main, myPageFragment) + binding.bnvMain.selectedItemId = R.id.menu_mypage + } + } + companion object { private const val EXTRA_UPLOAD_KEY = "upload" private const val EXTRA_DELETE_KEY = "delete" private const val EXTRA_REPORT_KEY = "report" + + 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 MY_FEED_SCREEN = "MyFeedFragment" } } diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt index c5d490fd..f54000cb 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt @@ -400,6 +400,7 @@ class WineyFeedFragment : val intent = Intent(requireContext(), DetailActivity::class.java) intent.putExtra(KEY_FEED_ID, wineyFeed.feedId) intent.putExtra(KEY_FEED_WRITER_ID, wineyFeed.userId) + intent.putExtra(KEY_PREV_SCREEN, WINEY_FEED_SCREEN) startActivity(intent) } @@ -442,5 +443,7 @@ class WineyFeedFragment : private const val KEY_FEED_ID = "feedId" private const val KEY_FEED_WRITER_ID = "feedWriterId" + private const val KEY_PREV_SCREEN = "PREV_SCREEN_NAME" + private const val WINEY_FEED_SCREEN = "WineyFeedFragment" } } diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/detail/DetailActivity.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/detail/DetailActivity.kt index 042a4c80..7256942f 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/detail/DetailActivity.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/detail/DetailActivity.kt @@ -43,6 +43,7 @@ class DetailActivity : BindingActivity(R.layout.activity_ private val feedId by lazy { intent.getIntExtra(KEY_FEED_ID, 0) } private val feedWriterId by lazy { intent.getIntExtra(KEY_FEED_WRITER_ID, 0) } + private val prevScreenName by lazy { intent.extras?.getString(KEY_PREV_SCREEN, "") } private var _detailFeedAdapter: DetailFeedAdapter? = null private val detailFeedAdapter get() = requireNotNull(_detailFeedAdapter) @@ -416,6 +417,7 @@ class DetailActivity : BindingActivity(R.layout.activity_ Intent(this, MainActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) putExtra(extraKey, true) + putExtra(KEY_PREV_SCREEN, prevScreenName) startActivity(this) } } @@ -454,9 +456,12 @@ class DetailActivity : BindingActivity(R.layout.activity_ companion object { private const val KEY_FEED_ID = "feedId" private const val KEY_FEED_WRITER_ID = "feedWriterId" + private const val KEY_PREV_SCREEN = "PREV_SCREEN_NAME" + private const val TAG_FEED_DELETE_DIALOG = "FEED_DELETE_DIALOG" private const val TAG_COMMENT_DELETE_DIALOG = "COMMENT_DELETE_DIALOG" private const val TAG_REPORT_DIALOG = "REPORT_DIALOG" + private const val POPUP_MENU_POS_OFFSET = 65 private const val MSG_DETAIL_ERROR = "ERROR" private const val EXTRA_DELETE_KEY = "delete" diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/MyPageFragment.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/MyPageFragment.kt index 09559145..8347b4ec 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/MyPageFragment.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/MyPageFragment.kt @@ -50,7 +50,7 @@ class MyPageFragment : BindingFragment(R.layout.fragment_ override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) amplitudeUtils.logEvent("view_mypage") - + initNavigation() init1On1ButtonClickListener() initTermsButtonClickListener() initLevelHelpButtonClickListener() @@ -67,8 +67,8 @@ class MyPageFragment : BindingFragment(R.layout.fragment_ override fun handleOnBackPressed() { val receivedBundle = arguments if (receivedBundle != null) { - val value = receivedBundle.getString("fromNoti") - if (value == "true") { + val value = receivedBundle.getBoolean(KEY_FROM_NOTI) + if (value) { val intent = Intent(requireContext(), NotificationActivity::class.java) startActivity(intent) requireActivity().finish() @@ -98,6 +98,17 @@ class MyPageFragment : BindingFragment(R.layout.fragment_ } } + private fun initNavigation() { + val receivedBundle = arguments + if (receivedBundle != null) { + val value = receivedBundle.getBoolean(KEY_TO_MYFEED) + if (value) { + navigateAndBackStack() + arguments?.clear() + } + } + } + private fun init1On1ButtonClickListener() { binding.clMypageTo1on1.setOnClickListener { val url = ONE_ON_ONE_URL @@ -282,5 +293,8 @@ class MyPageFragment : BindingFragment(R.layout.fragment_ private const val EXTRA_VALUE = "MyPageFragment" private const val TAG_LOGOUT_DIALOG = "LOGOUT_DIALOG" private const val TAGE_WITHDRAW_DIALOG = "WITHDRAW_DIALOG" + + private const val KEY_FROM_NOTI = "fromNoti" + private const val KEY_TO_MYFEED = "toMyFeed" } } diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedFragment.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedFragment.kt index 8d2dd317..e75716be 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedFragment.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedFragment.kt @@ -140,7 +140,11 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ viewModel.deleteMyFeedState.flowWithLifecycle(viewLifeCycle).onEach { state -> when (state) { is UiState.Success -> { - wineySnackbar(binding.root, true, stringOf(R.string.snackbar_feed_delete_success)) + wineySnackbar( + binding.root, + true, + stringOf(R.string.snackbar_feed_delete_success) + ) viewModel.initDeleteFeedState() } @@ -183,7 +187,8 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ is LoadState.NotLoading -> { binding.rvMyfeedPost.isVisible = myFeedAdapter.itemCount > 0 - binding.clMyfeedEmpty.isVisible = myFeedAdapter.itemCount == 0 + binding.clMyfeedEmpty.isVisible = + myFeedAdapter.itemCount == 0 restoreScrollPosition() } @@ -232,6 +237,7 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ val intent = Intent(requireContext(), DetailActivity::class.java) intent.putExtra(KEY_FEED_ID, wineyFeed.feedId) intent.putExtra(KEY_FEED_WRITER_ID, wineyFeed.userId) + intent.putExtra(KEY_PREV_SCREEN, MY_FEED_SCREEN) startActivity(intent) } @@ -246,8 +252,12 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ companion object { private const val KEY_FEED_ID = "feedId" private const val KEY_FEED_WRITER_ID = "feedWriterId" + private const val KEY_PREV_SCREEN = "PREV_SCREEN_NAME" + private const val POPUP_MENU_OFFSET = 65 private const val MSG_MYFEED_ERROR = "ERROR" private const val TAG_FEED_DELETE_DIALOG = "DELETE_DIALOG" + + private const val MY_FEED_SCREEN = "MyFeedFragment" } }