Skip to content

Commit

Permalink
Fix issues with premium purchase
Browse files Browse the repository at this point in the history
  • Loading branch information
jeisfeld committed Sep 8, 2015
1 parent 832b4a8 commit e57d6fa
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 39 deletions.
3 changes: 3 additions & 0 deletions Augendiagnose/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
<item>donation_big</item>
<item>donation_medium</item>
</string-array>
<string-array name="googlebilling_subscription_ids" translatable="false">
<item>donation_monthly_small</item>
</string-array>

</resources>
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package de.eisfeldj.augendiagnose;

import android.app.Activity;
import android.content.Intent;
import de.eisfeldj.augendiagnose.activities.MainActivity;
import de.jeisfeld.augendiagnoselib.Application.AuthorizationLevel;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

Expand Down Expand Up @@ -44,4 +47,10 @@ protected AuthorizationLevel getAuthorizationLevel() {
return level;
}
}

@Override
public void startApplication(final Activity triggeringActivity) {
Intent intent = new Intent(triggeringActivity, MainActivity.class);
triggeringActivity.startActivity(intent);
}
}
4 changes: 2 additions & 2 deletions AugendiagnoseLib/res/values-de/strings_dialogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<string name="message_dialog_failed_to_open_camera">Kamera konnte nicht gestartet werden.</string>
<string name="message_dialog_trial_names">In der Testversion der App können Sie nur bis zu drei Namen vergeben. Bitte erwerben Sie ein Premium-Paket, um die App unbegrenzt nutzen zu können.</string>
<string name="message_dialog_trial_time">Die Testversion der App ist nur einen Tag nutzbar. Bitte erwerben Sie ein Premium-Paket, um die App unbegrenzt nutzen zu können.</string>
<string name="message_dialog_donation_thanks">Danke für Ihre Spende!</string>
<string name="message_dialog_donation_thanks_premium">Danke für Ihren Kauf! Sie können die App nun unbegrenzt nutzen.</string>
<string name="message_dialog_purchase_thanks">Danke für Ihren Kauf!</string>
<string name="message_dialog_purchase_thanks_premium">Danke für Ihren Kauf! Sie können die App nun unbegrenzt nutzen.</string>
<string name="message_dialog_select_extsdcard">Bitte wählen Sie im folgenden Android-Dialog Ihre SD-Karte (entweder das Hauptverzeichnis der Karte oder das ausgewählte Unterverzeichnis), und bestätigen Sie am unteren Ende.</string>
<string name="message_dialog_unformatted_file">Datei %1$s ist falsch formatiert</string>
<string name="message_dialog_confirm_delete_date">Wollen Sie die Fotos von %1$s vom %2$s wirklich löschen?</string>
Expand Down
4 changes: 2 additions & 2 deletions AugendiagnoseLib/res/values-es/strings_dialogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<string name="message_dialog_failed_to_open_camera">No se ha podido abrir la cámara.</string>
<string name="message_dialog_trial_names">En la versión de prueba es permitido utilizar sólo hasta tres nombres. Por favor, compre un paquete premium para obtener acceso ilimitado.</string>
<string name="message_dialog_trial_time">La versión de prueba de la aplicación se puede utilizar solamente por un día. Por favor, compre un paquete premium para obtener acceso ilimitado.</string>
<string name="message_dialog_donation_thanks">¡Gracias por su donación!</string>
<string name="message_dialog_donation_thanks_premium">¡Gracias por su compra! Ahora puede utilizar la aplicación ilimitadamente.</string>
<string name="message_dialog_purchase_thanks">¡Gracias por su compra!</string>
<string name="message_dialog_purchase_thanks_premium">¡Gracias por su compra! Ahora puede utilizar la aplicación ilimitadamente.</string>
<string name="message_dialog_select_extsdcard">En el diálogo Android siguiente, por favor seleccione la tarjeta externa SD (ya sea la tarjeta sd completo o la carpeta seleccionada) y confirme en la parte inferior.</string>
<string name="message_dialog_unformatted_file">El archivo %1$s no está formateado correctamente</string>
<string name="message_dialog_confirm_delete_date">¿Realmente desea borrar las fotos de %1$s de %2$s?</string>
Expand Down
3 changes: 2 additions & 1 deletion AugendiagnoseLib/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
</string-array>
<string-array name="googlebilling_ids" translatable="false"></string-array>
<string-array name="googlebilling_premium_ids" translatable="false"></string-array>

<string-array name="googlebilling_subscription_ids" translatable="false"></string-array>

<!-- Resources defining available overlays -->

