-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5668b3b
commit 2942ac5
Showing
12 changed files
with
259 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
MaterialSample/app/src/main/java/com/suleiman/material/adapter/DessertAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.suleiman.material.adapter; | ||
|
||
import android.content.Context; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import com.suleiman.material.R; | ||
import com.suleiman.material.model.Dessert; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by Suleiman on 02/03/17. | ||
*/ | ||
|
||
public class DessertAdapter extends RecyclerView.Adapter<DessertAdapter.DessertVh> { | ||
|
||
|
||
private List<Dessert> desserts = new ArrayList<>(); | ||
|
||
private Context context; | ||
|
||
public DessertAdapter(Context context) { | ||
this.context = context; | ||
|
||
desserts = Dessert.prepareDesserts( | ||
context.getResources().getStringArray(R.array.dessert_names), | ||
context.getResources().getStringArray(R.array.dessert_descriptions)); | ||
} | ||
|
||
@Override | ||
public DessertVh onCreateViewHolder(ViewGroup parent, int viewType) { | ||
LayoutInflater inflater = LayoutInflater.from(parent.getContext()); | ||
View view = inflater.inflate(R.layout.item_dessert, parent, false); | ||
return new DessertAdapter.DessertVh(view); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(DessertVh holder, int position) { | ||
Dessert dessert = desserts.get(position); | ||
|
||
holder.mName.setText(dessert.getName()); | ||
holder.mDescription.setText(dessert.getDescription()); | ||
holder.mFirstLetter.setText(String.valueOf(dessert.getFirstLetter())); | ||
|
||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return desserts == null ? 0 : desserts.size(); | ||
} | ||
|
||
public static class DessertVh extends RecyclerView.ViewHolder { | ||
|
||
private TextView mName; | ||
private TextView mDescription; | ||
private TextView mFirstLetter; | ||
|
||
public DessertVh(View itemView) { | ||
super(itemView); | ||
|
||
mName = (TextView) itemView.findViewById(R.id.txt_name); | ||
mDescription = (TextView) itemView.findViewById(R.id.txt_desc); | ||
mFirstLetter = (TextView) itemView.findViewById(R.id.txt_firstletter); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
MaterialSample/app/src/main/java/com/suleiman/material/model/Dessert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.suleiman.material.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by Suleiman on 02/03/17. | ||
*/ | ||
|
||
public class Dessert { | ||
|
||
private String name; | ||
private String description; | ||
private String firstLetter; | ||
|
||
public Dessert(String name, String description) { | ||
this.name = name; | ||
this.firstLetter = String.valueOf(name.charAt(0)); | ||
this.description = description; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public String getFirstLetter() { | ||
return firstLetter; | ||
} | ||
|
||
public void setFirstLetter(String firstLetter) { | ||
this.firstLetter = firstLetter; | ||
} | ||
|
||
public static List<Dessert> prepareDesserts(String[] names, String[] descriptions) { | ||
List<Dessert> desserts = new ArrayList<>(names.length); | ||
|
||
for (int i = 0; i < names.length; i++) { | ||
Dessert dessert = new Dessert(names[i], descriptions[i]); | ||
desserts.add(dessert); | ||
} | ||
|
||
return desserts; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
<gradient | ||
android:angle="90" | ||
android:endColor="@android:color/transparent" | ||
android:startColor="#66000000"/> | ||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="?attr/selectableItemBackground" | ||
android:clickable="true" | ||
android:orientation="horizontal" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingStart="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_horizontal_margin" | ||
tools:background="@android:color/white" | ||
tools:ignore="RtlSymmetry"> | ||
|
||
<TextView | ||
android:id="@+id/txt_firstletter" | ||
style="@style/TextAppearance.AppCompat.Headline" | ||
android:layout_width="40dp" | ||
android:layout_height="40dp" | ||
android:alpha="0.30" | ||
android:gravity="center" | ||
android:textStyle="bold" | ||
tools:text="N"/> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/txt_name" | ||
style="@style/TextAppearance.AppCompat.Subhead" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginEnd="@dimen/activity_horizontal_margin" | ||
android:layout_marginLeft="@dimen/activity_horizontal_margin" | ||
android:layout_marginRight="@dimen/activity_horizontal_margin" | ||
android:layout_marginStart="@dimen/activity_horizontal_margin" | ||
android:ellipsize="end" | ||
android:fontFamily="sans-serif-medium" | ||
tools:targetApi="jelly_bean" | ||
tools:text="Nougat"/> | ||
|
||
<TextView | ||
android:id="@+id/txt_desc" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="@dimen/activity_horizontal_margin" | ||
android:layout_marginEnd="@dimen/activity_horizontal_margin" | ||
android:layout_marginLeft="@dimen/activity_horizontal_margin" | ||
android:layout_marginRight="@dimen/activity_horizontal_margin" | ||
android:layout_marginStart="@dimen/activity_horizontal_margin" | ||
android:layout_marginTop="@dimen/activity_margin_half" | ||
android:ellipsize="end" | ||
android:maxLines="2" | ||
tools:text="A family of confections made with sugar or honey, roasted nuts, whipped egg whites, and sometimes chopped candied fruit. The consistency of nougat is chewy, and it is used in a variety of candy bars and chocolates."/> | ||
|
||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="1dp" | ||
android:alpha="0.12" | ||
android:background="@android:color/black"/> | ||
|
||
</LinearLayout> | ||
|
||
</LinearLayout> |
Oops, something went wrong.