Repository navigation
Expand file tree
/
Copy pathPersonPage.dart
More file actions
182 lines (156 loc) · 5.21 KB
/
Copy pathPersonPage.dart
File metadata and controls
182 lines (156 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:gsy_github_app_flutter/common/dao/EventDao.dart';
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
import 'package:gsy_github_app_flutter/common/model/Event.dart';
import 'package:gsy_github_app_flutter/common/model/User.dart';
import 'package:gsy_github_app_flutter/common/model/UserOrg.dart';
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
import 'package:gsy_github_app_flutter/common/utils/EventUtils.dart';
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
import 'package:gsy_github_app_flutter/widget/BasePersonState.dart';
import 'package:gsy_github_app_flutter/widget/EventItem.dart';
import 'package:gsy_github_app_flutter/widget/GSYCommonOptionWidget.dart';
import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
import 'package:gsy_github_app_flutter/widget/GSYTitleBar.dart';
import 'package:gsy_github_app_flutter/widget/UserHeader.dart';
import 'package:gsy_github_app_flutter/widget/UserItem.dart';
/**
* 个人详情
* Created by guoshuyu
* Date: 2018-07-18
*/
class PersonPage extends StatefulWidget {
static final String sName = "person";
final String userName;
PersonPage(this.userName, {Key key}) : super(key: key);
@override
_PersonState createState() => _PersonState(userName);
}
class _PersonState extends BasePersonState<PersonPage> {
final String userName;
String beStaredCount = "---";
bool focusStatus = false;
String focus = "";
User userInfo = User.empty();
final List<UserOrg> orgList = new List();
final OptionControl titleOptionControl = new OptionControl();
_PersonState(this.userName);
_resolveUserInfo(res) {
if (isShow) {
setState(() {
userInfo = res.data;
titleOptionControl.url = res.data.html_url;
});
}
}
@override
Future<Null> handleRefresh() async {
if (isLoading) {
return null;
}
isLoading = true;
page = 1;
var userResult = await UserDao.getUserInfo(userName, needDb: true);
if (userResult != null && userResult.result) {
_resolveUserInfo(userResult);
if (userResult.next != null) {
userResult.next.then((resNext) {
_resolveUserInfo(resNext);
});
}
} else {
return null;
}
var res = await _getDataLogic();
resolveRefreshResult(res);
resolveDataResult(res);
if (res.next != null) {
var resNext = await res.next;
resolveRefreshResult(resNext);
resolveDataResult(resNext);
}
isLoading = false;
_getFocusStatus();
ReposDao.getUserRepository100StatusDao(_getUserName()).then((res) {
if (res != null && res.result) {
if (isShow) {
setState(() {
beStaredCount = res.data.toString();
});
}
}
});
return null;
}
_getFocusStatus() async {
var focusRes = await UserDao.checkFollowDao(userName);
if (isShow) {
setState(() {
focus = (focusRes != null && focusRes.result) ? CommonUtils.getLocale(context).user_focus : CommonUtils.getLocale(context).user_un_focus;
focusStatus = (focusRes != null && focusRes.result);
});
}
}
_getUserName() {
if (userInfo == null) {
return new User.empty();
}
return userInfo.login;
}
_getDataLogic() async {
if (userInfo.type == "Organization") {
return await UserDao.getMemberDao(_getUserName(), page);
}
getUserOrg(_getUserName());
return await EventDao.getEventDao(_getUserName(), page: page, needDb: page <= 1);
}
@override
bool get wantKeepAlive => true;
@override
requestRefresh() async {}
@override
requestLoadMore() async {
return await _getDataLogic();
}
@override
bool get isRefreshFirst => true;
@override
bool get needHeader => true;
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: GSYTitleBar(
(userInfo != null && userInfo.login != null) ? userInfo.login : "",
rightWidget: GSYCommonOptionWidget(titleOptionControl),
)),
floatingActionButton: new FloatingActionButton(
child: new Text(focus),
onPressed: () {
if (focus == '') {
return;
}
if (userInfo.type == "Organization") {
Fluttertoast.showToast(msg: CommonUtils.getLocale(context).user_focus_no_support);
return;
}
CommonUtils.showLoadingDialog(context);
UserDao.doFollowDao(userName, focusStatus).then((res) {
Navigator.pop(context);
_getFocusStatus();
});
}),
body: GSYPullLoadWidget(
pullLoadWidgetControl,
(BuildContext context, int index) => renderItem(index, userInfo, beStaredCount, null, null, orgList),
handleRefresh,
onLoadMore,
refreshKey: refreshIndicatorKey,
));
}
}