From 9302ecfb92a78620c92e8fbd5da6c885cb190dd9 Mon Sep 17 00:00:00 2001 From: inorichi Date: Fri, 25 Sep 2015 19:43:23 +0200 Subject: [PATCH] Display dummy data --- .../mangafeed/ui/adapter/LibraryAdapter.java | 81 +++++++++++++++++++ .../ui/fragment/LibraryFragment.java | 46 +++++------ app/src/main/res/layout/fragment_library.xml | 17 ++-- app/src/main/res/layout/item_library.xml | 38 +++++---- 4 files changed, 133 insertions(+), 49 deletions(-) create mode 100644 app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryAdapter.java 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 new file mode 100644 index 000000000..d0aec712e --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/LibraryAdapter.java @@ -0,0 +1,81 @@ +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 butterknife.Bind; +import butterknife.ButterKnife; +import eu.kanade.mangafeed.R; +import eu.kanade.mangafeed.data.entities.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; + } + + 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/fragment/LibraryFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java index b3da93d2c..4ed4dc3d3 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 @@ -5,15 +5,22 @@ import android.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ArrayAdapter; +import android.widget.GridView; import java.util.ArrayList; +import butterknife.Bind; +import butterknife.ButterKnife; import eu.kanade.mangafeed.R; +import eu.kanade.mangafeed.data.entities.Manga; import eu.kanade.mangafeed.ui.activity.BaseActivity; +import eu.kanade.mangafeed.ui.adapter.LibraryAdapter; public class LibraryFragment extends Fragment { + @Bind(R.id.gridView) + GridView grid; + public static LibraryFragment newInstance() { LibraryFragment fragment = new LibraryFragment(); Bundle args = new Bundle(); @@ -21,35 +28,26 @@ public class LibraryFragment extends Fragment { return fragment; } - public LibraryFragment() { - // Required empty public constructor - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ((BaseActivity) getActivity()).getSupportActionBar().setTitle(R.string.library_title); - - } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View view = inflater.inflate(R.layout.fragment_library, container, false); + ((BaseActivity) getActivity()).getSupportActionBar().setTitle(R.string.library_title); + + ButterKnife.bind(this, view); + + ArrayList mangas = new ArrayList<>(); + mangas.add(new Manga("One Piece")); + mangas.add(new Manga("Berserk")); + mangas.add(new Manga("Fate/stay night: Unlimited Blade Works")); + + LibraryAdapter adapter = new LibraryAdapter(getActivity(), + R.layout.item_library, mangas); + + grid.setAdapter(adapter); + return view; } - - public class LocalManga { - public String name; - public String url; - - public LocalManga(String name, String url) { - this.name = name; - this.url = url; - } - } - } diff --git a/app/src/main/res/layout/fragment_library.xml b/app/src/main/res/layout/fragment_library.xml index 0e4bc495c..020b2e601 100644 --- a/app/src/main/res/layout/fragment_library.xml +++ b/app/src/main/res/layout/fragment_library.xml @@ -1,20 +1,21 @@ - + + tools:listitem="@layout/item_library" /> diff --git a/app/src/main/res/layout/item_library.xml b/app/src/main/res/layout/item_library.xml index 9890c6b40..fb952a45e 100644 --- a/app/src/main/res/layout/item_library.xml +++ b/app/src/main/res/layout/item_library.xml @@ -1,25 +1,25 @@ - + - - - - + android:layout_height="144dp" + android:id="@+id/thumbnailImageView" + tools:src="@mipmap/ic_launcher" + tools:background="@color/md_red_100"/> + android:layout_height="42dp" + android:id="@+id/footerLinearLayout" + android:background="@color/md_blue_100"> + android:textSize="12sp" + android:id="@+id/nameTextView" + android:paddingRight="8dp" + android:paddingLeft="8dp" + tools:text="Sample name"/>