// Path: mvp/app/src/main/java/com/tinmegali/tutsmvp_sample/main/activity/MVP_Main.java
// public interface MVP_Main {
//     /**
//      * Required View methods available to Presenter.
//      * A passive layer, responsible to show data
//      * and receive user interactions
//      *      Presenter to View
//      */
//     interface RequiredViewOps {
//         Context getAppContext();
//         Context getActivityContext();
//         void showToast(Toast toast);
//         void showProgress();
//         void hideProgress();
//         void showAlert(AlertDialog dialog);
//         void notifyItemRemoved(int position);
//         void notifyDataSetChanged();
//         void notifyItemInserted(int layoutPosition);
//         void notifyItemRangeChanged(int positionStart, int itemCount);
//         void clearEditText();
//     }
// 
//     /**
//      * Operations offered to View to communicate with Presenter.
//      * Process user interaction, sends data requests to Model, etc.
//      *      View to Presenter
//      */
//     interface ProvidedPresenterOps {
//         void onDestroy(boolean isChangingConfiguration);
//         void setView(RequiredViewOps view);
//         NotesViewHolder createViewHolder(ViewGroup parent, int viewType);
//         void bindViewHolder(NotesViewHolder holder, int position);
//         int getNotesCount();
//         void clickNewNote(EditText editText);
//         void clickDeleteNote(Note note, int adapterPos, int layoutPos);
//     }
// 
//     /**
//      * Required Presenter methods available to Model.
//      *      Model to Presenter
//      */
//     interface RequiredPresenterOps {
//         Context getAppContext();
//         Context getActivityContext();
//     }
// 
//     /**
//      * Operations offered to Model to communicate with Presenter
//      * Handles all data business logic.
//      *      Presenter to Model
//      */
//     interface ProvidedModelOps {
//         void onDestroy(boolean isChangingConfiguration);
//         int insertNote(Note note);
//         boolean loadData();
//         Note getNote(int position);
//         boolean deleteNote(Note note, int adapterPos);
//         int getNotesCount();
//     }
// }
// 
// Path: mvp/app/src/main/java/com/tinmegali/tutsmvp_sample/main/activity/view/recycler/NotesViewHolder.java
// public class NotesViewHolder extends RecyclerView.ViewHolder {
// 
//     public RelativeLayout container;
//     public TextView text, date;
//     public ImageButton btnDelete;
// 
//     public NotesViewHolder(View itemView) {
//         super(itemView);
// 
//         setupViews(itemView);
//     }
// 
//     private void setupViews(View view) {
//         container = (RelativeLayout) view.findViewById(R.id.holder_container);
//         text = (TextView) view.findViewById(R.id.note_text);
//         date = (TextView) view.findViewById(R.id.note_date);
//         btnDelete = (ImageButton) view.findViewById(R.id.btn_delete);
//     }
// 
// 
// }
// 
// Path: mvp/app/src/main/java/com/tinmegali/tutsmvp_sample/models/Note.java
// public class Note {
// 
//     private int id = -1;
//     private String mText;
//     private String mDate;
// 
//     public Note() {
//     }
// 
//     public Note(int id, String mText, String mDate) {
//         this.id = id;
//         this.mText = mText;
//         this.mDate = mDate;
//     }
// 
//     public Note(String mText, String mDate) {
//         this.mText = mText;
//         this.mDate = mDate;
//     }
// 
//     public ContentValues getValues(){
//         ContentValues cv = new ContentValues();
//         if ( id!=-1) cv.put(DBSchema.TB_NOTES.ID, id);
//         cv.put(DBSchema.TB_NOTES.NOTE, mText);
//         cv.put(DBSchema.TB_NOTES.DATE, mDate);
//         return cv;
//     }
// 
//     public void setId(int id) {
//         this.id = id;
//     }
// 
//     public void setDate(String mDate) {
//         this.mDate = mDate;
//     }
// 
//     public void setText(String mText) {
//         this.mText = mText;
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
//     public String getDate() {
//         return mDate;
//     }
// 
//     public String getText() {
//         return mText;
//     }
// }


