From 81927ad4cda1a6f53fd33399639ca0561e7d481a Mon Sep 17 00:00:00 2001 From: biezhihua Date: Mon, 13 Jun 2022 16:01:02 +0800 Subject: [PATCH 1/4] feat: event follow --- .../gx-content-uper-top/index.databinding | 4 +-- .../gaiax/demo/EventTemplateActivity.kt | 32 ++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/GaiaXAndroidDemo/app/src/main/assets/templates/gx-content-uper-top/index.databinding b/GaiaXAndroidDemo/app/src/main/assets/templates/gx-content-uper-top/index.databinding index 2b373188e..4afbea45f 100755 --- a/GaiaXAndroidDemo/app/src/main/assets/templates/gx-content-uper-top/index.databinding +++ b/GaiaXAndroidDemo/app/src/main/assets/templates/gx-content-uper-top/index.databinding @@ -29,9 +29,9 @@ "value": "$recReason.title" }, "follow-text": { - "value":"'按钮'", + "value":"$isFollowed ? '已关注' : '关注'", "extend":{ - "color":"'#24a5ff'" + "color":"$isFollowed ? '#24a5ff' : 'red'" } }, "follow-bg": { diff --git a/GaiaXAndroidDemo/app/src/main/kotlin/com/alibaba/gaiax/demo/EventTemplateActivity.kt b/GaiaXAndroidDemo/app/src/main/kotlin/com/alibaba/gaiax/demo/EventTemplateActivity.kt index a7e8076c1..77d14522c 100644 --- a/GaiaXAndroidDemo/app/src/main/kotlin/com/alibaba/gaiax/demo/EventTemplateActivity.kt +++ b/GaiaXAndroidDemo/app/src/main/kotlin/com/alibaba/gaiax/demo/EventTemplateActivity.kt @@ -1,12 +1,12 @@ package com.alibaba.gaiax.demo import android.os.Bundle -import android.util.Log import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.LinearLayoutCompat import com.alibaba.gaiax.GXTemplateEngine import com.alibaba.gaiax.demo.utils.AssetsUtils import com.alibaba.gaiax.utils.GXScreenUtils +import com.alibaba.gaiax.utils.setValueExt class EventTemplateActivity : AppCompatActivity() { companion object { @@ -20,6 +20,8 @@ class EventTemplateActivity : AppCompatActivity() { renderTemplate1(this) } + var isFollowed = false + private fun renderTemplate1(activity: EventTemplateActivity) { // 初始化 GXTemplateEngine.instance.init(activity) @@ -31,24 +33,30 @@ class EventTemplateActivity : AppCompatActivity() { val size = GXTemplateEngine.GXMeasureSize(GXScreenUtils.getScreenWidthPx(this), null) // 模板数据 - val templateData = - GXTemplateEngine.GXTemplateData(AssetsUtils.parseAssets(activity, "data/uper.json")) + val data = AssetsUtils.parseAssets(activity, "data/uper.json") + val templateData = GXTemplateEngine.GXTemplateData(data) + + // 创建模板View + val view = GXTemplateEngine.instance.createView(params, size) + templateData.eventListener = object : GXTemplateEngine.GXIEventListener { override fun onGestureEvent(gxGesture: GXTemplateEngine.GXGesture) { super.onGestureEvent(gxGesture) - Log.d(TAG, "onGestureEvent() called with: gxGesture = $gxGesture") - } - - override fun onScrollEvent(gxScroll: GXTemplateEngine.GXScroll) { - super.onScrollEvent(gxScroll) - Log.d(TAG, "onScrollEvent() called with: gxScroll = $gxScroll") + if (gxGesture.nodeId == "follow") { + if (isFollowed) { + data.setValueExt("data.isFollowed", false) + GXTemplateEngine.instance.bindData(view, templateData) + isFollowed = false + } else { + data.setValueExt("data.isFollowed", true) + GXTemplateEngine.instance.bindData(view, templateData) + isFollowed = true + } + } } } - // 创建模板View - val view = GXTemplateEngine.instance.createView(params, size) - // 绑定数据 GXTemplateEngine.instance.bindData(view, templateData) From 1f5db6184b77c641e16bb3640f669055fe9c04a6 Mon Sep 17 00:00:00 2001 From: biezhihua Date: Mon, 13 Jun 2022 19:49:18 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DPOP=E7=9A=84?= =?UTF-8?q?=E5=9F=8B=E7=82=B9=E7=82=B9=E5=87=BB=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alibaba/gaiax/adapter/GXAdapterLottieAnimation.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/GaiaXAdapterAndroid/src/main/java/com/alibaba/gaiax/adapter/GXAdapterLottieAnimation.kt b/GaiaXAdapterAndroid/src/main/java/com/alibaba/gaiax/adapter/GXAdapterLottieAnimation.kt index 3064d5e58..fc1283def 100644 --- a/GaiaXAdapterAndroid/src/main/java/com/alibaba/gaiax/adapter/GXAdapterLottieAnimation.kt +++ b/GaiaXAdapterAndroid/src/main/java/com/alibaba/gaiax/adapter/GXAdapterLottieAnimation.kt @@ -174,7 +174,6 @@ class GXAdapterLottieAnimation : GXLottieAnimation() { if (lottieContainer.childCount == 0) { lottieView.isClickable = false - lottieContainer.isClickable = false lottieContainer.addView(lottieView) } } @@ -269,7 +268,6 @@ class GXAdapterLottieAnimation : GXLottieAnimation() { if (lottieContainer.childCount == 0) { lottieView.isClickable = false - lottieContainer.isClickable = false lottieContainer.addView(lottieView) } } From 7f81eeb4cd2ab71a63e6f55b263ea5fcff1946d3 Mon Sep 17 00:00:00 2001 From: biezhihua Date: Mon, 13 Jun 2022 20:02:27 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E7=9A=84=E6=8A=9B=E5=87=BA=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt | 2 +- .../com/alibaba/gaiax/data/cache/GXTemplateInfoSource.kt | 2 +- .../kotlin/com/alibaba/gaiax/render/node/GXTemplateNode.kt | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt index 8f5497b02..36044a1e3 100644 --- a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt +++ b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt @@ -139,7 +139,7 @@ class GXDataImpl(val context: Context) { dataSourceSorted.forEach { it.source.getTemplateInfo(gxTemplateItem)?.let { return it } } - throw IllegalStateException("Template exist but reference is null") + throw IllegalArgumentException("Template exist but reference is null") } fun registerByPriority( diff --git a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/cache/GXTemplateInfoSource.kt b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/cache/GXTemplateInfoSource.kt index 397d23a0b..397e26b5d 100644 --- a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/cache/GXTemplateInfoSource.kt +++ b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/cache/GXTemplateInfoSource.kt @@ -19,7 +19,7 @@ class GXTemplateInfoSource(val context: Context) : GXRegisterCenter.GXIExtension override fun getTemplateInfo(gxTemplateItem: GXTemplateEngine.GXTemplateItem): GXTemplateInfo? { return if (exist(gxTemplateItem.bizId, gxTemplateItem.templateId)) { dataCache[gxTemplateItem.bizId]?.get(gxTemplateItem.templateId) - ?: throw IllegalStateException("Template exist but reference is null") + ?: throw IllegalArgumentException("Template exist but reference is null") } else { val template = GXTemplateInfo.createTemplate(gxTemplateItem) return template.apply { diff --git a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/node/GXTemplateNode.kt b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/node/GXTemplateNode.kt index 789978ee5..a6dcdabbc 100644 --- a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/node/GXTemplateNode.kt +++ b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/render/node/GXTemplateNode.kt @@ -21,6 +21,7 @@ import com.alibaba.fastjson.JSONObject import com.alibaba.gaiax.context.GXTemplateContext import com.alibaba.gaiax.template.* import com.alibaba.gaiax.template.animation.GXAnimationBinding +import java.lang.IllegalArgumentException /** * @suppress @@ -218,7 +219,7 @@ data class GXTemplateNode( visualTemplateNode: GXTemplateNode? = null ): GXTemplateNode { val layer = template.findLayer(viewId) - ?: throw IllegalStateException("Not found layer by view id, viewId = $viewId") + ?: throw IllegalArgumentException("Not found layer by view id, viewId = $viewId") val css = template.findCss(viewId) ?: GXCss.create() val dataBinding = template.findData(viewId) val eventBinding = template.findEvent(viewId) From 0d615796774a71ac54522b652650de0cfe2bf0cf Mon Sep 17 00:00:00 2001 From: biezhihua Date: Mon, 13 Jun 2022 20:33:21 +0800 Subject: [PATCH 4/4] feat: log --- .../src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt index 36044a1e3..010d1a67b 100644 --- a/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt +++ b/GaiaXAndroid/src/main/kotlin/com/alibaba/gaiax/data/GXDataImpl.kt @@ -76,7 +76,7 @@ class GXDataImpl(val context: Context) { dataSourceSorted.forEach { it -> it.source.getTemplate(gxTemplateItem)?.let { return it } } - throw IllegalArgumentException("Not found target template path, templateItem = $gxTemplateItem") + throw IllegalArgumentException("Not found target gxTemplate, templateItem = $gxTemplateItem") } fun registerByPriority(source: GXRegisterCenter.GXIExtensionTemplateSource, priority: Int) { @@ -139,7 +139,7 @@ class GXDataImpl(val context: Context) { dataSourceSorted.forEach { it.source.getTemplateInfo(gxTemplateItem)?.let { return it } } - throw IllegalArgumentException("Template exist but reference is null") + throw IllegalArgumentException("Not found target gxTemplateInfo, templateItem = $gxTemplateItem") } fun registerByPriority(