From 669073f2b46a2f8450e7cea6a3ab3f17f0515f5e Mon Sep 17 00:00:00 2001 From: biezhihua Date: Wed, 26 Oct 2022 19:02:33 +0800 Subject: [PATCH] fix: init && destroy (#248) --- GaiaXAnalyze/GXAnalyzeAndroid/.classpath | 2 +- .../alibaba/gaiax/studio/GXClientToStudio.kt | 5 ++- .../com/alibaba/gaiax/demo/MainActivity.kt | 38 +++++++++---------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/GaiaXAnalyze/GXAnalyzeAndroid/.classpath b/GaiaXAnalyze/GXAnalyzeAndroid/.classpath index 4a04201ca..eb19361b5 100644 --- a/GaiaXAnalyze/GXAnalyzeAndroid/.classpath +++ b/GaiaXAnalyze/GXAnalyzeAndroid/.classpath @@ -1,6 +1,6 @@ - + diff --git a/GaiaXAndroidClientToStudio/src/main/java/com/alibaba/gaiax/studio/GXClientToStudio.kt b/GaiaXAndroidClientToStudio/src/main/java/com/alibaba/gaiax/studio/GXClientToStudio.kt index 51a0d6005..505cd58c5 100644 --- a/GaiaXAndroidClientToStudio/src/main/java/com/alibaba/gaiax/studio/GXClientToStudio.kt +++ b/GaiaXAndroidClientToStudio/src/main/java/com/alibaba/gaiax/studio/GXClientToStudio.kt @@ -57,11 +57,14 @@ class GXClientToStudio { fun init(context: Context) { applicationContext = context.applicationContext - socketHelper = GXSocket() + if (socketHelper == null) { + socketHelper = GXSocket() + } } fun destroy() { socketHelper?.disconnectToServer() + socketHelper = null } fun manualConnect(context: Context, params: JSONObject) { diff --git a/GaiaXAndroidDemo/app/src/main/kotlin/com/alibaba/gaiax/demo/MainActivity.kt b/GaiaXAndroidDemo/app/src/main/kotlin/com/alibaba/gaiax/demo/MainActivity.kt index 7a6e367c4..c9002bb1e 100644 --- a/GaiaXAndroidDemo/app/src/main/kotlin/com/alibaba/gaiax/demo/MainActivity.kt +++ b/GaiaXAndroidDemo/app/src/main/kotlin/com/alibaba/gaiax/demo/MainActivity.kt @@ -44,31 +44,27 @@ class MainActivity : AppCompatActivity() { GXClientToStudio.instance.init(applicationContext) - GXRegisterCenter.instance - .registerExtensionExpression(GXExtensionMultiVersionExpression()) - - GXRegisterCenter.instance - .registerExtensionException(object : - GXRegisterCenter.GXIExtensionException { - override fun exception(exception: Exception) { - exception.printStackTrace() - } - }) + GXRegisterCenter.instance.registerExtensionExpression(GXExtensionMultiVersionExpression()) + + GXRegisterCenter.instance.registerExtensionException(object : + GXRegisterCenter.GXIExtensionException { + override fun exception(exception: Exception) { + exception.printStackTrace() + } + }) - GXRegisterCenter.instance - .registerExtensionTemplateSource(GXManualPushSource.instance, 101) + GXRegisterCenter.instance.registerExtensionTemplateSource(GXManualPushSource.instance, 101) .registerExtensionTemplateSource(GXFastPreviewSource.instance, 102) - GXRegisterCenter.instance - .registerExtensionFontFamily(object : - GXRegisterCenter.GXIExtensionFontFamily { - override fun fontFamily(fontFamilyName: String): Typeface? { - if (fontFamilyName == "iconfont") { - return Typeface.createFromAsset(assets, "$fontFamilyName.ttf") - } - return null + GXRegisterCenter.instance.registerExtensionFontFamily(object : + GXRegisterCenter.GXIExtensionFontFamily { + override fun fontFamily(fontFamilyName: String): Typeface? { + if (fontFamilyName == "iconfont") { + return Typeface.createFromAsset(assets, "$fontFamilyName.ttf") } - }) + return null + } + }) findViewById(R.id.fastpreview)?.setOnClickListener { val intent = Intent(MainActivity@ this, GXQRCodeActivity::class.java)