social_detail_model.dart 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import 'dart:math';
  2. import 'package:shared_preferences/shared_preferences.dart';
  3. import 'package:sport/provider/lib/view_state_refresh_list_model.dart';
  4. import 'package:sport/services/api/inject_api.dart';
  5. class SocialDetailModel extends ViewStateRefreshListModel with InjectApi {
  6. int _type = 0;
  7. String _forumId;
  8. String _kw;
  9. String _isOfficial;
  10. SocialDetailModel(this._type);
  11. void swtichTab(int type) async {
  12. this._type = type;
  13. initData();
  14. }
  15. void setKeyword(String kw) async {
  16. this._type = 100;
  17. this._kw = kw;
  18. initData();
  19. }
  20. void setForumId(String forumId) async {
  21. this._type = 100;
  22. this._forumId = forumId;
  23. initData();
  24. }
  25. void setForumIdAndOrigin(int type, String forumId, String isOfficial) {
  26. this._forumId = forumId;
  27. this._isOfficial = isOfficial;
  28. this._type = type;
  29. initData();
  30. }
  31. @override
  32. Future<List> loadData({int pageNum = 1}) async {
  33. List results = [];
  34. switch (_type) {
  35. case 100:
  36. results =
  37. handlePage(await api.getPostList(kw: _kw, page: max(1, pageNum),forumId: _forumId,isOfficial: _isOfficial));
  38. break;
  39. // 第四个变成公共了...
  40. case 4:
  41. results =
  42. handlePage(await api.getPostListByOfficial(page: max(1, pageNum),forumId: _forumId,isOfficial: _isOfficial));
  43. break;
  44. // case 4:
  45. // SharedPreferences prefs = await SharedPreferences.getInstance();
  46. // results = handlePage(await api.getPostListByUser(
  47. // prefs.getInt("id").toString(),
  48. // forumId: _forumId,
  49. // page: max(1, pageNum)));
  50. // break;
  51. case 3:
  52. results =
  53. handlePage(await api.getPostList(isGood: 1, page: max(1, pageNum),forumId: _forumId,isOfficial: _isOfficial));
  54. break;
  55. case 2:
  56. results = handlePage(await api.getPostList(page: max(1, pageNum),forumId: _forumId,isOfficial: _isOfficial));
  57. break;
  58. case 1:
  59. SharedPreferences prefs = await SharedPreferences.getInstance();
  60. results = handlePage(
  61. await api.getPostListByFollow(prefs.getInt("id").toString(),
  62. page: max(1, pageNum),forumId: _forumId,isOfficial: _isOfficial),
  63. );
  64. break;
  65. default:
  66. results = handlePage(await api.getPostListByHot(page: max(1, pageNum),forumId: _forumId,isOfficial: _isOfficial));
  67. break;
  68. }
  69. return results;
  70. }
  71. }