Add donate activity and build flavors

This commit is contained in:
Boris Timofeev 2017-01-19 10:05:36 +03:00
parent 0c89a35060
commit 46e84b607c
14 changed files with 234 additions and 110 deletions

View file

@ -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'

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}
}

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.emunix.unipatcher">
<uses-permission android:name="com.android.vending.BILLING" />
<application />
</manifest>

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}
}

View file

@ -6,7 +6,6 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
@ -67,9 +66,8 @@
android:value="@integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
android:name=".ui.activity.DonateActivity"
android:label="@string/donate_activity_title" />
<service
android:name=".WorkerService"

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 2013-2016 Boris Timofeev
Copyright (C) 2013-2017 Boris Timofeev
This file is part of UniPatcher.
@ -20,9 +20,7 @@ along with UniPatcher. If not, see <http://www.gnu.org/licenses/>.
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;

View file

@ -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));

View file

@ -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();
}
}

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="org.emunix.unipatcher.ui.activity.DonateActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.NoActionBar.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.NoActionBar.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/donate_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

View file

@ -30,9 +30,9 @@
android:icon="@drawable/ic_thumb_up_grey600_24dp"
android:title="@string/nav_rate" />
<item
android:id="@+id/nav_buy"
android:id="@+id/nav_donate"
android:icon="@drawable/ic_shopping_cart_grey600_24dp"
android:title="@string/nav_buy" />
android:title="@string/nav_donate" />
<item
android:id="@+id/nav_share"
android:icon="@drawable/ic_share_grey600_24dp"

View file

@ -125,6 +125,8 @@
<string name="help_activity_action_send_feedback">Invia feedback</string>
<string name="help_activity_action_visit_site">Visita sito web</string>
<string name="donate_activity_title">Donate</string>
<string name="send_feedback_dialog_title">Invia e-mail</string>
<string name="send_feedback_error_no_email_apps">Non ci sono client email installati</string>
@ -138,7 +140,7 @@
<string name="nav_snes_add_del_smc_header">Aggiungi/Cancella intestazione SMC (SNES)</string>
<string name="nav_settings">Impostazioni</string>
<string name="nav_rate">Valuta questa App</string>
<string name="nav_buy">Offrimi una Birra</string>
<string name="nav_donate">Donate</string>
<string name="nav_share">Condividi</string>
<string name="nav_help">Aiuto</string>
<string name="nav_drawer_open">Apri cassetto di navigazione</string>
@ -150,7 +152,7 @@
<string name="rate_dialog_ok">Valuta</string>
<string name="rate_dialog_later">Ricorda dopo</string>
<string name="purchase_successful">Grazie!</string>
<string name="donation">Donation</string>
<string name="icon">icona</string>
</resources>

View file

@ -125,6 +125,8 @@
<string name="help_activity_action_send_feedback">Wyślij opinię</string>
<string name="help_activity_action_visit_site">Odwiedź stronę</string>
<string name="donate_activity_title">Donate</string>
<string name="send_feedback_dialog_title">Wyślij E-Maila</string>
<string name="send_feedback_error_no_email_apps">Tu nie ma żadnych klientów E-Mail zainstalowanych</string>
@ -137,7 +139,7 @@
<string name="nav_snes_add_del_smc_header">Dodaj/Usuń nagłówek SMC (SNES)</string>
<string name="nav_settings">Ustawienia</string>
<string name="nav_rate">Oceń tą aplikację</string>
<string name="nav_buy">Kup Mi Piwo</string>
<string name="nav_donate">Donate</string>
<string name="nav_share">Udostępnij</string>
<string name="nav_help">Pomoc</string>
<string name="nav_drawer_open">Otwórz kartę nawigacyjną</string>
@ -149,7 +151,7 @@
<string name="rate_dialog_ok">Oceń</string>
<string name="rate_dialog_later">Przypomnij mi później</string>
<string name="purchase_successful">Dziękuję!</string>
<string name="donation">Donation</string>
<string name="icon">ikona</string>
</resources>

View file

@ -125,6 +125,8 @@
<string name="help_activity_action_send_feedback">Написать письмо автору</string>
<string name="help_activity_action_visit_site">Посетить веб-сайт</string>
<string name="donate_activity_title">Donate</string>
<string name="send_feedback_dialog_title">Отправить e-mail</string>
<string name="send_feedback_error_no_email_apps">Не установлен email клиент</string>
@ -138,7 +140,7 @@
<string name="nav_snes_add_del_smc_header">SMC заголовок (SNES)</string>
<string name="nav_settings">Настройки</string>
<string name="nav_rate">Оценить приложение</string>
<string name="nav_buy">Убрать рекламу</string>
<string name="nav_donate">Donate</string>
<string name="nav_share">Рассказать друзьям</string>
<string name="nav_help">Помощь</string>
<string name="nav_drawer_open">Открыть главное меню</string>
@ -150,7 +152,7 @@
<string name="rate_dialog_ok">Поставить оценку</string>
<string name="rate_dialog_later">Напомнить позже</string>
<string name="purchase_successful">Спасибо!</string>
<string name="donation">Donation</string>
<string name="icon">иконка</string>
</resources>

View file

@ -125,6 +125,8 @@
<string name="help_activity_action_send_feedback">Send feedback</string>
<string name="help_activity_action_visit_site">Visit website</string>
<string name="donate_activity_title">Donate</string>
<string name="send_feedback_dialog_title">Send e-mail</string>
<string name="send_feedback_error_no_email_apps">There are no email clients installed</string>
@ -137,7 +139,7 @@
<string name="nav_snes_add_del_smc_header">Add/Del SMC header (SNES)</string>
<string name="nav_settings">Settings</string>
<string name="nav_rate">Rate this App</string>
<string name="nav_buy">Buy Me a Beer</string>
<string name="nav_donate">Donate</string>
<string name="nav_share">Share</string>
<string name="nav_help">Help</string>
<string name="nav_drawer_open">Open navigation drawer</string>
@ -149,7 +151,7 @@
<string name="rate_dialog_ok">Rate</string>
<string name="rate_dialog_later">Remind later</string>
<string name="purchase_successful">Thank you!</string>
<string name="donation">Donation</string>
<string name="icon">icon</string>
</resources>