fab support for all notify types

This commit is contained in:
Vincent Breitmoser 2015-02-28 02:30:59 +01:00
parent e4d91de8d2
commit f3710b12f6

View File

@ -47,24 +47,8 @@ public class Notify {
*/
public static void showNotify(final Activity activity, CharSequence text, Style style) {
Snackbar bar = Snackbar.with(activity)
.text(text)
.type(SnackbarType.MULTI_LINE)
.duration(SnackbarDuration.LENGTH_LONG);
if (activity instanceof FabContainer) {
bar.eventListener(new EventListenerAdapter() {
@Override
public void onShow(Snackbar snackbar) {
((FabContainer) activity).fabMoveUp(snackbar.getHeight());
}
@Override
public void onDismiss(Snackbar snackbar) {
((FabContainer) activity).fabRestorePosition();
}
});
}
Snackbar bar = getSnackbar(activity)
.text(text);
switch (style) {
case OK:
@ -82,9 +66,9 @@ public class Notify {
}
public static Showable createNotify (Activity activity, int resId, int duration, Style style) {
final Snackbar bar = Snackbar.with(activity)
.text(resId)
.type(SnackbarType.MULTI_LINE);
final Snackbar bar = getSnackbar(activity)
.text(resId);
if (duration == LENGTH_INDEFINITE) {
bar.duration(SnackbarDuration.LENGTH_INDEFINITE);
} else {
@ -118,16 +102,17 @@ public class Notify {
public static Showable createNotify(Activity activity, String msg, int duration, Style style,
final ActionListener listener, int resIdAction) {
final Snackbar bar = Snackbar.with(activity)
final Snackbar bar = getSnackbar(activity)
.text(msg)
.actionLabel(resIdAction)
.type(SnackbarType.MULTI_LINE)
.actionListener(new ActionClickListener() {
@Override
public void onActionClicked(Snackbar snackbar) {
listener.onAction();
}
});
if (duration == LENGTH_INDEFINITE) {
bar.duration(SnackbarDuration.LENGTH_INDEFINITE);
} else {
@ -165,6 +150,27 @@ public class Notify {
showNotify(activity, activity.getResources().getText(resId), style);
}
private static Snackbar getSnackbar(final Activity activity) {
Snackbar bar = Snackbar.with(activity)
.type(SnackbarType.MULTI_LINE)
.duration(SnackbarDuration.LENGTH_LONG);
if (activity instanceof FabContainer) {
bar.eventListener(new EventListenerAdapter() {
@Override
public void onShow(Snackbar snackbar) {
((FabContainer) activity).fabMoveUp(snackbar.getHeight());
}
@Override
public void onDismiss(Snackbar snackbar) {
((FabContainer) activity).fabRestorePosition();
}
});
}
return bar;
}
public interface Showable {
public void show();