-
Notifications
You must be signed in to change notification settings - Fork 0
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
[mod] 마이 피드 / 상세페이지에서 삭제시 화면 처리 #185
Changes from 12 commits
7ee2abd
6a68dc5
d7fa9a9
3f3a490
2ec4219
0ed3977
5a725d5
8f82975
012e269
8080f6e
113ad14
208cc7b
aaab924
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ class MainActivity : BindingActivity<ActivityMainBinding>(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<ActivityMainBinding>(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<WineyFeedFragment>() | ||
if (prevScreenName == MY_FEED_SCREEN) { | ||
navigateToMyPageWithBundle(KEY_TO_MYFEED, true) | ||
} else { | ||
navigateTo<WineyFeedFragment>() | ||
} | ||
} | ||
} | ||
|
||
|
@@ -131,9 +129,27 @@ class MainActivity : BindingActivity<ActivityMainBinding>(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 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fragment-ktx 를 이용하면 코드를 조금 더 단순화 할 수 있을 거 같아요!
fragmentManager().commit {
addToBackStack("...")
setCustomAnimations(
R.anim.enter_anim,
R.anim.exit_anim)
add(fragment, "...")
} /**
* Run [body] in a [FragmentTransaction] which is automatically committed if it completes without
* exception.
*
* The transaction will be completed by calling [FragmentTransaction.commit] unless [allowStateLoss]
* is set to `true` in which case [FragmentTransaction.commitAllowingStateLoss] will be used.
*/
public inline fun FragmentManager.commit(
allowStateLoss: Boolean = false,
body: FragmentTransaction.() -> Unit
) {
val transaction = beginTransaction()
transaction.body()
if (allowStateLoss) {
transaction.commitAllowingStateLoss()
} else {
transaction.commit()
}
} commit 확장 함수 안에서 body 라는 람다식을 사용하기 때문에 코드의 가독성이 좀 더 올라가는 거 같습니다! :) |
||
} | ||
|
||
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" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(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<FragmentMyPageBinding>(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<FragmentMyPageBinding>(R.layout.fragment_ | |
} | ||
} | ||
|
||
private fun initNavigation() { | ||
val receivedBundle = arguments | ||
if (receivedBundle != null) { | ||
val value = receivedBundle.getBoolean(KEY_TO_MYFEED) | ||
if (value) { | ||
navigateAndBackStack<MyFeedFragment>() | ||
arguments = null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
} | ||
|
||
private fun init1On1ButtonClickListener() { | ||
binding.clMypageTo1on1.setOnClickListener { | ||
val url = ONE_ON_ONE_URL | ||
|
@@ -282,5 +293,8 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(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" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
번들의 key 값도 상수화 시켜주면 더 좋을 거 같아요 😊