diff --git a/app/build.gradle b/app/build.gradle index 8f2419d46..05233c8cd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,5 +31,8 @@ dependencies { compile 'com.android.support:design:25.3.1' compile 'com.android.support:support-vector-drawable:25.3.1' compile 'com.android.support:support-v4:25.3.1' + compile 'com.android.support:recyclerview-v7:25.3.1' + compile 'com.squareup.picasso:picasso:2.5.2' + testCompile 'junit:junit:4.12' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d402764c6..2b6530a95 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,7 +11,7 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@android:style/Theme.DeviceDefault"> + android:theme="@style/Theme.AppCompat"> { - public ImageAdapter(Context c) { - this.mContext = c; + private Context context; + private ArrayList lista; + + public ImageAdapter(Context context, ArrayList lista) { + this.lista = lista; + this.context = context; } - public int getCount() { - return mThumbIds.length; + @Override + public ImageAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { + View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row_layout, viewGroup, false); + return new ViewHolder(view); } - public Object getItem(int position) { - return null; + @Override + public void onBindViewHolder(ImageAdapter.ViewHolder viewHolder, int i) { + + viewHolder.tv_android.setText(lista.get(i)); + Picasso.with(context).load(R.drawable.sample_0).into(viewHolder.img_android); } - public long getItemId(int position) { - return 0; + @Override + public int getItemCount() { + return lista.size(); } - // create a new ImageView for each item referenced by the Adapter - public View getView(int position, View convertView, ViewGroup parent) { - ImageView imageView; - if (convertView == null) { - // if it's not recycled, initialize some attributes - imageView = new ImageView(mContext); - imageView.setLayoutParams(new GridView.LayoutParams(85, 85)); - imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); - imageView.setPadding(8, 8, 8, 8); - } else { - imageView = (ImageView) convertView; + public class ViewHolder extends RecyclerView.ViewHolder{ + private TextView tv_android; + private ImageView img_android; + public ViewHolder(View view) { + super(view); + + tv_android = (TextView)view.findViewById(R.id.tv_android); + img_android = (ImageView) view.findViewById(R.id.img_android); } - - imageView.setImageResource(mThumbIds[position]); - return imageView; } - // references to our images - private Integer[] mThumbIds = { - R.drawable.sample_2, R.drawable.sample_3, - R.drawable.sample_4, R.drawable.sample_5, - R.drawable.sample_6, R.drawable.sample_7, - R.drawable.sample_0, R.drawable.sample_1, - R.drawable.sample_2, R.drawable.sample_3, - R.drawable.sample_4, R.drawable.sample_5, - R.drawable.sample_6, R.drawable.sample_7, - R.drawable.sample_0, R.drawable.sample_1, - R.drawable.sample_2, R.drawable.sample_3, - R.drawable.sample_4, R.drawable.sample_5, - R.drawable.sample_6, R.drawable.sample_7 - }; -} +} \ No newline at end of file diff --git a/app/src/main/java/io/github/wulkanowy/activity/dashboard/marks/MarksFragment.java b/app/src/main/java/io/github/wulkanowy/activity/dashboard/marks/MarksFragment.java index 7751756d6..84d43e40d 100644 --- a/app/src/main/java/io/github/wulkanowy/activity/dashboard/marks/MarksFragment.java +++ b/app/src/main/java/io/github/wulkanowy/activity/dashboard/marks/MarksFragment.java @@ -5,20 +5,33 @@ import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.support.v7.widget.GridLayoutManager; +import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.GridView; -import android.widget.Toast; -import android.widget.AdapterView.OnItemClickListener; +import java.util.ArrayList; +import java.util.Arrays; import io.github.wulkanowy.R; public class MarksFragment extends Fragment { Activity mActivity; + + final String lista[] = { + "Donut", + "Eclair", + "Froyo", + "Gingerbread", + "Honeycomb", + "Ice Cream Sandwich", + "Jelly Bean", + "KitKat", + "Lollipop", + "Marshmallow" + }; @Override public void onAttach(Context context) { super.onAttach(context); @@ -36,15 +49,15 @@ public class MarksFragment extends Fragment { View view = inflater.inflate(R.layout.fragment_marks, container, false); - GridView gridview = (GridView) view.findViewById(R.id.gridview); - gridview.setAdapter(new ImageAdapter(view.getContext())); // uses the view to get the context instead of getActivity() + RecyclerView recyclerView = (RecyclerView)view.findViewById(R.id.card_recycler_view); + recyclerView.setHasFixedSize(true); + RecyclerView.LayoutManager layoutManager = new GridLayoutManager(view.getContext(),2); + recyclerView.setLayoutManager(layoutManager); + + ArrayList array = new ArrayList<>(Arrays.asList(lista)); + ImageAdapter adapter = new ImageAdapter(view.getContext(),array); + recyclerView.setAdapter(adapter); - gridview.setOnItemClickListener(new OnItemClickListener() { - public void onItemClick(AdapterView parent, View v, - int position, long id) { - Toast.makeText(mActivity,"HALLO", Toast.LENGTH_SHORT).show(); - } - }); return view; } diff --git a/app/src/main/res/drawable/sample_0.jpg b/app/src/main/res/drawable/sample_0.jpg deleted file mode 100644 index 9dd3bce88..000000000 Binary files a/app/src/main/res/drawable/sample_0.jpg and /dev/null differ diff --git a/app/src/main/res/drawable/sample_0.png b/app/src/main/res/drawable/sample_0.png new file mode 100644 index 000000000..db882ce63 Binary files /dev/null and b/app/src/main/res/drawable/sample_0.png differ diff --git a/app/src/main/res/layout/fragment_marks.xml b/app/src/main/res/layout/fragment_marks.xml index 3db405dcb..0566036f7 100644 --- a/app/src/main/res/layout/fragment_marks.xml +++ b/app/src/main/res/layout/fragment_marks.xml @@ -1,18 +1,14 @@ - + - + android:layout_height="match_parent"/> - + \ No newline at end of file diff --git a/app/src/main/res/layout/row_layout.xml b/app/src/main/res/layout/row_layout.xml new file mode 100644 index 000000000..c09f541c8 --- /dev/null +++ b/app/src/main/res/layout/row_layout.xml @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file