Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions vending-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ dependencies {
implementation "com.android.volley:volley:$volleyVersion"

implementation "androidx.webkit:webkit:$webkitVersion"
implementation "androidx.browser:browser:1.8.0"

implementation "com.squareup.wire:wire-grpc-client:$wireVersion"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
package org.microg.vending.billing.ui

import android.accounts.Account
import android.accounts.AccountManager
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Rect
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.Gravity
Expand All @@ -20,6 +22,7 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.annotation.RequiresApi
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.os.bundleOf
import androidx.lifecycle.lifecycleScope
import com.android.billingclient.api.BillingClient
Expand All @@ -30,6 +33,8 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.microg.vending.billing.ADD_PAYMENT_METHOD_URL
import org.microg.vending.billing.TAG
import java.net.URLEncoder
import java.util.concurrent.TimeUnit

private const val ADD_PAYMENT_REQUEST_CODE = 30002

Expand Down Expand Up @@ -95,13 +100,17 @@ class InAppBillingHostActivity : ComponentActivity() {
}

private fun openPaymentMethodActivity(src: String?, account: Account?) {
val intent = Intent(this, PlayWebViewActivity::class.java)
intent.putExtra(KEY_WEB_VIEW_ACTION, WebViewAction.ADD_PAYMENT_METHOD.toString())
intent.putExtra(KEY_WEB_VIEW_OPEN_URL, ADD_PAYMENT_METHOD_URL)
account?.let {
intent.putExtra(KEY_WEB_VIEW_ACCOUNT, account)
lifecycleScope.launchWhenCreated {
val service = "weblogin:continue=" + URLEncoder.encode(ADD_PAYMENT_METHOD_URL, "utf-8")
val authUrl = withContext(Dispatchers.IO) {
val bundle =
AccountManager.get(this@InAppBillingHostActivity).getAuthToken(account, service, null, null, null, null).getResult(20, TimeUnit.SECONDS)
bundle.getString(AccountManager.KEY_AUTHTOKEN)
}
val customTabs = CustomTabsIntent.Builder().build()
customTabs.intent.setData(Uri.parse(authUrl))
startActivityForResult(customTabs.intent, ADD_PAYMENT_REQUEST_CODE, customTabs.startAnimationBundle)
}
startActivityForResult(intent, ADD_PAYMENT_REQUEST_CODE)
}

override fun onTouchEvent(event: MotionEvent?): Boolean {
Expand Down