LibraryPresenter.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package eu.kanade.mangafeed.presenter;
  2. import android.content.Intent;
  3. import javax.inject.Inject;
  4. import eu.kanade.mangafeed.App;
  5. import eu.kanade.mangafeed.data.helpers.DatabaseHelper;
  6. import eu.kanade.mangafeed.data.helpers.PreferencesHelper;
  7. import eu.kanade.mangafeed.data.models.Manga;
  8. import eu.kanade.mangafeed.ui.activity.MangaDetailActivity;
  9. import eu.kanade.mangafeed.ui.adapter.LibraryAdapter;
  10. import eu.kanade.mangafeed.view.LibraryView;
  11. import static rx.android.schedulers.AndroidSchedulers.mainThread;
  12. public class LibraryPresenter extends BasePresenter {
  13. private LibraryView view;
  14. @Inject DatabaseHelper db;
  15. @Inject PreferencesHelper prefs;
  16. LibraryAdapter<Manga> adapter;
  17. public LibraryPresenter(LibraryView view) {
  18. this.view = view;
  19. App.getComponent(view.getActivity()).inject(this);
  20. //TODO remove, only for testing
  21. if (prefs.isFirstRun()) {
  22. db.manga.createDummyManga();
  23. db.chapter.createDummyChapters();
  24. prefs.setNotFirstRun();
  25. }
  26. }
  27. public void onMangaClick(int position) {
  28. Intent intent = MangaDetailActivity.newIntent(
  29. view.getActivity(),
  30. adapter.getItem(position)
  31. );
  32. view.getActivity().startActivity(intent);
  33. }
  34. public void initializeMangas() {
  35. db.manga.get()
  36. .observeOn(mainThread())
  37. .subscribe(mangas -> {
  38. adapter = new LibraryAdapter<>(view.getActivity(), mangas);
  39. view.setAdapter(adapter);
  40. });
  41. }
  42. public void onQueryTextChange(String query) {
  43. adapter.getFilter().filter(query);
  44. }
  45. }