-- 设置为竖屏模式
activity.setRequestedOrientation(1)

function hexToColor(hex)
 -- 去掉 # 前缀
 hex = hex:gsub("#", "")
 -- 将十六进制转换为数字
 local color = tonumber(hex, 16)
 return color
end

local hexColor = "#ff009688"
local MyColor = hexToColor(hexColor)
写入文件(随机色,MyColor)
读取颜色(随机色,随机色)

layout = {
 LinearLayout,
 orientation ='vertical',
 layout_width = 'fill',
 layout_height = 'fill',
 background = '#ffffff',
 {
 TextView,
 text = '影视推荐',
 textSize = '20sp',
 textColor = '#333333',
 layout_gravity = "center|bottom",
 layout_marginTop = '35px',
 },
 {
 TextView,
 layout_width = '97.4%w',
 layout_height = '5px',
 layout_marginTop = '10dp',
 layout_marginBottom = '10dp',
 layout_gravity = 'center',
 backgroundColor = MyColor
 },
 {
 GridView,
 id = "list",
 numColumns = 3,
 layout_width = 'fill',
 layout_height = 'fill',
 horizontalSpacing = "3dp",
 verticalSpacing = "0dp",
 layout_gravity = "center",
 OverScrollMode = 2
 }
}

webView.addView(loadlayout(layout))

function 布局边框(边框粗细, 边框颜色, 背景颜色, 圆角大小)
 import "android.graphics.drawable.GradientDrawable"
 drawable = GradientDrawable()
 drawable.setShape(GradientDrawable.RECTANGLE)
 drawable.setStroke(边框粗细, tonumber(边框颜色))
 drawable.setColor(tonumber(背景颜色))
 drawable.setCornerRadius(圆角大小)
 return drawable
end

item = {
 LinearLayout,
 layout_height = "48dp",
 layout_width = "fill",
 {
 LinearLayout,
 layout_height = "fill",
 layout_width = "fill",
 layout_margin = "5dp",
 BackgroundDrawable = 布局边框(4,MyColor, 0x00000000, 15),
 {
 TextView,
 id = "name",
 layout_height = "fill",
 layout_width = "fill",
 gravity = "center",
 textColor = "#FF000000"
 },
 {
 TextView,
 id = "tools",
 layout_width = "0dp",
 layout_height = "0dp"
 }
 }
}

adapter = LuaAdapter(activity, item)

function getToolsText(v)
 return v.Tag.tools and v.Tag.tools.text or ""
end

list.onItemClick = function(l, v, p, i)
 local toolsText = getToolsText(v)
 if toolsText:find '://' then
 子页面('安卓',toolsText)
 else
 -------------------
 WEB小程序(toolsText)
 -------------------
 end
end

list.onItemLongClick = function(l, v, p, i)
 local toolsText = getToolsText(v)
 if toolsText:find '://' then
 if v.Tag.name.text:find '多功能工具' or v.Tag.name.text:find '本地' or v.Tag.name.text:find '历史记录' then
 print("软件内置工具，不支持使用系统默认浏览器打开😃！")
 return true
 end
 调用浏览器(toolsText)
 return true
 else
 return true
 end
end

list.Adapter = adapter

local dataList = {
 {name = "三维空间\nsan.txcgb.site", tools = "http://san.txcgb.site/jx/so/"},
 {name = "web10301\nm.txcgb.site", tools = "https://m.txcgb.site/jx/so/"},
 {name = "web10613\nmov.txcgb.site", tools = "https://mov.txcgb.site/jx/so/"},
 {name = "三维空间\ntxcgb.v2free.cf", tools = "http://txcgb.v2free.cf/jx/so/"},
 {name = "web10301\nyu.v2free.cf", tools = "https://yu.v2free.cf/jx/so/"},
 {name = "web10613\nmov.v2free.cf", tools = "https://mov.v2free.cf/jx/so/"},
-- {name = "多功能工具", tools = "file:///android_asset/index.html"},
 {name = "本地导航", tools = "http://192.168.10.110:44444/dh/index.htm"},
 {name = "三维空间免费", tools = "http://txcgb.web3v.work/dh/"},
 {name="腾讯视频",tools ="https://film.qq.com/weixin/all.html?t=movie&ptag=viphome"},
 {name="优酷视频",tools ="http://www.youku.com/"},
 {name="芒果TV",tools ="http://m.mgtv.com/#/channel/home"},
 {name="爱奇艺",tools ="https://m.iqiyi.com/dianying"},
 {name="哔哩哔哩电影",tools ="https://m.bilibili.com/channel/v/movie/chinese"},
 {name="搜狐视频",tools ="https://m.tv.sohu.com/"},
 {name="乐视视频",tools ="http://m.le.com/"},
}

for _, data in ipairs(dataList) do
 adapter.add(data)
end