PoemGalleryView.cs 26 KB

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