Skip to content

Commit

Permalink
fix: avoid priming message is showed always as long as permission is …
Browse files Browse the repository at this point in the history
…denied
  • Loading branch information
aitorvs committed Dec 17, 2015
1 parent 058090c commit cfcea76
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions library/src/main/java/com/aitorvs/android/allowme/AllowMe.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.preference.PreferenceManager;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
Expand Down Expand Up @@ -282,7 +284,7 @@ public void request(@IntRange(from = 1, to = Integer.MAX_VALUE) final int reques
}

// permission priming ?
if (this.primingMessage != null) {
if (this.primingMessage != null && shouldShowPrimingMessage()) {
// show the priming message
AlertDialog.Builder builder = new AlertDialog.Builder(safeActivity(), rationalThemeId)
.setTitle("")
Expand All @@ -296,7 +298,7 @@ public void onClick(DialogInterface dialog, int which) {
.setNegativeButton("Not now", null);

builder.show();
} else {
} else if (this.primingMessage == null){
// request permission directly
requestPermission(requestCode);
}
Expand All @@ -309,6 +311,16 @@ private void requestPermission(int requestCode) {
AllowMe.requestPermissionWithRational(this.callback, requestCode, rational, rationalThemeId, this.permission);
}
}

public boolean shouldShowPrimingMessage() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(safeActivity());
boolean value = sharedPreferences.getBoolean("should_show_priming", true);

// we've been called, set it to false again
sharedPreferences.edit().putBoolean("should_show_priming", false).apply();

return value;
}
}

}

0 comments on commit cfcea76

Please sign in to comment.