Last active
May 19, 2019 14:47
-
-
Save cesarferreira/380d2c960f6da4a34fdabf3e74d3c3e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FriendsFragment : BaseFragment() { | |
override fun layoutId(): Int = R.layout.fragment_friends | |
private lateinit var friendsViewModel: FriendsViewModel | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
appComponent.inject(this) | |
friendsViewModel = viewModel(viewModelFactory) { | |
observe(state, ::onFriendsStateChange) | |
} | |
} | |
private fun onFriendsStateChange(state: FriendsState?) { | |
when (val friendsState = state!!) { | |
is FriendsState.Loading -> showLoading() | |
is FriendsState.Empty -> showEmptyState() | |
is FriendsState.Success -> renderList(friendsState.users) | |
} | |
} | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
friendsViewModel.loadData() | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment