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

Commit

Permalink
Reverted some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderEggers committed Dec 9, 2017
1 parent 2f9c38e commit 35d7208
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 32 deletions.
38 changes: 6 additions & 32 deletions library/src/main/java/org/hitogo/alert/core/AlertBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
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 @@ -42,7 +39,6 @@ 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 @@ -79,7 +75,6 @@ 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 @@ -89,33 +84,6 @@ 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 @@ -181,6 +149,12 @@ 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,13 +19,20 @@ 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 @@ -61,5 +68,6 @@ 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,6 +35,7 @@ public class PopupAlertBuilder extends AlertBuilder<PopupAlertBuilder, PopupAler

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

private Transition enterTransition;
private Transition exitTransition;
Expand All @@ -46,6 +47,12 @@ 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 @@ -176,6 +183,7 @@ 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: 34 additions & 0 deletions library/src/main/java/org/hitogo/alert/view/ViewAlertBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

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 @@ -19,6 +24,7 @@ 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 @@ -61,6 +67,33 @@ 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 @@ -156,6 +189,7 @@ 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 35d7208

Please sign in to comment.