Skip to content

Commit

Permalink
Merge pull request #17 from OussEmaDevCode/issue-#16
Browse files Browse the repository at this point in the history
Fix #16 - Lack of default text
  • Loading branch information
Pradyuman7 authored Nov 1, 2020
2 parents 371fa4b + 4304b2d commit 4b24a42
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
16 changes: 8 additions & 8 deletions app/src/main/java/com/pd/snickers/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,57 +34,57 @@ public void onClick(View v) {
findViewById(R.id.button_success).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ChocoBar.builder().setActivity(MainActivity.this).setText("GREEN").setDuration(ChocoBar.LENGTH_SHORT).green().show();
ChocoBar.builder().setActivity(MainActivity.this).setDuration(ChocoBar.LENGTH_SHORT).green().show();
}
});

findViewById(R.id.button_info).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Snackbar warningSnackBar = ChocoBar.builder().setActivity(MainActivity.this).setText("ORANGE").setDuration(ChocoBar.LENGTH_LONG).orange();
Snackbar warningSnackBar = ChocoBar.builder().setActivity(MainActivity.this).setDuration(ChocoBar.LENGTH_LONG).orange();
warningSnackBar.show();
}
});

findViewById(R.id.button_warning).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ChocoBar.builder().setView(v).setText("CYAN").centerText().setDuration(ChocoBar.LENGTH_LONG).cyan().show();
ChocoBar.builder().setView(v).centerText().setDuration(ChocoBar.LENGTH_LONG).cyan().show();
}
});

findViewById(R.id.button_error).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ChocoBar.builder().setView(v).setText("RED").setDuration(ChocoBar.LENGTH_INDEFINITE).setActionText(android.R.string.ok).red().show();
ChocoBar.builder().setView(v).setDuration(ChocoBar.LENGTH_INDEFINITE).setActionText(android.R.string.ok).red().show();
}
});

findViewById(R.id.button_good).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ChocoBar.builder().setView(v).setText("GRAY_GOOD").centerText().setDuration(ChocoBar.LENGTH_LONG).good().show();
ChocoBar.builder().setView(v).centerText().setDuration(ChocoBar.LENGTH_LONG).good().show();
}
});

findViewById(R.id.button_bad).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ChocoBar.builder().setView(v).setText("GRAY_BAD").centerText().setDuration(ChocoBar.LENGTH_LONG).bad().show();
ChocoBar.builder().setView(v).centerText().setDuration(ChocoBar.LENGTH_LONG).bad().show();
}
});

findViewById(R.id.button_off_notification).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ChocoBar.builder().setView(v).setText("Black").centerText().setDuration(ChocoBar.LENGTH_LONG).black().show();
ChocoBar.builder().setView(v).centerText().setDuration(ChocoBar.LENGTH_LONG).black().show();
}
});

findViewById(R.id.button_love).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ChocoBar.builder().setView(v).setText("Love").centerText().setDuration(ChocoBar.LENGTH_LONG).love().show();
ChocoBar.builder().setView(v).centerText().setDuration(ChocoBar.LENGTH_LONG).love().show();
}
});

Expand Down
33 changes: 22 additions & 11 deletions chocobar/src/main/java/com/pd/chocobar/ChocoBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,28 @@ public class ChocoBar {

private enum Type {

DEFAULT(null, null, null),
GREEN(Color.parseColor("#388E3C"), R.drawable.check_mark, Color.WHITE),
RED(Color.parseColor("#D50000"), R.drawable.cross_mark, Color.WHITE),
CYAN(Color.parseColor("#e0ffff"), R.drawable.info_mark, Color.WHITE),
ORANGE(Color.parseColor("#ffa500"), R.drawable.warning_mark, Color.BLACK),
GOOD(Color.parseColor("#C5BEBE"), R.drawable.good_mark, Color.WHITE),
BAD(Color.parseColor("#C5BEBE"), R.drawable.bad_mark, Color.WHITE),
BLACK(Color.parseColor("#000000"), R.drawable.off_notification_mark, Color.WHITE),
LOVE(Color.parseColor("#E8290B"), R.drawable.ic_love, Color.BLACK);
DEFAULT(null, null, null, null),
GREEN(Color.parseColor("#388E3C"), R.drawable.check_mark, Color.WHITE, "SUCCESS !"),
RED(Color.parseColor("#D50000"), R.drawable.cross_mark, Color.WHITE, "ERROR !"),
CYAN(Color.parseColor("#e0ffff"), R.drawable.info_mark, Color.WHITE, "CYAN"),
ORANGE(Color.parseColor("#ffa500"), R.drawable.warning_mark, Color.BLACK, "WARNING !"),
GOOD(Color.parseColor("#C5BEBE"), R.drawable.good_mark, Color.WHITE, "GRAY_GOOD"),
BAD(Color.parseColor("#C5BEBE"), R.drawable.bad_mark, Color.WHITE, "GRAY_BAD"),
BLACK(Color.parseColor("#000000"), R.drawable.off_notification_mark, Color.WHITE, "Black"),
LOVE(Color.parseColor("#E8290B"), R.drawable.ic_love, Color.BLACK, "LOVE");

private Integer color;
private Integer iconResId;
private Integer standardTextColor;
private CharSequence text;

Type(@ColorInt Integer color, @DrawableRes Integer iconResId, @ColorInt Integer standardTextColor) {
Type(@ColorInt Integer color, @DrawableRes Integer iconResId, @ColorInt Integer standardTextColor, CharSequence text) {
this.color = color;

this.iconResId = iconResId;
this.standardTextColor = standardTextColor;

this.text = text;
}

public Integer getColor() {
Expand All @@ -74,6 +77,10 @@ public Drawable getIcon(Context context) {
public Integer getStandardTextColor() {
return standardTextColor;
}

public CharSequence getText() {
return text;
}
}

private final Builder builder;
Expand All @@ -84,6 +91,10 @@ private ChocoBar(Builder builder) {

private Snackbar make() {

if(builder.text == null) {
builder.text = builder.type.getText();
}

Snackbar chocolate = Snackbar.make(builder.view, builder.text, builder.duration);

if (builder.actionClickListener != null || builder.actionText != null) {
Expand Down Expand Up @@ -221,7 +232,7 @@ public static class Builder {
private View view = null;
private Type type = Type.DEFAULT;
private int duration = Snackbar.LENGTH_SHORT;
private CharSequence text = "";
private CharSequence text = null;
private int textResId = 0;
private Integer textColor = null;
private ColorStateList textColors = null;
Expand Down

0 comments on commit 4b24a42

Please sign in to comment.