93 lines
2.8 KiB
Lua
93 lines
2.8 KiB
Lua
-- xx单元
|
||
local _cell = {}
|
||
---@type Coolape.CLCellLua
|
||
local csSelf = nil
|
||
local transform = nil
|
||
local mData = nil
|
||
local uiobjs = {}
|
||
local isDownLoading = false
|
||
local www
|
||
|
||
-- 初始化,只调用一次
|
||
function _cell.init(csObj)
|
||
csSelf = csObj
|
||
transform = csSelf.transform
|
||
uiobjs.Label = getCC(transform, "Label", "UILabel")
|
||
uiobjs.ButtonDel = getChild(transform, "ButtonDel").gameObject
|
||
uiobjs.SpriteIcon = getCC(transform, "SpriteIcon", "UISprite")
|
||
uiobjs.SpriteRight = getChild(transform, "SpriteRight").gameObject
|
||
uiobjs.ButtonDownload = getChild(transform, "ButtonDownload").gameObject
|
||
uiobjs.DownloadProgress = getChild(transform, "DownloadProgress")
|
||
uiobjs.DownloadProgressLb = getCC(uiobjs.DownloadProgress, "Label", "UILabel")
|
||
end
|
||
|
||
-- 显示,
|
||
-- 注意,c#侧不会在调用show时,调用refresh
|
||
function _cell.show(go, data)
|
||
mData = data
|
||
SetActive(uiobjs.ButtonDel, false)
|
||
uiobjs.Label.text = mData.name
|
||
if MyUtl.isImage(mData.name) then
|
||
uiobjs.SpriteIcon.spriteName = "work_img-icon"
|
||
else
|
||
uiobjs.SpriteIcon.spriteName = "work_wenjian-icon"
|
||
end
|
||
SetActive(uiobjs.DownloadProgress.gameObject, false)
|
||
|
||
--//TODO:权限判断,如果有权限的可以考虑直接显示图片
|
||
if DBTextures.hadDownloaded(mData.name) then
|
||
SetActive(uiobjs.ButtonDownload, false)
|
||
SetActive(uiobjs.SpriteRight, true)
|
||
else
|
||
SetActive(uiobjs.ButtonDownload, true)
|
||
SetActive(uiobjs.SpriteRight, false)
|
||
end
|
||
end
|
||
|
||
-- 取得数据
|
||
function _cell.getData()
|
||
return mData
|
||
end
|
||
|
||
function _cell.download()
|
||
if isDownLoading then
|
||
return
|
||
end
|
||
|
||
isDownLoading = true
|
||
SetActive(uiobjs.ButtonDownload, false)
|
||
www =
|
||
DBTextures.download(
|
||
mData.name,
|
||
mData.url,
|
||
function(content, localPath)
|
||
isDownLoading = false
|
||
www = nil
|
||
if content and localPath then
|
||
-- 附件下载完成
|
||
MyUtl.toastS(joinStr("附件已保存本地:" .. localPath))
|
||
SetActive(uiobjs.SpriteRight, true)
|
||
else
|
||
SetActive(uiobjs.ButtonDownload, true)
|
||
end
|
||
end
|
||
)
|
||
_cell.refreshProgress()
|
||
end
|
||
|
||
function _cell.refreshProgress()
|
||
if www == nil then
|
||
SetActive(uiobjs.DownloadProgress.gameObject, false)
|
||
return
|
||
else
|
||
SetActive(uiobjs.DownloadProgress.gameObject, true)
|
||
local progressVal = www.downloadProgress or 0 -- downloadProgress uploadProgress
|
||
uiobjs.DownloadProgressLb.text = joinStr(math.floor(progressVal * 100), "%")
|
||
end
|
||
|
||
csSelf:invoke4Lua(_cell.refreshProgress, 0.1)
|
||
end
|
||
|
||
--------------------------------------------
|
||
return _cell
|