|
@@ -1,26 +1,44 @@
|
|
package cn.yyxx.eyuancomm.core
|
|
package cn.yyxx.eyuancomm.core
|
|
|
|
|
|
import android.app.Activity
|
|
import android.app.Activity
|
|
|
|
+import android.app.Activity.RESULT_OK
|
|
import android.content.Intent
|
|
import android.content.Intent
|
|
|
|
+import android.text.TextUtils
|
|
import cn.yyxx.eyuancomm.comm.entity.SdkChargeInfo
|
|
import cn.yyxx.eyuancomm.comm.entity.SdkChargeInfo
|
|
|
|
+import cn.yyxx.eyuancomm.comm.entity.SdkLoginInfo
|
|
import cn.yyxx.eyuancomm.comm.entity.SdkRoleInfo
|
|
import cn.yyxx.eyuancomm.comm.entity.SdkRoleInfo
|
|
|
|
+import cn.yyxx.eyuancomm.comm.internal.ICallback
|
|
import cn.yyxx.eyuancomm.comm.utils.Logger
|
|
import cn.yyxx.eyuancomm.comm.utils.Logger
|
|
-import cn.yyxx.eyuancomm.core.impl.GameSdkImpl
|
|
|
|
-import cn.yyxx.eyuancomm.core.internal.IOrder
|
|
|
|
|
|
+import cn.yyxx.eyuancomm.comm.utils.MMKVManager
|
|
|
|
+import cn.yyxx.eyuancomm.core.entity.bean.InitBean
|
|
|
|
+import cn.yyxx.eyuancomm.core.impl.InAppBilling
|
|
|
|
+import cn.yyxx.eyuancomm.core.impl.center.HybridFeatureContainer
|
|
|
|
+import cn.yyxx.eyuancomm.core.impl.floatball.FloatCenterServiceManager
|
|
|
|
+import cn.yyxx.eyuancomm.core.impl.login.LoginActivity
|
|
|
|
+import cn.yyxx.eyuancomm.core.impl.share.ShareImpl
|
|
|
|
+import cn.yyxx.eyuancomm.core.network.SdkRequest
|
|
|
|
+import cn.yyxx.eyuancomm.core.widget.dialog.TipsDialog
|
|
|
|
+import cn.yyxx.support.ResUtils
|
|
|
|
+import cn.yyxx.support.device.DeviceInfoUtils
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author #Suyghur.
|
|
* @author #Suyghur.
|
|
- * Created on 2021/06/09
|
|
|
|
|
|
+ * Created on 2021/06/16
|
|
*/
|
|
*/
|
|
-class EYuanGameSdk private constructor() {
|
|
|
|
|
|
+class EYuanGameSdk {
|
|
|
|
|
|
- private val impl: GameSdkImpl by lazy {
|
|
|
|
- GameSdkImpl()
|
|
|
|
- }
|
|
|
|
|
|
+ private var isSubmitRoleData = false
|
|
|
|
+
|
|
|
|
+ private var exitDialog: TipsDialog? = null
|
|
|
|
|
|
private var doSdkInit = false
|
|
private var doSdkInit = false
|
|
|
|
|
|
companion object {
|
|
companion object {
|
|
|
|
+ var isLandscape = false
|
|
|
|
+ lateinit var initBean: InitBean
|
|
|
|
+ var floatBallLogoutCallback: ICallback? = null
|
|
|
|
+
|
|
@JvmStatic
|
|
@JvmStatic
|
|
fun getInstance(): EYuanGameSdk {
|
|
fun getInstance(): EYuanGameSdk {
|
|
return EYuanGameSdkHolder.INSTANCE
|
|
return EYuanGameSdkHolder.INSTANCE
|
|
@@ -38,177 +56,232 @@ class EYuanGameSdk private constructor() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * SDK初始化
|
|
|
|
- *
|
|
|
|
- * @param activity Activity上下文
|
|
|
|
- * @param isLandscape 是否横屏
|
|
|
|
- * @param callback SDK初始化回调
|
|
|
|
- */
|
|
|
|
- fun initialize(activity: Activity, isLandscape: Boolean, callback: (Int, String) -> Unit) {
|
|
|
|
|
|
+ fun initialize(activity: Activity, isLandscape: Boolean, callback: ICallback) {
|
|
|
|
+ Logger.i("EYuanGameSdk initialize ...")
|
|
//有些CP在资源再加时候回重复调用初始化,这里拦截一下
|
|
//有些CP在资源再加时候回重复调用初始化,这里拦截一下
|
|
if (doSdkInit) {
|
|
if (doSdkInit) {
|
|
Logger.e("EYuanGameSdk initialize 已经执行,拦截此次调用")
|
|
Logger.e("EYuanGameSdk initialize 已经执行,拦截此次调用")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- impl.initialize(activity, isLandscape) { code, result ->
|
|
|
|
- doSdkInit = code == 0
|
|
|
|
- callback(code, result)
|
|
|
|
- }
|
|
|
|
|
|
+ Companion.isLandscape = isLandscape
|
|
|
|
+ doSdkInit = true
|
|
|
|
+ callback.onResult(0, "SDK初始化成功")
|
|
}
|
|
}
|
|
|
|
|
|
fun installConfig(activity: Activity, config: String) {
|
|
fun installConfig(activity: Activity, config: String) {
|
|
if (checkSdkNonInit("installConfig", null)) {
|
|
if (checkSdkNonInit("installConfig", null)) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- impl.installConfig(activity, config)
|
|
|
|
|
|
+
|
|
|
|
+ initBean = InitBean.toBean(config)
|
|
|
|
+ cacheImageResource(activity)
|
|
|
|
+ FloatCenterServiceManager.instance.init(activity)
|
|
}
|
|
}
|
|
|
|
|
|
- fun setOnFloatBallLogoutCallback(callback: (Int, String) -> Unit) {
|
|
|
|
|
|
+ fun setOnFloatBallLogoutCallback(callback: ICallback) {
|
|
if (checkSdkNonInit("setOnFloatBallLogoutCallback", null)) {
|
|
if (checkSdkNonInit("setOnFloatBallLogoutCallback", null)) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- impl.setOnFloatBallLogoutCallback(callback)
|
|
|
|
|
|
+ floatBallLogoutCallback = callback
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun cacheImageResource(activity: Activity) {
|
|
|
|
+ //全图标
|
|
|
|
+ SdkRequest.instance.downloadImageFile(activity, initBean.floatCfg.floatIconUrl)
|
|
|
|
+ //左边
|
|
|
|
+ SdkRequest.instance.downloadImageFile(activity, initBean.floatCfg.floatIconLeftUrl)
|
|
|
|
+ //右边
|
|
|
|
+ SdkRequest.instance.downloadImageFile(activity, initBean.floatCfg.floatIconRightUrl)
|
|
|
|
+ //会员中心
|
|
|
|
+ SdkRequest.instance.downloadImageFile(activity, initBean.floatCfg.floatIconUrl)
|
|
|
|
+ //礼包
|
|
|
|
+ SdkRequest.instance.downloadImageFile(activity, initBean.floatCfg.floatIconUrl)
|
|
|
|
+ //客服
|
|
|
|
+ SdkRequest.instance.downloadImageFile(activity, initBean.floatCfg.floatIconUrl)
|
|
|
|
+ //储值
|
|
|
|
+ SdkRequest.instance.downloadImageFile(activity, initBean.floatCfg.floatIconUrl)
|
|
|
|
+ //邀请
|
|
|
|
+ SdkRequest.instance.downloadImageFile(activity, initBean.floatCfg.floatIconUrl)
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * SDK用户登录
|
|
|
|
- *
|
|
|
|
- * @param activity Activity上下文
|
|
|
|
- * @param isAutoLogin 是否自动登录
|
|
|
|
- * @param callback 登录回调对象
|
|
|
|
- */
|
|
|
|
- fun login(activity: Activity, isAutoLogin: Boolean, callback: (Int, String) -> Unit) {
|
|
|
|
|
|
+ fun login(activity: Activity, isAutoLogin: Boolean, callback: ICallback) {
|
|
|
|
+ Logger.i("EYuanGameSdk login ...")
|
|
|
|
+
|
|
if (checkSdkNonInit("login", callback)) {
|
|
if (checkSdkNonInit("login", callback)) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- impl.login(activity, isAutoLogin, callback)
|
|
|
|
|
|
+ SdkLoginInfo.instance.reset()
|
|
|
|
+ LoginActivity.login(activity, isAutoLogin) { code, result ->
|
|
|
|
+ callback.onResult(code, result)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * SDK用户登出账号
|
|
|
|
- *
|
|
|
|
- * @param activity Activity上下文
|
|
|
|
- * @param callback 登出回调对象
|
|
|
|
- */
|
|
|
|
- fun logout(activity: Activity, callback: (Int, String) -> Unit) {
|
|
|
|
|
|
+ fun logout(activity: Activity, callback: ICallback) {
|
|
|
|
+ Logger.i("EYuanGameSdk logout ...")
|
|
if (checkSdkNonInit("logout", callback)) {
|
|
if (checkSdkNonInit("logout", callback)) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- impl.logout(activity, callback)
|
|
|
|
|
|
+ SdkLoginInfo.instance.reset()
|
|
|
|
+ FloatCenterServiceManager.instance.detach()
|
|
|
|
+ callback.onResult(0, "用户登出成功")
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * SDK用户支付
|
|
|
|
- *
|
|
|
|
- * @param activity Activity上下文
|
|
|
|
- * @param chargeInfo 支付信息实体对象
|
|
|
|
- * @param callback 支付回调对象
|
|
|
|
- */
|
|
|
|
- fun charge(activity: Activity, chargeInfo: SdkChargeInfo, callback: (Int, String, IOrder?) -> Unit) {
|
|
|
|
- if (!doSdkInit) {
|
|
|
|
- Logger.e("invoke charge error ... EYuanGameSdk not initialized yet")
|
|
|
|
- callback(-1, "EYuanGameSdk 还未进行初始化", null)
|
|
|
|
|
|
+ fun charge(activity: Activity, chargeInfo: SdkChargeInfo, callback: ICallback) {
|
|
|
|
+ Logger.i("EYuanGameSdk charge ...")
|
|
|
|
+
|
|
|
|
+ if (checkSdkNonInit("charge", callback)) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- impl.charge(activity, chargeInfo, callback)
|
|
|
|
|
|
+ if (TextUtils.isEmpty(SdkLoginInfo.instance.userId)) {
|
|
|
|
+ Logger.e("支付失败,用户未登录或登录失败")
|
|
|
|
+ callback.onResult(-1, "支付失败,用户未登录或登录失败")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if (!isSubmitRoleData) {
|
|
|
|
+ Logger.e("支付失败,角色未登录或登录失败")
|
|
|
|
+ callback.onResult(-1, "支付失败,角色未登录或登录失败")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if (!DeviceInfoUtils.isNetworkConnected(activity)) {
|
|
|
|
+ Logger.e("当前网络连接异常,请重试")
|
|
|
|
+ callback.onResult(-1, "当前网络连接异常,请重试")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (chargeInfo.payment == 3) {
|
|
|
|
+ // h5支付
|
|
|
|
+ HybridFeatureContainer(activity, initBean.floatCfg.chargeCfg.url).show()
|
|
|
|
+ } else {
|
|
|
|
+ InAppBilling.instance.charge(activity, chargeInfo, callback)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fun consumeOrder(activity: Activity, chargeInfo: SdkChargeInfo, purchaseToken: String, cache: Boolean) {
|
|
|
|
+ InAppBilling.instance.consumeOrder(activity, chargeInfo, purchaseToken, cache)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fun disconnectPlayService() {
|
|
|
|
+ InAppBilling.instance.disconnectPlayService()
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * SDK角色创建信息上报
|
|
|
|
- *
|
|
|
|
- * @param activity Activity上下文
|
|
|
|
- * @param roleInfo 角色信息实体
|
|
|
|
- */
|
|
|
|
fun roleCreate(activity: Activity, roleInfo: SdkRoleInfo) {
|
|
fun roleCreate(activity: Activity, roleInfo: SdkRoleInfo) {
|
|
|
|
+ Logger.i("EYuanGameSdk roleCreate ...")
|
|
if (checkSdkNonInit("roleCreate", null)) {
|
|
if (checkSdkNonInit("roleCreate", null)) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- impl.roleCreate(activity, roleInfo)
|
|
|
|
|
|
+ isSubmitRoleData = true
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * SDK角色登录信息上报
|
|
|
|
- *
|
|
|
|
- * @param activity Activity上下文
|
|
|
|
- * @param roleInfo 角色信息实体
|
|
|
|
- */
|
|
|
|
fun roleLauncher(activity: Activity, roleInfo: SdkRoleInfo) {
|
|
fun roleLauncher(activity: Activity, roleInfo: SdkRoleInfo) {
|
|
|
|
+ Logger.i("EYuanGameSdk roleLauncher ...")
|
|
if (checkSdkNonInit("roleLauncher", null)) {
|
|
if (checkSdkNonInit("roleLauncher", null)) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-
|
|
|
|
- impl.roleLauncher(activity, roleInfo)
|
|
|
|
|
|
+ isSubmitRoleData = true
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * SDK角色升级信息上报
|
|
|
|
- *
|
|
|
|
- * @param activity Activity上下文
|
|
|
|
- * @param roleInfo 角色信息实体
|
|
|
|
- */
|
|
|
|
fun roleLevelUp(activity: Activity, roleInfo: SdkRoleInfo) {
|
|
fun roleLevelUp(activity: Activity, roleInfo: SdkRoleInfo) {
|
|
|
|
+ Logger.i("EYuanGameSdk roleLevelUp ...")
|
|
if (checkSdkNonInit("roleLevelUp", null)) {
|
|
if (checkSdkNonInit("roleLevelUp", null)) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-
|
|
|
|
- impl.roleLevelUp(activity, roleInfo)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 显示退出框
|
|
|
|
- *
|
|
|
|
- * @param activity Activity上下文
|
|
|
|
- * @param callback 退出回调对象
|
|
|
|
- */
|
|
|
|
- fun openExitView(activity: Activity, callback: (Int, String) -> Unit) {
|
|
|
|
- impl.openExitView(activity) { code, result ->
|
|
|
|
- callback(code, result)
|
|
|
|
|
|
+ fun openExitView(activity: Activity, callback: ICallback) {
|
|
|
|
+ Logger.i("EYuanGameSdk openExitView ...")
|
|
|
|
+
|
|
|
|
+ exitDialog?.apply {
|
|
|
|
+ dismiss()
|
|
|
|
+ exitDialog = null
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ exitDialog = TipsDialog(activity, isLandscape, true)
|
|
|
|
+ exitDialog?.apply {
|
|
|
|
+ textView.text = ResUtils.getResString(activity, "yyxx_tv_exit_content")
|
|
|
|
+ leftButton.text = ResUtils.getResString(activity, "yyxx_tv_exit_left")
|
|
|
|
+ leftButton.setOnClickListener {
|
|
|
|
+ if (isShowing) {
|
|
|
|
+ dismiss()
|
|
|
|
+ exitDialog = null
|
|
|
|
+ }
|
|
|
|
+ callback.onResult(0, "退出游戏")
|
|
|
|
+ }
|
|
|
|
+ rightButton.text = ResUtils.getResString(activity, "yyxx_tv_exit_right")
|
|
|
|
+ rightButton.setOnClickListener {
|
|
|
|
+ if (isShowing) {
|
|
|
|
+ dismiss()
|
|
|
|
+ exitDialog = null
|
|
|
|
+ }
|
|
|
|
+ callback.onResult(-1, "继续游戏")
|
|
|
|
+ }
|
|
|
|
+ show()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
fun onStart(activity: Activity) {
|
|
fun onStart(activity: Activity) {
|
|
- impl.onStart(activity)
|
|
|
|
|
|
+ Logger.i("EYuanGameSdk onStart ...")
|
|
}
|
|
}
|
|
|
|
|
|
fun onRestart(activity: Activity) {
|
|
fun onRestart(activity: Activity) {
|
|
- impl.onRestart(activity)
|
|
|
|
|
|
+ Logger.i("EYuanGameSdk onRestart ...")
|
|
}
|
|
}
|
|
|
|
|
|
fun onResume(activity: Activity) {
|
|
fun onResume(activity: Activity) {
|
|
- impl.onResume(activity)
|
|
|
|
|
|
+ Logger.i("EYuanGameSdk onResume ...")
|
|
|
|
+ FloatCenterServiceManager.instance.attach()
|
|
}
|
|
}
|
|
|
|
|
|
fun onPause(activity: Activity) {
|
|
fun onPause(activity: Activity) {
|
|
- impl.onPause(activity)
|
|
|
|
|
|
+ Logger.i("EYuanGameSdk onPause ...")
|
|
|
|
+ FloatCenterServiceManager.instance.detach()
|
|
}
|
|
}
|
|
|
|
|
|
fun onStop(activity: Activity) {
|
|
fun onStop(activity: Activity) {
|
|
- impl.onStop(activity)
|
|
|
|
|
|
+ Logger.i("EYuanGameSdk onStop ...")
|
|
}
|
|
}
|
|
|
|
|
|
fun onDestroy(activity: Activity) {
|
|
fun onDestroy(activity: Activity) {
|
|
- impl.onDestroy(activity)
|
|
|
|
|
|
+ Logger.i("EYuanGameSdk onDestroy ...")
|
|
|
|
+ FloatCenterServiceManager.instance.release()
|
|
|
|
+ MMKVManager.instance.release()
|
|
}
|
|
}
|
|
|
|
|
|
fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, data: Intent?) {
|
|
fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, data: Intent?) {
|
|
- impl.onActivityResult(activity, requestCode, resultCode, data)
|
|
|
|
|
|
+ Logger.i("EYuanGameSdk onActivityResult ...")
|
|
|
|
|
|
|
|
+ if (requestCode == HybridFeatureContainer.FILE_CHOOSER_RESULT_CODE_FOR_ANDROID_5) {
|
|
|
|
+ Logger.d("onActivityResult FILE_CHOOSER_RESULT_CODE_FOR_ANDROID_5")
|
|
|
|
+ if (HybridFeatureContainer.uploadMessageForAndroid5 == null) {
|
|
|
|
+ Logger.d("mUploadMessageForAndroid5 == null")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if (data == null) {
|
|
|
|
+ HybridFeatureContainer.uploadMessageForAndroid5!!.onReceiveValue(arrayOf())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ val result = if (resultCode != RESULT_OK) null else data.data
|
|
|
|
+ if (result == null) {
|
|
|
|
+ HybridFeatureContainer.uploadMessageForAndroid5!!.onReceiveValue(arrayOf())
|
|
|
|
+ } else {
|
|
|
|
+ HybridFeatureContainer.uploadMessageForAndroid5!!.onReceiveValue(arrayOf(result))
|
|
|
|
+ }
|
|
|
|
+ HybridFeatureContainer.uploadMessageForAndroid5 = null
|
|
|
|
+ } else if (requestCode == ShareImpl.FACEBOOK_SHARE_RESULT_CODE) {
|
|
|
|
+ ShareImpl.instance.onShareResult(requestCode, resultCode, data)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
fun onNewIntent(activity: Activity, intent: Intent?) {
|
|
fun onNewIntent(activity: Activity, intent: Intent?) {
|
|
- impl.onNewIntent(activity, intent)
|
|
|
|
|
|
+ Logger.i("EYuanGameSdk onNewIntent ...")
|
|
}
|
|
}
|
|
|
|
|
|
- private fun checkSdkNonInit(function: String, callback: ((Int, String) -> Unit)?): Boolean {
|
|
|
|
|
|
+ private fun checkSdkNonInit(function: String, callback: ICallback?): Boolean {
|
|
return if (!doSdkInit) {
|
|
return if (!doSdkInit) {
|
|
Logger.e("invoke $function error ... EYuanGameSdk not initialized yet")
|
|
Logger.e("invoke $function error ... EYuanGameSdk not initialized yet")
|
|
- if (callback != null) {
|
|
|
|
- callback(-1, "EYuanGameSdk 还未进行初始化")
|
|
|
|
- }
|
|
|
|
|
|
+ callback?.onResult(-1, "EYuanGameSdk 还未进行初始化")
|
|
true
|
|
true
|
|
} else {
|
|
} else {
|
|
false
|
|
false
|