<array name="overlays_left">
Expand Down
4 changes: 2 additions & 2 deletions AugendiagnoseLib/res/values/strings_dialogs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<string name="message_dialog_failed_to_open_camera">Failed to open the camera.</string>
<string name="message_dialog_trial_names">In the trial version you are allowed to use only up to three names. Please purchase a premium pack to get unlimited access.</string>
<string name="message_dialog_trial_time">The trial version of the app can be used only for one day. Please purchase a premium pack to get unlimited access.</string>
<string name="message_dialog_donation_thanks">Thanks for your donation!</string>
<string name="message_dialog_donation_thanks_premium">Thanks for your donation! You can now use the app without limitations.</string>
<string name="message_dialog_purchase_thanks">Thanks for your purchase!</string>
<string name="message_dialog_purchase_thanks_premium">Thanks for your purchase! You can now use the app without limitations.</string>
<string name="message_dialog_select_extsdcard">In the following Android dialog, please select the external SD card (either the full card or your selected folder) and confirm at the bottom.</string>
<string name="message_dialog_unformatted_file">File %1$s is not formatted correctly</string>
<string name="message_dialog_confirm_delete_date">Do you really want to delete the photos of %1$s from %2$s?</string>
Expand Down
12 changes: 12 additions & 0 deletions AugendiagnoseLib/src/de/jeisfeld/augendiagnoselib/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.lang.Thread.UncaughtExceptionHandler;
import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
Expand Down Expand Up @@ -118,6 +119,17 @@ public static AuthorizationLevel getAuthorizationLevel() {
return getApplicationSettings().getAuthorizationLevel();
}

/**
* start the application.
*
* @param triggeringActivity
* the triggering activity.
*
*/
public static void startApplication(final Activity triggeringActivity) {
getApplicationSettings().startApplication(triggeringActivity);
}

