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.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.GridView;
import java.util.ArrayList; import java.util.ArrayList;
import butterknife.Bind;
import butterknife.ButterKnife;
import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.entities.Manga;
import eu.kanade.mangafeed.ui.activity.BaseActivity; import eu.kanade.mangafeed.ui.activity.BaseActivity;
import eu.kanade.mangafeed.ui.adapter.LibraryAdapter;
public class LibraryFragment extends Fragment { public class LibraryFragment extends Fragment {
@Bind(R.id.gridView)
GridView grid;
public static LibraryFragment newInstance() { public static LibraryFragment newInstance() {
LibraryFragment fragment = new LibraryFragment(); LibraryFragment fragment = new LibraryFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
@ -21,35 +28,26 @@ public class LibraryFragment extends Fragment {
return 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 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_library, container, false); 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; 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" <FrameLayout
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent" xmlns:tools="http://schemas.android.com/tools"
tools:context="eu.kanade.mangafeed.ui.fragment.LibraryFragment"> android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView <GridView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="4dp" android:id="@+id/gridView"
android:padding="10dp"
android:clipToPadding="false" android:clipToPadding="false"
android:verticalSpacing="4dp" android:verticalSpacing="4dp"
android:horizontalSpacing="4dp" android:horizontalSpacing="8dp"
android:columnWidth="96dp" android:columnWidth="96dp"
android:numColumns="auto_fit" android:numColumns="auto_fit"
android:stretchMode="columnWidth" android:stretchMode="columnWidth"
android:drawSelectorOnTop="true"
android:fastScrollEnabled="true" android:fastScrollEnabled="true"
android:id="@+id/gridView" /> tools:listitem="@layout/item_library" />
</FrameLayout> </FrameLayout>

View File

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