Skip to content

Commit

Permalink
* don't force age confirmation for non personalised ads
Browse files Browse the repository at this point in the history
  • Loading branch information
MFlisar committed May 22, 2018
1 parent 98037c1 commit 49cbb77
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ repositories {
2. add the compile statement to your module's `build.gradle`:
```groovy
dependencies {
implementation 'com.github.MFlisar:GDPRDialog:0.2'
implementation 'com.github.MFlisar:GDPRDialog:0.3'
}
```

Expand All @@ -62,7 +62,7 @@ GDPRSetup setup = new GDPRSetup(GDPR.ADMOB_NETWORK); // add all networks you use
// optionally change setup:
// setup.withAllowNoConsent(true);
// setup.withPaidVersion(allowNonPersonalisedOptionAsWell);
// setup.withAskForAge(true);
// setup.withExplicitAgeConfirmation(true);
// setup.withCheckRequestLocation(true);
GDPR.getInstance().checkIfNeedsToBeShown(this /* extends AppCompatActivity & GDPR.IGDPRCallback */, setup);
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void onConsentInfoUpdate(GDPRConsent consentState, boolean isNewState) {
// never happens!
break;
case NO_CONSENT:
Toast.makeText(this, "User does NOT accept ANY ads - depending on oyur setup he may want to buy the app though, handle this!", Toast.LENGTH_LONG).show();
Toast.makeText(this, "User does NOT accept ANY ads - depending on your setup he may want to buy the app though, handle this!", Toast.LENGTH_LONG).show();
break;
case NON_PERSONAL_CONSENT_ONLY:
Toast.makeText(this, "User accepts NON PERSONAL ads", Toast.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void onClick(View v)
setup.withPaidVersion(cbAllowNonPersonalisedForPaidVersions.isChecked());
}
if (cbAskForAge.isChecked()) {
setup.withAskForAgeConfirmation(true);
setup.withExplicitAgeConfirmation(true);
}
if (cbCheckRequestLocation.isChecked()) {
setup.withCheckRequestLocation(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public <T extends AppCompatActivity & IGDPRCallback> void checkIfNeedsToBeShown(
checkConsent = true;
break;
case NO_CONSENT:
if (!setup.allowNoConsent()) {
if (!setup.allowAnyNoConsent()) {
checkConsent = true;
break;
}
Expand Down
20 changes: 12 additions & 8 deletions library/src/main/java/com/michaelflisar/gdprdialog/GDPRSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class GDPRSetup implements Parcelable {
private boolean mAllowNoConsent = false;
private GDPRNetwork mAdNetworks[];

private boolean mAskForAgeConfirmation = false;
private boolean mExplicitAgeConfirmation = false;
private boolean mNoToolbarTheme = false;
private boolean mCheckRequestLocation = false;

Expand All @@ -33,8 +33,8 @@ public GDPRSetup withAllowNoConsent(boolean allowNoConsent) {
return this;
}

public GDPRSetup withAskForAgeConfirmation(boolean askForAgeConfirmation) {
mAskForAgeConfirmation = askForAgeConfirmation;
public GDPRSetup withExplicitAgeConfirmation(boolean explicitAgeConfirmation) {
mExplicitAgeConfirmation = explicitAgeConfirmation;
return this;
}

Expand Down Expand Up @@ -77,11 +77,15 @@ public final boolean allowNonPersonalisedForPaidVersion() {
}

public final boolean allowNoConsent() {
return mAllowNoConsent || mAllowNonPersonalisedForPaidVersion;
return mAllowNoConsent;
}

public final boolean askForAgeConfirmation() {
return mAskForAgeConfirmation;
public final boolean allowAnyNoConsent() {
return mAllowNoConsent || mAllowNonPersonalisedForPaidVersion;
}

public final boolean explicitAgeConfirmation() {
return mExplicitAgeConfirmation;
}

public final boolean noToolbarTheme() {
Expand Down Expand Up @@ -114,7 +118,7 @@ public GDPRSetup(Parcel in) {
for (int i = 0; i < adNetworks.length; i++) {
mAdNetworks[i] = (GDPRNetwork)adNetworks[i];
}
mAskForAgeConfirmation = in.readByte() == 1;
mExplicitAgeConfirmation = in.readByte() == 1;
mNoToolbarTheme = in.readByte() == 1;
mCheckRequestLocation = in.readByte() == 1;
}
Expand All @@ -130,7 +134,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mAllowNonPersonalisedForPaidVersion ? (byte) 1 : 0);
dest.writeInt(mAllowNoConsent ? (byte) 1 : 0);
dest.writeParcelableArray(mAdNetworks, 0);
dest.writeByte(mAskForAgeConfirmation ? (byte) 1 : 0);
dest.writeByte(mExplicitAgeConfirmation ? (byte) 1 : 0);
dest.writeByte(mNoToolbarTheme ? (byte) 1 : 0);
dest.writeByte(mCheckRequestLocation ? (byte) 1 : 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public GDPR.IGDPRCallback getCallback() {
}

public boolean shouldCloseApp() {
return mSelectedConsent == null || (mSelectedConsent == GDPRConsent.NO_CONSENT && mSetup.allowNoConsent());
return mSelectedConsent == null || (mSelectedConsent == GDPRConsent.NO_CONSENT && !mSetup.allowAnyNoConsent());
}

public void init(Activity activity, View view, IOnFinishView onFinishViewListener) {
Expand All @@ -91,7 +91,7 @@ public void init(Activity activity, View view, IOnFinishView onFinishViewListene
final TextView tvAdsInfo = view.findViewById(R.id.tvAdsInfo);
final CheckBox cbAge = view.findViewById(R.id.cbAge);
String text = activity.getString(R.string.gdpr_dialog_text_part1, mSetup.getNetworksCommaSeperated(activity, true));
if (mSetup.askForAgeConfirmation()) {
if (mSetup.explicitAgeConfirmation()) {
text += activity.getString(R.string.gdpr_dialog_text_part2_no_age);
} else {
text += activity.getString(R.string.gdpr_dialog_text_part2_with_age);
Expand All @@ -111,7 +111,7 @@ public void init(Activity activity, View view, IOnFinishView onFinishViewListene
tvAdsInfo.setVisibility(View.GONE);
}

if (!mSetup.askForAgeConfirmation()) {
if (!mSetup.explicitAgeConfirmation()) {
cbAge.setVisibility(View.GONE);
} else {
cbAge.setChecked(mAgeConfirmed);
Expand All @@ -136,7 +136,7 @@ public void init(Activity activity, View view, IOnFinishView onFinishViewListene
// ------------------

view.findViewById(R.id.btAgree).setOnClickListener(v -> {
if (!isAgeValid(v.getContext())) {
if (!isAgeValid(v.getContext(), true)) {
return;
}
mSelectedConsent = GDPRConsent.PERSONAL_CONSENT;
Expand All @@ -145,7 +145,7 @@ public void init(Activity activity, View view, IOnFinishView onFinishViewListene
});

view.findViewById(R.id.btDisagree).setOnClickListener(v -> {
if (!isAgeValid(v.getContext())) {
if (!isAgeValid(v.getContext(), false)) {
return;
}
if (mSetup.hasPaidVersion()) {
Expand All @@ -164,7 +164,7 @@ public void init(Activity activity, View view, IOnFinishView onFinishViewListene
updateSelectedPage(vfFlipper, view);
});

if (!mSetup.allowNoConsent()) {
if (!mSetup.allowAnyNoConsent()) {
btNoConsentAtAll.setVisibility(View.GONE);
} else {
btNoConsentAtAll.setOnClickListener(v -> {
Expand Down Expand Up @@ -205,9 +205,10 @@ public void reset() {
// Helper function
// ---------------

private boolean isAgeValid(Context context) {
if (mSetup.askForAgeConfirmation()) {
if (!mAgeConfirmed) {
private boolean isAgeValid(Context context, boolean agree) {
if (mSetup.explicitAgeConfirmation()) {
// we only need to check age for personalised ads
if ((agree && !mAgeConfirmed)) {// || (!agree && mSetup.hasPaidVersion() && mSetup.allowNonPersonalisedForPaidVersion())) {
Toast.makeText(context, R.string.gdpr_age_not_confirmed, Toast.LENGTH_LONG).show();
return false;
}
Expand Down

0 comments on commit 49cbb77

Please sign in to comment.