diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java index e7b9ef3f4..7f4e0367f 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/LibraryPresenter.java @@ -1,7 +1,6 @@ package eu.kanade.mangafeed.presenter; import android.content.Intent; -import android.widget.GridView; import java.util.ArrayList; @@ -11,8 +10,8 @@ import de.greenrobot.event.EventBus; import eu.kanade.mangafeed.App; import eu.kanade.mangafeed.data.helpers.DatabaseHelper; import eu.kanade.mangafeed.ui.activity.MangaDetailActivity; -import eu.kanade.mangafeed.ui.adapter.LibraryAdapter; import eu.kanade.mangafeed.view.LibraryView; +import uk.co.ribot.easyadapter.EasyAdapter; import static rx.android.schedulers.AndroidSchedulers.mainThread; @@ -28,7 +27,7 @@ public class LibraryPresenter { App.getComponent(libraryView.getActivity()).inject(this); } - public void onMangaClick(LibraryAdapter adapter, int position) { + public void onMangaClick(EasyAdapter adapter, int position) { Intent intent = new Intent(mLibraryView.getActivity(), MangaDetailActivity.class); EventBus.getDefault().postSticky(adapter.getItem(position)); mLibraryView.getActivity().startActivity(intent); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryAdapter.java b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryAdapter.java deleted file mode 100644 index edb2b21fa..000000000 --- a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryAdapter.java +++ /dev/null @@ -1,90 +0,0 @@ -package eu.kanade.mangafeed.ui.adapter; - -import android.app.Activity; -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.TextView; - -import com.bumptech.glide.Glide; - -import java.util.ArrayList; -import java.util.List; - -import butterknife.Bind; -import butterknife.ButterKnife; -import eu.kanade.mangafeed.R; -import eu.kanade.mangafeed.data.models.Manga; -import uk.co.ribot.easyadapter.annotations.LayoutId; - -/** - * Created by len on 25/09/2015. - */ - -@LayoutId(R.layout.item_library) -public class LibraryAdapter extends ArrayAdapter { - - Context context; - int layoutResourceId; - ArrayList data; - - public LibraryAdapter(Context context, int layoutResourceId, ArrayList data) { - super(context, layoutResourceId, data); - this.context = context; - this.layoutResourceId = layoutResourceId; - this.data = data; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - View row = convertView; - MangoHolder holder = null; - - if(row == null) { - LayoutInflater inflater = ((Activity)context).getLayoutInflater(); - row = inflater.inflate(layoutResourceId, parent, false); - - holder = new MangoHolder(row); - row.setTag(holder); - } - else { - holder = (MangoHolder)row.getTag(); - } - - Manga m = data.get(position); - holder.nameText.setText(m.title); - Glide.with(getContext()) - .load(getImageUrl()) - .centerCrop() - .into(holder.thumbnail); - - return row; - } - - public void setData(ArrayList mangas) { - // Avoid calling dataSetChanged twice - data.clear(); - addAll(mangas); - } - - private String getImageUrl() { - return "http://img1.wikia.nocookie.net/__cb20090524204255/starwars/images/thumb/1/1a/R2d2.jpg/400px-R2d2.jpg"; - } - - static class MangoHolder { - @Bind(R.id.thumbnailImageView) - ImageView thumbnail; - - @Bind(R.id.nameTextView) - TextView nameText; - - public MangoHolder(View view) { - ButterKnife.bind(this, view); - } - } - - -} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/MangaLibraryHolder.java b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/MangaLibraryHolder.java new file mode 100644 index 000000000..4f5411f35 --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/MangaLibraryHolder.java @@ -0,0 +1,38 @@ +package eu.kanade.mangafeed.ui.adapter; + +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bumptech.glide.Glide; + +import eu.kanade.mangafeed.R; +import eu.kanade.mangafeed.data.models.Manga; +import uk.co.ribot.easyadapter.ItemViewHolder; +import uk.co.ribot.easyadapter.PositionInfo; +import uk.co.ribot.easyadapter.annotations.LayoutId; +import uk.co.ribot.easyadapter.annotations.ViewId; + + +@LayoutId(R.layout.item_library) +public class MangaLibraryHolder extends ItemViewHolder { + + @ViewId(R.id.thumbnailImageView) + ImageView mImageView; + + @ViewId(R.id.nameTextView) + TextView mTextView; + + public MangaLibraryHolder(View view) { + super(view); + } + + public void onSetValues(Manga manga, PositionInfo positionInfo) { + mTextView.setText(manga.title); + Glide.with(getContext()) + .load("http://img1.wikia.nocookie.net/__cb20090524204255/starwars/images/thumb/1/1a/R2d2.jpg/400px-R2d2.jpg") + .centerCrop() + .into(mImageView); + } + +} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java index 21b2752ce..0a0777b80 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java @@ -15,15 +15,16 @@ import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.data.models.Manga; import eu.kanade.mangafeed.presenter.LibraryPresenter; import eu.kanade.mangafeed.ui.activity.BaseActivity; -import eu.kanade.mangafeed.ui.adapter.LibraryAdapter; +import eu.kanade.mangafeed.ui.adapter.MangaLibraryHolder; import eu.kanade.mangafeed.view.LibraryView; +import uk.co.ribot.easyadapter.EasyAdapter; public class LibraryFragment extends Fragment implements LibraryView { @Bind(R.id.gridView) GridView grid; LibraryPresenter mLibraryPresenter; - LibraryAdapter mAdapter; + EasyAdapter mEasyAdapter; public static LibraryFragment newInstance() { LibraryFragment fragment = new LibraryFragment(); @@ -54,14 +55,15 @@ public class LibraryFragment extends Fragment implements LibraryView { } public void setMangas(ArrayList mangas) { - if (mAdapter == null) { - mAdapter = new LibraryAdapter( + if (mEasyAdapter == null) { + mEasyAdapter = new EasyAdapter( getActivity(), - R.layout.item_library, - mangas); - grid.setAdapter(mAdapter); + MangaLibraryHolder.class, + mangas + ); + grid.setAdapter(mEasyAdapter); } else { - mAdapter.setData(mangas); + mEasyAdapter.setItems(mangas); } } @@ -69,7 +71,7 @@ public class LibraryFragment extends Fragment implements LibraryView { private void setMangaClickListener() { grid.setOnItemClickListener( (parent, view, position, id) -> - mLibraryPresenter.onMangaClick(mAdapter, position) + mLibraryPresenter.onMangaClick(mEasyAdapter, position) ); } diff --git a/app/src/main/res/layout/fragment_library.xml b/app/src/main/res/layout/fragment_library.xml index 020b2e601..15a186c99 100644 --- a/app/src/main/res/layout/fragment_library.xml +++ b/app/src/main/res/layout/fragment_library.xml @@ -10,7 +10,7 @@ android:id="@+id/gridView" android:padding="10dp" android:clipToPadding="false" - android:verticalSpacing="4dp" + android:verticalSpacing="8dp" android:horizontalSpacing="8dp" android:columnWidth="96dp" android:numColumns="auto_fit"