/**
* Get a resource string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.concurrent.TimeUnit;

import android.app.Activity;
import de.jeisfeld.augendiagnoselib.Application.AuthorizationLevel;
import de.jeisfeld.augendiagnoselib.util.EncryptionUtil;
import de.jeisfeld.augendiagnoselib.util.PreferenceUtil;
Expand Down Expand Up @@ -31,4 +32,12 @@ protected AuthorizationLevel getAuthorizationLevel() {
return System.currentTimeMillis() < firstStartTime + TimeUnit.DAYS.toMillis(1)
? AuthorizationLevel.TRIAL_ACCESS : AuthorizationLevel.NO_ACCESS;
}

/**
* Start the application.
*
* @param triggeringActivity
* the triggering activity.
*/
public abstract void startApplication(final Activity triggeringActivity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,7 @@ protected void onCreate(final Bundle savedInstanceState) {

if (Intent.ACTION_MAIN.equals(getIntent().getAction())) {
if (Application.getAuthorizationLevel() == AuthorizationLevel.NO_ACCESS) {
isCreationFailed = true;
DialogUtil.displayAuthorizationError(this, R.string.message_dialog_trial_time);
return;
}

if (savedInstanceState == null) {
boolean firstStart = false;

// Initial tip is triggered first, so that it is hidden behind release notes.
DialogUtil.displayTip(this, R.string.message_tip_firstuse, R.string.key_tip_firstuse);

// When starting from launcher, check if started the first time in this version. If yes, display release
// notes.
String storedVersionString = PreferenceUtil.getSharedPreferenceString(R.string.key_internal_stored_version);
if (storedVersionString == null || storedVersionString.length() == 0) {
storedVersionString = "0";
firstStart = true;
}
int storedVersion = Integer.parseInt(storedVersionString);
int currentVersion = Application.getVersion();

if (storedVersion < currentVersion) {
ReleaseNotesUtil.displayReleaseNotes(this, firstStart, storedVersion + 1, currentVersion);
}
final Intent starterIntent = getIntent();

// Check in-app purchases
GoogleBillingHelper.initialize(this, new OnInventoryFinishedListener() {
Expand All @@ -74,10 +51,53 @@ public void handleProducts(final List<PurchasedSku> purchases, final List<SkuDet
final boolean isPremium) {
PreferenceUtil.setSharedPreferenceBoolean(R.string.key_internal_has_premium_pack, isPremium);
GoogleBillingHelper.dispose();

if (isPremium) {
startActivity(starterIntent);
finish();
}
else {
DialogUtil.displayAuthorizationError(BaseActivity.this, R.string.message_dialog_trial_time);
}
}
});
isCreationFailed = true;
return;
}
else {
if (savedInstanceState == null) {
boolean firstStart = false;

// Initial tip is triggered first, so that it is hidden behind release notes.
DialogUtil.displayTip(this, R.string.message_tip_firstuse, R.string.key_tip_firstuse);

// When starting from launcher, check if started the first time in this version. If yes, display release
// notes.
String storedVersionString = PreferenceUtil.getSharedPreferenceString(R.string.key_internal_stored_version);
if (storedVersionString == null || storedVersionString.length() == 0) {
storedVersionString = "0";
firstStart = true;
}
int storedVersion = Integer.parseInt(storedVersionString);
int currentVersion = Application.getVersion();

test();
if (storedVersion < currentVersion) {
ReleaseNotesUtil.displayReleaseNotes(this, firstStart, storedVersion + 1, currentVersion);
}

// Check in-app purchases
GoogleBillingHelper.initialize(this, new OnInventoryFinishedListener() {

@Override
public void handleProducts(final List<PurchasedSku> purchases, final List<SkuDetails> availableProducts,
final boolean isPremium) {
PreferenceUtil.setSharedPreferenceBoolean(R.string.key_internal_has_premium_pack, isPremium);
GoogleBillingHelper.dispose();
}
});

test();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,20 +410,22 @@ public void handlePurchase(final Purchase purchase, final boolean addedPremiumPr
PreferenceUtil.setSharedPreferenceBoolean(R.string.key_internal_has_premium_pack, true);
}
int messageResource =
addedPremiumProduct ? R.string.message_dialog_donation_thanks_premium
: R.string.message_dialog_donation_thanks;
addedPremiumProduct ? R.string.message_dialog_purchase_thanks_premium
: R.string.message_dialog_purchase_thanks;

MessageDialogListener listener = new MessageDialogListener() {
private static final long serialVersionUID = 1L;

@Override
public void onDialogClick(final DialogFragment dialog) {
getActivity().finish();
Application.startApplication(getActivity());
}

@Override
public void onDialogCancel(final DialogFragment dialog) {
getActivity().finish();
Application.startApplication(getActivity());
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.util.Log;
import android.widget.Toast;
import de.jeisfeld.augendiagnoselib.Application;
import de.jeisfeld.augendiagnoselib.Application.AuthorizationLevel;
import de.jeisfeld.augendiagnoselib.R;
import de.jeisfeld.augendiagnoselib.activities.SettingsActivity;
import de.jeisfeld.augendiagnoselib.util.DialogUtil.ConfirmDialogFragment.ConfirmDialogListener;
Expand Down Expand Up @@ -176,7 +177,10 @@ public void onDialogClick(final DialogFragment dialog) {

@Override
public void onDialogCancel(final DialogFragment dialog) {
// do nothing
if (Application.getAuthorizationLevel() == AuthorizationLevel.NO_ACCESS) {
SettingsActivity.startActivity(activity);
activity.finish();
}
}
};
displayInfo(activity, listener, resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class GoogleBillingHelper {
* The product ids which are subscriptions.
*/
private static final String[] SUBSCRIPTION_IDS =
new String[] { "donation_monthly_small" };
Application.getAppContext().getResources().getStringArray(R.array.googlebilling_subscription_ids);

/**
* An instance of GoogleBillingHelper.
Expand Down
2 changes: 1 addition & 1 deletion Miniris/res/values-de/strings_releasenotes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<string-array name="releasenotes_version_notes">
<item>Erste Version, basierend auf der Augendiagnose-App, mit deutlich verbesserter Aufnahmefunktion.</item>
<item>Verschiedene Fehlerkorrekturen.</item>
<item>Fehlerkorrekturen.</item>
<item>Fehlerkorrektur für den Premium-Kauf</item>
</string-array>

</resources>
2 changes: 1 addition & 1 deletion Miniris/res/values-es/strings_releasenotes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<string-array name="releasenotes_version_notes">
<item>Versión inicial, basado en la aplicación Diagnóstico ocular, con grandes mejoras en el uso de la cámara.</item>
<item>Varias correcciones de errores.</item>
<item>Correcciones de errores.</item>
<item>Corregidos problemas con la compra de paquete premium.</item>
</string-array>

</resources>
3 changes: 3 additions & 0 deletions Miniris/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<item>standard_pack</item>
<item>monthly_pack</item>
</string-array>
<string-array name="googlebilling_subscription_ids" translatable="false">
<item>monthly_pack</item>
</string-array>

<!-- Resources defining availalble help screens -->

Expand Down
2 changes: 1 addition & 1 deletion Miniris/res/values/strings_releasenotes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<string-array name="releasenotes_version_notes">
<item>Initial version, based on Eye Diagnosis app, with largely improved camera flow.</item>
<item>Various Bugfixes.</item>
<item>Bugfixes.</item>
<item>Fixed issues with premium purchase.</item>
</string-array>

</resources>
8 changes: 8 additions & 0 deletions Miniris/src/de/jeisfeld/miniris/ApplicationSettings.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.jeisfeld.miniris;

import android.app.Activity;
import de.jeisfeld.augendiagnoselib.activities.CameraActivity;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
Expand Down Expand Up @@ -30,4 +32,10 @@ public static ApplicationSettings getInstance() {
}
return instance;
}

@Override
public void startApplication(final Activity triggeringActivity) {
CameraActivity.startActivity(triggeringActivity);
}

}

0 comments on commit e57d6fa

Please sign in to comment.