From c856257dfefbec323280583d969c9db93339e681 Mon Sep 17 00:00:00 2001 From: Boris Timofeev Date: Wed, 25 Jan 2017 20:02:21 +0300 Subject: [PATCH] Remove rate app dialog and set different urls for flavors --- app/build.gradle | 2 + .../unipatcher/ui/activity/MainActivity.java | 15 +++- .../unipatcher/ui/dialog/RateThisApp.java | 89 ------------------- 3 files changed, 14 insertions(+), 92 deletions(-) delete mode 100644 app/src/main/java/org/emunix/unipatcher/ui/dialog/RateThisApp.java diff --git a/app/build.gradle b/app/build.gradle index f4e4243..c6151e2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -38,12 +38,14 @@ android { productFlavors { free { + buildConfigField "String", "RATE_URL", "\"https://github.com/btimofeev/UniPatcher\"" buildConfigField "String", "SHARE_URL", "\"https://github.com/btimofeev/UniPatcher\"" buildConfigField "String", "PAYPAL_USER", "\"btimofeev@emunix.org\"" buildConfigField "String", "PAYPAL_CURRENCY_CODE", "\"USD\"" buildConfigField "String", "BITCOIN_ADDRESS", "\"16coztryz7xbNNDNhhf98wuHmi3hEintsW\"" } google { + buildConfigField "String", "RATE_URL", "\"market://details?id=org.eminix.unipatcher\"" buildConfigField "String", "SHARE_URL", "\"https://play.google.com/store/apps/details?id=org.eminix.unipatcher\"" buildConfigField "String", "GOOGLE_PLAY_PUBKEY", "\"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA384jTCBEuJ8nCWaC4S6AFrnMQN4mBlmkOXHV3Xg5hlFOl8TkVwiCfqz8r20yJpEy0IJ1+3QRnlq59zadUxbkD+PacJlGB/r2b3mbKfu+m0K+e/0aL6eWupjMSIyPgpnbN3uswiBEGUb4ytzYF53ZKTbLARnruQdMnjV6+VyfwMgpor/48anVQawDARBj/AIAj6VGtRHLmg6DmKDyOGQ7uCgXSv+ysnBKJjtIX/L/5nQgL8Q+9jsr2knuWY7j9BmrtpUXaDH3Kb50M1TOCKiqxPGa8lInOOIndABWxcpqmSMXP06SPYOanUlEH7lT0jjqpHpFNx8hRTT9xf652rgMJwIDAQAB\"" } diff --git a/app/src/main/java/org/emunix/unipatcher/ui/activity/MainActivity.java b/app/src/main/java/org/emunix/unipatcher/ui/activity/MainActivity.java index 3a5a7bf..e521667 100644 --- a/app/src/main/java/org/emunix/unipatcher/ui/activity/MainActivity.java +++ b/app/src/main/java/org/emunix/unipatcher/ui/activity/MainActivity.java @@ -21,6 +21,7 @@ package org.emunix.unipatcher.ui.activity; import android.content.Intent; import android.content.SharedPreferences; +import android.net.Uri; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.NavigationView; @@ -43,7 +44,6 @@ import com.google.firebase.analytics.FirebaseAnalytics; import org.emunix.unipatcher.BuildConfig; import org.emunix.unipatcher.Globals; import org.emunix.unipatcher.R; -import org.emunix.unipatcher.ui.dialog.RateThisApp; import org.emunix.unipatcher.ui.fragment.ActionFragment; import org.emunix.unipatcher.ui.fragment.PatchingFragment; import org.emunix.unipatcher.ui.fragment.SmdFixChecksumFragment; @@ -100,7 +100,6 @@ public class MainActivity extends AppCompatActivity } parseArgument(); - RateThisApp.launch(this); } private void setTheme() { @@ -138,7 +137,7 @@ public class MainActivity extends AppCompatActivity Intent settingsIntent = new Intent(this, SettingsActivity.class); startActivity(settingsIntent); } else if (id == R.id.nav_rate) { - RateThisApp.rate(this); + rateApp(); } else if (id == R.id.nav_donate) { Intent donateIntent = new Intent(this, DonateActivity.class); startActivity(donateIntent); @@ -188,4 +187,14 @@ public class MainActivity extends AppCompatActivity shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text) + BuildConfig.SHARE_URL); startActivity(Intent.createChooser(shareIntent, getString(R.string.share_dialog_title))); } + + public void rateApp() { + Intent rateAppIntent = new Intent(Intent.ACTION_VIEW); + rateAppIntent.setData(Uri.parse(BuildConfig.RATE_URL)); + if (getPackageManager().queryIntentActivities(rateAppIntent, 0).size() == 0) { + // Market app is not installed. Open web browser + rateAppIntent.setData(Uri.parse(BuildConfig.SHARE_URL)); + } + startActivity(rateAppIntent); + } } diff --git a/app/src/main/java/org/emunix/unipatcher/ui/dialog/RateThisApp.java b/app/src/main/java/org/emunix/unipatcher/ui/dialog/RateThisApp.java deleted file mode 100644 index 5682c7c..0000000 --- a/app/src/main/java/org/emunix/unipatcher/ui/dialog/RateThisApp.java +++ /dev/null @@ -1,89 +0,0 @@ -/* -Copyright (C) 2013 Boris Timofeev - -This file is part of UniPatcher. - -UniPatcher is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -UniPatcher is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with UniPatcher. If not, see . -*/ - -package org.emunix.unipatcher.ui.dialog; - -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; -import android.net.Uri; -import android.support.v7.app.AlertDialog; - -import org.emunix.unipatcher.R; - -public class RateThisApp { - - private final static int LAUNCHES_UNTIL_PROMPT = 7; - - public static void launch(Context context) { - SharedPreferences preferences = context.getSharedPreferences("RateThisApp", 0); - if (preferences.getBoolean("dont_show_again", false)) - return; - - SharedPreferences.Editor editor = preferences.edit(); - long launchCount = preferences.getLong("launch_count", 0) + 1; - editor.putLong("launch_count", launchCount); - - if (launchCount % LAUNCHES_UNTIL_PROMPT == 0) - showDialog(context); - - editor.apply(); - } - - public static void rate(Context context) { - String packageName = context.getApplicationContext().getPackageName(); - Intent rateAppIntent = new Intent(Intent.ACTION_VIEW); - rateAppIntent.setData(Uri.parse("market://details?id=" + packageName)); - if (context.getPackageManager().queryIntentActivities(rateAppIntent, 0).size() == 0) { - // Market app is not installed. Open web browser - rateAppIntent.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)); - } - context.startActivity(rateAppIntent); - dontShowDialogAgain(context); - } - - private static void showDialog(final Context context) { - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(R.string.rate_dialog_title); - builder.setMessage(R.string.rate_dialog_message); - builder.setPositiveButton(R.string.rate_dialog_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - rate(context); - } - }); - - builder.setNegativeButton(R.string.rate_dialog_later, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - dialogInterface.cancel(); - } - }); - AlertDialog dialog = builder.create(); - dialog.show(); - } - - private static void dontShowDialogAgain(Context context) { - SharedPreferences preferences = context.getSharedPreferences("RateThisApp", 0); - SharedPreferences.Editor editor = preferences.edit(); - editor.putBoolean("dont_show_again", true); - editor.apply(); - } -}