From c61c0b15fd254c1f48176c2b2dbc90814412a371 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 17 Jul 2016 18:49:07 +0200 Subject: [PATCH] Fixed IAB --- .../eu/faircode/netguard/ActivityPro.java | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/faircode/netguard/ActivityPro.java b/app/src/main/java/eu/faircode/netguard/ActivityPro.java index b82ed1f6..962210da 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivityPro.java +++ b/app/src/main/java/eu/faircode/netguard/ActivityPro.java @@ -51,6 +51,14 @@ public class ActivityPro extends AppCompatActivity { // adb shell pm clear com.android.vending // android.test.purchased + + private static final int SKU_LOG_ID = 1; + private static final int SKU_FILTER_ID = 2; + private static final int SKU_NOTIFY_ID = 3; + private static final int SKU_SPEED_ID = 4; + private static final int SKU_THEME_ID = 5; + private static final int SKU_PRO1_ID = 6; + public static final String SKU_LOG = "log"; public static final String SKU_FILTER = "filter"; public static final String SKU_NOTIFY = "notify"; @@ -146,22 +154,30 @@ public class ActivityPro extends AppCompatActivity { @Override public void onClick(View view) { try { + int id = 0; PendingIntent pi = null; - if (view == btnLog) + if (view == btnLog) { + id = SKU_LOG_ID; pi = iab.getBuyIntent(SKU_LOG); - else if (view == btnFilter) + } else if (view == btnFilter) { + id = SKU_FILTER_ID; pi = iab.getBuyIntent(SKU_FILTER); - else if (view == btnNotify) + } else if (view == btnNotify) { + id = SKU_NOTIFY_ID; pi = iab.getBuyIntent(SKU_NOTIFY); - else if (view == btnSpeed) + } else if (view == btnSpeed) { + id = SKU_SPEED_ID; pi = iab.getBuyIntent(SKU_SPEED); - else if (view == btnTheme) + } else if (view == btnTheme) { + id = SKU_THEME_ID; pi = iab.getBuyIntent(SKU_THEME); - else if (view == btnAll) + } else if (view == btnAll) { + id = SKU_PRO1_ID; pi = iab.getBuyIntent(SKU_PRO1); + } - if (pi != null) - startIntentSenderForResult(pi.getIntentSender(), view.getId(), new Intent(), 0, 0, 0); + if (id > 0 && pi != null) + startIntentSenderForResult(pi.getIntentSender(), id, new Intent(), 0, 0, 0); } catch (Throwable ex) { Log.i(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } @@ -216,27 +232,27 @@ public class ActivityPro extends AppCompatActivity { protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { switch (requestCode) { - case R.id.btnLog: + case SKU_LOG_ID: IAB.setBought(SKU_LOG, this); updateState(); break; - case R.id.btnFilter: + case SKU_FILTER_ID: IAB.setBought(SKU_FILTER, this); updateState(); break; - case R.id.btnNotify: + case SKU_NOTIFY_ID: IAB.setBought(SKU_NOTIFY, this); updateState(); break; - case R.id.btnSpeed: + case SKU_SPEED_ID: IAB.setBought(SKU_SPEED, this); updateState(); break; - case R.id.btnTheme: + case SKU_THEME_ID: IAB.setBought(SKU_THEME, this); updateState(); break; - case R.id.btnAll: + case SKU_PRO1_ID: IAB.setBought(SKU_PRO1, this); updateState(); break;