Skip to content

Commit

Permalink
Merge pull request #3 from TakuSemba/make-title-nullable
Browse files Browse the repository at this point in the history
make title nullable
  • Loading branch information
takahirom authored Apr 18, 2018
2 parents 6edfa4c + b297ba4 commit b3985ac
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class DebugApp extends App {
@Override public void onCreate() {
super.onCreate();

final SimpleItem item = new SimpleItem.Builder("all: this is the title")
final SimpleItem item = new SimpleItem.Builder()
.title("all: this is the title")
.text("this is the text")
.image(R.drawable.ic_list_black_24dp)
.clickListener(new View.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.view.View;

public class SimpleItem {
@NonNull public final String title;
@Nullable public final String title;
@Nullable public final String text;
@Nullable public final View.OnClickListener clickListener;
@DrawableRes public final int image;
Expand All @@ -24,8 +24,12 @@ public static final class Builder {
private View.OnClickListener clickListener;
private int image;

public Builder(@NonNull String title) {
public Builder() {
}

public Builder title(String title) {
this.title = title;
return this;
}

public Builder text(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public SimpleItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int vi
@Override public void onBindViewHolder(@NonNull final SimpleItemViewHolder holder, int position) {
final SimpleItem item = items.get(position);
holder.title.setText(item.title);
holder.title.setVisibility(item.title == null ? View.GONE : View.VISIBLE);
holder.text.setText(item.text);
holder.text.setVisibility(item.text == null ? View.GONE : View.VISIBLE);
holder.image.setImageResource(item.image);
Expand Down
11 changes: 10 additions & 1 deletion hyperion-simple-item/src/main/res/layout/layout_simple_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
app:layout_constraintTop_toTopOf="parent"
app:tint="@color/hype_plugin_color_selector"
tools:src="@android:drawable/alert_light_frame"
tools:visibility="visible"
/>
<TextView
android:id="@+id/title"
Expand All @@ -40,20 +41,28 @@
app:layout_goneMarginLeft="0dp"
app:layout_goneMarginStart="0dp"
tools:text="title"
tools:visibility="visible"
/>
<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="28dp"
android:layout_marginRight="8dp"
android:layout_marginStart="28dp"
android:duplicateParentState="true"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@color/hype_plugin_color_selector"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/title"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toEndOf="@id/image"
app:layout_constraintTop_toBottomOf="@id/title"
app:layout_constraintVertical_chainStyle="packed"
app:layout_goneMarginLeft="0dp"
app:layout_goneMarginStart="0dp"
tools:text="text\nThis can long text.This can long text.This can long text.This can long text.This can long text.This can long text."
tools:visibility="visible"
/>
</android.support.constraint.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
public class DebugApp extends App {
@Override public void onCreate() {
super.onCreate();
final SimpleItem onlyTitleItem = new SimpleItem.Builder("only title: title")
final SimpleItem onlyTitleItem = new SimpleItem.Builder()
.text("this test description")
.clickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Toast.makeText(DebugApp.this, "click 1",Toast.LENGTH_SHORT).show();
}
})
.build();
SimpleItemHyperionPlugin.addItem(onlyTitleItem);
final SimpleItem titleTextItem = new SimpleItem.Builder("title and text: this is the title")
final SimpleItem titleTextItem = new SimpleItem.Builder()
.title("title and text: this is the title")
.text("this is the text")
.clickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Expand All @@ -26,7 +28,8 @@ public class DebugApp extends App {
})
.build();
SimpleItemHyperionPlugin.addItem(titleTextItem);
final SimpleItem imageItem = new SimpleItem.Builder("all: this is the title")
final SimpleItem imageItem = new SimpleItem.Builder()
.title("all: this is the title")
.text("this is the text")
.image(R.drawable.ic_list_black_24dp)
.clickListener(new View.OnClickListener() {
Expand Down

0 comments on commit b3985ac

Please sign in to comment.