Skip to content

Commit

Permalink
init sample App
Browse files Browse the repository at this point in the history
Bug fixing
  • Loading branch information
nordan committed Jul 20, 2020
1 parent 9c10949 commit 7480c98
Show file tree
Hide file tree
Showing 14 changed files with 533 additions and 154 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Add this to your module's `build.gradle` file:
```gradle
dependencies {
...
implementation 'com.github.Dan629pl:nordan-material-dialog-android:1.0.4'
implementation 'com.github.Dan629pl:nordan-material-dialog-android:1.0.5'
}
```
<h1>Nordan Alert Dialog</h1>
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "Nordan Material Dialog v1.0.1"
versionName "Nordan Material Dialog v1.0.5"
}

buildTypes {
Expand Down
49 changes: 35 additions & 14 deletions app/src/main/java/com/nordan/dialog/NordanAlertDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;

import com.google.android.material.button.MaterialButton;
import com.google.android.material.textview.MaterialTextView;

import java.util.Optional;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import pl.droidsonroids.gif.GifImageView;
Expand All @@ -26,11 +30,13 @@ public static class Builder {
private String negativeBtnText;
private Activity activity;
private Animation animation;
private int icon;
private int headerIconResource;
private int dialogAccentColor;
private Bitmap headerIconDrawable;
private boolean isGif;
private NordanAlertDialogListener positiveListener;
private NordanAlertDialogListener negativeListener;
private int backgroundColor;
private int headerColor;
private boolean isCancelable;
private DialogType dialogType;

Expand All @@ -48,8 +54,13 @@ public Builder setDialogType(DialogType dialogType) {
return this;
}

public Builder setBackgroundColor(int bgColor) {
this.backgroundColor = bgColor;
public Builder setDialogAccentColor(int color) {
this.dialogAccentColor = color;
return this;
}

public Builder setHeaderColor(int bgColor) {
this.headerColor = bgColor;
return this;
}

Expand All @@ -69,7 +80,13 @@ public Builder setNegativeBtnText(String negativeBtnText) {
}

public Builder setIcon(int icon, boolean isGif) {
this.icon = icon;
this.headerIconResource = icon;
this.isGif = isGif;
return this;
}

public Builder setIcon(Bitmap icon, boolean isGif) {
this.headerIconDrawable = icon;
this.isGif = isGif;
return this;
}
Expand Down Expand Up @@ -139,23 +156,23 @@ public Dialog build() {
} else {
setCustomDialog(dialog, iconImg, view);
}
if (positiveBtnText != null) {
if (positiveBtnText != null && !positiveBtnText.isEmpty()) {
positiveButton.setText(positiveBtnText);
}
if (negativeBtnText != null) {
if (negativeBtnText != null && !negativeBtnText.isEmpty()) {
negativeButton.setText(negativeBtnText);
} else {
negativeButton.setVisibility(View.GONE);
}
if (positiveListener != null) {
if (positiveListener != null && positiveBtnText != null && !positiveBtnText.isEmpty()) {
positiveButton.setOnClickListener(click -> {
positiveListener.onClick();
dialog.dismiss();
});
} else {
positiveButton.setOnClickListener(click -> dialog.dismiss());
}
if (negativeListener != null) {
if (negativeListener != null && negativeBtnText != null && !negativeBtnText.isEmpty()) {
negativeButton.setVisibility(View.VISIBLE);
negativeButton.setOnClickListener(view1 -> {
negativeListener.onClick();
Expand All @@ -164,6 +181,10 @@ public Dialog build() {
} else {
negativeButton.setOnClickListener(click -> dialog.dismiss());
}
if (dialogAccentColor > 0) {
positiveButton.setBackgroundColor(activity.getColor(dialogAccentColor));
negativeButton.setTextColor(activity.getColor(dialogAccentColor));
}
return dialog;
}

Expand Down Expand Up @@ -199,20 +220,20 @@ private void setInformationDialog(GifImageView iconImg, View view) {

private void setCustomDialog(Dialog dialog, GifImageView iconImg, View view) {
RelativeLayout relativeHeader = dialog.findViewById(R.id.relative_header);
if (icon == 0 && backgroundColor == 0) {
if (headerIconResource == 0 && headerColor == 0 && headerIconDrawable == null) {
relativeHeader.setVisibility(View.GONE);
return;
}
if (icon != 0) {
iconImg.setImageResource(icon);
if (headerIconResource != 0) {
iconImg.setImageResource(headerIconResource);
iconImg.setVisibility(View.VISIBLE);
if (isGif) {
relativeHeader.getLayoutParams().height = 250;
iconImg.setScaleType(ScaleType.CENTER_CROP);
}
}
if (backgroundColor != 0) {
view.setBackgroundColor(backgroundColor);
if (headerColor != 0) {
view.setBackgroundColor(headerColor);
}
}

Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/nordan/dialog/NordanLoadingDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,34 @@
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Window;
import android.widget.ProgressBar;

import com.google.android.material.textview.MaterialTextView;

import java.util.Optional;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class NordanLoadingDialog {

public static Dialog createLoadingDialog(Activity activity, String loadingText) {
return createLoadingDialog(activity, loadingText, 0);
}

public static Dialog createLoadingDialog(Activity activity, String loadingText, int accentColor) {
Dialog loadingDialog = new Dialog(activity);
loadingDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
Optional.ofNullable(loadingDialog.getWindow())
.ifPresent(window -> window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)));
loadingDialog.setCancelable(false);
loadingDialog.setContentView(R.layout.nordan_loading_dialog);
((MaterialTextView) loadingDialog.findViewById(R.id.loading_text)).setText(loadingText);
ProgressBar loadingBar = loadingDialog.findViewById(R.id.progress_bar);
if (accentColor > 0) {
loadingBar.getIndeterminateDrawable().setColorFilter(activity.getColor(accentColor), android.graphics.PorterDuff.Mode.MULTIPLY);
}
return loadingDialog;
}
}
59 changes: 29 additions & 30 deletions app/src/main/res/layout/nordan_alert_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,38 @@
android:visibility="gone" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/relative_header"
android:padding="16dp">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:elegantTextHeight="true"
android:fontFamily="@font/product_sans_bold"
android:gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_below="@+id/relative_header"
android:padding="12dp">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:elegantTextHeight="true"
android:fontFamily="@font/product_sans_bold"
android:gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/dialog_tittle"
android:textAlignment="center"
android:textColor="@color/grayFontColor"
android:textSize="18sp" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_marginTop="16dp"
android:elegantTextHeight="true"
android:fontFamily="@font/product_sans_regular"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/dialog_message"
android:textAlignment="center"
android:textSize="16sp" />
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_marginTop="10dp"
android:elegantTextHeight="true"
android:fontFamily="@font/product_sans_regular"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/dialog_message"
android:textAlignment="center"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -76,11 +76,10 @@
android:orientation="horizontal"
android:weightSum="100">
<com.google.android.material.button.MaterialButton
android:id="@+id/negativeBtn"
style="@style/NordanDialogButtonTheme"
android:layout_marginEnd="20dp"
android:layout_weight="50"
android:text="@android:string/cancel" />
android:id="@+id/negativeBtn"
style="@style/NordanDialogButtonTextTheme"
android:layout_weight="50"
android:text="@android:string/cancel" />
<com.google.android.material.button.MaterialButton
android:id="@+id/positiveBtn"
style="@style/NordanDialogButtonTheme"
Expand Down
69 changes: 33 additions & 36 deletions app/src/main/res/layout/nordan_loading_dialog.xml
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:orientation="vertical">
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="10dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:minWidth="150dp"
android:minHeight="150dp"
android:orientation="vertical">
<include
android:id="@+id/progress_bar"
layout="@layout/main_progress_bar"
android:visibility="visible" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/loading_text"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:orientation="vertical">
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:fontFamily="@font/product_sans_regular"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Loading…"
android:textAlignment="center"
android:textSize="20sp" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
android:layout_centerInParent="true"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="10dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="12dp"
android:gravity="center"
android:orientation="horizontal">
<include
android:id="@+id/progress_bar"
layout="@layout/main_progress_bar"
android:visibility="visible" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/loading_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:fontFamily="@font/product_sans_regular"
android:gravity="center"
android:text="Loading…"
android:textAlignment="center"
android:textSize="24sp" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</RelativeLayout>
45 changes: 21 additions & 24 deletions app/src/main/res/values/style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,27 @@
<item name="colorAccent">@color/colorRed</item>
</style>


<style name="NordanDialogButtonTheme" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="singleLine">true</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:elegantTextHeight">true</item>
<item name="android:textColor">@color/grayFontColor</item>
<item name="fontFamily">@font/product_sans_bold</item>
</style>

<style name="NordanButtonTheme" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="singleLine">true</item>
<item name="android:elegantTextHeight">true</item>
<item name="android:textColor">@color/grayFontColor</item>
<item name="fontFamily">@font/product_sans_regular</item>
</style>

<style name="NordanTextBase">
<item name="android:gravity">center</item>
<item name="android:elegantTextHeight">true</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<style name="NordanDialogButtonTheme">
<item name="singleLine">true</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:elegantTextHeight">true</item>
<item name="fontFamily">@font/product_sans_bold</item>
</style>

<style name="NordanDialogButtonTextTheme" parent="Widget.MaterialComponents.Button.TextButton">
<item name="singleLine">true</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:elegantTextHeight">true</item>
<item name="fontFamily">@font/product_sans_bold</item>
</style>

<style name="NordanTextBase">
<item name="android:gravity">center</item>
<item name="android:elegantTextHeight">true</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>

<style name="NordanTextRegular" parent="NordanTextBase">
Expand Down
Loading

0 comments on commit 7480c98

Please sign in to comment.