From 6a16412a9a4177434cea80a4b6ea6e18416b5192 Mon Sep 17 00:00:00 2001 From: Mordag Date: Sat, 9 Dec 2017 20:54:15 +0100 Subject: [PATCH] Moved asDismissble to the parent builder --- .../org/hitogo/alert/core/AlertBuilder.java | 38 ++++++++++++++++--- .../alert/dialog/DialogAlertBuilder.java | 8 ---- .../hitogo/alert/popup/PopupAlertBuilder.java | 8 ---- .../hitogo/alert/view/ViewAlertBuilder.java | 34 ----------------- 4 files changed, 32 insertions(+), 56 deletions(-) diff --git a/library/src/main/java/org/hitogo/alert/core/AlertBuilder.java b/library/src/main/java/org/hitogo/alert/core/AlertBuilder.java index 624733c..3c0c19a 100644 --- a/library/src/main/java/org/hitogo/alert/core/AlertBuilder.java +++ b/library/src/main/java/org/hitogo/alert/core/AlertBuilder.java @@ -3,15 +3,18 @@ import android.os.Bundle; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.util.Log; import android.util.SparseArray; import org.hitogo.alert.view.ViewAlertBuilder; import org.hitogo.button.core.Button; +import org.hitogo.core.Hitogo; import org.hitogo.core.HitogoContainer; import org.hitogo.core.HitogoController; import java.lang.ref.WeakReference; +import java.security.InvalidParameterException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -39,6 +42,7 @@ public abstract class AlertBuilder { private String tag; private AlertType builderType; private Integer layoutRes; + private boolean isDismissible; public AlertBuilder(@NonNull Class targetClass, @NonNull Class paramClass, @@ -75,6 +79,7 @@ private void onProvidePrivateData(AlertParamsHolder holder) { privateBundle.putSerializable(AlertParamsKeys.TYPE_KEY, builderType); privateBundle.putSerializable(AlertParamsKeys.STATE_KEY, state); privateBundle.putSerializable(AlertParamsKeys.LAYOUT_RES_KEY, layoutRes); + privateBundle.putBoolean(AlertParamsKeys.IS_DISMISSIBLE_KEY, isDismissible); holder.provideVisibilityListener(visibilityListener); holder.provideTextMap(textMap); @@ -84,6 +89,33 @@ private void onProvidePrivateData(AlertParamsHolder holder) { protected abstract void onProvideData(AlertParamsHolder holder); + @NonNull + public T asDismissible(@Nullable Button closeButton) { + this.isDismissible = true; + + if (closeButton != null) { + this.closeButton = closeButton; + } + return (T) this; + } + + @NonNull + public T asDismissible() { + this.isDismissible = true; + + try { + this.closeButton = Hitogo.with(getContainer()) + .asActionButton() + .forViewAction() + .build(); + } catch (InvalidParameterException ex) { + Log.e(ViewAlertBuilder.class.getName(), "Cannot add default close button."); + Log.e(ViewAlertBuilder.class.getName(), "Reason: " + ex.getMessage()); + } + + return (T) this; + } + @NonNull public final T setController(HitogoController controller) { this.controller = controller; @@ -149,12 +181,6 @@ public final T addButton(@NonNull Button... buttons) { return (T) this; } - @NonNull - protected final T addCloseButton(@NonNull Button closeButton) { - this.closeButton = closeButton; - return (T) this; - } - @NonNull public final T setLayout(@LayoutRes Integer layoutRes) { this.layoutRes = layoutRes; diff --git a/library/src/main/java/org/hitogo/alert/dialog/DialogAlertBuilder.java b/library/src/main/java/org/hitogo/alert/dialog/DialogAlertBuilder.java index 9e2c191..c4f9659 100644 --- a/library/src/main/java/org/hitogo/alert/dialog/DialogAlertBuilder.java +++ b/library/src/main/java/org/hitogo/alert/dialog/DialogAlertBuilder.java @@ -19,7 +19,6 @@ public class DialogAlertBuilder extends AlertBuilder targetClass, @NonNull Class paramClass, @@ -27,12 +26,6 @@ public DialogAlertBuilder(@NonNull Class targetClass, super(targetClass, paramClass, container, type); } - @NonNull - public DialogAlertBuilder asDismissible() { - this.isDismissible = true; - return this; - } - @NonNull public DialogAlertBuilder asSimpleDialog(@NonNull String title, @NonNull String text) { super.setTitle(title); @@ -68,6 +61,5 @@ public DialogAlertBuilder setStyle(@Nullable @StyleRes Integer dialogThemeResId) @Override protected void onProvideData(AlertParamsHolder holder) { holder.provideInteger(DialogAlertParamsKeys.DIALOG_THEME_RES_ID, dialogThemeResId); - holder.provideBoolean(DialogAlertParamsKeys.IS_DISMISSIBLE_KEY, isDismissible); } } diff --git a/library/src/main/java/org/hitogo/alert/popup/PopupAlertBuilder.java b/library/src/main/java/org/hitogo/alert/popup/PopupAlertBuilder.java index c261fd5..9731a19 100644 --- a/library/src/main/java/org/hitogo/alert/popup/PopupAlertBuilder.java +++ b/library/src/main/java/org/hitogo/alert/popup/PopupAlertBuilder.java @@ -35,7 +35,6 @@ public class PopupAlertBuilder extends AlertBuilder targetClass, super(targetClass, paramClass, container, type); } - @NonNull - public PopupAlertBuilder asDismissible() { - this.isDismissible = true; - return this; - } - @NonNull public PopupAlertBuilder setAnchor(int anchorViewId) { this.anchorViewId = anchorViewId; @@ -183,7 +176,6 @@ protected void onProvideData(AlertParamsHolder holder) { holder.provideFloat(PopupAlertParamsKeys.ELEVATION_KEY, elevation); holder.provideString(PopupAlertParamsKeys.ANCHOR_VIEW_TAG_KEY, anchorViewTag); - holder.provideBoolean(PopupAlertParamsKeys.IS_DISMISSIBLE_KEY, isDismissible); holder.provideTransition(enterTransition); holder.provideTransition(exitTransition); diff --git a/library/src/main/java/org/hitogo/alert/view/ViewAlertBuilder.java b/library/src/main/java/org/hitogo/alert/view/ViewAlertBuilder.java index f082c68..18e1350 100644 --- a/library/src/main/java/org/hitogo/alert/view/ViewAlertBuilder.java +++ b/library/src/main/java/org/hitogo/alert/view/ViewAlertBuilder.java @@ -2,13 +2,8 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.util.Log; - -import java.security.InvalidParameterException; import org.hitogo.core.HitogoAnimation; -import org.hitogo.button.core.Button; -import org.hitogo.core.Hitogo; import org.hitogo.alert.core.AlertBuilder; import org.hitogo.core.HitogoContainer; import org.hitogo.alert.core.AlertImpl; @@ -24,7 +19,6 @@ public class ViewAlertBuilder extends AlertBuilder private Integer containerId; private Integer innerLayoutViewId; - private boolean isDismissible; private boolean closeOthers; private boolean dismissByClick; @@ -67,33 +61,6 @@ public ViewAlertBuilder withoutAnimations() { return this; } - @NonNull - public ViewAlertBuilder asDismissible(@Nullable Button closeButton) { - this.isDismissible = true; - - if (closeButton != null) { - return super.addCloseButton(closeButton); - } - return this; - } - - @NonNull - public ViewAlertBuilder asDismissible() { - this.isDismissible = true; - - try { - return super.addCloseButton(Hitogo.with(getContainer()) - .asActionButton() - .forViewAction() - .build()); - } catch (InvalidParameterException ex) { - Log.e(ViewAlertBuilder.class.getName(), "Cannot add default close button."); - Log.e(ViewAlertBuilder.class.getName(), "Reason: " + ex.getMessage()); - } - - return this; - } - @NonNull public ViewAlertBuilder asIgnoreLayout() { this.containerId = null; @@ -189,7 +156,6 @@ public final void showDelayed(long millis, boolean force) { protected void onProvideData(AlertParamsHolder holder) { holder.provideInteger(ViewAlertParamsKeys.CONTAINER_ID_KEY, containerId); holder.provideInteger(ViewAlertParamsKeys.INNER_LAYOUT_VIEW_ID_KEY, innerLayoutViewId); - holder.provideBoolean(ViewAlertParamsKeys.IS_DISMISSIBLE_KEY, isDismissible); holder.provideBoolean(ViewAlertParamsKeys.CLOSE_OTHERS_KEY, closeOthers); holder.provideBoolean(ViewAlertParamsKeys.DISMISS_BY_CLICK_KEY, dismissByClick);