Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion library/src/main/java/com/rampo/updatechecker/UpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ public class UpdateChecker implements ASyncCheckResult, UpdateCheckerResult {
static Store DEFAULT_STORE = Store.GOOGLE_PLAY;
static int DEFAULT_SUCCESSFUL_CHECKS_REQUIRED = 5;
static int DEFAULT_NOTICE_ICON_RES_ID = 0;
static int DEFAULT_DIALOG_STYLE_RES_ID = R.style.Theme_AppCompat_Dialog;
static Notice DEFAULT_NOTICE = Notice.DIALOG;

static Activity mActivity;
static Store mStore;
static int mSuccessfulChecksRequired;
static Notice mNotice;
static int mNoticeIconResId;
static int mDialogStyleResId;
static UpdateCheckerResult mLibraryResultCallaback;
static ASyncCheckResult mCheckResultCallback;
static boolean mCustomImplementation;
Expand All @@ -56,6 +58,7 @@ public UpdateChecker(Activity activity) {
mSuccessfulChecksRequired = DEFAULT_SUCCESSFUL_CHECKS_REQUIRED;
mNotice = DEFAULT_NOTICE;
mNoticeIconResId = DEFAULT_NOTICE_ICON_RES_ID;
mDialogStyleResId = DEFAULT_DIALOG_STYLE_RES_ID;
mCheckResultCallback = this;
mLibraryResultCallaback = this;
mCustomImplementation = false;
Expand Down Expand Up @@ -121,6 +124,20 @@ public static void setNoticeIcon(int noticeIconResId) {
}
}

/**
* Set the Dialog style. If you don't call this, the Dialog will have the default style.
*
* @param dialogStyleResId Res Id of the dialog style to be set.
* @see com.rampo.updatechecker.notice.Notification
* @see com.rampo.updatechecker.notice.Dialog
*/
public static void setDialogStyle(int dialogStyleResId) {
mDialogStyleResId = dialogStyleResId;
if (mCustomImplementation) {
throw new IllegalStateException("You can't set the notice Icon when you choose a custom implementation.\nThe Notice is controlled manually by you with the callbacks.\nTo call setNotice() use the UpdateChecker constructor with one argument.");
}
}

/**
* Start the process
*/
Expand Down Expand Up @@ -286,7 +303,7 @@ private void saveNumberOfChecksForUpdatedVersion(String versionDownloadable, int
* Show Dialog
*/
public void showDialog(String versionDownloadable) {
Dialog.show(mActivity, mStore, versionDownloadable, mNoticeIconResId);
Dialog.show(mActivity, mStore, versionDownloadable, mNoticeIconResId, mDialogStyleResId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
*/
package com.rampo.updatechecker.notice;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v7.view.ContextThemeWrapper;
import android.view.WindowManager;

import com.rampo.updatechecker.R;
Expand All @@ -38,15 +40,16 @@
*/
public class Dialog {

public static void show(final Context context, final Store store, final String versionDownloadable, final int dialogIconResId) {
public static void show(final Context context, final Store store, final String versionDownloadable, final int dialogIconResId, final int dialogStyleResId) {
try {
String storeName = null;
if (store == Store.GOOGLE_PLAY) {
storeName = context.getString(R.string.googlePlay);
} else if (store == Store.AMAZON) {
storeName = context.getString(R.string.amazonStore);
}
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
@SuppressLint("RestrictedApi")
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(context, dialogStyleResId));
String appName = null;
try {
appName = (String) context.getPackageManager().getApplicationLabel(context.getPackageManager().getApplicationInfo(context.getPackageName(), 0));
Expand Down