Skip to content

Instantly share code, notes, and snippets.

@ZakTaccardi
Last active February 1, 2022 16:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZakTaccardi/26039a9960fefc1b8b87 to your computer and use it in GitHub Desktop.
Save ZakTaccardi/26039a9960fefc1b8b87 to your computer and use it in GitHub Desktop.
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.
@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 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);
}
@reustonium
Copy link

Should the return type of MvpView.getWordByPosition be String rather than void ?

@anotherdev
Copy link

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