From 6df2101dc444f11c0503c46a99d5efb5979a0881 Mon Sep 17 00:00:00 2001 From: Vishal Nehra Date: Mon, 15 Jul 2024 01:58:49 +0530 Subject: [PATCH 1/2] Fixing purchase flow crash --- .../fileutilities/PermissionsActivity.kt | 34 +++++++++---------- .../home_page/WelcomePermissionScreen.kt | 34 +++++++++---------- .../home_page/ui/options/Billing.kt | 24 +++++++++---- 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt b/app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt index 34250277..4f362cd3 100644 --- a/app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt +++ b/app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt @@ -165,29 +165,29 @@ open class PermissionsActivity : if (VERSION.SDK_INT >= Build.VERSION_CODES.R) { try { isFound = ( - ActivityCompat.checkSelfPermission( - this, Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION - ) - == PackageManager.PERMISSION_GRANTED - ) || ( - ActivityCompat.checkSelfPermission( - this, Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION - ) + ActivityCompat.checkSelfPermission( + this, Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION + ) + == PackageManager.PERMISSION_GRANTED + ) || ( + ActivityCompat.checkSelfPermission( + this, Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION + ) - == PackageManager.PERMISSION_GRANTED - ) || Environment.isExternalStorageManager() + == PackageManager.PERMISSION_GRANTED + ) || Environment.isExternalStorageManager() } catch (anfe: ActivityNotFoundException) { - log.warn("all files access permission activity missing, fallback to default",anfe) + log.warn("all files access permission activity missing, fallback to default", anfe) } } if (!isFound) { isFound = ( - ActivityCompat.checkSelfPermission( - this, - Manifest.permission.WRITE_EXTERNAL_STORAGE - ) - == PackageManager.PERMISSION_GRANTED - ) + ActivityCompat.checkSelfPermission( + this, + Manifest.permission.WRITE_EXTERNAL_STORAGE + ) + == PackageManager.PERMISSION_GRANTED + ) } return isFound } diff --git a/app/src/main/java/com/amaze/fileutilities/home_page/WelcomePermissionScreen.kt b/app/src/main/java/com/amaze/fileutilities/home_page/WelcomePermissionScreen.kt index a6010e29..2f926b34 100644 --- a/app/src/main/java/com/amaze/fileutilities/home_page/WelcomePermissionScreen.kt +++ b/app/src/main/java/com/amaze/fileutilities/home_page/WelcomePermissionScreen.kt @@ -151,29 +151,29 @@ abstract class WelcomePermissionScreen : if (VERSION.SDK_INT >= Build.VERSION_CODES.R) { try { isFound = ( - ActivityCompat.checkSelfPermission( - this, Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION - ) - == PackageManager.PERMISSION_GRANTED - ) || ( - ActivityCompat.checkSelfPermission( - this, Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION - ) + ActivityCompat.checkSelfPermission( + this, Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION + ) + == PackageManager.PERMISSION_GRANTED + ) || ( + ActivityCompat.checkSelfPermission( + this, Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION + ) - == PackageManager.PERMISSION_GRANTED - ) || Environment.isExternalStorageManager() + == PackageManager.PERMISSION_GRANTED + ) || Environment.isExternalStorageManager() } catch (anfe: ActivityNotFoundException) { - log.warn("all files access permission activity missing, fallback to default",anfe) + log.warn("all files access permission activity missing, fallback to default", anfe) } } if (!isFound) { isFound = ( - ActivityCompat.checkSelfPermission( - this, - Manifest.permission.WRITE_EXTERNAL_STORAGE - ) - == PackageManager.PERMISSION_GRANTED - ) + ActivityCompat.checkSelfPermission( + this, + Manifest.permission.WRITE_EXTERNAL_STORAGE + ) + == PackageManager.PERMISSION_GRANTED + ) } return isFound } diff --git a/app/src/play/java/com/amaze/fileutilities/home_page/ui/options/Billing.kt b/app/src/play/java/com/amaze/fileutilities/home_page/ui/options/Billing.kt index 911072f7..294d4fc7 100644 --- a/app/src/play/java/com/amaze/fileutilities/home_page/ui/options/Billing.kt +++ b/app/src/play/java/com/amaze/fileutilities/home_page/ui/options/Billing.kt @@ -163,7 +163,10 @@ class Billing(val context: Context, private var uniqueId: String) : response.responseCode, purchases?.size, ) - activity.getString(R.string.operation_failed).let { activity.showToastInCenter(it) } + if (::activity.isInitialized && !activity.isFinishing + && !activity.isDestroyed) { + activity.getString(R.string.operation_failed).let { activity.showToastInCenter(it) } + } } } @@ -226,7 +229,8 @@ class Billing(val context: Context, private var uniqueId: String) : } catch (e: Exception) { log.warn("failed to update subscription state for trial validation", e) } - if (!activity.isFinishing && !activity.isDestroyed) { + if (::activity.isInitialized && !activity.isFinishing + && !activity.isDestroyed) { activity.runOnUiThread { purchaseDialog?.dismiss() Utils.buildSubscriptionPurchasedDialog(activity).show() @@ -241,7 +245,11 @@ class Billing(val context: Context, private var uniqueId: String) : purchaseToken, ) activity.getString(R.string.operation_failed).let { - activity.showToastInCenter(it) + if (::activity.isInitialized && !activity.isFinishing + && !activity.isDestroyed) { + activity.showToastInCenter(it) + } + } } } @@ -486,8 +494,11 @@ class Billing(val context: Context, private var uniqueId: String) : val billingFlowParams = BillingFlowParams.newBuilder().setProductDetailsParamsList( listOf(productDetailsParams) ).build() - activity.let { - billingClient.launchBillingFlow(it, billingFlowParams) + if (::activity.isInitialized && !activity.isFinishing + && !activity.isDestroyed) { + activity.let { + billingClient.launchBillingFlow(it, billingFlowParams) + } } } @@ -550,7 +561,8 @@ class Billing(val context: Context, private var uniqueId: String) : * * */ - if (!activity.isFinishing && !activity.isDestroyed) { + if (::activity.isInitialized && !activity.isFinishing + && !activity.isDestroyed) { activity.runOnUiThread { val dialogBuilder = AlertDialog.Builder(activity, R.style.Custom_Dialog_Dark) .setTitle(R.string.subscribe) From 9e8746a97e10deda52aa4bd788295d663f7a96d6 Mon Sep 17 00:00:00 2001 From: Vishal Nehra Date: Mon, 15 Jul 2024 01:59:51 +0530 Subject: [PATCH 2/2] Apply spotless --- .../home_page/ui/options/Billing.kt | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/src/play/java/com/amaze/fileutilities/home_page/ui/options/Billing.kt b/app/src/play/java/com/amaze/fileutilities/home_page/ui/options/Billing.kt index 294d4fc7..bf123bd4 100644 --- a/app/src/play/java/com/amaze/fileutilities/home_page/ui/options/Billing.kt +++ b/app/src/play/java/com/amaze/fileutilities/home_page/ui/options/Billing.kt @@ -163,8 +163,9 @@ class Billing(val context: Context, private var uniqueId: String) : response.responseCode, purchases?.size, ) - if (::activity.isInitialized && !activity.isFinishing - && !activity.isDestroyed) { + if (::activity.isInitialized && !activity.isFinishing && + !activity.isDestroyed + ) { activity.getString(R.string.operation_failed).let { activity.showToastInCenter(it) } } } @@ -229,8 +230,9 @@ class Billing(val context: Context, private var uniqueId: String) : } catch (e: Exception) { log.warn("failed to update subscription state for trial validation", e) } - if (::activity.isInitialized && !activity.isFinishing - && !activity.isDestroyed) { + if (::activity.isInitialized && !activity.isFinishing && + !activity.isDestroyed + ) { activity.runOnUiThread { purchaseDialog?.dismiss() Utils.buildSubscriptionPurchasedDialog(activity).show() @@ -245,11 +247,11 @@ class Billing(val context: Context, private var uniqueId: String) : purchaseToken, ) activity.getString(R.string.operation_failed).let { - if (::activity.isInitialized && !activity.isFinishing - && !activity.isDestroyed) { + if (::activity.isInitialized && !activity.isFinishing && + !activity.isDestroyed + ) { activity.showToastInCenter(it) } - } } } @@ -494,8 +496,9 @@ class Billing(val context: Context, private var uniqueId: String) : val billingFlowParams = BillingFlowParams.newBuilder().setProductDetailsParamsList( listOf(productDetailsParams) ).build() - if (::activity.isInitialized && !activity.isFinishing - && !activity.isDestroyed) { + if (::activity.isInitialized && !activity.isFinishing && + !activity.isDestroyed + ) { activity.let { billingClient.launchBillingFlow(it, billingFlowParams) } @@ -561,8 +564,9 @@ class Billing(val context: Context, private var uniqueId: String) : * * */ - if (::activity.isInitialized && !activity.isFinishing - && !activity.isDestroyed) { + if (::activity.isInitialized && !activity.isFinishing && + !activity.isDestroyed + ) { activity.runOnUiThread { val dialogBuilder = AlertDialog.Builder(activity, R.style.Custom_Dialog_Dark) .setTitle(R.string.subscribe)