스팀 앱 - 개발 중: 사용자 히스토리 항목 클릭 (5) 내용 정리: 프로필/포스트/지갑 화면에 파라메터 정의
스팀 앱 - 개발 중: 사용자 히스토리 항목 클릭 (5) 내용 정리: 프로필/포스트/지갑 화면에 파라메터 정의
2024. 08. 22 (목) | Written by @dorian-mobileapp
지난 포스트에서 프래그먼트 간 내비게이션에 대해 설명했습니다. 사용자 히스토리 화면에서 프로필(ProfileFragment), 포스트(PostContentFragment), 지갑(WalletFragment) 화면으로 이동할 때 전달할 파라메터를 정의했지요. 오늘은 이 파라메터들을 코드로 어떻게 정의하고 사용하는지 보여 드립니다.
ProfileFragment 클래스에 파라메터 추가, 적용
class ProfileFragment : BaseFragment<FragmentProfileBinding, ProfileViewModel>(R.layout.fragment_profile) {
// 정의한 파라메터
private val args: ProfileFragmentArgs by navArgs()
// ...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// ...
// 파라메터가 유효하고 프로필이 빈 상태이면, 프로필을 로딩
if (args.account.isNotEmpty() and (viewModel.profileState.value is State.Empty)) {
viewLifecycleOwner.lifecycleScope.launch {
viewModel.readSteemitProfile(args.account)
}
}
}
// ...
}
PostContentFragment 클래스에 파라메터 추가, 적용
class PostContentFragment : BaseFragment<FragmentPostBinding, PostContentViewModel>(R.layout.fragment_post) {
// 정의한 파라메터
val args: PostContentFragmentArgs by navArgs()
// ...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// 파라메터로부터 계정, 링크를 읽고, 포스트를 로딩
val author = args.author
val permlink = args.permlink
viewModel.initState(author, permlink)
}
// ...
}
WalletFragment 클래스에 파라메터 추가, 적용
class WalletFragment : BaseFragment<FragmentWalletBinding, WalletViewModel>(R.layout.fragment_wallet) {
private val args: WalletFragmentArgs by navArgs()
// ...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// ...
// 파라메터가 유효하고 지갑이 빈 상태이면, 지갑을 로딩
if (args.account.isNotEmpty() and (viewModel.flowWalletState.value is State.Empty)) {
viewLifecycleOwner.lifecycleScope.launch {
viewModel.readSteemitWallet(args.account)
}
}
}
// ...
}
마치며...
내용 정리를 하면서 제가 무엇을 했는지가 눈에 명확히 들어오네요. 코드를 복기하며 복습을 하는 것이 좋은 것 같습니다. 남은 정리도 마저 하며 실력 향상을 도모하겠습니다.
Layout provided by Steemit Enhancer hommage by ayogom
Posted through the ECblog app (https://blog.etain.club)
안녕하세요.
SteemitKorea팀에서 제공하는 'steemit-enhancer'를 사용해 주셔서 감사합니다. 개선 사항이 있으면 언제나 저에게 연락을 주시면 되고, 관심이 있으신 분들은 https://cafe.naver.com/steemitkorea/425 에서 받아보실 수 있습니다. 사용시 @응원해 가 포함이 되며, 악용시에는 모든 서비스에서 제외될 수 있음을 알려드립니다.
[광고] STEEM 개발자 커뮤니티에 참여 하시면, 다양한 혜택을 받을 수 있습니다.
안녕하세요.
이 글은 SteemitKorea팀(@ayogom)님께서 저자이신 @dorian-mobileapp님을 응원하는 글입니다.
소정의 보팅을 해드렸습니다 ^^ 항상 좋은글 부탁드립니다
SteemitKorea팀에서는 보다 즐거운 steemit 생활을 위해 노력하고 있습니다.
이 글은 다음날 다시 한번 포스팅을 통해 소개 될 예정입니다. 감사합니다!
Thank you, friend!


I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
please click it!
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)
The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.
Upvoted! Thank you for supporting witness @jswit.