Display dummy data

This commit is contained in:
inorichi 2015-09-25 19:43:23 +02:00
parent 207aca60b2
commit 9302ecfb92
4 changed files with 133 additions and 49 deletions

View File

@ -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<Manga> {
Context context;
int layoutResourceId;
ArrayList<Manga> data;
public LibraryAdapter(Context context, int layoutResourceId, ArrayList<Manga> 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);
}
}
}

View File

@ -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<Manga> 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;
}
}
}

View File

@ -1,20 +1,21 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="eu.kanade.mangafeed.ui.fragment.LibraryFragment">
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp"
android:id="@+id/gridView"
android:padding="10dp"
android:clipToPadding="false"
android:verticalSpacing="4dp"
android:horizontalSpacing="4dp"
android:horizontalSpacing="8dp"
android:columnWidth="96dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:drawSelectorOnTop="true"
android:fastScrollEnabled="true"
android:id="@+id/gridView" />
tools:listitem="@layout/item_library" />
</FrameLayout>

View File

@ -1,25 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="match_parent"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="144dp"
android:id="@+id/thumbnailImageView"/>
</FrameLayout>
android:id="@+id/thumbnailImageView"
tools:src="@mipmap/ic_launcher"
tools:background="@color/md_red_100"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="48dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:id="@+id/footerLinearLayout">
android:layout_height="42dp"
android:id="@+id/footerLinearLayout"
android:background="@color/md_blue_100">
<TextView
android:layout_width="match_parent"
@ -27,9 +27,13 @@
android:layout_gravity="center_vertical"
android:ellipsize="middle"
android:maxLines="2"
android:textColor="@color/white"
android:textColor="@color/black_87pc"
android:textStyle="bold"
android:id="@+id/nameTextView" />
android:textSize="12sp"
android:id="@+id/nameTextView"
android:paddingRight="8dp"
android:paddingLeft="8dp"
tools:text="Sample name"/>
</LinearLayout>