Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. /**
  2. * Date: 15.11.2016
  3. * Time: 9:41
  4. *
  5. * @author Savin Mikhail
  6. * @author Alexey Korshun
  7. */
  8. public abstract class MvpViewHolder extends RecyclerView.ViewHolder {
  9.  
  10. private MvpDelegate mMvpDelegate;
  11.  
  12. private final MvpDelegate mParentDelegate;
  13.  
  14. public MvpViewHolder(MvpDelegate<?> parentDelegate, final View itemView) {
  15. super(itemView);
  16. mParentDelegate = parentDelegate;
  17. }
  18.  
  19. @Nullable
  20. protected MvpDelegate getMvpDelegate() {
  21. if (mMvpDelegate == null && getMvpChildId() != null) {
  22. mMvpDelegate = new MvpDelegate<>(this);
  23. mMvpDelegate.setParentDelegate(mParentDelegate, getMvpChildId());
  24. }
  25. return mMvpDelegate;
  26. }
  27.  
  28. protected void destroyMvpDelegate() {
  29. if (getMvpDelegate() != null) {
  30. getMvpDelegate().onSaveInstanceState();
  31. getMvpDelegate().onDetach();
  32. mMvpDelegate = null;
  33. }
  34. }
  35.  
  36. protected void createMvpDelegate() {
  37. if (getMvpDelegate() != null) {
  38. getMvpDelegate().onCreate();
  39. getMvpDelegate().onAttach();
  40. getMvpDelegate().onSaveInstanceState();
  41. }
  42. }
  43.  
  44. protected abstract String getMvpChildId();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement