Last active
August 14, 2018 16:18
-
-
Save catalinghita8/f9e3bf8d881d8ab4da93516963dfe9d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@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