Skip to content

Commit

Permalink
Merge pull request #174 from TeamAmaze/bugfix/purchase-flow
Browse files Browse the repository at this point in the history
Fixing purchase flow crash
  • Loading branch information
VishalNehra authored Jul 14, 2024
2 parents 1eaf9c2 + 9e8746a commit 34f554f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 40 deletions.
34 changes: 17 additions & 17 deletions app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ 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) }
}
}
}

Expand Down Expand Up @@ -226,7 +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.isFinishing && !activity.isDestroyed) {
if (::activity.isInitialized && !activity.isFinishing &&
!activity.isDestroyed
) {
activity.runOnUiThread {
purchaseDialog?.dismiss()
Utils.buildSubscriptionPurchasedDialog(activity).show()
Expand All @@ -241,7 +247,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)
}
}
}
}
Expand Down Expand Up @@ -486,8 +496,12 @@ 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)
}
}
}

Expand Down Expand Up @@ -550,7 +564,9 @@ 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)
Expand Down

0 comments on commit 34f554f

Please sign in to comment.