@Override
handlerRecommendItem = CampaignHandler { campaign ->
if (!campaign.isControlGroup) {
val recitems = campaign.data.getJSONArray("RecItems")
val titleText = campaign.data["RecItemTitle"]
val titleSize = campaign.data["RecItemTitleFontSize"]
val titleColor = campaign.data["RecItemTitleFontColor"]
val titleAlign = campaign.data["RecItemTitleAlign"]
val campaignItem = CampaignItem(
titleText as String,
titleSize as String,
titleColor as String,
titleAlign as String,
)
recommendItemArray.add( Gson().toJson(campaignItem) )
for (i in 0 until recitems.length()) {
val id = recitems.getJSONObject(i)["_id"]
val name = recitems.getJSONObject(i)["name"]
val imageUrl = recitems.getJSONObject(i)["imageUrl"]
val price = recitems.getJSONObject(i)["price"]
val recItem = RecommendItem(
id as String,
name as String,
imageUrl as String,
price as Double,
)
recommendItemArray.add( Gson().toJson(recItem) )
}
val carouselWebView = findViewById<View>(R.id.webview_top) as WebView
carouselWebView.webChromeClient = WebChromeClient()
carouselWebView.settings.javaScriptEnabled = true
carouselWebView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
Log.d("CLICK", request.url.toString())
return true
}
override fun onPageFinished(view: WebView, urlString: String) {
Log.i("campaign", campaign.getData().toString())
carouselWebView.loadUrl("javascript:loadVariables($recommendItemArray)")
}
}
carouselWebView.loadUrl("file:///android_asset/carousel.html")
}
}
screen.trackAction("App Foreground")
screen.setCampaignHandler(this.handlerPopup, "Targetで指定したキャンペーン名")