PoemGalleryView.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.Poem;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. class TabType
  9. {
  10. /// <summary>
  11. /// 首页
  12. /// </summary>
  13. public static int RECOVER = 0;
  14. /// <summary>
  15. /// 投稿
  16. /// </summary>
  17. public static int JOIN = 1;
  18. /// <summary>
  19. /// 收藏
  20. /// </summary>
  21. public static int FAVORITES = 2;
  22. }
  23. class RecommendType
  24. {
  25. /// <summary>
  26. /// 推荐
  27. /// </summary>
  28. public static int RECOMMEND = 0;
  29. /// <summary>
  30. /// 好友
  31. /// </summary>
  32. public static int FRIEND = 1;
  33. /// <summary>
  34. /// 排行榜
  35. /// </summary>
  36. public static int RANK = 2;
  37. }
  38. class FavoritesType
  39. {
  40. /// <summary>
  41. /// 我的收藏
  42. /// </summary>
  43. public static int FAVORITE = 0;
  44. /// <summary>
  45. /// 我的作品
  46. /// </summary>
  47. public static int MY_SELF = 1;
  48. }
  49. public class PoemGalleryView : BaseWindow
  50. {
  51. private UI_PoemGalleryUI _ui;
  52. private GList _list;
  53. private GList _list1;
  54. private GComponent _comScroll;
  55. // private List<PoemGalleryData> _galleryDatas = new List<PoemGalleryData>();
  56. private List<long> _galleryDatas = new List<long>();
  57. private int _sortType = 0;//由GallerySortType定义
  58. private int _pageCount = 10;
  59. private int _tabIndex = 0;//当前选中大页签下标,首页0投稿1收藏2
  60. private int _subtabIndex = 0;//当前选中小页签下标,推荐0好友1排行榜2;我的收藏0我的作品1
  61. private bool isPullDown = false;//是否下拉刷新中,刷新中再次下拉不会重新请求更新数据
  62. private bool isPullUp = false;//是否上拉刷新中,刷新中再次下拉不会重新请求更新数据
  63. public override void Dispose()
  64. {
  65. if (_ui != null)
  66. {
  67. _ui.Dispose();
  68. _ui = null;
  69. }
  70. base.Dispose();
  71. }
  72. protected override void OnInit()
  73. {
  74. base.OnInit();
  75. packageName = UI_PoemGalleryUI.PACKAGE_NAME;
  76. _ui = UI_PoemGalleryUI.Create();
  77. this.viewCom = _ui.target;
  78. isfullScreen = true;
  79. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  80. _ui.m_comNormal.m_comBoBox.items = new string[] { "推荐", "最新" };
  81. _ui.m_comNormal.m_comBoBox.icons = new string[] { "ui://Poem/hl_pxpx", "ui://Poem/hl_zxzx" };
  82. _ui.m_comNormal.m_comBoBox.onChanged.Add(OnNormalTabChange);
  83. _ui.m_btnback.onClick.Add(OnBtnBackClick);
  84. _ui.m_btnRecover.onClick.Add(OnBtnRecoverClick);
  85. _ui.m_btnJoin.onClick.Add(OnBtnJoinClick);
  86. _ui.m_btnFavorites.onClick.Add(OnBtnFavoritesClick);
  87. _ui.m_comNormal.m_comScroll.target.scrollPane.onPullDownRelease.Add(onPullDownRelease);
  88. _ui.m_comNormal.m_comScroll.target.scrollPane.onPullUpRelease.Add(OnPullUpToRefresh);
  89. _ui.m_comNormal.m_comScroll.target.scrollPane.onScrollEnd.Add(onScrollEnd);
  90. _ui.m_comFavorites.m_comScroll.target.scrollPane.onPullDownRelease.Add(onPullDownRelease);
  91. _ui.m_comFavorites.m_comScroll.target.scrollPane.onPullUpRelease.Add(OnPullUpToRefresh);
  92. _ui.m_comFavorites.m_comScroll.target.scrollPane.onScrollEnd.Add(onScrollEnd);
  93. _ui.m_comNormal.m_comScroll.m_listRecommend.itemRenderer = RenderListItem;
  94. _ui.m_comNormal.m_comScroll.m_listRecommend1.itemRenderer = RenderListItem1;
  95. _ui.m_comFavorites.m_comScroll.m_listRecommend.itemRenderer = RenderListItem;
  96. _ui.m_comFavorites.m_comScroll.m_listRecommend1.itemRenderer = RenderListItem1;
  97. _ui.m_comNormal.m_listRank.itemRenderer = RenderListRankItem;
  98. _ui.m_comNormal.m_listRank.SetVirtual();
  99. _ui.m_comNormal.m_btnShop.onClick.Add(OnBtnShopClick);
  100. _ui.m_comNormal.m_btnReward.onClick.Add(OnBtnRewardClick);
  101. _ui.m_comNormal.m_c1.onChanged.Add(OnNormalTabChange);
  102. _ui.m_comFavorites.m_c1.onChanged.Add(OnFavoritesTabChange);
  103. }
  104. protected override void AddEventListener()
  105. {
  106. base.AddEventListener();
  107. // EventAgent.AddEventListener(ConstMessage.GALLERY_DATA_CHANGE, UpdateGalleryList);
  108. // EventAgent.AddEventListener(ConstMessage.GALLERY_RANK_DATA_CHANGE, UpdateGalleryRankList);
  109. }
  110. protected override async void OnShown()
  111. {
  112. base.OnShown();
  113. if (this.viewData != null)
  114. {
  115. _tabIndex = (int)(this.viewData as object[])[0];
  116. _subtabIndex = (int)(this.viewData as object[])[1];
  117. _ui.m_comNormal.m_comBoBox.selectedIndex = (int)(this.viewData as object[])[2];
  118. if (_tabIndex == TabType.RECOVER)
  119. {
  120. _ui.m_comNormal.m_c1.selectedIndex = _subtabIndex;
  121. }
  122. else if (_tabIndex == TabType.FAVORITES)
  123. {
  124. _ui.m_comFavorites.m_c1.selectedIndex = _subtabIndex;
  125. }
  126. UpdateGalleryList();
  127. }
  128. else
  129. {
  130. _tabIndex = TabType.RECOVER;
  131. _subtabIndex = RecommendType.RECOMMEND;
  132. _ui.m_comNormal.m_comBoBox.selectedIndex = 0;
  133. _ui.m_comNormal.m_c1.selectedIndex = _subtabIndex;
  134. _ui.m_comFavorites.m_c1.selectedIndex = _subtabIndex;
  135. _comScroll = _ui.m_comNormal.m_comScroll.target;
  136. if (_ui.m_comNormal.m_comScroll.m_listRecommend.numItems > 0) _ui.m_comNormal.m_comScroll.m_listRecommend.ScrollToView(0);
  137. if (_ui.m_comNormal.m_comScroll.m_listRecommend1.numItems > 0) _ui.m_comNormal.m_comScroll.m_listRecommend1.ScrollToView(0);
  138. if (_ui.m_comFavorites.m_comScroll.m_listRecommend.numItems > 0) _ui.m_comFavorites.m_comScroll.m_listRecommend.ScrollToView(0);
  139. if (_ui.m_comFavorites.m_comScroll.m_listRecommend1.numItems > 0) _ui.m_comFavorites.m_comScroll.m_listRecommend1.ScrollToView(0);
  140. _ui.m_comNormal.m_comScroll.m_listRecommend.numItems = 0;
  141. _ui.m_comNormal.m_comScroll.m_listRecommend1.numItems = 0;
  142. _ui.m_comFavorites.m_comScroll.m_listRecommend.numItems = 0;
  143. _ui.m_comFavorites.m_comScroll.m_listRecommend1.numItems = 0;
  144. OnFavoritesTabChange();
  145. OnNormalTabChange();
  146. }
  147. _ui.m_c1.selectedIndex = _tabIndex;
  148. UpdateView();
  149. if (PoemGalleryDataManager.Instance.HasBonus)
  150. {
  151. bool result = await PoemGallerySProxy.ReqGetGalleryRankBonus();
  152. if (result && PoemGalleryDataManager.Instance.MyWorksRanks.Count > 0)
  153. {
  154. ViewManager.Show<PoemGalleryRewardGetView>();
  155. }
  156. }
  157. }
  158. protected override void OnHide()
  159. {
  160. base.OnHide();
  161. ResetPullRelease();
  162. _ui.m_comNormal.m_comBoBox.selectedIndex = 0;
  163. }
  164. protected override void RemoveEventListener()
  165. {
  166. base.RemoveEventListener();
  167. // EventAgent.RemoveEventListener(ConstMessage.GALLERY_DATA_CHANGE, UpdateGalleryList);
  168. // EventAgent.RemoveEventListener(ConstMessage.GALLERY_RANK_DATA_CHANGE, UpdateGalleryRankList);
  169. }
  170. private void OnBtnBackClick()
  171. {
  172. ViewManager.GoBackFrom(typeof(PoemGalleryView).FullName);
  173. }
  174. /// <summary>
  175. /// 积分商店
  176. /// </summary>
  177. private void OnBtnShopClick()
  178. {
  179. object[] gobackParamDatas = new object[] { _tabIndex, _subtabIndex, _ui.m_comNormal.m_comBoBox.selectedIndex };
  180. ViewManager.Show<GalleryShopView>(new object[] { ConstStoreId.GALLERY_STORE_ID }, new object[] { typeof(PoemGalleryView).FullName, gobackParamDatas }, true);
  181. }
  182. /// <summary>
  183. /// 排行榜奖励
  184. /// </summary>
  185. private void OnBtnRewardClick()
  186. {
  187. ViewManager.Show<PoemGalleryRewardView>(null, new object[] { typeof(PoemGalleryView).FullName, this.viewData });
  188. }
  189. /********************************************************页签切换*************************************************/
  190. /// <summary>
  191. /// 首页
  192. /// </summary>
  193. private void OnBtnRecoverClick()
  194. {
  195. if (_tabIndex == TabType.RECOVER)//当前在推荐页要刷新
  196. {
  197. if (_ui.m_comNormal.m_c1.selectedIndex == RecommendType.RECOMMEND)//重新拉取数据
  198. {
  199. PullDown();
  200. onPullDownRelease();
  201. }
  202. else//切页签并重新拉取数据
  203. {
  204. _ui.m_comNormal.m_c1.selectedIndex = RecommendType.RECOMMEND;
  205. }
  206. }
  207. else//更新列表
  208. {
  209. _ui.m_comNormal.m_c1.selectedIndex = RecommendType.RECOMMEND;
  210. UpdateList();
  211. UpdateGalleryList();
  212. }
  213. _tabIndex = _ui.m_c1.selectedIndex;
  214. _subtabIndex = _ui.m_comNormal.m_c1.selectedIndex;
  215. _comScroll = _ui.m_comNormal.m_comScroll.target;
  216. }
  217. /// <summary>
  218. /// 投稿
  219. /// </summary>
  220. private void OnBtnJoinClick()
  221. {
  222. object[] gobackParamDatas = new object[] { _tabIndex, _subtabIndex, _ui.m_comNormal.m_comBoBox.selectedIndex };
  223. ViewManager.Show<DressUpView>(1, new object[] { typeof(PoemGalleryView).FullName, gobackParamDatas }, true);
  224. }
  225. /// <summary>
  226. ///收藏夹
  227. /// </summary>
  228. private void OnBtnFavoritesClick()
  229. {
  230. if (_tabIndex == TabType.FAVORITES) return;
  231. ResetPullRelease();
  232. _tabIndex = _ui.m_c1.selectedIndex;
  233. _comScroll = _ui.m_comFavorites.m_comScroll.target;
  234. _ui.m_comFavorites.m_c1.selectedIndex = FavoritesType.FAVORITE;
  235. _subtabIndex = _ui.m_comFavorites.m_c1.selectedIndex;
  236. OnFavoritesTabChange();
  237. }
  238. /// <summary>
  239. /// 切换首页页签
  240. /// </summary>
  241. private void OnNormalTabChange()
  242. {
  243. ResetPullRelease();
  244. _ui.m_comNormal.m_comScroll.target.scrollPane.header.visible = false;
  245. _subtabIndex = _ui.m_comNormal.m_c1.selectedIndex;
  246. if (_ui.m_comNormal.m_c1.selectedIndex == RecommendType.RANK)//排行榜
  247. {
  248. _galleryDatas = PoemGalleryDataManager.Instance.RankDatas;
  249. ReqGalleryRankList();
  250. }
  251. else
  252. {
  253. UpdateList();
  254. if (_list.numItems > 0) _list.ScrollToView(0);
  255. if (_list1.numItems > 0) _list.ScrollToView(0);
  256. _list.numItems = 0;
  257. _list1.numItems = 0;
  258. ReqGalleryList(0);
  259. }
  260. }
  261. private void UpdateList()
  262. {
  263. if (_ui.m_comNormal.m_c1.selectedIndex == RecommendType.RECOMMEND)//首页
  264. {
  265. _ui.m_comNormal.m_comScroll.target.scrollPane.header.visible = true;
  266. if (_ui.m_comNormal.m_comBoBox.selectedIndex == 0)//推荐
  267. {
  268. _sortType = (int)GallerySortType.Recommend;
  269. _galleryDatas = PoemGalleryDataManager.Instance.RecommendDatas;
  270. }
  271. else//最新
  272. {
  273. _sortType = (int)GallerySortType.Newest;
  274. _galleryDatas = PoemGalleryDataManager.Instance.NewestDatas;
  275. }
  276. }
  277. else if (_ui.m_comNormal.m_c1.selectedIndex == RecommendType.FRIEND)//好友
  278. {
  279. _sortType = (int)GallerySortType.Friend;
  280. _galleryDatas = PoemGalleryDataManager.Instance.FrinedDatas;
  281. }
  282. _list = _ui.m_comNormal.m_comScroll.m_listRecommend;
  283. _list1 = _ui.m_comNormal.m_comScroll.m_listRecommend1;
  284. }
  285. /// <summary>
  286. /// 切换收藏页签
  287. /// </summary>
  288. private void OnFavoritesTabChange()
  289. {
  290. _ui.m_comFavorites.m_comScroll.target.scrollPane.header.visible = false;
  291. _subtabIndex = _ui.m_comFavorites.m_c1.selectedIndex;
  292. if (_ui.m_comFavorites.m_c1.selectedIndex == FavoritesType.FAVORITE)//我的收藏
  293. {
  294. _sortType = (int)GallerySortType.MyCollect;
  295. _galleryDatas = PoemGalleryDataManager.Instance.FavoriteDatas;
  296. }
  297. else if (_ui.m_comFavorites.m_c1.selectedIndex == FavoritesType.MY_SELF)//我的作品
  298. {
  299. _sortType = (int)GallerySortType.MyWorks;
  300. _galleryDatas = PoemGalleryDataManager.Instance.MySelfDatas;
  301. }
  302. _list = _ui.m_comFavorites.m_comScroll.m_listRecommend;
  303. _list1 = _ui.m_comFavorites.m_comScroll.m_listRecommend1;
  304. if (_list.numItems > 0) _list.ScrollToView(0);
  305. if (_list1.numItems > 0) _list.ScrollToView(0);
  306. ReqGalleryList(0);
  307. }
  308. /********************************************************请求更新列表*************************************************/
  309. private void onScrollEnd()
  310. {
  311. if (_comScroll.scrollPane.percY == 1)
  312. {
  313. ReqGalleryList(_galleryDatas.Count + 1);
  314. }
  315. }
  316. //请求刷新
  317. private async void ReqGalleryList(int startIndex)
  318. {
  319. bool result = await PoemGallerySProxy.ReqGalleryList(_sortType, startIndex, _pageCount);
  320. if (result)
  321. {
  322. Timers.inst.StartCoroutine(PictureStorageHelper.Download(_galleryDatas, startIndex, UpdateGalleryList));
  323. }
  324. }
  325. private void UpdateGalleryList()
  326. {
  327. if (_tabIndex == TabType.RECOVER && _subtabIndex == RecommendType.RANK)
  328. {
  329. _ui.m_comNormal.m_listRank.numItems = _galleryDatas.Count;
  330. }
  331. else
  332. {
  333. if (_galleryDatas.Count % 2 == 0)
  334. {
  335. _list.numItems = _galleryDatas.Count / 2;
  336. _list1.numItems = _galleryDatas.Count / 2;
  337. }
  338. else
  339. {
  340. _list.numItems = (_galleryDatas.Count + 1) / 2;
  341. _list1.numItems = (_galleryDatas.Count - 1) / 2;
  342. }
  343. _list.ResizeToFit();
  344. _list1.ResizeToFit();
  345. }
  346. UpdateView();
  347. ResetPullRelease();
  348. }
  349. //请求排行榜刷新
  350. private async void ReqGalleryRankList()
  351. {
  352. bool result = await PoemGallerySProxy.ReqRankList();
  353. if (result)
  354. {
  355. Timers.inst.StartCoroutine(PictureStorageHelper.Download(_galleryDatas, 0, UpdateGalleryRankList));
  356. }
  357. }
  358. private void UpdateGalleryRankList()
  359. {
  360. _ui.m_comNormal.m_listRank.numItems = _galleryDatas.Count;
  361. UpdateView();
  362. }
  363. /********************************************************界面更新*************************************************/
  364. private void UpdateView()
  365. {
  366. GalleryThemeCfg themeCfg = GalleryThemeCfgArray.Instance.GetCfg((int)PoemGalleryDataManager.Instance.ThemeId);
  367. _ui.m_comNormal.m_txtTheme.text = string.Format("本期主题:{0}", themeCfg.theme);
  368. _ui.m_comNormal.m_txtRank.text = string.Format("我的排名: {0}", PoemGalleryDataManager.Instance.MyRank > 0 ? PoemGalleryDataManager.Instance.MyRank.ToString() : "- -");
  369. _ui.m_comNormal.m_txtRewardCount.text = string.Format("奖励次数:{0}/{1}", GameGlobal.myNumericComponent.GetAsInt(NumericType.LikeGalleryWorksCountDaily), GalleryRewardCfgArray.Instance.dataArray.Length);
  370. _ui.m_comNormal.m_txtTime.text = string.Format("截止日期:{0}", PoemGalleryDataManager.Instance.GetThemeTime());
  371. _ui.m_comNormal.m_grpResult.visible = PoemGalleryDataManager.Instance.IsResulting();
  372. }
  373. private void RenderListItem(int index, GObject obj)
  374. {
  375. long workId = _galleryDatas[index * 2];
  376. UpdateListItem(workId, obj);
  377. }
  378. private void RenderListItem1(int index, GObject obj)
  379. {
  380. long workId = _galleryDatas[index * 2 + 1];
  381. UpdateListItem(workId, obj);
  382. }
  383. private void UpdateListItem(long workId, GObject obj)
  384. {
  385. PoemGalleryData data = PoemGalleryDataManager.Instance.GetGalleryDataById(workId);
  386. UI_ListItem item = UI_ListItem.Proxy(obj);
  387. item.m_loaIcon.texture = data.Ntexture;
  388. item.m_loaIcon.height = item.m_loaIcon.width * item.m_loaIcon.texture.height / item.m_loaIcon.texture.width;
  389. item.m_txtName.text = data.AuthorName;
  390. item.m_btnCollect.title = data.CollectCount.ToString();
  391. item.m_btnCollect.selected = data.CollectOrNot;
  392. item.m_btnVote.title = data.VoteCount.ToString();
  393. item.m_btnVote.selected = data.VoteOrNot;
  394. if (item.m_loaIcon.data == null)
  395. {
  396. item.m_loaIcon.onClick.Add(OnLoaIconClick);
  397. }
  398. item.m_loaIcon.data = workId;
  399. if (item.m_btnCollect.data == null)
  400. {
  401. item.m_btnCollect.onClick.Add(OnBtnCollectClick);
  402. }
  403. item.m_btnCollect.data = workId;
  404. if (item.m_btnVote.data == null)
  405. {
  406. item.m_btnVote.onClick.Add(OnBtnVoteClick);
  407. }
  408. item.m_btnVote.data = workId;
  409. UI_ListItem.ProxyEnd();
  410. }
  411. private void RenderListRankItem(int index, GObject obj)
  412. {
  413. long workId = _galleryDatas[index];
  414. PoemGalleryData data = PoemGalleryDataManager.Instance.GetGalleryDataById(workId);
  415. UI_ListRankItem item = UI_ListRankItem.Proxy(obj);
  416. item.m_loaIcon.texture = data.Ntexture;
  417. item.m_loaIcon.height = item.m_loaIcon.width * item.m_loaIcon.texture.height / item.m_loaIcon.texture.width;
  418. item.m_txtName.text = data.AuthorName;
  419. item.m_btnCollect.title = data.CollectCount.ToString();
  420. item.m_btnCollect.selected = data.CollectOrNot;
  421. item.m_btnVote.title = data.VoteCount.ToString();
  422. item.m_btnVote.selected = data.VoteOrNot;
  423. item.m_txtRank.text = data.Rank.ToString();
  424. item.m_c1.selectedIndex = index < 3 ? index : 3;
  425. if (item.m_loaIcon.data == null)
  426. {
  427. item.m_loaIcon.onClick.Add(OnLoaIconClick);
  428. }
  429. item.m_loaIcon.data = workId;
  430. if (item.m_btnCollect.data == null)
  431. {
  432. item.m_btnCollect.onClick.Add(OnBtnCollectClick);
  433. }
  434. item.m_btnCollect.data = workId;
  435. if (item.m_btnVote.data == null)
  436. {
  437. item.m_btnVote.onClick.Add(OnBtnVoteClick);
  438. }
  439. item.m_btnVote.data = workId;
  440. UI_ListRankItem.ProxyEnd();
  441. }
  442. private void OnLoaIconClick(EventContext context)
  443. {
  444. GObject obj = context.sender as GObject;
  445. long workId = (long)obj.data;
  446. object[] gobackParamDatas = new object[] { _tabIndex, _subtabIndex, _ui.m_comNormal.m_comBoBox.selectedIndex };
  447. ViewManager.Show<PoemGalleryPreviewView>(new object[] { _sortType, workId }, new object[] { typeof(PoemGalleryView).FullName, gobackParamDatas });
  448. }
  449. private async void OnBtnCollectClick(EventContext context)
  450. {
  451. GObject obj = context.sender as GObject;
  452. long workId = (long)obj.data;
  453. PoemGalleryData galleryData = PoemGalleryDataManager.Instance.GetGalleryDataById(workId);
  454. if (galleryData.CollectOrNot)
  455. {
  456. bool result = await PoemGallerySProxy.ReqCancelCollecteGalleryWorks(workId);
  457. if (result)
  458. {
  459. if (_tabIndex == TabType.FAVORITES && _subtabIndex == FavoritesType.FAVORITE)
  460. {
  461. ReqGalleryList(0);//当前为收藏页要重新拉取数据
  462. }
  463. else
  464. {
  465. UpdateGalleryList();
  466. }
  467. }
  468. }
  469. else
  470. {
  471. bool result = await PoemGallerySProxy.ReqCollecteGalleryWorks(workId);
  472. if (result)
  473. {
  474. if (_tabIndex == TabType.FAVORITES && _subtabIndex == FavoritesType.FAVORITE)
  475. {
  476. ReqGalleryList(0);//当前为收藏页要重新拉取数据
  477. }
  478. else
  479. {
  480. UpdateGalleryList();
  481. }
  482. }
  483. }
  484. }
  485. private async void OnBtnVoteClick(EventContext context)
  486. {
  487. GObject obj = context.sender as GObject;
  488. long workId = (long)obj.data;
  489. PoemGalleryData galleryData = PoemGalleryDataManager.Instance.GetGalleryDataById(workId);
  490. if (galleryData.VoteOrNot) return;
  491. bool result = await PoemGallerySProxy.ReqVoteGalleryWorks(workId);
  492. if (result)
  493. {
  494. UpdateGalleryList();
  495. int Count = GameGlobal.myNumericComponent.GetAsInt(NumericType.LikeGalleryWorksCountDaily);
  496. GalleryIntegralCfg integralCfg = GalleryIntegralCfgArray.Instance.GetCfg(Count);
  497. if (integralCfg != null)
  498. {
  499. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(integralCfg.itemId);
  500. PromptController.Instance.ShowFloatTextPrompt(string.Format("{0} +{1}", itemCfg.name, integralCfg.Count));
  501. }
  502. }
  503. }
  504. /********************************************************下拉刷新*************************************************/
  505. //自动下拉
  506. private void PullDown()
  507. {
  508. _list.ScrollToView(0);
  509. GComponent header = _comScroll.scrollPane.header;
  510. header.height = header.sourceHeight;
  511. }
  512. //下拉刷新
  513. private async void onPullDownRelease()
  514. {
  515. GComponent header = _comScroll.scrollPane.header;
  516. if (!header.visible || header.height < header.sourceHeight || isPullDown) return;
  517. isPullDown = true;
  518. _comScroll.scrollPane.LockHeader(header.sourceHeight);
  519. bool result = await PoemGallerySProxy.ReqGalleryList(_sortType, 0, _pageCount);
  520. // OnPullDownTimeComplete();
  521. if (result)
  522. {
  523. Timers.inst.StartCoroutine(PictureStorageHelper.Download(_galleryDatas, 0, UpdateGalleryList));
  524. }
  525. }
  526. private void OnPullDownTimeComplete()
  527. {
  528. GComponent header = _comScroll.scrollPane.header;
  529. Transition transition = header.GetTransition("t0");
  530. transition.Stop();
  531. _comScroll.scrollPane.LockHeader(0);
  532. isPullDown = false;
  533. }
  534. //上拉刷新
  535. private async void OnPullUpToRefresh()
  536. {
  537. GComponent footer = _comScroll.scrollPane.footer;
  538. if (footer.height < footer.sourceHeight || isPullUp) return;
  539. isPullUp = true;
  540. _comScroll.scrollPane.LockFooter(footer.sourceHeight + 10);
  541. bool result = await PoemGallerySProxy.ReqGalleryList(_sortType, _galleryDatas.Count, _pageCount);
  542. // OnPullUpTimeComplete();
  543. if (result)
  544. {
  545. Timers.inst.StartCoroutine(PictureStorageHelper.Download(_galleryDatas, _galleryDatas.Count, UpdateGalleryList));
  546. }
  547. }
  548. private void OnPullUpTimeComplete()
  549. {
  550. GComponent footer = _comScroll.scrollPane.footer;
  551. Transition transition = footer.GetTransition("t0");
  552. transition.Stop();
  553. // header.GetController("c1").selectedIndex = 2;
  554. _comScroll.scrollPane.LockFooter(0);
  555. isPullUp = false;
  556. }
  557. //重置上拉/下拉刷新状态
  558. private void ResetPullRelease()
  559. {
  560. // Timers.inst.Remove(OnPullDownTimeComplete);
  561. OnPullDownTimeComplete();
  562. // Timers.inst.Remove(OnPullUpTimeComplete);
  563. OnPullUpTimeComplete();
  564. }
  565. }
  566. }