Skip to content

Commit

Permalink
Allow app usage while purchase is pending
Browse files Browse the repository at this point in the history
  • Loading branch information
jeisfeld committed Jul 27, 2023
1 parent fc0430c commit c2477f3
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 50 deletions.
1 change: 1 addition & 0 deletions AugendiagnoseIdea/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/AugendiagnoseIdea.iml
/projectFilesBackup/
/augendiagnoseMaristela/
/*/release/*.aab
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ Kamera benutzen. Bitte informieren Sie mich, wenn solche Probleme auftreten.</p>
<item>Auf Android 11 API umgestellt</item>
<item>Fehlerkorrekturen</item>
<item>Fehlerkorrekturen. Anpassungen für Android 12.</item>
<item>Fehlerkorrekturen</item>
<item>Fehlerkorrekturen. Anpassungen für Android 13.</item>
<item>Vollständige App-Nutzung, während die Paketzahlung aussteht</item>
</string-array>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ primera vez con un nuevo dispositivo o con una nueva cámara. Por favor, me info
<item>Cambiado a la API de Android 11</item>
<item>Corrección de errores</item>
<item>Corrección de errores. Adaptado para Android 12.</item>
<item>Corrección de errores</item>
<item>Corrección de errores. Adaptado para Android 13.</item>
<item>Uso completo de la aplicación mientras el pago del paquete está pendiente</item>
</string-array>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Primeira vez com um novo dispositivo ou com uma nova câmera. Por favor, informe
<item>Mudou para Android 11 API</item>
<item>Correções de bugs</item>
<item>Correções de bugs. Adaptado para Android 12.</item>
<item>Correções de bugs</item>
<item>Correções de bugs. Adaptado para Android 13.</item>
<item>Uso total do aplicativo enquanto o pagamento do pacote está pendente</item>
</string-array>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ when using the app for the first time with a new device or with a new camera. Pl
<item>Switched to Android 11 API</item>
<item>Bugfixes</item>
<item>Bugfixes. Adapted for Android 12.</item>
<item>Bugfixes</item>
<item>Bugfixes. Adapted for Android 13.</item>
<item>Full app usage while pack payment is pending</item>
</string-array>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public abstract class ApplicationSettings {
protected AuthorizationLevel getAuthorizationLevel() {
String userKey = PreferenceUtil.getSharedPreferenceString(R.string.key_user_key);
boolean hasPremiumPack = PreferenceUtil.getSharedPreferenceBoolean(R.string.key_internal_has_premium_pack);
boolean hasPremiumSubscription = PreferenceUtil.getSharedPreferenceBoolean(R.string.key_internal_has_premium_subscription);
boolean hasUnlockerApp = PreferenceUtil.getSharedPreferenceBoolean(R.string.key_internal_has_unlocker_app);
KeyValidationResult userKeyValidationResult = EncryptionUtil.validateUserKey(userKey);
boolean isAuthorizedUser = hasPremiumPack || hasUnlockerApp || userKeyValidationResult == KeyValidationResult.SUCCESS;
boolean isAuthorizedUser =
hasPremiumPack || hasPremiumSubscription || hasUnlockerApp || userKeyValidationResult == KeyValidationResult.SUCCESS;

if (isAuthorizedUser) {
return AuthorizationLevel.FULL_ACCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import de.jeisfeld.augendiagnoselib.util.DialogUtil.DisplayMessageDialogFragment.MessageDialogListener;
import de.jeisfeld.augendiagnoselib.util.EncryptionUtil;
import de.jeisfeld.augendiagnoselib.util.GoogleBillingHelper;
import de.jeisfeld.augendiagnoselib.util.GoogleBillingHelper.OnPurchaseQueryCompletedListener;
import de.jeisfeld.augendiagnoselib.util.Logger;
import de.jeisfeld.augendiagnoselib.util.PreferenceUtil;
import de.jeisfeld.augendiagnoselib.util.ReleaseNotesUtil;
import de.jeisfeld.augendiagnoselib.util.SystemUtil;
Expand All @@ -56,7 +56,7 @@ public abstract class StandardActivity extends BaseActivity {
/**
* The request code used to query for permission.
*/
protected static final int REQUEST_CODE_PERMISSION = 6;
private static final int REQUEST_CODE_PERMISSION = 6;
/**
* The requestCode with which the storage access framework is triggered for eye photo folder.
*/
Expand Down Expand Up @@ -164,13 +164,13 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
checkUnlockerApp();

