// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/BooksApplication.java
// public class BooksApplication extends Application {
// 
//     private static BooksApplication sInstance;
//     private ObjectGraph mApplicationGraph;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         sInstance = this;
//         initRealmConfiguration();
//         initApplicationGraph();
//     }
// 
//     private void initRealmConfiguration() {
//         RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this)
//                 .deleteRealmIfMigrationNeeded()
//                 .build();
//         Realm.setDefaultConfiguration(realmConfiguration);
//     }
// 
//     private void initApplicationGraph() {
//         mApplicationGraph = ObjectGraph.create(new ApplicationModule());
//     }
// 
//     public static void injectModules(@NonNull final Object object, final Object... modules) {
//         sInstance.mApplicationGraph.plus(modules).inject(object);
//     }
// }
// 
// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/model/Book.java
// public class Book extends RealmObject {
// 
//     @PrimaryKey
//     private int id;
// 
//     private String isbn;
//     private String title;
//     private Author author;
//     private Publisher publisher;
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(final int id) {
//         this.id = id;
//     }
// 
//     public String getIsbn() {
//         return isbn;
//     }
// 
//     public void setIsbn(final String isbn) {
//         this.isbn = isbn;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public void setTitle(final String title) {
//         this.title = title;
//     }
// 
//     public Author getAuthor() {
//         return author;
//     }
// 
//     public void setAuthor(final Author author) {
//         this.author = author;
//     }
// 
//     public Publisher getPublisher() {
//         return publisher;
//     }
// 
//     public void setPublisher(final Publisher publisher) {
//         this.publisher = publisher;
//     }
// 
//     public String getDetails() {
//         String details = "";
//         details += getAuthorFullName();
//         details += " | ";
//         details += getPublisher().getName();
//         return details;
//     }
// 
//     public String getAuthorFullName() {
//         return String.format("%s %s", getAuthor().getName(), getAuthor().getLastname());
//     }
// }
// 
// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/BaseActivity.java
// public abstract class BaseActivity extends AppCompatActivity {
// 
//     @Override
//     public void onCreate(final Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         BooksApplication.injectModules(this, getModule());
//     }
// 
//     @Override
//     protected void onDestroy() {
//         closeRealm();
//         super.onDestroy();
//     }
// 
//     protected abstract Object getModule();
//     protected abstract void closeRealm();
// }
// 
// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/adapter/BookGridAdapter.java
// public class BookGridAdapter extends RecyclerView.Adapter<BookGridAdapter.ViewHolder> {
// 
//     private RealmList<Book> mBooks;
// 
//     @Override
//     public ViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
//         View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_publisher_book, parent, false);
//         return new ViewHolder(view);
//     }
// 
//     @Override
//     public void onBindViewHolder(final ViewHolder holder, final int position) {
//         holder.mTextTitle.setText(mBooks.get(position).getTitle());
//     }
// 
//     @Override
//     public int getItemCount() {
//         return mBooks.size();
//     }
// 
//     public void setBooks(final RealmList<Book> books) {
//         mBooks = books;
//         notifyDataSetChanged();
//     }
// 
//     public class ViewHolder extends RecyclerView.ViewHolder {
// 
//         @Bind(R.id.text_title) TextView mTextTitle;
// 
//         public ViewHolder(final View itemView) {
//             super(itemView);
//             ButterKnife.bind(this, itemView);
//         }
//     }
// }


import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import butterknife.Bind;
import butterknife.ButterKnife;
import io.realm.RealmList;
import javax.inject.Inject;
import pl.droidsonroids.examplerealmmvp.BooksApplication;
import pl.droidsonroids.examplerealmmvp.R;
import pl.droidsonroids.examplerealmmvp.model.Book;
import pl.droidsonroids.examplerealmmvp.ui.BaseActivity;
import pl.droidsonroids.examplerealmmvp.ui.adapter.BookGridAdapter;
        ButterKnife.bind(this);

        initList();
    }

    @Override
    protected Object getModule() {
        return new AuthorModule(getIntent().getExtras().getString(EXTRA_AUTHOR));
    }

    private void initList() {
        mAdapter = new BookGridAdapter();
        mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
        mRecyclerView.setAdapter(mAdapter);
    }

    @Override
    protected void onStart() {
        super.onStart();
        mAuthorPresenter.setView(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        mAuthorPresenter.clearView();
    }

    @Override
    protected void closeRealm() {
// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/BooksApplication.java
// public class BooksApplication extends Application {
// 
//     private static BooksApplication sInstance;
//     private ObjectGraph mApplicationGraph;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         sInstance = this;
//         initRealmConfiguration();
//         initApplicationGraph();
//     }
// 
//     private void initRealmConfiguration() {
//         RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this)
//                 .deleteRealmIfMigrationNeeded()
//                 .build();
//         Realm.setDefaultConfiguration(realmConfiguration);
//     }
// 
//     private void initApplicationGraph() {
//         mApplicationGraph = ObjectGraph.create(new ApplicationModule());
//     }
// 
//     public static void injectModules(@NonNull final Object object, final Object... modules) {
//         sInstance.mApplicationGraph.plus(modules).inject(object);
//     }
// }
// 
// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/model/Book.java
// public class Book extends RealmObject {
// 
//     @PrimaryKey
//     private int id;
// 
//     private String isbn;
//     private String title;
//     private Author author;
//     private Publisher publisher;
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(final int id) {
//         this.id = id;
//     }
// 
//     public String getIsbn() {
//         return isbn;
//     }
// 
//     public void setIsbn(final String isbn) {
//         this.isbn = isbn;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public void setTitle(final String title) {
//         this.title = title;
//     }
// 
//     public Author getAuthor() {
//         return author;
//     }
// 
//     public void setAuthor(final Author author) {
//         this.author = author;
//     }
// 
//     public Publisher getPublisher() {
//         return publisher;
//     }
// 
//     public void setPublisher(final Publisher publisher) {
//         this.publisher = publisher;
//     }
// 
//     public String getDetails() {
//         String details = "";
//         details += getAuthorFullName();
//         details += " | ";
//         details += getPublisher().getName();
//         return details;
//     }
// 
//     public String getAuthorFullName() {
//         return String.format("%s %s", getAuthor().getName(), getAuthor().getLastname());
//     }
// }
// 
// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/BaseActivity.java
// public abstract class BaseActivity extends AppCompatActivity {
// 
//     @Override
//     public void onCreate(final Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//         BooksApplication.injectModules(this, getModule());
//     }
// 
//     @Override
//     protected void onDestroy() {
//         closeRealm();
//         super.onDestroy();
//     }
// 
//     protected abstract Object getModule();
//     protected abstract void closeRealm();
// }
// 
// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/adapter/BookGridAdapter.java
// public class BookGridAdapter extends RecyclerView.Adapter<BookGridAdapter.ViewHolder> {
// 
//     private RealmList<Book> mBooks;
// 
//     @Override
//     public ViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
//         View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_publisher_book, parent, false);
//         return new ViewHolder(view);
//     }
// 
//     @Override
//     public void onBindViewHolder(final ViewHolder holder, final int position) {
//         holder.mTextTitle.setText(mBooks.get(position).getTitle());
//     }
// 
//     @Override
//     public int getItemCount() {
//         return mBooks.size();
//     }
// 
//     public void setBooks(final RealmList<Book> books) {
//         mBooks = books;
//         notifyDataSetChanged();
//     }
// 
//     public class ViewHolder extends RecyclerView.ViewHolder {
// 
//         @Bind(R.id.text_title) TextView mTextTitle;
// 
//         public ViewHolder(final View itemView) {
//             super(itemView);
//             ButterKnife.bind(this, itemView);
//         }
//     }
// }


// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/author/AuthorActivity.java
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import butterknife.Bind;
import butterknife.ButterKnife;
import io.realm.RealmList;
import javax.inject.Inject;
import pl.droidsonroids.examplerealmmvp.BooksApplication;
import pl.droidsonroids.examplerealmmvp.R;
import pl.droidsonroids.examplerealmmvp.model.Book;
import pl.droidsonroids.examplerealmmvp.ui.BaseActivity;
import pl.droidsonroids.examplerealmmvp.ui.adapter.BookGridAdapter;

        ButterKnife.bind(this);

        initList();
    }

    @Override
    protected Object getModule() {
        return new AuthorModule(getIntent().getExtras().getString(EXTRA_AUTHOR));
    }

    private void initList() {
        mAdapter = new BookGridAdapter();
        mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
        mRecyclerView.setAdapter(mAdapter);
    }

    @Override
    protected void onStart() {
        super.onStart();
        mAuthorPresenter.setView(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        mAuthorPresenter.clearView();
    }

    @Override
    protected void closeRealm() {
        mAuthorPresenter.closeRealm();