From 46e84b607caf6f56ddd39cca0ea4c8f3795844e3 Mon Sep 17 00:00:00 2001 From: Boris Timofeev Date: Thu, 19 Jan 2017 10:05:36 +0300 Subject: [PATCH] Add donate activity and build flavors --- app/build.gradle | 13 ++- .../ui/activity/DonateActivity.java | 69 +++++++++++++++ app/src/google/AndroidManifest.xml | 9 ++ .../ui/activity/DonateActivity.java | 88 +++++++++++++++++++ app/src/main/AndroidManifest.xml | 6 +- .../java/org/emunix/unipatcher/Globals.java | 16 +--- .../java/org/emunix/unipatcher/Utils.java | 11 +-- .../unipatcher/ui/activity/MainActivity.java | 74 +--------------- app/src/main/res/layout/activity_donate.xml | 30 +++++++ .../main/res/menu/activity_main_drawer.xml | 4 +- app/src/main/res/values-it/strings.xml | 6 +- app/src/main/res/values-pl/strings.xml | 6 +- app/src/main/res/values-ru/strings.xml | 6 +- app/src/main/res/values/strings.xml | 6 +- 14 files changed, 234 insertions(+), 110 deletions(-) create mode 100644 app/src/fdroid/java/org/emunix/unipatcher/ui/activity/DonateActivity.java create mode 100644 app/src/google/AndroidManifest.xml create mode 100644 app/src/google/java/org/emunix/unipatcher/ui/activity/DonateActivity.java create mode 100644 app/src/main/res/layout/activity_donate.xml diff --git a/app/build.gradle b/app/build.gradle index af89d0c..eeda79f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,6 +36,17 @@ android { } } + productFlavors { + fdroid { + buildConfigField "String", "PAYPAL_USER", "\"mashin87@gmail.com\"" + buildConfigField "String", "PAYPAL_CURRENCY_CODE", "\"USD\"" + buildConfigField "String", "BITCOIN_ADDRESS", "\"16coztryz7xbNNDNhhf98wuHmi3hEintsW\"" + } + google { + buildConfigField "String", "GOOGLE_PLAY_PUBKEY", "\"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA384jTCBEuJ8nCWaC4S6AFrnMQN4mBlmkOXHV3Xg5hlFOl8TkVwiCfqz8r20yJpEy0IJ1+3QRnlq59zadUxbkD+PacJlGB/r2b3mbKfu+m0K+e/0aL6eWupjMSIyPgpnbN3uswiBEGUb4ytzYF53ZKTbLARnruQdMnjV6+VyfwMgpor/48anVQawDARBj/AIAj6VGtRHLmg6DmKDyOGQ7uCgXSv+ysnBKJjtIX/L/5nQgL8Q+9jsr2knuWY7j9BmrtpUXaDH3Kb50M1TOCKiqxPGa8lInOOIndABWxcpqmSMXP06SPYOanUlEH7lT0jjqpHpFNx8hRTT9xf652rgMJwIDAQAB\"" + } + } + externalNativeBuild { cmake { path "CMakeLists.txt" @@ -79,8 +90,8 @@ dependencies { compile 'com.android.support:design:25.1.0' compile 'com.google.firebase:firebase-core:10.0.1' compile 'com.google.firebase:firebase-crash:10.0.1' - compile 'com.anjlab.android.iab.v3:library:1.0.38' compile 'commons-io:commons-io:2.5' + compile 'org.sufficientlysecure:donations:2.5' compile 'org.sufficientlysecure:html-textview:3.0' compile 'org.commonjava.googlecode.markdown4j:markdown4j:2.2-cj-1.1' compile 'com.afollestad.material-dialogs:core:0.9.2.3' diff --git a/app/src/fdroid/java/org/emunix/unipatcher/ui/activity/DonateActivity.java b/app/src/fdroid/java/org/emunix/unipatcher/ui/activity/DonateActivity.java new file mode 100644 index 0000000..ba13bdb --- /dev/null +++ b/app/src/fdroid/java/org/emunix/unipatcher/ui/activity/DonateActivity.java @@ -0,0 +1,69 @@ +/* + Copyright (c) 2017 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.activity; + +import android.os.Bundle; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.MenuItem; + +import org.emunix.unipatcher.BuildConfig; +import org.emunix.unipatcher.R; +import org.sufficientlysecure.donations.DonationsFragment; + +public class DonateActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_donate); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + try { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } catch (NullPointerException e) { + /* empty */ + } + getSupportActionBar().setTitle(R.string.donate_activity_title); + + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + DonationsFragment donationsFragment = DonationsFragment.newInstance(BuildConfig.DEBUG, + false, null, null, null, + true, BuildConfig.PAYPAL_USER, BuildConfig.PAYPAL_CURRENCY_CODE, getString(R.string.donation), + false, null, null, + true, BuildConfig.BITCOIN_ADDRESS); + + ft.replace(R.id.donate_fragment, donationsFragment, "fragment"); + ft.commit(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +} diff --git a/app/src/google/AndroidManifest.xml b/app/src/google/AndroidManifest.xml new file mode 100644 index 0000000..d7ff1a7 --- /dev/null +++ b/app/src/google/AndroidManifest.xml @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/app/src/google/java/org/emunix/unipatcher/ui/activity/DonateActivity.java b/app/src/google/java/org/emunix/unipatcher/ui/activity/DonateActivity.java new file mode 100644 index 0000000..59d1df6 --- /dev/null +++ b/app/src/google/java/org/emunix/unipatcher/ui/activity/DonateActivity.java @@ -0,0 +1,88 @@ +/* + Copyright (c) 2017 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.activity; + +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.MenuItem; + +import org.emunix.unipatcher.BuildConfig; +import org.emunix.unipatcher.R; +import org.sufficientlysecure.donations.DonationsFragment; + +public class DonateActivity extends AppCompatActivity { + + private static final String[] GOOGLE_PLAY_CATALOG = new String[]{"donate_1", "donate_3", + "donate_5", "donate_10", "donate_25", "donate_50", "donate_100"}; + private static final String[] GOOGLE_PLAY_COST = new String[]{"$1", "$3", "$5", "$10", + "$25", "$50", "$100"}; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_donate); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + try { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + } catch (NullPointerException e) { + /* empty */ + } + getSupportActionBar().setTitle(R.string.donate_activity_title); + + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + DonationsFragment donationsFragment = DonationsFragment.newInstance(BuildConfig.DEBUG, + true, BuildConfig.GOOGLE_PLAY_PUBKEY, GOOGLE_PLAY_CATALOG, GOOGLE_PLAY_COST, + false, null, null, null, + false, null, null, + false, null); + + ft.replace(R.id.donate_fragment, donationsFragment, "donationsFragment"); + ft.commit(); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + FragmentManager fragmentManager = getSupportFragmentManager(); + Fragment fragment = fragmentManager.findFragmentByTag("donationsFragment"); + if (fragment != null) { + fragment.onActivityResult(requestCode, resultCode, data); + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3b6c3f0..5b31313 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,7 +6,6 @@ - @@ -67,9 +66,8 @@ android:value="@integer/google_play_services_version" /> + android:name=".ui.activity.DonateActivity" + android:label="@string/donate_activity_title" /> . package org.emunix.unipatcher; public class Globals { - private static final String KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA384jTCBEuJ8nCWaC4S6AFrnMQN4mBlmkOXHV3Xg5hlFOl8TkVwiCfqz8r20yJpEy0IJ1+3QRnlq59zadUxbkD+PacJlGB/r2b3mbKfu+m0K+e/0aL6eWupjMSIyPgpnbN3uswiBEGUb4ytzYF53ZKTbLARnruQdMnjV6+VyfwMgpor/48anVQawDARBj/AIAj6VGtRHLmg6DmKDyOGQ7uCgXSv+ysnBKJjtIX/L/5nQgL8Q+9jsr2knuWY7j9BmrtpUXaDH3Kb50M1TOCKiqxPGa8lInOOIndABWxcpqmSMXP06SPYOanUlEH7lT0jjqpHpFNx8hRTT9xf652rgMJwIDAQAB"; private static String cmdArgument = null; - private static boolean isFullVersion = false; public static String getCmdArgument() { return cmdArgument; @@ -32,18 +30,6 @@ public class Globals { Globals.cmdArgument = cmdArgument; } - public static boolean isFullVersion() { - return isFullVersion; - } - - public static void setFullVersion() { - isFullVersion = true; - } - - public static String getKey() { - return KEY; - } - public static final int ACTION_PATCHING = 1; public static final int ACTION_SMD_FIX_CHECKSUM = 2; public static final int ACTION_SNES_ADD_SMC_HEADER = 3; diff --git a/app/src/main/java/org/emunix/unipatcher/Utils.java b/app/src/main/java/org/emunix/unipatcher/Utils.java index 6b71564..912e2f8 100644 --- a/app/src/main/java/org/emunix/unipatcher/Utils.java +++ b/app/src/main/java/org/emunix/unipatcher/Utils.java @@ -1,5 +1,5 @@ /* -Copyright (C) 2013-2016 Boris Timofeev +Copyright (C) 2013-2017 Boris Timofeev This file is part of UniPatcher. @@ -24,8 +24,6 @@ import android.annotation.TargetApi; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; import android.os.Build; import android.os.StatFs; import android.support.v4.content.ContextCompat; @@ -42,7 +40,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.channels.FileChannel; -import java.util.ArrayList; import java.util.Arrays; import java.util.Locale; @@ -67,12 +64,6 @@ public class Utils { == PackageManager.PERMISSION_GRANTED; } - public static boolean isOnline(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo netInfo = cm.getActiveNetworkInfo(); - return netInfo != null && netInfo.isConnectedOrConnecting(); - } - public static int dpToPx(Context context, int dp) { DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT)); 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 8c2ef59..270f675 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 @@ -1,5 +1,5 @@ /* -Copyright (C) 2013-2016 Boris Timofeev +Copyright (C) 2013-2017 Boris Timofeev This file is part of UniPatcher. @@ -37,10 +37,7 @@ import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.MenuItem; import android.view.View; -import android.widget.Toast; -import com.anjlab.android.iab.v3.BillingProcessor; -import com.anjlab.android.iab.v3.TransactionDetails; import com.google.firebase.analytics.FirebaseAnalytics; import org.emunix.unipatcher.BuildConfig; @@ -60,10 +57,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { private static final String LOG_TAG = "org.emunix.unipatcher"; - private static final String SKU_FULL = "full"; - private static final String SKU_REMOVE_ADS = "ad"; - private boolean readyToPurchase = false; - private BillingProcessor bp; private FirebaseAnalytics firebaseAnalytics; @Override @@ -107,35 +100,6 @@ public class MainActivity extends AppCompatActivity } parseArgument(); - bp = new BillingProcessor(this, Globals.getKey(), new BillingProcessor.IBillingHandler() { - @Override - public void onBillingInitialized() { - Log.d(LOG_TAG, "Billing initialized"); - readyToPurchase = true; - if (bp.isPurchased(SKU_FULL) || bp.isPurchased(SKU_REMOVE_ADS)) { - setFullVersion(); - } - } - @Override - public void onProductPurchased(String productId, TransactionDetails details) { - Log.d(LOG_TAG, "Item purchased: " + productId); - complain(getString(R.string.purchase_successful)); - setFullVersion(); - } - @Override - public void onBillingError(int errorCode, Throwable error) { - if (errorCode != 110) // cancel purchase - complain("Billing error: " + Integer.toString(errorCode)); - } - @Override - public void onPurchaseHistoryRestored() { - for(String sku : bp.listOwnedProducts()) - Log.d(LOG_TAG, "Owned Managed Product: " + sku); - if (bp.isPurchased(SKU_FULL) || bp.isPurchased(SKU_REMOVE_ADS)) { - setFullVersion(); - } - } - }); RateThisApp.launch(this); } @@ -175,8 +139,9 @@ public class MainActivity extends AppCompatActivity startActivity(settingsIntent); } else if (id == R.id.nav_rate) { RateThisApp.rate(this); - } else if (id == R.id.nav_buy) { - buyFullVersion(); + } else if (id == R.id.nav_donate) { + Intent donateIntent = new Intent(this, DonateActivity.class); + startActivity(donateIntent); } else if (id == R.id.nav_share) { shareApp(); } else if (id == R.id.nav_help) { @@ -211,13 +176,6 @@ public class MainActivity extends AppCompatActivity } } - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data){ - Log.d(LOG_TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data); - if (!bp.handleActivityResult(requestCode, resultCode, data)) - super.onActivityResult(requestCode, resultCode, data); - } - private void shareApp() { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); @@ -225,28 +183,4 @@ public class MainActivity extends AppCompatActivity shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text) + "https://play.google.com/store/apps/details?id=org.eminix.unipatcher"); startActivity(Intent.createChooser(shareIntent, getString(R.string.share_dialog_title))); } - - private void buyFullVersion() { - if (readyToPurchase) - bp.purchase(this, SKU_REMOVE_ADS); - else - complain("Billing not initialized."); - } - - private void setFullVersion() { - Globals.setFullVersion(); - } - - private void complain(String message) { - Log.d(LOG_TAG, message); - Toast.makeText(this, message, Toast.LENGTH_LONG).show(); - } - - @Override - public void onDestroy() { - if (bp != null) { - bp.release(); - } - super.onDestroy(); - } } diff --git a/app/src/main/res/layout/activity_donate.xml b/app/src/main/res/layout/activity_donate.xml new file mode 100644 index 0000000..35c854b --- /dev/null +++ b/app/src/main/res/layout/activity_donate.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/menu/activity_main_drawer.xml b/app/src/main/res/menu/activity_main_drawer.xml index e9e54c2..fec97d2 100644 --- a/app/src/main/res/menu/activity_main_drawer.xml +++ b/app/src/main/res/menu/activity_main_drawer.xml @@ -30,9 +30,9 @@ android:icon="@drawable/ic_thumb_up_grey600_24dp" android:title="@string/nav_rate" /> + android:title="@string/nav_donate" /> Invia feedback Visita sito web + Donate + Invia e-mail Non ci sono client email installati @@ -138,7 +140,7 @@ Aggiungi/Cancella intestazione SMC (SNES) Impostazioni Valuta questa App - Offrimi una Birra + Donate Condividi Aiuto Apri cassetto di navigazione @@ -150,7 +152,7 @@ Valuta Ricorda dopo - Grazie! + Donation icona diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index bd0cd7d..26dd0e8 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -125,6 +125,8 @@ Wyślij opinię Odwiedź stronę + Donate + Wyślij E-Maila Tu nie ma żadnych klientów E-Mail zainstalowanych @@ -137,7 +139,7 @@ Dodaj/Usuń nagłówek SMC (SNES) Ustawienia Oceń tą aplikację - Kup Mi Piwo + Donate Udostępnij Pomoc Otwórz kartę nawigacyjną @@ -149,7 +151,7 @@ Oceń Przypomnij mi później - Dziękuję! + Donation ikona diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 7eaa883..6e28292 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -125,6 +125,8 @@ Написать письмо автору Посетить веб-сайт + Donate + Отправить e-mail Не установлен email клиент @@ -138,7 +140,7 @@ SMC заголовок (SNES) Настройки Оценить приложение - Убрать рекламу + Donate Рассказать друзьям Помощь Открыть главное меню @@ -150,7 +152,7 @@ Поставить оценку Напомнить позже - Спасибо! + Donation иконка diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1be7b78..4c2368b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -125,6 +125,8 @@ Send feedback Visit website + Donate + Send e-mail There are no email clients installed @@ -137,7 +139,7 @@ Add/Del SMC header (SNES) Settings Rate this App - Buy Me a Beer + Donate Share Help Open navigation drawer @@ -149,7 +151,7 @@ Rate Remind later - Thank you! + Donation icon