Last active
June 2, 2017 13:17
-
-
Save amitkma/47c9fbe0b25ba04cf364b41cf1576d93 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 class MainPresenterImpl implements MainContract.Presenter { | |
private final MainContract.View mView; | |
private final DataManager mDataManager; | |
// Constructor with view and datamanger parameters. | |
public MainPresenterImpl(MainContract.View view, DataManager dataManager) { | |
this.mView = view; | |
mDataManager = dataManager; | |
mView.setPresenter(this); // Set presenter to the mView. | |
} | |
//BEGIN | |
// Implementation of MainContract.Presenter | |
@Override | |
public void addNote(String note) { | |
if(note != null && note.length() > 0) | |
mView.updateView(mDataManager.addNote(new Note(mDataManager.getNoteListSize() + 1, note))); | |
} | |
@Override | |
public void removeNote(Note note) { | |
mView.updateView(mDataManager.removeNote(note)); | |
} | |
@Override | |
public void getAllNotes() { | |
mView.showProgress(); | |
// Delay to simulate api as remote api. | |
new Handler().postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
mView.updateView(mDataManager.getAllNotes()); | |
mView.hideProgress(); | |
} | |
}, 3000); | |
} | |
@Override | |
public void clearAll() { | |
mView.showProgress(); | |
// Delay to simulate api as remote api. | |
new Handler().postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
mView.updateView(mDataManager.removeAllNotes()); | |
mView.hideProgress(); | |
} | |
}, 3000); | |
} | |
// END | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment