Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuklis committed Apr 26, 2024
1 parent 4d4f3ed commit 3be0912
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

import androidx.core.util.Supplier;
import com.getcapacitor.JSArray;
import com.getcapacitor.JSObject;
Expand All @@ -19,7 +18,6 @@
import com.google.android.ump.ConsentRequestParameters;
import com.google.android.ump.FormError;
import com.google.android.ump.UserMessagingPlatform;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -36,13 +34,13 @@ public AdConsentExecutor(
super(contextSupplier, activitySupplier, notifyListenersFunction, pluginLogTag, "AdConsentExecutor");
}

public boolean canShowPersonalizedAds(){
public boolean canShowPersonalizedAds() {
Context context = contextSupplier.get();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
String purposeConsent = prefs.getString("IABTCF_PurposeConsents", "");
String vendorConsent = prefs.getString("IABTCF_VendorConsents","");
String vendorLI = prefs.getString("IABTCF_VendorLegitimateInterests","");
String purposeLI = prefs.getString("IABTCF_PurposeLegitimateInterests","");
String vendorConsent = prefs.getString("IABTCF_VendorConsents", "");
String vendorLI = prefs.getString("IABTCF_VendorLegitimateInterests", "");
String purposeLI = prefs.getString("IABTCF_PurposeLegitimateInterests", "");

int googleId = 755;
boolean hasGoogleVendorConsent = hasAttribute(vendorConsent, googleId);
Expand All @@ -59,17 +57,19 @@ public boolean canShowPersonalizedAds(){
indexesLI.add(9);
indexesLI.add(10);

return hasConsentFor(indexes, purposeConsent, hasGoogleVendorConsent)
&& hasConsentOrLegitimateInterestFor(indexesLI, purposeConsent, purposeLI, hasGoogleVendorConsent, hasGoogleVendorLI);

return (
hasConsentFor(indexes, purposeConsent, hasGoogleVendorConsent) &&
hasConsentOrLegitimateInterestFor(indexesLI, purposeConsent, purposeLI, hasGoogleVendorConsent, hasGoogleVendorLI)
);
}
public boolean canShowAds(){

public boolean canShowAds() {
Context context = contextSupplier.get();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
String purposeConsent = prefs.getString("IABTCF_PurposeConsents", "");
String vendorConsent = prefs.getString("IABTCF_VendorConsents","");
String vendorLI = prefs.getString("IABTCF_VendorLegitimateInterests","");
String purposeLI = prefs.getString("IABTCF_PurposeLegitimateInterests","");
String vendorConsent = prefs.getString("IABTCF_VendorConsents", "");
String vendorLI = prefs.getString("IABTCF_VendorLegitimateInterests", "");
String purposeLI = prefs.getString("IABTCF_PurposeLegitimateInterests", "");

int googleId = 755;
boolean hasGoogleVendorConsent = hasAttribute(vendorConsent, googleId);
Expand All @@ -84,9 +84,10 @@ public boolean canShowAds(){
indexesLI.add(9);
indexesLI.add(10);

return hasConsentFor(indexes, purposeConsent, hasGoogleVendorConsent)
&& hasConsentOrLegitimateInterestFor(indexesLI, purposeConsent, purposeLI, hasGoogleVendorConsent, hasGoogleVendorLI);

return (
hasConsentFor(indexes, purposeConsent, hasGoogleVendorConsent) &&
hasConsentOrLegitimateInterestFor(indexesLI, purposeConsent, purposeLI, hasGoogleVendorConsent, hasGoogleVendorLI)
);
}

@PluginMethod
Expand Down Expand Up @@ -206,24 +207,30 @@ private void ensureConsentInfo() {

private boolean hasAttribute(String input, int index) {
if (input == null) return false;
return input.length() >= index && input.charAt(index-1) == '1';
return input.length() >= index && input.charAt(index - 1) == '1';
}

private boolean hasConsentFor(List<Integer> indexes, String purposeConsent, boolean hasVendorConsent) {
for (Integer p: indexes) {
for (Integer p : indexes) {
if (!hasAttribute(purposeConsent, p)) {
return false;
}
}
return hasVendorConsent;
}

private boolean hasConsentOrLegitimateInterestFor(List<Integer> indexes, String purposeConsent, String purposeLI, boolean hasVendorConsent, boolean hasVendorLI){
for (Integer p: indexes) {
private boolean hasConsentOrLegitimateInterestFor(
List<Integer> indexes,
String purposeConsent,
String purposeLI,
boolean hasVendorConsent,
boolean hasVendorLI
) {
for (Integer p : indexes) {
boolean purposeAndVendorLI = hasAttribute(purposeLI, p) && hasVendorLI;
boolean purposeConsentAndVendorConsent = hasAttribute(purposeConsent, p) && hasVendorConsent;
boolean isOk = purposeAndVendorLI || purposeConsentAndVendorConsent;
if (!isOk){
if (!isOk) {
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3be0912

Please sign in to comment.