-
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 6 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) | ||
|
@@ -46,16 +47,13 @@ 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 | ||
navigateToMyPageWithBundle("fromNoti", "true") | ||
} else { | ||
navigateTo<WineyFeedFragment>() | ||
if (prevScreenName == MY_FEED_SCREEN) { | ||
navigateToMyPageWithBundle("toMyFeed", "true") | ||
} else { | ||
navigateTo<WineyFeedFragment>() | ||
} | ||
} | ||
} | ||
|
||
|
@@ -131,9 +129,26 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main | |
} | ||
} | ||
|
||
private fun navigateToMyPageWithBundle(key: String, value: String) { | ||
supportFragmentManager.commit { | ||
val bundle = Bundle() | ||
bundle.putString(key, value) | ||
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. true, false는 문자열 대신 Boolean 타입을 사용하는 게 어떨까요?? ex) putBoolean 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. 상욱오빠 코드가 저렇게되어있길래 반복되는 코드 함수화하고 싶어서 맞춰서 저렇게 했는데 동의하면 같이 바꿔둬도 될까요 ? @Sangwook123 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. 넵 !! Boolean이 더 좋겠습니다 👍👍 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. 넵 그럼 알림쪽도 같이 바꿔둘게요 ~ |
||
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 | ||
} | ||
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 MY_FEED_SCREEN = "MyFeedFragment" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ class DetailActivity : BindingActivity<ActivityDetailBinding>(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<ActivityDetailBinding>(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,15 @@ class DetailActivity : BindingActivity<ActivityDetailBinding>(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 MY_FEED_SCREEN = "MyFeedFragment" | ||
private const val WINEY_FEED_SCREEN = "WineyFeedFragment" | ||
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 const val POPUP_MENU_POS_OFFSET = 65 | ||
private const val MSG_DETAIL_ERROR = "ERROR" | ||
private const val EXTRA_DELETE_KEY = "delete" | ||
|
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 값도 상수화 시켜주면 더 좋을 거 같아요 😊