Last active
February 1, 2022 16:34
-
-
Save ZakTaccardi/26039a9960fefc1b8b87 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
public void elementClicked(int position){ | |
if (view != null){ | |
final int word = view.getWordByPosition(int position) | |
view.doAnimationStuff(); | |
view.launchActivityWithWord(word); | |
} | |
} | |
//because there are no android dependencies here, it becomes easy to implement Mockito style behavioral testing. |
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
@Override | |
public void onElementClick(int position){ | |
presenter.elementClicked(int position) | |
} | |
@Override | |
public void getWordByPosition(int position){ | |
return mWordRepo.get(position).getWord(); | |
} | |
@Override | |
public void doAnimationStuff(){ | |
//do stuff | |
} | |
@Override | |
public void launchActivityWithWord(int word){ | |
Intent i = new Intent (mContext, DetailActivity.class); | |
i.putExtra(HomeActivity.WORD_ID, word); | |
mContext.startActivity(i); | |
} |
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
//this is bad because the presenter has Android dependencies | |
@Override | |
public void onElementClick(int position) { | |
int word = mWordRepo.get(position).getWord(); | |
Intent i = new Intent (mContext, DetailActivity.class); | |
i.putExtra(HomeActivity.WORD_ID, word); | |
//do animation stuff | |
mContext.startActivity(i); | |
} |
The view implementation is hardcoded (DetailActivity.class) and you need one method for each screen you want to navigate to from current view. Is there a better way?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should the return type of
MvpView.getWordByPosition
beString
rather thanvoid
?