update some code

This commit is contained in:
CounterFire2023 2023-11-15 16:51:35 +08:00
parent 17cfd36705
commit 8c7fd6013b
5 changed files with 15 additions and 26 deletions

View File

@ -182,9 +182,7 @@ class MainActivity : UnityPlayerActivity(), Cocos2dxHelperListener {
Log.w(TAG, "already login: " + account.idToken)
mGoogleSignInClient!!.silentSignIn()
.addOnCompleteListener(this) { completedTask: Task<GoogleSignInAccount> ->
handleSignInResult(
completedTask
)
handleSignInResult(completedTask)
}
} else {
val signInIntent = mGoogleSignInClient!!.signInIntent
@ -198,10 +196,7 @@ class MainActivity : UnityPlayerActivity(), Cocos2dxHelperListener {
Log.w(TAG, "need refresh accessToken")
mAppAuthSvr!!.refreshToken(funId, null)
} else {
Log.w(
TAG,
"already login, accessToken not expired, id token:: ${state.idToken}"
)
Log.w(TAG, "already login, accessToken not expired, id token:: ${state.idToken}")
JcSDK.nativeCb(this.funId, null, state.idToken)
}
} else {
@ -218,8 +213,7 @@ class MainActivity : UnityPlayerActivity(), Cocos2dxHelperListener {
private fun handleSignInResult(completedTask: Task<GoogleSignInAccount>) {
try {
val account = completedTask.getResult(ApiException::class.java)
Log.w(TAG, "signIn success: ")
Log.w(TAG, "gsa idToken: ${account.idToken}")
Log.w(TAG, "success: gsa idToken: ${account.idToken}")
JcSDK.nativeCb(funId, null, account.idToken)
// Signed in successfully, show authenticated UI.
} catch (e: ApiException) {

View File

@ -40,7 +40,6 @@ class JcSDK {
/**
* @Deprecated
* 不使用该方法, 直接由unity调用cpp方法
* @param password
*/
@JvmStatic
@ -150,7 +149,7 @@ class JcSDK {
val skuList: MutableList<String> = ArrayList()
if (skuListStr.contains(",")) {
val skuArr = skuListStr.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
skuList.addAll(Arrays.asList(*skuArr))
skuList.addAll(listOf(*skuArr))
} else {
skuList.add(skuListStr)
}
@ -200,7 +199,6 @@ class JcSDK {
}
fun nativeCb(funId: String?, error: String?, dataStr: String?) {
var funId = funId
val result = JSONObject()
try {
if (Strings.isNullOrEmpty(error)) {
@ -213,15 +211,11 @@ class JcSDK {
} catch (e: JSONException) {
Log.e(TAG, "JSONException: " + e.message)
}
if (funId == null || funId.isEmpty()) {
funId = MainActivity.app!!.funId
}
Log.i(TAG, String.format("%s native cb, error: %s, data: %s", funId, error, dataStr))
if (funId != null && funId.startsWith(FUNID_PREFIX)) {
EventBus.getDefault().post(CallJSEvent(funId, result.toString()))
} else {
val finalFunId = funId
ThreadUtils.runInMain { runJS(finalFunId, "jniCallback", arrayOf(result.toString())) }
ThreadUtils.runInMain { runJS(funId, "jniCallback", arrayOf(result.toString())) }
}
}

View File

@ -1,5 +1,6 @@
package com.jc.jcfw.google
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.util.Log
@ -102,8 +103,8 @@ class PayClient : Activity(), PurchasesUpdatedListener {
}
private fun purchaseUpdateCb(funId: String?, error: String?, dataStr: String?) {
if (funId == null || funId.isEmpty()) {
if (mFunId != null && !mFunId!!.isEmpty()) {
if (funId.isNullOrEmpty()) {
if (!mFunId.isNullOrEmpty()) {
runOnUiThread { JcSDK.nativeCb(mFunId, error, dataStr) }
mFunId = null
}
@ -150,7 +151,7 @@ class PayClient : Activity(), PurchasesUpdatedListener {
.build()
billingClient!!.queryProductDetailsAsync(
params
) { billingResult: BillingResult?, productDetailsList: List<ProductDetails> ->
) { _: BillingResult?, productDetailsList: List<ProductDetails> ->
// Process the result
val pMap: MutableMap<String, ProductDetails> = HashMap()
for (details in productDetailsList) {
@ -176,7 +177,7 @@ class PayClient : Activity(), PurchasesUpdatedListener {
fun queryPurchase(funId: String?) {
billingClient!!.queryPurchasesAsync(
QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build()
) { billingResult: BillingResult?, purchases: List<Purchase> ->
) { _: BillingResult?, purchases: List<Purchase> ->
// Process the result
val dataArr = JSONArray()
var hasErr = false
@ -197,7 +198,7 @@ class PayClient : Activity(), PurchasesUpdatedListener {
}
fun buyOne(funId: String?, productId: String, orderId: String?) {
if (mFunId != null && !mFunId!!.isEmpty()) {
if (!mFunId.isNullOrEmpty()) {
purchaseUpdateCb(funId, "another purchase is in progress", null)
return
}
@ -231,6 +232,7 @@ class PayClient : Activity(), PurchasesUpdatedListener {
companion object {
private const val TAG = "GooglePayClient"
@SuppressLint("StaticFieldLeak")
@Volatile
private var mInstance: PayClient? = null
private var billingClient: BillingClient? = null

View File

@ -42,7 +42,7 @@ object DriveUtils {
.execute()
querySuccess = true
for (file in files.files) {
Log.i(TAG, String.format("Found file: %s (%s)\n", file.name, file.id))
Log.i(TAG, "Found file: ${file.name} (${file.id})\n")
if (file.name == fileName) {
fileId = file.id
break
@ -90,7 +90,7 @@ object DriveUtils {
val file = service.files().create(fileMetadata, mediaContent)
.setFields("id")
.execute()
Log.i(TAG, String.format("%s upload success, File ID: %s", fileName, file.id))
Log.i(TAG, "%fileName upload success, File ID: ${file.id}")
return file.id
}
}

View File

@ -17,7 +17,6 @@ import java.io.File
import java.io.IOException
class DriverApiUtils {
private val TAG = javaClass.simpleName
var token = ""
constructor() {}
@ -30,7 +29,7 @@ class DriverApiUtils {
val client = OkHttpClient().newBuilder()
.build()
val request: Request = Builder()
.url(driveApiBase + "?spaces=appDataFolder&fields=files(id, name, modifiedTime)")
.url("$driveApiBase?spaces=appDataFolder&fields=files(id, name, modifiedTime)")
.get()
.addHeader("Authorization", "Bearer $token")
.build()