import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Parcelable;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;
import com.tinmegali.tutsmvp_sample.R;
import com.tinmegali.tutsmvp_sample.main.activity.MVP_Main;
import com.tinmegali.tutsmvp_sample.main.activity.view.recycler.NotesViewHolder;
import com.tinmegali.tutsmvp_sample.models.Note;
import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
     * @param note          Note to delete
     * @param adapterPos    Adapter position
     * @param layoutPos     Recycler layout position
     */
    public void deleteNote(final Note note, final int adapterPos, final int layoutPos) {
        getView().showProgress();
        new AsyncTask<Void, Void, Boolean>() {
            @Override
            protected Boolean doInBackground(Void... params) {
                // Delete note on Model, returning result
                return mModel.deleteNote(note, adapterPos);
            }

            @Override
            protected void onPostExecute(Boolean result) {
                try {
                    getView().hideProgress();
                    if ( result ) {
                        // Remove item from RecyclerView
                        getView().notifyItemRemoved(layoutPos);
                        getView().showToast(makeToast("Note deleted."));
                    } else {
                        // Inform about error
                        getView().showToast(makeToast("Error deleting note["+note.getId()+"]"));
                    }
                } catch (NullPointerException e) {
                    e.printStackTrace();
                }

            }
// Path: mvp/app/src/main/java/com/tinmegali/tutsmvp_sample/main/activity/MVP_Main.java
// public interface MVP_Main {
//     /**
//      * Required View methods available to Presenter.
//      * A passive layer, responsible to show data
//      * and receive user interactions
//      *      Presenter to View
//      */
//     interface RequiredViewOps {
//         Context getAppContext();
//         Context getActivityContext();
//         void showToast(Toast toast);
//         void showProgress();
//         void hideProgress();
//         void showAlert(AlertDialog dialog);
//         void notifyItemRemoved(int position);
//         void notifyDataSetChanged();
//         void notifyItemInserted(int layoutPosition);
//         void notifyItemRangeChanged(int positionStart, int itemCount);
//         void clearEditText();
//     }
// 
//     /**
//      * Operations offered to View to communicate with Presenter.
//      * Process user interaction, sends data requests to Model, etc.
//      *      View to Presenter
//      */
//     interface ProvidedPresenterOps {
//         void onDestroy(boolean isChangingConfiguration);
//         void setView(RequiredViewOps view);
//         NotesViewHolder createViewHolder(ViewGroup parent, int viewType);
//         void bindViewHolder(NotesViewHolder holder, int position);
//         int getNotesCount();
//         void clickNewNote(EditText editText);
//         void clickDeleteNote(Note note, int adapterPos, int layoutPos);
//     }
// 
//     /**
//      * Required Presenter methods available to Model.
//      *      Model to Presenter
//      */
//     interface RequiredPresenterOps {
//         Context getAppContext();
//         Context getActivityContext();
//     }
// 
//     /**
//      * Operations offered to Model to communicate with Presenter
//      * Handles all data business logic.
//      *      Presenter to Model
//      */
//     interface ProvidedModelOps {
//         void onDestroy(boolean isChangingConfiguration);
//         int insertNote(Note note);
//         boolean loadData();
//         Note getNote(int position);
//         boolean deleteNote(Note note, int adapterPos);
//         int getNotesCount();
//     }
// }
// 
// Path: mvp/app/src/main/java/com/tinmegali/tutsmvp_sample/main/activity/view/recycler/NotesViewHolder.java
// public class NotesViewHolder extends RecyclerView.ViewHolder {
// 
//     public RelativeLayout container;
//     public TextView text, date;
//     public ImageButton btnDelete;
// 
//     public NotesViewHolder(View itemView) {
//         super(itemView);
// 
//         setupViews(itemView);
//     }
// 
//     private void setupViews(View view) {
//         container = (RelativeLayout) view.findViewById(R.id.holder_container);
//         text = (TextView) view.findViewById(R.id.note_text);
//         date = (TextView) view.findViewById(R.id.note_date);
//         btnDelete = (ImageButton) view.findViewById(R.id.btn_delete);
//     }
// 
// 
// }
// 
// Path: mvp/app/src/main/java/com/tinmegali/tutsmvp_sample/models/Note.java
// public class Note {
// 
//     private int id = -1;
//     private String mText;
//     private String mDate;
// 
//     public Note() {
//     }
// 
//     public Note(int id, String mText, String mDate) {
//         this.id = id;
//         this.mText = mText;
//         this.mDate = mDate;
//     }
// 
//     public Note(String mText, String mDate) {
//         this.mText = mText;
//         this.mDate = mDate;
//     }
// 
//     public ContentValues getValues(){
//         ContentValues cv = new ContentValues();
//         if ( id!=-1) cv.put(DBSchema.TB_NOTES.ID, id);
//         cv.put(DBSchema.TB_NOTES.NOTE, mText);
//         cv.put(DBSchema.TB_NOTES.DATE, mDate);
//         return cv;
//     }
// 
//     public void setId(int id) {
//         this.id = id;
//     }
// 
//     public void setDate(String mDate) {
//         this.mDate = mDate;
//     }
// 
//     public void setText(String mText) {
//         this.mText = mText;
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
//     public String getDate() {
//         return mDate;
//     }
// 
//     public String getText() {
//         return mText;
//     }
// }


// Path: mvp/app/src/main/java/com/tinmegali/tutsmvp_sample/main/activity/presenter/MainPresenter.java
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Parcelable;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;
import com.tinmegali.tutsmvp_sample.R;
import com.tinmegali.tutsmvp_sample.main.activity.MVP_Main;
import com.tinmegali.tutsmvp_sample.main.activity.view.recycler.NotesViewHolder;
import com.tinmegali.tutsmvp_sample.models.Note;
import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

     * @param note          Note to delete
     * @param adapterPos    Adapter position
     * @param layoutPos     Recycler layout position
     */
    public void deleteNote(final Note note, final int adapterPos, final int layoutPos) {
        getView().showProgress();
        new AsyncTask<Void, Void, Boolean>() {
            @Override
            protected Boolean doInBackground(Void... params) {
                // Delete note on Model, returning result
                return mModel.deleteNote(note, adapterPos);
            }

            @Override
            protected void onPostExecute(Boolean result) {
                try {
                    getView().hideProgress();
                    if ( result ) {
                        // Remove item from RecyclerView
                        getView().notifyItemRemoved(layoutPos);
                        getView().showToast(makeToast("Note deleted."));
                    } else {
                        // Inform about error
                        getView().showToast(makeToast("Error deleting note["+note.getId()+"]"));
                    }
                } catch (NullPointerException e) {
                    e.printStackTrace();
                }

            }
        }.execute();