From 5d1674a0aab9981fc06330e3498d6185257c3084 Mon Sep 17 00:00:00 2001 From: Alex Dibrivnyi Date: Thu, 9 Feb 2017 21:01:59 +0200 Subject: [PATCH] Changed logic to check build type (Close #6) --- .../aboutbox/activity/AboutActivity.java | 56 +++++++++++++------ .../aboutbox/share/EmailUtil.java | 15 +++-- 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/library/src/main/java/com/eggheadgames/aboutbox/activity/AboutActivity.java b/library/src/main/java/com/eggheadgames/aboutbox/activity/AboutActivity.java index f3e024c..e28832b 100644 --- a/library/src/main/java/com/eggheadgames/aboutbox/activity/AboutActivity.java +++ b/library/src/main/java/com/eggheadgames/aboutbox/activity/AboutActivity.java @@ -65,7 +65,7 @@ public class AboutActivity extends MaterialAboutActivity { .setOnClickListener(new MaterialAboutActionItem.OnClickListener() { @Override public void onClick() { - openApp(config.packageName, config.buildType == AboutConfig.BuildType.GOOGLE); + openApp(config.buildType, config.packageName); if (config.analytics != null) { config.analytics.logUiEvent(config.logUiEventName, getString(R.string.review_log_event)); } @@ -94,7 +94,7 @@ public class AboutActivity extends MaterialAboutActivity { .setOnClickListener(new MaterialAboutActionItem.OnClickListener() { @Override public void onClick() { - openPublisher(config.buildType == AboutConfig.BuildType.GOOGLE, config.appPublisher, config.packageName); + openPublisher(config.buildType, config.appPublisher, config.packageName); if (config.analytics != null) { config.analytics.logUiEvent(config.logUiEventName, getString(R.string.try_other_app_log_event)); } @@ -235,7 +235,6 @@ public class AboutActivity extends MaterialAboutActivity { } } - public static void startTwitter(Activity context, String name) { try { context.getPackageManager().getPackageInfo("com.twitter.android", 0); @@ -253,27 +252,48 @@ public class AboutActivity extends MaterialAboutActivity { } - public void openApp(String packageName, boolean googlePlay) {//true if Google Play, false if Amazon Store - try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse((googlePlay ? "market://details?id=" : "amzn://apps/android?p=") + packageName))); - } catch (ActivityNotFoundException e1) { - try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse((googlePlay ? "http://play.google.com/store/apps/details?id=" : "http://www.amazon.com/gp/mas/dl/android?p=") + packageName))); - } catch (ActivityNotFoundException e2) { - Toast.makeText(this, R.string.can_not_open, Toast.LENGTH_SHORT).show(); - } + public void openApp(AboutConfig.BuildType buildType, String packageName) {//true if Google Play, false if Amazon Store + String appURI = null; + String webURI = null; + switch (buildType) { + case GOOGLE: + appURI = "market://details?id=" + packageName; + webURI = "http://play.google.com/store/apps/details?id=" + packageName; + break; + case AMAZON: + appURI = "amzn://apps/android?p=" + packageName; + webURI = "http://www.amazon.com/gp/mas/dl/android?p=" + packageName; + break; + default: + //nothing } + open(appURI, webURI); } - public void openPublisher(boolean googlePlay, String publisher, String packageName) {//true if Google Play, false if Amazon Store - String pub = googlePlay ? publisher : packageName; + public void openPublisher(AboutConfig.BuildType buildType, String publisher, String packageName) {//true if Google Play, false if Amazon Store + String appURI = null; + String webURI = null; + switch (buildType) { + case GOOGLE: + appURI = "market://search?q=pub:" + publisher; + webURI = "http://play.google.com/store/search?q=pub:" + publisher; + break; + case AMAZON: + appURI = "amzn://apps/android?showAll=1&p=" + packageName; + webURI = "http://www.amazon.com/gp/mas/dl/android?showAll=1&p=" + packageName; + break; + default: + //nothing + } + open(appURI, webURI); + } + + private void open(String appURI, String webURI) { try { - String uriString = (googlePlay ? "market://search?q=pub:" : "amzn://apps/android?showAll=1&p=") + pub; - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(uriString))); + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(appURI))); } catch (ActivityNotFoundException e1) { try { - String uriString = (googlePlay ? "http://play.google.com/store/search?q=pub:" : "http://www.amazon.com/gp/mas/dl/android?showAll=1&p=") + pub; - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(uriString))); + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(webURI))); } catch (ActivityNotFoundException e2) { Toast.makeText(this, R.string.can_not_open, Toast.LENGTH_SHORT).show(); } diff --git a/library/src/main/java/com/eggheadgames/aboutbox/share/EmailUtil.java b/library/src/main/java/com/eggheadgames/aboutbox/share/EmailUtil.java index 9f7cbb7..62ccbf3 100644 --- a/library/src/main/java/com/eggheadgames/aboutbox/share/EmailUtil.java +++ b/library/src/main/java/com/eggheadgames/aboutbox/share/EmailUtil.java @@ -19,12 +19,15 @@ public final class EmailUtil { final String emailSubject; - if (config.buildType == AboutConfig.BuildType.GOOGLE) { - emailSubject = config.emailSubject + "G"; - } else if (config.buildType == AboutConfig.BuildType.AMAZON) { - emailSubject = config.emailSubject + "K"; - } else { - emailSubject = config.emailSubject; + switch (config.buildType) { + case GOOGLE: + emailSubject = config.emailSubject + "G"; + break; + case AMAZON: + emailSubject = config.emailSubject + "K"; + break; + default: + emailSubject = config.emailSubject; } try {