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

[mod] 마이 피드 / 상세페이지에서 삭제시 화면 처리 #185

Merged
merged 13 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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>()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

번들의 key 값도 상수화 시켜주면 더 좋을 거 같아요 😊

}
}

Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, false는 문자열 대신 Boolean 타입을 사용하는 게 어떨까요?? ex) putBoolean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상욱오빠 코드가 저렇게되어있길래 반복되는 코드 함수화하고 싶어서 맞춰서 저렇게 했는데 동의하면 같이 바꿔둬도 될까요 ? @Sangwook123

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 !! Boolean이 더 좋겠습니다 👍👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fragment-ktx 를 이용하면 코드를 조금 더 단순화 할 수 있을 거 같아요!

The Fragment KTX module provides a number of extensions to simplify the fragment API.
With the Fragment KTX module, you can simplify fragment transactions with lambdas, for example:

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
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The 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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -98,6 +98,15 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
}
}

private fun initNavigation() {
val receivedBundle = arguments
if (receivedBundle != null) {
val value = receivedBundle.getString("toMyFeed")
if (value == "true") {
navigateAndBackStack<MyFeedFragment>()
}
}
}
private fun init1On1ButtonClickListener() {
binding.clMypageTo1on1.setOnClickListener {
val url = ONE_ON_ONE_URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ class MyFeedFragment : BindingFragment<FragmentMyfeedBinding>(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()
}

Expand Down Expand Up @@ -183,7 +187,8 @@ class MyFeedFragment : BindingFragment<FragmentMyfeedBinding>(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()
}

Expand Down Expand Up @@ -232,6 +237,7 @@ class MyFeedFragment : BindingFragment<FragmentMyfeedBinding>(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)
}

Expand All @@ -246,8 +252,12 @@ class MyFeedFragment : BindingFragment<FragmentMyfeedBinding>(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"
}
}