2020-08-01 17:55:18 +08:00
|
|
|
|
-- xx单元
|
|
|
|
|
|
local _cell = {}
|
|
|
|
|
|
---@type Coolape.CLCellLua
|
|
|
|
|
|
local csSelf = nil
|
|
|
|
|
|
local transform = nil
|
|
|
|
|
|
local mData = nil
|
|
|
|
|
|
local uiobjs = {}
|
2020-08-07 07:27:09 +08:00
|
|
|
|
local isDownLoading = false
|
|
|
|
|
|
local www
|
2020-08-01 17:55:18 +08:00
|
|
|
|
|
|
|
|
|
|
-- 初始化,只调用一次
|
|
|
|
|
|
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")
|
2020-08-07 22:40:04 +08:00
|
|
|
|
uiobjs.SpriteRight = getChild(transform, "SpriteRight").gameObject
|
2020-08-07 07:27:09 +08:00
|
|
|
|
uiobjs.ButtonDownload = getChild(transform, "ButtonDownload").gameObject
|
|
|
|
|
|
uiobjs.DownloadProgress = getChild(transform, "DownloadProgress")
|
|
|
|
|
|
uiobjs.DownloadProgressLb = getCC(uiobjs.DownloadProgress, "Label", "UILabel")
|
2020-08-01 17:55:18 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- 显示,
|
|
|
|
|
|
-- 注意,c#侧不会在调用show时,调用refresh
|
|
|
|
|
|
function _cell.show(go, data)
|
|
|
|
|
|
mData = data
|
2020-08-07 07:27:09 +08:00
|
|
|
|
SetActive(uiobjs.ButtonDel, false)
|
2020-08-01 17:55:18 +08:00
|
|
|
|
uiobjs.Label.text = mData.name
|
2020-08-07 07:27:09 +08:00
|
|
|
|
if MyUtl.isImage(mData.name) then
|
2020-08-07 22:40:04 +08:00
|
|
|
|
uiobjs.SpriteIcon.spriteName = "work_img-icon"
|
2020-08-07 07:27:09 +08:00
|
|
|
|
else
|
2020-08-07 22:40:04 +08:00
|
|
|
|
uiobjs.SpriteIcon.spriteName = "work_wenjian-icon"
|
2020-08-07 07:27:09 +08:00
|
|
|
|
end
|
2020-08-07 22:40:04 +08:00
|
|
|
|
SetActive(uiobjs.DownloadProgress.gameObject, false)
|
2020-08-07 07:27:09 +08:00
|
|
|
|
|
2020-08-01 17:55:18 +08:00
|
|
|
|
--//TODO:权限判断,如果有权限的可以考虑直接显示图片
|
2020-08-17 11:13:33 +08:00
|
|
|
|
if DBAttachment.hadDownloaded(mData.name) then
|
2020-08-07 07:27:09 +08:00
|
|
|
|
SetActive(uiobjs.ButtonDownload, false)
|
2020-08-07 22:40:04 +08:00
|
|
|
|
SetActive(uiobjs.SpriteRight, true)
|
2020-08-07 07:27:09 +08:00
|
|
|
|
else
|
|
|
|
|
|
SetActive(uiobjs.ButtonDownload, true)
|
2020-08-07 22:40:04 +08:00
|
|
|
|
SetActive(uiobjs.SpriteRight, false)
|
2020-08-07 07:27:09 +08:00
|
|
|
|
end
|
2020-08-01 17:55:18 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- 取得数据
|
|
|
|
|
|
function _cell.getData()
|
|
|
|
|
|
return mData
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2020-08-07 07:27:09 +08:00
|
|
|
|
function _cell.download()
|
|
|
|
|
|
if isDownLoading then
|
|
|
|
|
|
return
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
isDownLoading = true
|
|
|
|
|
|
SetActive(uiobjs.ButtonDownload, false)
|
|
|
|
|
|
www =
|
2020-08-17 11:13:33 +08:00
|
|
|
|
DBAttachment.download(
|
2020-08-07 07:27:09 +08:00
|
|
|
|
mData.name,
|
|
|
|
|
|
mData.url,
|
|
|
|
|
|
function(content, localPath)
|
|
|
|
|
|
isDownLoading = false
|
|
|
|
|
|
www = nil
|
|
|
|
|
|
if content and localPath then
|
|
|
|
|
|
-- 附件下载完成
|
|
|
|
|
|
MyUtl.toastS(joinStr("附件已保存本地:" .. localPath))
|
2020-08-07 22:40:04 +08:00
|
|
|
|
SetActive(uiobjs.SpriteRight, true)
|
2020-08-07 07:27:09 +08:00
|
|
|
|
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
|
2020-08-07 22:40:04 +08:00
|
|
|
|
uiobjs.DownloadProgressLb.text = joinStr(math.floor(progressVal * 100), "%")
|
2020-08-07 07:27:09 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
csSelf:invoke4Lua(_cell.refreshProgress, 0.1)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2020-08-01 17:55:18 +08:00
|
|
|
|
--------------------------------------------
|
|
|
|
|
|
return _cell
|