-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for Amazon purchase dialog not showing up #552
Changes from 30 commits
3de0b41
a11a295
619967e
4b6faea
0e93706
e8c5a3e
5aa5306
7d9a3fa
51c425b
94d85a6
e1d7863
7792135
bb5cfeb
6bef4de
03cbd27
72659e3
4cde5a3
8a32ed4
dfdc9a4
90f9631
885b343
4fc2c9c
177c964
bafef41
2516c89
9bd8e0f
72672ac
2cbd49c
28ee907
0b147e4
3cf3048
3d03404
3ed4185
22a4aa3
9a17cb2
11dad87
bfed36f
a9f6872
f8bb051
252d825
0872ebb
f641be4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.revenuecat.purchases.amazon | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.os.ResultReceiver | ||
import com.revenuecat.purchases.amazon.purchasing.ProxyAmazonBillingDelegate | ||
|
||
internal class ProxyAmazonBillingActivity : Activity() { | ||
|
||
companion object { | ||
const val EXTRAS_RESULT_RECEIVER = "result_receiver" | ||
const val EXTRAS_SKU = "sku" | ||
const val EXTRAS_SERVICE_PROVIDER = "service_provider" | ||
const val EXTRAS_REQUEST_ID = "request_id" | ||
|
||
fun newStartIntent( | ||
context: Context, | ||
resultReceiver: ResultReceiver, | ||
sku: String, | ||
purchasingServiceProvider: PurchasingServiceProvider | ||
): Intent { | ||
val intent = Intent(context, ProxyAmazonBillingActivity::class.java) | ||
intent.putExtra(EXTRAS_RESULT_RECEIVER, resultReceiver) | ||
intent.putExtra(EXTRAS_SKU, sku) | ||
intent.putExtra(EXTRAS_SERVICE_PROVIDER, purchasingServiceProvider) | ||
return intent | ||
} | ||
} | ||
|
||
private var proxyAmazonBillingDelegate: ProxyAmazonBillingDelegate? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
// Applying theme programmatically because when applying via AndroidManifest, theme is not being | ||
// applied correctly. | ||
// What happens is that applying @android:style/Theme.Translucent.NoTitleBar in the manifest works | ||
// but applying a theme that has that theme as parent, the Activity is not translucent | ||
setTheme(R.style.ProxyAmazonBillingActivityTheme) | ||
super.onCreate(savedInstanceState) | ||
|
||
proxyAmazonBillingDelegate = ProxyAmazonBillingDelegate() | ||
proxyAmazonBillingDelegate?.onCreate(this, savedInstanceState) | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
proxyAmazonBillingDelegate?.onDestroy(this) | ||
proxyAmazonBillingDelegate = null | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.revenuecat.purchases.amazon | ||
|
||
import android.app.Activity | ||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.IntentFilter | ||
import androidx.annotation.VisibleForTesting | ||
import java.lang.ref.WeakReference | ||
|
||
internal class ProxyAmazonBillingActivityBroadcastReceiver(activity: Activity) : BroadcastReceiver() { | ||
|
||
private val activity: WeakReference<Activity> | ||
|
||
init { | ||
this.activity = WeakReference(activity) | ||
} | ||
|
||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) | ||
var onReceiveCalled = false | ||
vegaro marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is only added for a test... I'm not sure but is there a way of testing whether the activity was finished in the test scenario? If so we could remove this property entirely. If not, I guess we can keep it for better tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried but I couldn't find anything 😢 I thought about checking if state is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will probably be hard to mock, since it's created by the activity. I think it's ok, we can leave as is 👍 |
||
|
||
override fun onReceive(context: Context, intent: Intent) { | ||
onReceiveCalled = true | ||
activity.get()?.finish() | ||
} | ||
|
||
companion object { | ||
vegaro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const val PURCHASE_FINISHED_ACTION = "com.revenuecat.purchases.purchase_finished" | ||
|
||
fun newPurchaseFinishedIntentFilter(): IntentFilter = IntentFilter(PURCHASE_FINISHED_ACTION) | ||
|
||
fun newPurchaseFinishedIntent(applicationContext: Context): Intent { | ||
return Intent(PURCHASE_FINISHED_ACTION).also { intent -> | ||
intent.setPackage(applicationContext.packageName) | ||
vegaro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tonidero any ideas on how to test that this is called? I could do some little DI framework that injects a mocked
ProxyAmazonBillingDelegate
but I think that's too much lol