// Path: app/src/main/java/org/kaerdan/mvp_navigation/core/data/Article.java
// public class Article {
//     private final int id;
//     private final String title;
//     private final String body;
//     private final boolean isFavourite;
// 
//     public Article(int id, String title, String body, boolean isFavourite) {
//         this.id = id;
//         this.title = title;
//         this.body = body;
//         this.isFavourite = isFavourite;
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public String getBody() {
//         return body;
//     }
// 
//     public boolean isFavourite() {
//         return isFavourite;
//     }
// }
// 
// Path: app/src/main/java/org/kaerdan/mvp_navigation/core/ui/ArticleListAdapter.java
// public class ArticleListAdapter extends RecyclerView.Adapter<ArticleListAdapter.ArticleViewHolder> {
// 
//     private final List<Article> mArticles;
//     private final OnArticleClickListener mOnArticleClickListener;
// 
//     public ArticleListAdapter(@NonNull final List<Article> articles,
//             @NonNull final OnArticleClickListener onArticleClickListener) {
//         this.mArticles = articles;
//         this.mOnArticleClickListener = onArticleClickListener;
//     }
// 
//     @Override
//     public ArticleViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
//         return new ArticleViewHolder(new Button(parent.getContext()));
//     }
// 
//     @Override
//     public void onBindViewHolder(final ArticleViewHolder holder, final int position) {
//         final Article article = mArticles.get(position);
//         ((Button) holder.itemView).setText(article.getTitle());
//         holder.itemView.setOnClickListener(new View.OnClickListener() {
//                 @Override
//                 public void onClick(final View v) {
//                     mOnArticleClickListener.onArticleClick(article.getId());
//                 }
//             });
//     }
// 
//     @Override
//     public int getItemCount() {
//         return mArticles.size();
//     }
// 
//     static class ArticleViewHolder extends RecyclerView.ViewHolder {
//         public ArticleViewHolder(final View itemView) {
//             super(itemView);
//         }
//     }
// }
// 
// Path: app/src/main/java/org/kaerdan/mvp_navigation/core/ui/OnArticleClickListener.java
// public interface OnArticleClickListener {
//     void onArticleClick(int id);
// }


import java.util.List;
import org.kaerdan.mvp_navigation.R;
import org.kaerdan.mvp_navigation.core.data.Article;
import org.kaerdan.mvp_navigation.core.ui.ArticleListAdapter;
import org.kaerdan.mvp_navigation.core.ui.OnArticleClickListener;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
    protected ArticleListContract.Navigator getNavigator(final ArticleListContract.Presenter presenter) {
        Fragment parentFragment = getParentFragment();
        if (parentFragment != null && parentFragment instanceof ArticleListContract.NavigatorProvider) {
            return ((ArticleListContract.NavigatorProvider) parentFragment).getNavigator(presenter);
        } else {
            Activity activity = getActivity();
            if (activity instanceof ArticleListContract.NavigatorProvider) {
                return ((ArticleListContract.NavigatorProvider) activity).getNavigator(presenter);
            }
        }

        throw new IllegalStateException("Activity or parent Fragment must implement "
                + "ArticleListContract.NavigatorProvider");
    }

    @Override
    public void onStart() {
        super.onStart();
        mPresenter.onAttachView(this);
    }

    @Override
    public void onStop() {
        super.onStop();
        mPresenter.onDetachView();
    }

    @Override
    public void displayArticles(@NonNull final List<Article> articles,
            @NonNull final OnArticleClickListener onArticleClickListener) {
// Path: app/src/main/java/org/kaerdan/mvp_navigation/core/data/Article.java
// public class Article {
//     private final int id;
//     private final String title;
//     private final String body;
//     private final boolean isFavourite;
// 
//     public Article(int id, String title, String body, boolean isFavourite) {
//         this.id = id;
//         this.title = title;
//         this.body = body;
//         this.isFavourite = isFavourite;
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public String getBody() {
//         return body;
//     }
// 
//     public boolean isFavourite() {
//         return isFavourite;
//     }
// }
// 
// Path: app/src/main/java/org/kaerdan/mvp_navigation/core/ui/ArticleListAdapter.java
// public class ArticleListAdapter extends RecyclerView.Adapter<ArticleListAdapter.ArticleViewHolder> {
// 
//     private final List<Article> mArticles;
//     private final OnArticleClickListener mOnArticleClickListener;
// 
//     public ArticleListAdapter(@NonNull final List<Article> articles,
//             @NonNull final OnArticleClickListener onArticleClickListener) {
//         this.mArticles = articles;
//         this.mOnArticleClickListener = onArticleClickListener;
//     }
// 
//     @Override
//     public ArticleViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
//         return new ArticleViewHolder(new Button(parent.getContext()));
//     }
// 
//     @Override
//     public void onBindViewHolder(final ArticleViewHolder holder, final int position) {
//         final Article article = mArticles.get(position);
//         ((Button) holder.itemView).setText(article.getTitle());
//         holder.itemView.setOnClickListener(new View.OnClickListener() {
//                 @Override
//                 public void onClick(final View v) {
//                     mOnArticleClickListener.onArticleClick(article.getId());
//                 }
//             });
//     }
// 
//     @Override
//     public int getItemCount() {
//         return mArticles.size();
//     }
// 
//     static class ArticleViewHolder extends RecyclerView.ViewHolder {
//         public ArticleViewHolder(final View itemView) {
//             super(itemView);
//         }
//     }
// }
// 
// Path: app/src/main/java/org/kaerdan/mvp_navigation/core/ui/OnArticleClickListener.java
// public interface OnArticleClickListener {
//     void onArticleClick(int id);
// }


// Path: app/src/main/java/org/kaerdan/mvp_navigation/core/ui/article_list/ArticleListFragment.java
import java.util.List;
import org.kaerdan.mvp_navigation.R;
import org.kaerdan.mvp_navigation.core.data.Article;
import org.kaerdan.mvp_navigation.core.ui.ArticleListAdapter;
import org.kaerdan.mvp_navigation.core.ui.OnArticleClickListener;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

    protected ArticleListContract.Navigator getNavigator(final ArticleListContract.Presenter presenter) {
        Fragment parentFragment = getParentFragment();
        if (parentFragment != null && parentFragment instanceof ArticleListContract.NavigatorProvider) {
            return ((ArticleListContract.NavigatorProvider) parentFragment).getNavigator(presenter);
        } else {
            Activity activity = getActivity();
            if (activity instanceof ArticleListContract.NavigatorProvider) {
                return ((ArticleListContract.NavigatorProvider) activity).getNavigator(presenter);
            }
        }

        throw new IllegalStateException("Activity or parent Fragment must implement "
                + "ArticleListContract.NavigatorProvider");
    }

    @Override
    public void onStart() {
        super.onStart();
        mPresenter.onAttachView(this);
    }

    @Override
    public void onStop() {
        super.onStop();
        mPresenter.onDetachView();
    }

    @Override
    public void displayArticles(@NonNull final List<Article> articles,
            @NonNull final OnArticleClickListener onArticleClickListener) {
        mRecyclerView.setAdapter(new ArticleListAdapter(articles, onArticleClickListener));