update some code
This commit is contained in:
parent
17cfd36705
commit
8c7fd6013b
@ -182,9 +182,7 @@ class MainActivity : UnityPlayerActivity(), Cocos2dxHelperListener {
|
|||||||
Log.w(TAG, "already login: " + account.idToken)
|
Log.w(TAG, "already login: " + account.idToken)
|
||||||
mGoogleSignInClient!!.silentSignIn()
|
mGoogleSignInClient!!.silentSignIn()
|
||||||
.addOnCompleteListener(this) { completedTask: Task<GoogleSignInAccount> ->
|
.addOnCompleteListener(this) { completedTask: Task<GoogleSignInAccount> ->
|
||||||
handleSignInResult(
|
handleSignInResult(completedTask)
|
||||||
completedTask
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val signInIntent = mGoogleSignInClient!!.signInIntent
|
val signInIntent = mGoogleSignInClient!!.signInIntent
|
||||||
@ -198,10 +196,7 @@ class MainActivity : UnityPlayerActivity(), Cocos2dxHelperListener {
|
|||||||
Log.w(TAG, "need refresh accessToken")
|
Log.w(TAG, "need refresh accessToken")
|
||||||
mAppAuthSvr!!.refreshToken(funId, null)
|
mAppAuthSvr!!.refreshToken(funId, null)
|
||||||
} else {
|
} else {
|
||||||
Log.w(
|
Log.w(TAG, "already login, accessToken not expired, id token:: ${state.idToken}")
|
||||||
TAG,
|
|
||||||
"already login, accessToken not expired, id token:: ${state.idToken}"
|
|
||||||
)
|
|
||||||
JcSDK.nativeCb(this.funId, null, state.idToken)
|
JcSDK.nativeCb(this.funId, null, state.idToken)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -218,8 +213,7 @@ class MainActivity : UnityPlayerActivity(), Cocos2dxHelperListener {
|
|||||||
private fun handleSignInResult(completedTask: Task<GoogleSignInAccount>) {
|
private fun handleSignInResult(completedTask: Task<GoogleSignInAccount>) {
|
||||||
try {
|
try {
|
||||||
val account = completedTask.getResult(ApiException::class.java)
|
val account = completedTask.getResult(ApiException::class.java)
|
||||||
Log.w(TAG, "signIn success: ")
|
Log.w(TAG, "success: gsa idToken: ${account.idToken}")
|
||||||
Log.w(TAG, "gsa idToken: ${account.idToken}")
|
|
||||||
JcSDK.nativeCb(funId, null, account.idToken)
|
JcSDK.nativeCb(funId, null, account.idToken)
|
||||||
// Signed in successfully, show authenticated UI.
|
// Signed in successfully, show authenticated UI.
|
||||||
} catch (e: ApiException) {
|
} catch (e: ApiException) {
|
||||||
|
@ -40,7 +40,6 @@ class JcSDK {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @Deprecated
|
* @Deprecated
|
||||||
* 不使用该方法, 直接由unity调用cpp方法
|
|
||||||
* @param password
|
* @param password
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@ -150,7 +149,7 @@ class JcSDK {
|
|||||||
val skuList: MutableList<String> = ArrayList()
|
val skuList: MutableList<String> = ArrayList()
|
||||||
if (skuListStr.contains(",")) {
|
if (skuListStr.contains(",")) {
|
||||||
val skuArr = skuListStr.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
val skuArr = skuListStr.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||||
skuList.addAll(Arrays.asList(*skuArr))
|
skuList.addAll(listOf(*skuArr))
|
||||||
} else {
|
} else {
|
||||||
skuList.add(skuListStr)
|
skuList.add(skuListStr)
|
||||||
}
|
}
|
||||||
@ -200,7 +199,6 @@ class JcSDK {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun nativeCb(funId: String?, error: String?, dataStr: String?) {
|
fun nativeCb(funId: String?, error: String?, dataStr: String?) {
|
||||||
var funId = funId
|
|
||||||
val result = JSONObject()
|
val result = JSONObject()
|
||||||
try {
|
try {
|
||||||
if (Strings.isNullOrEmpty(error)) {
|
if (Strings.isNullOrEmpty(error)) {
|
||||||
@ -213,15 +211,11 @@ class JcSDK {
|
|||||||
} catch (e: JSONException) {
|
} catch (e: JSONException) {
|
||||||
Log.e(TAG, "JSONException: " + e.message)
|
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))
|
Log.i(TAG, String.format("%s native cb, error: %s, data: %s", funId, error, dataStr))
|
||||||
if (funId != null && funId.startsWith(FUNID_PREFIX)) {
|
if (funId != null && funId.startsWith(FUNID_PREFIX)) {
|
||||||
EventBus.getDefault().post(CallJSEvent(funId, result.toString()))
|
EventBus.getDefault().post(CallJSEvent(funId, result.toString()))
|
||||||
} else {
|
} else {
|
||||||
val finalFunId = funId
|
ThreadUtils.runInMain { runJS(funId, "jniCallback", arrayOf(result.toString())) }
|
||||||
ThreadUtils.runInMain { runJS(finalFunId, "jniCallback", arrayOf(result.toString())) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.jc.jcfw.google
|
package com.jc.jcfw.google
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@ -102,8 +103,8 @@ class PayClient : Activity(), PurchasesUpdatedListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun purchaseUpdateCb(funId: String?, error: String?, dataStr: String?) {
|
private fun purchaseUpdateCb(funId: String?, error: String?, dataStr: String?) {
|
||||||
if (funId == null || funId.isEmpty()) {
|
if (funId.isNullOrEmpty()) {
|
||||||
if (mFunId != null && !mFunId!!.isEmpty()) {
|
if (!mFunId.isNullOrEmpty()) {
|
||||||
runOnUiThread { JcSDK.nativeCb(mFunId, error, dataStr) }
|
runOnUiThread { JcSDK.nativeCb(mFunId, error, dataStr) }
|
||||||
mFunId = null
|
mFunId = null
|
||||||
}
|
}
|
||||||
@ -150,7 +151,7 @@ class PayClient : Activity(), PurchasesUpdatedListener {
|
|||||||
.build()
|
.build()
|
||||||
billingClient!!.queryProductDetailsAsync(
|
billingClient!!.queryProductDetailsAsync(
|
||||||
params
|
params
|
||||||
) { billingResult: BillingResult?, productDetailsList: List<ProductDetails> ->
|
) { _: BillingResult?, productDetailsList: List<ProductDetails> ->
|
||||||
// Process the result
|
// Process the result
|
||||||
val pMap: MutableMap<String, ProductDetails> = HashMap()
|
val pMap: MutableMap<String, ProductDetails> = HashMap()
|
||||||
for (details in productDetailsList) {
|
for (details in productDetailsList) {
|
||||||
@ -176,7 +177,7 @@ class PayClient : Activity(), PurchasesUpdatedListener {
|
|||||||
fun queryPurchase(funId: String?) {
|
fun queryPurchase(funId: String?) {
|
||||||
billingClient!!.queryPurchasesAsync(
|
billingClient!!.queryPurchasesAsync(
|
||||||
QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build()
|
QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build()
|
||||||
) { billingResult: BillingResult?, purchases: List<Purchase> ->
|
) { _: BillingResult?, purchases: List<Purchase> ->
|
||||||
// Process the result
|
// Process the result
|
||||||
val dataArr = JSONArray()
|
val dataArr = JSONArray()
|
||||||
var hasErr = false
|
var hasErr = false
|
||||||
@ -197,7 +198,7 @@ class PayClient : Activity(), PurchasesUpdatedListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun buyOne(funId: String?, productId: String, orderId: String?) {
|
fun buyOne(funId: String?, productId: String, orderId: String?) {
|
||||||
if (mFunId != null && !mFunId!!.isEmpty()) {
|
if (!mFunId.isNullOrEmpty()) {
|
||||||
purchaseUpdateCb(funId, "another purchase is in progress", null)
|
purchaseUpdateCb(funId, "another purchase is in progress", null)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -231,6 +232,7 @@ class PayClient : Activity(), PurchasesUpdatedListener {
|
|||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "GooglePayClient"
|
private const val TAG = "GooglePayClient"
|
||||||
|
|
||||||
|
@SuppressLint("StaticFieldLeak")
|
||||||
@Volatile
|
@Volatile
|
||||||
private var mInstance: PayClient? = null
|
private var mInstance: PayClient? = null
|
||||||
private var billingClient: BillingClient? = null
|
private var billingClient: BillingClient? = null
|
||||||
|
@ -42,7 +42,7 @@ object DriveUtils {
|
|||||||
.execute()
|
.execute()
|
||||||
querySuccess = true
|
querySuccess = true
|
||||||
for (file in files.files) {
|
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) {
|
if (file.name == fileName) {
|
||||||
fileId = file.id
|
fileId = file.id
|
||||||
break
|
break
|
||||||
@ -90,7 +90,7 @@ object DriveUtils {
|
|||||||
val file = service.files().create(fileMetadata, mediaContent)
|
val file = service.files().create(fileMetadata, mediaContent)
|
||||||
.setFields("id")
|
.setFields("id")
|
||||||
.execute()
|
.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
|
return file.id
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,6 @@ import java.io.File
|
|||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
class DriverApiUtils {
|
class DriverApiUtils {
|
||||||
private val TAG = javaClass.simpleName
|
|
||||||
var token = ""
|
var token = ""
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
@ -30,7 +29,7 @@ class DriverApiUtils {
|
|||||||
val client = OkHttpClient().newBuilder()
|
val client = OkHttpClient().newBuilder()
|
||||||
.build()
|
.build()
|
||||||
val request: Request = Builder()
|
val request: Request = Builder()
|
||||||
.url(driveApiBase + "?spaces=appDataFolder&fields=files(id, name, modifiedTime)")
|
.url("$driveApiBase?spaces=appDataFolder&fields=files(id, name, modifiedTime)")
|
||||||
.get()
|
.get()
|
||||||
.addHeader("Authorization", "Bearer $token")
|
.addHeader("Authorization", "Bearer $token")
|
||||||
.build()
|
.build()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user