|
@@ -7,10 +7,10 @@ import android.content.Intent
|
|
|
import android.os.Bundle
|
|
|
import android.text.TextUtils
|
|
|
import cn.yyxx.eyuancomm.comm.entity.SdkChargeInfo
|
|
|
+import cn.yyxx.eyuancomm.comm.ext.setThrottleListener
|
|
|
import cn.yyxx.eyuancomm.comm.internal.feature.IApplication
|
|
|
import cn.yyxx.eyuancomm.comm.internal.feature.IFeature
|
|
|
import cn.yyxx.eyuancomm.comm.internal.feature.ILifeCycle
|
|
|
-import cn.yyxx.eyuancomm.comm.internal.feature.IOrder
|
|
|
import cn.yyxx.eyuancomm.comm.utils.Logger
|
|
|
import cn.yyxx.eyuancomm.comm.widget.ScaleLoadingDialog
|
|
|
import com.huawei.agconnect.AGCRoutePolicy
|
|
@@ -19,6 +19,7 @@ import com.huawei.agconnect.AGConnectOptionsBuilder
|
|
|
import com.huawei.agconnect.api.AGConnectApi
|
|
|
import com.huawei.agconnect.auth.AGConnectAuth
|
|
|
import com.huawei.agconnect.auth.AGConnectAuthCredential
|
|
|
+import com.huawei.hmf.tasks.Task
|
|
|
import com.huawei.hms.analytics.HiAnalytics
|
|
|
import com.huawei.hms.analytics.HiAnalyticsInstance
|
|
|
import com.huawei.hms.analytics.HiAnalyticsTools
|
|
@@ -41,12 +42,13 @@ import org.json.JSONObject
|
|
|
* @author #Suyghur.
|
|
|
* Created on 2022/01/26
|
|
|
*/
|
|
|
-class ChannelSdkHuawei : IFeature, IApplication, ILifeCycle,IOrder {
|
|
|
+class ChannelSdkHuawei : IFeature, IApplication, ILifeCycle {
|
|
|
|
|
|
private var loginDialog: HuaweiLoginDialog? = null
|
|
|
private var loadingDialog: ScaleLoadingDialog? = null
|
|
|
private lateinit var loginCallback: (Int, String) -> Unit
|
|
|
private lateinit var analytics: HiAnalyticsInstance
|
|
|
+ private lateinit var initTask: Task<Void>
|
|
|
|
|
|
private var buoyClient: BuoyClient? = null
|
|
|
|
|
@@ -68,10 +70,8 @@ class ChannelSdkHuawei : IFeature, IApplication, ILifeCycle,IOrder {
|
|
|
}
|
|
|
|
|
|
override fun initialize(activity: Activity, isLandscape: Boolean, callback: (Int, String) -> Unit) {
|
|
|
- val params = AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM_GAME
|
|
|
- val appClient = JosApps.getJosAppsClient(activity)
|
|
|
ResourceLoaderUtil.setmContext(activity)
|
|
|
- val initTask = appClient.init(AppParams(params) {
|
|
|
+ this.initTask = JosApps.getJosAppsClient(activity).init(AppParams(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM_GAME) {
|
|
|
// 该回调会在如下两种情况下返回:
|
|
|
// 1.未成年人实名帐号在白天登录游戏,华为会弹框提示玩家不允许游戏,玩家点击“确定”,华为返回回调
|
|
|
// 2.未成年实名帐号在国家允许的时间登录游戏,到晚上9点,华为会弹框提示玩家已到时间,玩家点击“知道了”,华为返回回调
|
|
@@ -101,17 +101,25 @@ class ChannelSdkHuawei : IFeature, IApplication, ILifeCycle,IOrder {
|
|
|
Logger.d("Sdk init on failure")
|
|
|
if (e is ApiException) {
|
|
|
Logger.d("Sdk init on failure, code: ${e.statusCode}, msg: ${e.localizedMessage}")
|
|
|
- val statusCode = e.statusCode
|
|
|
- if (statusCode == JosStatusCodes.JOS_PRIVACY_PROTOCOL_REJECTED) {
|
|
|
- // 错误码为7401时表示用户未同意华为联运隐私协议
|
|
|
- // 此处您需禁止玩家进入游戏
|
|
|
- Logger.e("has reject the protocol")
|
|
|
- } else if (statusCode == GamesStatusCodes.GAME_STATE_NETWORK_ERROR) {
|
|
|
- // 错误码7002表示网络异常
|
|
|
- // 此处您可提示玩家检查网络,请不要重复调用init接口,否则断网情况下可能会造成手机高耗电。
|
|
|
- Logger.e("Network error")
|
|
|
- } else {
|
|
|
- // 在此处实现其他错误码的处理
|
|
|
+ when (e.statusCode) {
|
|
|
+ JosStatusCodes.JOS_PRIVACY_PROTOCOL_REJECTED -> {
|
|
|
+ // 错误码为7401时表示用户未同意华为联运隐私协议
|
|
|
+ // 此处您需禁止玩家进入游戏
|
|
|
+ Logger.e("has reject the protocol")
|
|
|
+ }
|
|
|
+ JosStatusCodes.JOS_PRIVACY_PROTOCOL_NO_AGREE -> {
|
|
|
+ Logger.e("has reject the protocol")
|
|
|
+
|
|
|
+ }
|
|
|
+ GamesStatusCodes.GAME_STATE_NETWORK_ERROR -> {
|
|
|
+ // 错误码7002表示网络异常
|
|
|
+ // 此处您可提示玩家检查网络,请不要重复调用init接口,否则断网情况下可能会造成手机高耗电。
|
|
|
+ Logger.e("Network error")
|
|
|
+ }
|
|
|
+
|
|
|
+ else -> {
|
|
|
+ // 在此处实现其他错误码的处理
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -126,18 +134,17 @@ class ChannelSdkHuawei : IFeature, IApplication, ILifeCycle,IOrder {
|
|
|
}
|
|
|
loginDialog = HuaweiLoginDialog(activity)
|
|
|
loginDialog?.apply {
|
|
|
- ivHw.setOnClickListener {
|
|
|
+ ivHw.setThrottleListener {
|
|
|
doSignIn(activity, AGConnectAuthCredential.HMS_Provider)
|
|
|
}
|
|
|
- ivGoogle.setOnClickListener {
|
|
|
+ ivGoogle.setThrottleListener {
|
|
|
doSignIn(activity, AGConnectAuthCredential.Google_Provider)
|
|
|
}
|
|
|
- ivFacebook.setOnClickListener {
|
|
|
+ ivFacebook.setThrottleListener {
|
|
|
doSignIn(activity, AGConnectAuthCredential.Facebook_Provider)
|
|
|
}
|
|
|
show()
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
override fun logout(activity: Activity, callback: (Int, String) -> Unit) {
|
|
@@ -146,13 +153,7 @@ class ChannelSdkHuawei : IFeature, IApplication, ILifeCycle,IOrder {
|
|
|
callback(0, "用户登出成功")
|
|
|
}
|
|
|
|
|
|
- override fun getOrderExt(activity: Activity, chargeInfo: SdkChargeInfo, callback: (Int, String) -> Unit) {
|
|
|
- Logger.d("getOrderExt")
|
|
|
- callback(0, "test_ext")
|
|
|
- }
|
|
|
-
|
|
|
override fun charge(activity: Activity, chargeInfo: SdkChargeInfo, callback: (Int, String) -> Unit) {
|
|
|
- Logger.d("charge")
|
|
|
HuaweiInAppPay.instance.charge(activity, chargeInfo, object : HuaweiInAppPay.InAppPayCallback {
|
|
|
override fun onResult(code: Int, result: String) {
|
|
|
callback(code, result)
|
|
@@ -224,10 +225,16 @@ class ChannelSdkHuawei : IFeature, IApplication, ILifeCycle,IOrder {
|
|
|
val bundle = Bundle()
|
|
|
bundle.putString(HAParamType.LOANCHANNEL, channelName)
|
|
|
analytics.onEvent(HAEventType.SIGNIN, bundle)
|
|
|
- }.addOnFailureListener {
|
|
|
+ }.addOnFailureListener { e ->
|
|
|
// onFailure
|
|
|
- dismissLoadingDialog()
|
|
|
- loginCallback(-1, "登录失败")
|
|
|
+ if (e is ApiException && e.statusCode == JosStatusCodes.JOS_PRIVACY_PROTOCOL_NO_AGREE) {
|
|
|
+ Logger.e("reInit...")
|
|
|
+ this.initTask = JosApps.getJosAppsClient(activity).init(AppParams(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM_GAME))
|
|
|
+ doSignIn(activity, channel)
|
|
|
+ } else {
|
|
|
+ dismissLoadingDialog()
|
|
|
+ loginCallback(-1, "登录失败")
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|