Skip to content

Instantly share code, notes, and snippets.

@catalinghita8
Last active August 14, 2018 16:18
Show Gist options
  • Save catalinghita8/f9e3bf8d881d8ab4da93516963dfe9d5 to your computer and use it in GitHub Desktop.
Save catalinghita8/f9e3bf8d881d8ab4da93516963dfe9d5 to your computer and use it in GitHub Desktop.
@ActivityScoped
public class MessageFragment extends DaggerFragment implements BaseView {
private TextView mMessageTextView;
private MessageViewModel mViewModel;
@Inject
ViewModelProvider.Factory viewModelFactory;
@Inject
public MessageFragment() {
// Required empty public constructor
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// get ViewModel
mViewModel = ViewModelProviders.of(this, viewModelFactory).get(MessageViewModel.class);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View root = inflater.inflate(R.layout.fragment_message, container, false);
mMessageTextView = root.findViewById(R.id.message_tv);
return root;
}
@Override
public void bindViewModel() {
updateView(mViewModel.getUiModel());
}
private void updateView(MessageUiModel uiModel) {
mMessageTextView.setText(uiModel.getMessageText());
}
@Override
public void onResume() {
super.onResume();
bindViewModel();
}
@Override
public void onPause() {
super.onPause();
unbindViewModel();
}
@Override
public void unbindViewModel() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment