Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Moved asDismissble to the parent builder
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderEggers committed Dec 9, 2017
1 parent 722afcd commit 6a16412
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 56 deletions.
38 changes: 32 additions & 6 deletions library/src/main/java/org/hitogo/alert/core/AlertBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,6 +42,7 @@ public abstract class AlertBuilder<T, A extends Alert> {
private String tag;
private AlertType builderType;
private Integer layoutRes;
private boolean isDismissible;

public AlertBuilder(@NonNull Class<? extends AlertImpl> targetClass,
@NonNull Class<? extends AlertParams> paramClass,
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,13 @@ public class DialogAlertBuilder extends AlertBuilder<DialogAlertBuilder, DialogA
private static final AlertType type = AlertType.DIALOG;

private Integer dialogThemeResId;
private boolean isDismissible;

public DialogAlertBuilder(@NonNull Class<? extends AlertImpl> targetClass,
@NonNull Class<? extends AlertParams> paramClass,
@NonNull HitogoContainer container) {
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);
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class PopupAlertBuilder extends AlertBuilder<PopupAlertBuilder, PopupAler

private Float elevation;
private String anchorViewTag;
private boolean isDismissible;

private Transition enterTransition;
private Transition exitTransition;
Expand All @@ -47,12 +46,6 @@ public PopupAlertBuilder(@NonNull Class<? extends AlertImpl> targetClass,
super(targetClass, paramClass, container, type);
}

@NonNull
public PopupAlertBuilder asDismissible() {
this.isDismissible = true;
return this;
}

@NonNull
public PopupAlertBuilder setAnchor(int anchorViewId) {
this.anchorViewId = anchorViewId;
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 0 additions & 34 deletions library/src/main/java/org/hitogo/alert/view/ViewAlertBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +19,6 @@ public class ViewAlertBuilder extends AlertBuilder<ViewAlertBuilder, ViewAlert>
private Integer containerId;
private Integer innerLayoutViewId;

private boolean isDismissible;
private boolean closeOthers;
private boolean dismissByClick;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6a16412

Please sign in to comment.