// Check in-app purchases
GoogleBillingHelper.getInstance(this).hasPremiumPack(new OnPurchaseQueryCompletedListener() {
@Override
public void onHasPremiumPack(final boolean hasPremiumPack, final boolean isPending) {
PreferenceUtil.setSharedPreferenceBoolean(R.string.key_internal_has_premium_pack, hasPremiumPack);
if (hasPremiumPack) {
invalidateOptionsMenu();
}
GoogleBillingHelper.getInstance(this).hasPremiumPack((isSubscription, hasPremiumPack, isPending) -> {
PreferenceUtil.setSharedPreferenceBoolean(
isSubscription ? R.string.key_internal_has_premium_subscription : R.string.key_internal_has_premium_pack,
hasPremiumPack || isPending);
Logger.log("Pending:" + isPending + ", Success:" + hasPremiumPack);
if (hasPremiumPack || isPending) {
invalidateOptionsMenu();
}
});
}
Expand Down Expand Up @@ -427,19 +427,15 @@ public void onDialogNegativeClick(final DialogFragment dialog2) {
*/
private void checkPremiumPackAfterAuthorizationFailure() {
if (mIsCreationFailed) {
GoogleBillingHelper.getInstance(this).hasPremiumPack(new OnPurchaseQueryCompletedListener() {
@Override
public void onHasPremiumPack(final boolean hasPremiumPack, final boolean isPending) {
PreferenceUtil.setSharedPreferenceBoolean(R.string.key_internal_has_premium_pack, hasPremiumPack);
if (hasPremiumPack) {
restartActivity();
}
else if (isPending) {
DialogUtil.displayAuthorizationError(StandardActivity.this, R.string.message_dialog_trial_pending);
}
else {
DialogUtil.displayAuthorizationError(StandardActivity.this, R.string.message_dialog_trial_time);
}
GoogleBillingHelper.getInstance(this).hasPremiumPack((isSubscription, isPremium, isPending) -> {
PreferenceUtil.setSharedPreferenceBoolean(
isSubscription ? R.string.key_internal_has_premium_subscription : R.string.key_internal_has_premium_pack,
isPremium || isPending);
if (isPremium || isPending) {
restartActivity();
}
else {
DialogUtil.displayAuthorizationError(StandardActivity.this, R.string.message_dialog_trial_time);
}
});
}
Expand Down Expand Up @@ -747,7 +743,7 @@ protected enum SafMigrationStatus {
*
* @return The stored value.
*/
protected static SafMigrationStatus getStoredValue() {
private static SafMigrationStatus getStoredValue() {
int ordinal = PreferenceUtil.getSharedPreferenceInt(R.string.key_internal_saf_migration_status, -1);
for (SafMigrationStatus safMigrationStatus : values()) {
if (safMigrationStatus.ordinal() == ordinal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ public static GoogleBillingHelper getInstance(final Context context) {
*/
public void hasPremiumPack(final OnPurchaseQueryCompletedListener listener) {
if (mIsConnected) {
doHasPremiumPack(listener);
doHasPremiumPack(INAPP, listener);
doHasPremiumPack(SUBS, listener);
}
else {
mBillingClient.startConnection(new BillingClientStateListener() {
Expand All @@ -153,7 +154,8 @@ public void onBillingSetupFinished(@NonNull final BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingResponseCode.OK) {
Log.d(TAG, "Google Billing Connection established.");
mIsConnected = true;
doHasPremiumPack(listener);
doHasPremiumPack(INAPP, listener);
doHasPremiumPack(SUBS, listener);
}
else {
Log.i(TAG, "Google Billing Connection failed - " + billingResult.getDebugMessage());
Expand All @@ -173,10 +175,11 @@ public void onBillingServiceDisconnected() {
/**
* Get information if there is a premium pack for the app.
*
* @param listener The listener called when the information is available.
* @param productType The product type.
* @param listener The listener called when the information is available.
*/
private void doHasPremiumPack(final OnPurchaseQueryCompletedListener listener) {
mBillingClient.queryPurchasesAsync(QueryPurchasesParams.newBuilder().setProductType(INAPP).build(),
private void doHasPremiumPack(final String productType, final OnPurchaseQueryCompletedListener listener) {
mBillingClient.queryPurchasesAsync(QueryPurchasesParams.newBuilder().setProductType(productType).build(),
(billingResultInApp, listInApp) ->
mBillingClient.queryPurchasesAsync(QueryPurchasesParams.newBuilder().setProductType(INAPP).build(),
(billingResultSubs, listSubs) -> {
Expand Down Expand Up @@ -205,8 +208,8 @@ private void doHasPremiumPack(final OnPurchaseQueryCompletedListener listener) {
}
}
}

listener.onHasPremiumPack(result == PURCHASED, result == PENDING);
Logger.log("hasPremiumPack " + productType + ": " + result);
listener.onHasPremiumPack(SUBS.equals(productType), result == PURCHASED, result == PENDING);
}));

}
Expand Down Expand Up @@ -514,10 +517,11 @@ public interface OnPurchaseQueryCompletedListener {
/**
* Callback called if premium pack status is available.
*
* @param hasPremiumPack true if premium pack is available.
* @param isPending trie if there is a pending purchase.
* @param isSubscription indicator if this is subscription or pack.
* @param isPremium true if premium pack is available.
* @param isPending true if there is a pending purchase.
*/
void onHasPremiumPack(boolean hasPremiumPack, boolean isPending);
void onHasPremiumPack(boolean isSubscription, boolean isPremium, boolean isPending);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
<string name="message_dialog_failed_to_open_google_play">Google Play 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 zwei Wochen nutzbar. Bitte erwerben Sie ein Premium-Paket, um die App unbegrenzt nutzen zu können.</string>
<string name="message_dialog_trial_pending">Ihre Kauftransaktion des Premium Packs steht noch aus. Sie können die App verwenden, sobald die Transaktion abgeschlossen ist.</string>
<string name="message_dialog_trial_pending">Ihre Kauftransaktion des Premium Packs steht noch aus. Bitte stellen Sie sicher, dass die Transaktion abgeschlossen wird.</string>
<string name="message_dialog_trial_overlays">Die Testversion der App ist auf drei Overlays beschränkt. Bitte erwerben Sie ein Premium-Paket, um die App unbegrenzt nutzen zu können.</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_purchase_thanks_pending">Danke für ihren Kauf! Sobald die Transaktion bestätigt wurde, können Sie die App ohne Einschränkungen verwenden.</string>
<string name="message_dialog_purchase_thanks_pending">Danke für ihren Kauf! Bitte stellen Sie sicher, dass die Transaktion abgeschlossen wird.</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_select_photos_folder">Wählen Sie im folgenden Android-Dialogfeld den Ordner aus, in dem Sie Augenfotos speichern möchten, und bestätigen Sie unten.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
<string name="message_dialog_failed_to_open_google_play">Error al abrir Google Play.</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 dos semanas. Por favor, compre un paquete premium para obtener acceso ilimitado.</string>
<string name="message_dialog_trial_pending">Su transacción de compra del paquete premium está pendiente. Puede usar la aplicación tan pronto como se complete la transacción.</string>
<string name="message_dialog_trial_pending">Su transacción de compra del paquete premium está pendiente. Por favor, asegúrese de que la transacción se completará.</string>
<string name="message_dialog_trial_overlays">La versión de prueba de la aplicación limita el uso a los mapas iridológicos 1–3 solamente. Por favor, compre un paquete premium para obtener acceso ilimitado.</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_purchase_thanks_pending">¡Gracias por su compra! Tan pronto como se confirme la transacción, puede usar la aplicación sin limitaciones.</string>
<string name="message_dialog_purchase_thanks_pending">¡Gracias por su compra! Por favor, asegúrese de que la transacción se completará.</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_select_photos_folder">En el siguiente cuadro de diálogo de Android, seleccione la carpeta donde desea almacenar las fotos de los ojos y confirme en la parte inferior.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
<string name="message_dialog_failed_to_open_google_play">Erro ao abrir o Google Play.</string>
<string name="message_dialog_trial_names">Na versão de teste, é permitido usar apenas até três nomes. Por favor, compre um pacote premium para obter acesso ilimitado.</string>
<string name="message_dialog_trial_time">A versão de avaliação do aplicativo pode ser usada apenas por duas semanas. Por favor, compre um pacote premium para obter acesso ilimitado.</string>
<string name="message_dialog_trial_pending">Sua transação de compra do pacote premium está pendente. Você pode usar o aplicativo assim que a transação for concluída.</string>
<string name="message_dialog_trial_pending">Sua transação de compra do pacote premium está pendente. Certifique-se de que a transação será concluída.</string>
<string name="message_dialog_trial_overlays">A versão experimental do aplicativo limita o uso apenas aos mapas iridológicos 1–3. Por favor, compre um pacote premium para obter acesso ilimitado.</string>
<string name="message_dialog_purchase_thanks">Obrigado pela sua compra!</string>
<string name="message_dialog_purchase_thanks_premium">Obrigado pela sua compra! Agora você pode usar o aplicativo ilimitadamente.</string>
<string name="message_dialog_purchase_thanks_pending">Obrigado pela sua compra! Assim que a transação for confirmada, você poderá usar o aplicativo sem limitações.</string>
<string name="message_dialog_purchase_thanks_pending">Obrigado pela sua compra! Certifique-se de que a transação será concluída.</string>

<string name="message_dialog_select_extsdcard">Na seguinte caixa de diálogo do Android, selecione o cartão SD externo (o cartão SD completo ou a pasta selecionada) e confirme na parte inferior.</string>
<string name="message_dialog_select_photos_folder">Na caixa de diálogo a seguir do Android, selecione a pasta em que deseja armazenar as fotos dos olhos e confirme na parte inferior.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
<string name="message_dialog_failed_to_open_google_play">Failed to open Google Play.</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 two weeks. Please purchase a premium pack to get unlimited access.</string>
<string name="message_dialog_trial_pending">Your purchase transaction of premium pack is pending. You can use the app as soon as the transaction is complete.</string>
<string name="message_dialog_trial_pending">Your purchase transaction of premium pack is pending. Please ensure that the transaction will be completed.</string>
<string name="message_dialog_trial_overlays">The trial version of the app is limited to three overlays. Please purchase a premium pack to get unlimited access.</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_purchase_thanks_pending">Thanks for your purchase! As soon as the transaction is confirmed, you can use the app without limitations.</string>
<string name="message_dialog_purchase_thanks_pending">Thanks for your purchase! Please ensure that the transaction will be completed.</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_select_photos_folder">In the following Android dialog, please select the folder where you want to store eye photos and confirm at the bottom.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<string name="key_internal_show_utilities_halfscreen" translatable="false">show_utilities_halfscreen</string>
<string name="key_internal_outofmemoryerror" translatable="false">outofmemoryerror</string>
<string name="key_internal_has_premium_pack" translatable="false">has_premium_pack</string>
<string name="key_internal_has_premium_subscription" translatable="false">has_premium_subscription</string>
<string name="key_internal_has_unlocker_app" translatable="false">has_unlocker_app</string>
<string name="key_internal_unlocker_app_retries" translatable="false">unlocker_app_retries</string>
<string name="key_internal_counter_tempfiles" translatable="false">counter_tempfiles</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
<item>Auf Android 11 API umgestellt</item>
<item>Fehlerkorrekturen</item>
<item>Fehlerkorrekturen. Anpassungen für Android 12.</item>
<item>Fehlerkorrekturen</item>
<item>Fehlerkorrekturen. Anpassungen für Android 13.</item>
<item>Vollständige App-Nutzung, während die Paketzahlung aussteht</item>
</string-array>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
<item>Cambiado a la API de Android 11</item>
<item>Corrección de errores</item>
<item>Corrección de errores. Adaptado para Android 12.</item>
<item>Corrección de errores</item>
<item>Corrección de errores. Adaptado para Android 13.</item>
<item>Uso completo de la aplicación mientras el pago del paquete está pendiente</item>
</string-array>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<item>Mudou para Android 11 API</item>
<item>Correções de bugs</item>
<item>Correções de bugs. Adaptado para Android 12.</item>
<item>Correções de bugs</item>
<item>Correções de bugs. Adaptado para Android 13.</item>
<item>Uso total do aplicativo enquanto o pagamento do pacote está pendente</item>
</string-array>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
<item>Switched to Android 11 API</item>
<item>Bugfixes</item>
<item>Bugfixes. Adapted for Android 12.</item>
<item>Bugfixes</item>
<item>Bugfixes. Adapted for Android 13.</item>
<item>Full app usage while pack payment is pending</item>
</string-array>

</resources>

0 comments on commit c2477f3

Please sign in to comment.