Skip to content

Commit

Permalink
Merge branch 'main' into androidsupport
Browse files Browse the repository at this point in the history
  • Loading branch information
biezhihua committed Jun 14, 2022
2 parents b35eeb3 + 0ff2384 commit c96ff78
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ class GXAdapterLottieAnimation : GXLottieAnimation() {

if (lottieContainer.childCount == 0) {
lottieView.isClickable = false
lottieContainer.isClickable = false
lottieContainer.addView(lottieView)
}
}
Expand Down Expand Up @@ -269,7 +268,6 @@ class GXAdapterLottieAnimation : GXLottieAnimation() {

if (lottieContainer.childCount == 0) {
lottieView.isClickable = false
lottieContainer.isClickable = false
lottieContainer.addView(lottieView)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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("Not found target gxTemplateInfo, templateItem = $gxTemplateItem")
}

fun registerByPriority(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"value": "$recReason.title"
},
"follow-text": {
"value":"'按钮'",
"value":"$isFollowed ? '已关注' : '关注'",
"extend":{
"color":"'#24a5ff'"
"color":"$isFollowed ? '#24a5ff' : 'red'"
}
},
"follow-bg": {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -20,6 +20,8 @@ class EventTemplateActivity : AppCompatActivity() {
renderTemplate1(this)
}

var isFollowed = false

private fun renderTemplate1(activity: EventTemplateActivity) {
// 初始化
GXTemplateEngine.instance.init(activity)
Expand All @@ -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)

Expand Down

0 comments on commit c96ff78

Please sign in to comment.