2015-09-26 18:58:01 +02:00
|
|
|
package eu.kanade.mangafeed.presenter;
|
|
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
|
|
|
|
import eu.kanade.mangafeed.App;
|
|
|
|
|
import eu.kanade.mangafeed.data.helpers.DatabaseHelper;
|
2015-09-29 14:40:36 +02:00
|
|
|
import eu.kanade.mangafeed.data.helpers.PreferencesHelper;
|
2015-09-28 12:42:16 +02:00
|
|
|
import eu.kanade.mangafeed.data.models.Manga;
|
2015-09-26 18:58:01 +02:00
|
|
|
import eu.kanade.mangafeed.ui.activity.MangaDetailActivity;
|
|
|
|
|
import eu.kanade.mangafeed.view.LibraryView;
|
2015-09-28 02:35:54 +02:00
|
|
|
import uk.co.ribot.easyadapter.EasyAdapter;
|
2015-09-26 18:58:01 +02:00
|
|
|
|
|
|
|
|
import static rx.android.schedulers.AndroidSchedulers.mainThread;
|
|
|
|
|
|
|
|
|
|
public class LibraryPresenter {
|
|
|
|
|
|
2015-09-28 15:02:46 +02:00
|
|
|
private LibraryView view;
|
2015-09-26 18:58:01 +02:00
|
|
|
|
|
|
|
|
@Inject
|
2015-09-29 14:40:36 +02:00
|
|
|
DatabaseHelper db;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
PreferencesHelper prefs;
|
2015-09-26 18:58:01 +02:00
|
|
|
|
2015-09-28 15:02:46 +02:00
|
|
|
public LibraryPresenter(LibraryView view) {
|
|
|
|
|
this.view = view;
|
|
|
|
|
App.getComponent(view.getActivity()).inject(this);
|
2015-09-29 14:40:36 +02:00
|
|
|
|
|
|
|
|
//TODO remove, only for testing
|
|
|
|
|
if (prefs.isFirstRun()) {
|
|
|
|
|
db.manga.createDummyManga();
|
|
|
|
|
db.chapter.createDummyChapters();
|
|
|
|
|
prefs.setNotFirstRun();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-26 18:58:01 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-28 12:42:16 +02:00
|
|
|
public void onMangaClick(EasyAdapter<Manga> adapter, int position) {
|
|
|
|
|
Intent intent = MangaDetailActivity.newIntent(
|
2015-09-28 15:02:46 +02:00
|
|
|
view.getActivity(),
|
2015-09-28 12:42:16 +02:00
|
|
|
adapter.getItem(position)
|
|
|
|
|
);
|
2015-09-28 15:02:46 +02:00
|
|
|
view.getActivity().startActivity(intent);
|
2015-09-26 18:58:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initializeMangas() {
|
|
|
|
|
db.manga.get()
|
|
|
|
|
.observeOn(mainThread())
|
2015-09-28 15:02:46 +02:00
|
|
|
.subscribe(view::setMangas);
|
2015-09-26 18:58:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|