Skip to content

Commit

Permalink
Replace Dialog with AlertDialog to fix missing title issue (Close #37)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDibrivnyy committed Dec 7, 2017
1 parent f53ff56 commit 86ee18a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
5 changes: 4 additions & 1 deletion library/build.gradle
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply from: "quality.gradle"

group='com.github.eggheadgames'
group = 'com.github.eggheadgames'

android {
compileSdkVersion 25
Expand All @@ -22,6 +22,9 @@ android {
}
lintOptions {
warningsAsErrors true

disable 'OldTargetApi'
disable 'GradleDependency'
}
}

Expand Down
43 changes: 23 additions & 20 deletions library/src/main/java/com/eggheadgames/siren/SirenAlertWrapper.java
@@ -1,8 +1,10 @@
package com.eggheadgames.siren;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.app.AlertDialog;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
Expand All @@ -17,7 +19,6 @@ public class SirenAlertWrapper {
private final String mMinAppVersion;
private final SirenSupportedLocales mLocale;
private final SirenHelper mSirenHelper;
private int mTheme;

public SirenAlertWrapper(Activity activity, ISirenListener sirenListener, SirenAlertType sirenAlertType,
String minAppVersion, SirenSupportedLocales locale, SirenHelper sirenHelper) {
Expand All @@ -29,12 +30,6 @@ public SirenAlertWrapper(Activity activity, ISirenListener sirenListener, SirenA
this.mActivityRef = new WeakReference<>(activity);
}

@SuppressWarnings("unused")
public SirenAlertWrapper(Activity activity, ISirenListener sirenListener, SirenAlertType sirenAlertType,
String minAppVersion, SirenSupportedLocales locale, SirenHelper sirenHelper, int theme) {
this(activity, sirenListener, sirenAlertType, minAppVersion, locale, sirenHelper);
this.mTheme = theme;
}

public void show() {
Activity activity = mActivityRef.get();
Expand All @@ -43,25 +38,33 @@ public void show() {
mSirenListener.onError(new NullPointerException("activity reference is null"));
}
} else if (Build.VERSION.SDK_INT >= 17 && !activity.isDestroyed() || Build.VERSION.SDK_INT < 17 && !activity.isFinishing()) {
Dialog dialog;
if (mTheme > 0) {
dialog = new Dialog(activity, mTheme);
} else {
dialog = new Dialog(activity);
}
setupDialog(dialog);
dialog.setCancelable(false);
dialog.show();

AlertDialog alertDialog = initDialog(activity);
setupDialog(alertDialog);

if (mSirenListener != null) {
mSirenListener.onShowUpdateDialog();
}
}
}

private void setupDialog(final Dialog dialog) {
dialog.setTitle(mSirenHelper.getLocalizedString(mActivityRef.get(), R.string.update_available, mLocale));
dialog.setContentView(R.layout.siren_dialog);
@SuppressLint("InflateParams")
private AlertDialog initDialog(Activity activity) {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(activity);

alertBuilder.setTitle(mSirenHelper.getLocalizedString(mActivityRef.get(), R.string.update_available, mLocale));
alertBuilder.setCancelable(false);

View dialogView = LayoutInflater.from(activity).inflate(R.layout.siren_dialog, null);
alertBuilder.setView(dialogView);

AlertDialog alertDialog = alertBuilder.create();
alertDialog.show();

return alertDialog;
}

private void setupDialog(final AlertDialog dialog) {
TextView message = (TextView) dialog.findViewById(R.id.tvSirenAlertMessage);
Button update = (Button) dialog.findViewById(R.id.btnSirenUpdate);
Button nextTime = (Button) dialog.findViewById(R.id.btnSirenNextTime);
Expand Down

0 comments on commit 86ee18a

Please sign in to comment.