You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
5.2 KiB

  1. --[[
  2. 子活动分享奖励界面
  3. --]]
  4. local ActivityShareView = class("ActivityShareView", cc.UIView)
  5. function ActivityShareView:ctor(mission)--活动类型 ,是否显示关闭按钮
  6. ActivityShareView.super.ctor(self)
  7. self.ui = loadUI("res/ui/ui_dating/ui_activity_share.ui")
  8. self:addChild(self.ui)
  9. self.mission = mission
  10. -- self.aType = activityType
  11. -- self.isShowCloseBtn = isShowCloseBtn
  12. self.lastClick = 0
  13. end
  14. function ActivityShareView:onEnter()
  15. ActivityShareView.super.onEnter(self)
  16. self.ui.Items.Button_share:registerClick(handler(self, self.onShare))
  17. -- self.ui.Items.Button_Close:registerClick(handler(self, self.onClickClose))
  18. -- if self.isShowCloseBtn then
  19. -- self.ui.Items.Button_Close:setVisible(true)
  20. -- else
  21. self.ui.Items.Button_Close:setVisible(false)
  22. -- end
  23. self.ui.Items.Layout_share:setVisible(false)
  24. --self.ui.Items.ImageView_ShareImage:setVisible(false)
  25. self:bindEvent(app, "onGetShareRewardResponse", handler(self, self.onGetShareRewardResponse))
  26. -- local activityData = app.php.activityData;
  27. -- if not activityData then
  28. -- return
  29. -- end
  30. -- self.attyData = app.php.activityData[""..self.aType]
  31. -- if not self._Timer then--定一个3秒的定时器,如果3秒内未获取到图片,自动关闭分享界面
  32. -- self._Timer = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  33. -- if not tolua.isnull(self) then
  34. -- self:removeFromParent()
  35. -- end
  36. -- end,3,false)
  37. -- end
  38. local ext = json.decode(self.mission.ext)
  39. local urlfile1, time1 = convertIconUrl(self.mission.pic)
  40. local urlfile2, time2 = convertIconUrl(ext.share_pic)
  41. local isneedReq = cc.UserDefault:getInstance():getBoolForKey("needRequestShareImage")
  42. --local imagePath1 = cc.FileUtils:getInstance():getWritablePath().."activityShare.png"--显示在活动页面上的图
  43. --local imagePath2 = cc.FileUtils:getInstance():getWritablePath().."activityShareOut.png"--分享到朋友圈的图
  44. self.fileName1 = getImageNameFromUrl(urlfile1)
  45. self.fileName2 = getImageNameFromUrl(urlfile2)
  46. local fullPath = cc.FileUtils:getInstance():getWritablePath()..self.fileName1;
  47. local isExist = cc.FileSystem:fileExists(fullPath)
  48. if isneedReq or (not isExist) then
  49. cc.UserDefault:getInstance():setBoolForKey("needRequestShareImage",false)
  50. getImageFromUrlWithTime(ext.share_pic, self.fileName2, nil, function()
  51. getImageFromUrlWithTime(self.mission.pic, self.fileName1, nil, function()
  52. self:updateView()
  53. end)
  54. end)
  55. else
  56. self:updateView()
  57. end
  58. end
  59. function ActivityShareView:updateView()
  60. if tolua.isnull(self) then
  61. return
  62. end
  63. -- if self._Timer then
  64. -- cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self._Timer)
  65. -- self._Timer = nil
  66. -- end
  67. local texture = loadTextureFromFile(self.fileName1)
  68. if not texture then
  69. -- self:removeFromParent()
  70. return
  71. end
  72. self.ui.Items.ImageView_ShareImage:setTexture2(texture)
  73. self.ui.Items.Layout_share:setVisible(true)
  74. --self.ui.Items.ImageView_ShareImage:setVisible(true)
  75. end
  76. function ActivityShareView:onClickClose()
  77. playBtnEffect()
  78. self:removeFromParent()
  79. end
  80. function ActivityShareView:onShare()
  81. playBtnEffect()
  82. local timeNow = os.time();
  83. if timeNow - self.lastClick <= 5 then
  84. showTooltip("点击太过频繁,请稍后再试")
  85. return
  86. end
  87. self.lastClick = timeNow;
  88. if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then
  89. local imagePath = cc.FileUtils:getInstance():getWritablePath()..self.fileName2;
  90. --local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  91. local function requestGetReward()
  92. app.php:requestGetShareReward()
  93. end
  94. local info = {}
  95. info.scene = "friend"
  96. info.contentType = "image"
  97. info.image = imagePath
  98. info.imageWidth = 1000
  99. info.thumbWidth = 100
  100. app.plugin:shareGame(info,requestGetReward)
  101. else
  102. app.php:requestGetShareReward()
  103. end
  104. --app.php:requestGetShareReward()
  105. --self:onGetShareRewardResponse()
  106. end
  107. function ActivityShareView:onGetShareRewardResponse(result)
  108. if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_ANDROID then
  109. if result.data.flag == -1 then
  110. showTooltip("今日已领取过奖励!")
  111. else
  112. local addNum = result.data.add
  113. --显示获得房卡动画
  114. local view = import("luaScript.Views.Main.JiangLi"):new(addNum)
  115. view:setAnchorPoint(cc.p(0.5, 0.5))
  116. app:showWaitDialog(view, 200, true)
  117. end
  118. else
  119. local imagePath = cc.FileUtils:getInstance():getWritablePath()..self.fileName2;
  120. --local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  121. local function requestGetReward()
  122. --app.php:requestGetShareReward()
  123. end
  124. local info = {}
  125. info.scene = "friend"
  126. info.contentType = "image"
  127. info.image = imagePath
  128. info.imageWidth = 1000
  129. info.thumbWidth = 100
  130. app.plugin:shareGame(info,requestGetReward)
  131. if result.data.flag == -1 then
  132. showTooltip("今日已领取过奖励!")
  133. else
  134. self:runAction(cc.Sequence:create(cc.DelayTime:create(1.2),cc.CallFunc:create(function ()
  135. local addNum = result.data.add
  136. --显示获得房卡动画
  137. local view = import("luaScript.Views.Main.JiangLi"):new(addNum)
  138. view:setAnchorPoint(cc.p(0.5, 0.5))
  139. app:showWaitDialog(view, 200, true)
  140. end)))
  141. end
  142. end
  143. end
  144. return ActivityShareView;