Create adapter in presenter
This commit is contained in:
parent
d7bb4a6a2a
commit
db49c3ee88
@ -9,14 +9,8 @@ import eu.kanade.mangafeed.data.helpers.DatabaseHelper;
|
|||||||
import eu.kanade.mangafeed.data.helpers.PreferencesHelper;
|
import eu.kanade.mangafeed.data.helpers.PreferencesHelper;
|
||||||
import eu.kanade.mangafeed.data.models.Manga;
|
import eu.kanade.mangafeed.data.models.Manga;
|
||||||
import eu.kanade.mangafeed.ui.activity.MangaDetailActivity;
|
import eu.kanade.mangafeed.ui.activity.MangaDetailActivity;
|
||||||
|
import eu.kanade.mangafeed.ui.adapter.LibraryAdapter;
|
||||||
import eu.kanade.mangafeed.view.LibraryView;
|
import eu.kanade.mangafeed.view.LibraryView;
|
||||||
import rx.Observable;
|
|
||||||
import rx.Subscription;
|
|
||||||
import rx.android.schedulers.AndroidSchedulers;
|
|
||||||
import rx.schedulers.Schedulers;
|
|
||||||
import rx.subjects.PublishSubject;
|
|
||||||
import timber.log.Timber;
|
|
||||||
import uk.co.ribot.easyadapter.EasyAdapter;
|
|
||||||
|
|
||||||
import static rx.android.schedulers.AndroidSchedulers.mainThread;
|
import static rx.android.schedulers.AndroidSchedulers.mainThread;
|
||||||
|
|
||||||
@ -24,11 +18,10 @@ public class LibraryPresenter extends BasePresenter {
|
|||||||
|
|
||||||
private LibraryView view;
|
private LibraryView view;
|
||||||
|
|
||||||
@Inject
|
@Inject DatabaseHelper db;
|
||||||
DatabaseHelper db;
|
@Inject PreferencesHelper prefs;
|
||||||
|
|
||||||
@Inject
|
LibraryAdapter<Manga> adapter;
|
||||||
PreferencesHelper prefs;
|
|
||||||
|
|
||||||
public LibraryPresenter(LibraryView view) {
|
public LibraryPresenter(LibraryView view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
@ -43,7 +36,7 @@ public class LibraryPresenter extends BasePresenter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onMangaClick(EasyAdapter<Manga> adapter, int position) {
|
public void onMangaClick(int position) {
|
||||||
Intent intent = MangaDetailActivity.newIntent(
|
Intent intent = MangaDetailActivity.newIntent(
|
||||||
view.getActivity(),
|
view.getActivity(),
|
||||||
adapter.getItem(position)
|
adapter.getItem(position)
|
||||||
@ -52,13 +45,17 @@ public class LibraryPresenter extends BasePresenter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initializeMangas() {
|
public void initializeMangas() {
|
||||||
|
|
||||||
db.manga.get()
|
db.manga.get()
|
||||||
.observeOn(mainThread())
|
.observeOn(mainThread())
|
||||||
.subscribe(view::setMangas);
|
.subscribe(mangas -> {
|
||||||
|
adapter = new LibraryAdapter<>(view.getActivity(), mangas);
|
||||||
|
view.setAdapter(adapter);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onQueryTextChange(String query) {
|
public void onQueryTextChange(String query) {
|
||||||
view.getAdapter().getFilter().filter(query);
|
adapter.getFilter().filter(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public class LibraryAdapter<T> extends EasyAdapter<T> implements Filterable {
|
|||||||
FilterResults results = new FilterResults();
|
FilterResults results = new FilterResults();
|
||||||
String query = charSequence.toString().toLowerCase();
|
String query = charSequence.toString().toLowerCase();
|
||||||
|
|
||||||
if (query == null || query.length() == 0) {
|
if (query.length() == 0) {
|
||||||
results.values = mangas;
|
results.values = mangas;
|
||||||
results.count = mangas.size();
|
results.count = mangas.size();
|
||||||
} else {
|
} else {
|
||||||
|
@ -9,18 +9,12 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.GridView;
|
import android.widget.GridView;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import eu.kanade.mangafeed.R;
|
import eu.kanade.mangafeed.R;
|
||||||
import eu.kanade.mangafeed.data.models.Manga;
|
|
||||||
import eu.kanade.mangafeed.presenter.LibraryPresenter;
|
import eu.kanade.mangafeed.presenter.LibraryPresenter;
|
||||||
import eu.kanade.mangafeed.ui.activity.MainActivity;
|
import eu.kanade.mangafeed.ui.activity.MainActivity;
|
||||||
import eu.kanade.mangafeed.ui.adapter.CatalogueArrayAdapter;
|
|
||||||
import eu.kanade.mangafeed.ui.adapter.MangaLibraryHolder;
|
|
||||||
import eu.kanade.mangafeed.view.LibraryView;
|
import eu.kanade.mangafeed.view.LibraryView;
|
||||||
import timber.log.Timber;
|
|
||||||
import uk.co.ribot.easyadapter.EasyAdapter;
|
import uk.co.ribot.easyadapter.EasyAdapter;
|
||||||
|
|
||||||
|
|
||||||
@ -28,7 +22,6 @@ public class LibraryFragment extends BaseFragment implements LibraryView {
|
|||||||
|
|
||||||
@Bind(R.id.gridView) GridView grid;
|
@Bind(R.id.gridView) GridView grid;
|
||||||
LibraryPresenter presenter;
|
LibraryPresenter presenter;
|
||||||
CatalogueArrayAdapter<Manga> adapter;
|
|
||||||
MainActivity activity;
|
MainActivity activity;
|
||||||
|
|
||||||
public static LibraryFragment newInstance() {
|
public static LibraryFragment newInstance() {
|
||||||
@ -62,7 +55,6 @@ public class LibraryFragment extends BaseFragment implements LibraryView {
|
|||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
setupToolbar();
|
|
||||||
setMangaClickListener();
|
setMangaClickListener();
|
||||||
presenter.initializeMangas();
|
presenter.initializeMangas();
|
||||||
}
|
}
|
||||||
@ -89,35 +81,17 @@ public class LibraryFragment extends BaseFragment implements LibraryView {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// LibraryView
|
|
||||||
|
|
||||||
public void setMangas(List<Manga> mangas) {
|
|
||||||
if (adapter == null) {
|
|
||||||
adapter = new CatalogueArrayAdapter<>(
|
|
||||||
getActivity(),
|
|
||||||
MangaLibraryHolder.class,
|
|
||||||
mangas
|
|
||||||
);
|
|
||||||
grid.setAdapter(adapter);
|
|
||||||
} else {
|
|
||||||
adapter.setItems(mangas);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setMangaClickListener() {
|
private void setMangaClickListener() {
|
||||||
grid.setOnItemClickListener(
|
grid.setOnItemClickListener(
|
||||||
(parent, view, position, id) ->
|
(parent, view, position, id) ->
|
||||||
presenter.onMangaClick(adapter, position)
|
presenter.onMangaClick(position)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupToolbar() {
|
// LibraryView
|
||||||
//activity.getSupportActionBar().
|
|
||||||
}
|
|
||||||
|
|
||||||
public CatalogueArrayAdapter getAdapter() {
|
public void setAdapter(EasyAdapter adapter) {
|
||||||
return adapter;
|
grid.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
package eu.kanade.mangafeed.view;
|
package eu.kanade.mangafeed.view;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import uk.co.ribot.easyadapter.EasyAdapter;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import eu.kanade.mangafeed.data.models.Manga;
|
|
||||||
import eu.kanade.mangafeed.ui.adapter.CatalogueArrayAdapter;
|
|
||||||
|
|
||||||
public interface LibraryView extends BaseView {
|
public interface LibraryView extends BaseView {
|
||||||
|
|
||||||
void setMangas(List<Manga> mangas);
|
void setAdapter(EasyAdapter mangas);
|
||||||
CatalogueArrayAdapter getAdapter();
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user