Skip to content

Commit ff0e035

Browse files
committed
增加用户组织
1 parent cb3baf0 commit ff0e035

File tree

6 files changed

+148
-42
lines changed

6 files changed

+148
-42
lines changed

lib/common/dao/UserDao.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:gsy_github_app_flutter/common/dao/DaoResult.dart';
1111
import 'package:gsy_github_app_flutter/common/local/LocalStorage.dart';
1212
import 'package:gsy_github_app_flutter/common/model/Notification.dart';
1313
import 'package:gsy_github_app_flutter/common/model/User.dart';
14+
import 'package:gsy_github_app_flutter/common/model/UserOrg.dart';
1415
import 'package:gsy_github_app_flutter/common/net/Address.dart';
1516
import 'package:gsy_github_app_flutter/common/net/Api.dart';
1617
import 'package:gsy_github_app_flutter/common/redux/UserRedux.dart';
@@ -316,4 +317,25 @@ class UserDao {
316317
}
317318
return new DataResult(null, false);
318319
}
320+
321+
/**
322+
* 获取用户组织
323+
*/
324+
static getUserOrgsDao(userName, page, {needDb = false}) async {
325+
String url = Address.getUserOrgs(userName) + Address.getPageParams("?", page);
326+
var res = await HttpManager.netFetch(url, null, null, null);
327+
if (res != null && res.result) {
328+
List<UserOrg> list = new List();
329+
var data = res.data;
330+
if (data == null || data.length == 0) {
331+
return new DataResult(null, false);
332+
}
333+
for (int i = 0; i < data.length; i++) {
334+
list.add(new UserOrg.fromJson(data[i]));
335+
}
336+
return new DataResult(list, true);
337+
} else {
338+
return new DataResult(null, false);
339+
}
340+
}
319341
}

lib/common/style/GSYStyle.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ class GSYStrings {
316316
static const String user_un_focus = "关注";
317317
static const String user_focus_no_support = "不支持关注组织。";
318318
static const String user_create_at = "创建于:";
319+
static const String user_orgs_title = "所在组织";
319320

320321
static const String repos_tab_readme = "详情";
321322
static const String repos_tab_info = "动态";

lib/page/CommonListPage.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ class _CommonListPageState extends GSYListState<CommonListPage> {
5757
});
5858
case 'user':
5959
return new UserItem(UserItemViewModel.fromMap(data), onPressed: () {
60-
NavigatorUtils.goPerson(context, data.userName);
60+
NavigatorUtils.goPerson(context, data.login);
6161
});
6262
case 'org':
63-
return null;
63+
return new UserItem(UserItemViewModel.fromOrgMap(data), onPressed: () {
64+
NavigatorUtils.goPerson(context, data.login);
65+
});
6466
case 'issue':
6567
return null;
6668
case 'release':
@@ -99,7 +101,7 @@ class _CommonListPageState extends GSYListState<CommonListPage> {
99101
case 'user_be_stared':
100102
return null;
101103
case 'user_orgs':
102-
return null;
104+
return await UserDao.getUserOrgsDao(userName, page, needDb: page <= 1);
103105
}
104106
}
105107

lib/page/PersonPage.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
77
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
88
import 'package:gsy_github_app_flutter/common/model/Event.dart';
99
import 'package:gsy_github_app_flutter/common/model/User.dart';
10+
import 'package:gsy_github_app_flutter/common/model/UserOrg.dart';
1011
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
1112
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
1213
import 'package:gsy_github_app_flutter/common/utils/EventUtils.dart';
@@ -46,6 +47,8 @@ class _PersonState extends GSYListState<PersonPage> {
4647

4748
User userInfo = User.empty();
4849

50+
final List<UserOrg> orgList = new List();
51+
4952
final OptionControl titleOptionControl = new OptionControl();
5053

5154
_PersonState(this.userName);
@@ -117,7 +120,7 @@ class _PersonState extends GSYListState<PersonPage> {
117120

118121
_renderEventItem(index) {
119122
if (index == 0) {
120-
return new UserHeaderItem(userInfo, beStaredCount);
123+
return new UserHeaderItem(userInfo, beStaredCount, orgList: orgList);
121124
}
122125
if (userInfo.type == "Organization") {
123126
return new UserItem(UserItemViewModel.fromMap(pullLoadWidgetControl.dataList[index - 1]), onPressed: () {
@@ -138,10 +141,24 @@ class _PersonState extends GSYListState<PersonPage> {
138141
return userInfo.login;
139142
}
140143

144+
_getUserOrg() {
145+
if (page <= 1) {
146+
UserDao.getUserOrgsDao(userName, page, needDb: true).then((res) {
147+
if (res != null && res.result) {
148+
setState(() {
149+
orgList.clear();
150+
orgList.addAll(res.data);
151+
});
152+
}
153+
});
154+
}
155+
}
156+
141157
_getDataLogic() async {
142158
if (userInfo.type == "Organization") {
143159
return await UserDao.getMemberDao(_getUserName(), page);
144160
}
161+
_getUserOrg();
145162
return await EventDao.getEventDao(_getUserName(), page: page, needDb: page <= 1);
146163
}
147164

lib/widget/UserHeader.dart

Lines changed: 96 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_spinkit/flutter_spinkit.dart';
33
import 'package:flutter_svg/flutter_svg.dart';
44
import 'package:gsy_github_app_flutter/common/model/User.dart';
5+
import 'package:gsy_github_app_flutter/common/model/UserOrg.dart';
56
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
67
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
78
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
89
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
910
import 'package:gsy_github_app_flutter/widget/GSYIConText.dart';
11+
import 'package:gsy_github_app_flutter/widget/GSYUserIconWidget.dart';
1012

1113
/**
1214
* 用户详情头部
@@ -22,12 +24,16 @@ class UserHeaderItem extends StatelessWidget {
2224

2325
final VoidCallback refreshCallBack;
2426

25-
UserHeaderItem(this.userInfo, this.beStaredCount, {this.notifyColor, this.refreshCallBack});
27+
final List<UserOrg> orgList;
28+
29+
UserHeaderItem(this.userInfo, this.beStaredCount, {this.notifyColor, this.refreshCallBack, this.orgList});
2630

2731
///底部状态栏
2832
_getBottomItem(String title, var value, onPressed) {
2933
String data = value == null ? "" : value.toString();
30-
TextStyle valueStyle = (value != null && value.toString().length > 4) ? GSYConstant.minSmallText : GSYConstant.subSmallText;
34+
TextStyle valueStyle = (value != null && value
35+
.toString()
36+
.length > 4) ? GSYConstant.minSmallText : GSYConstant.subSmallText;
3137
return new Expanded(
3238
child: new Center(
3339
child: new FlatButton(
@@ -70,46 +76,92 @@ class UserHeaderItem extends StatelessWidget {
7076
});
7177
}
7278

79+
///用户组织
80+
_renderOrgs(BuildContext context, List<UserOrg> orgList) {
81+
if (orgList == null || orgList.length == 0) {
82+
return new Container();
83+
}
84+
List<Widget> list = new List();
85+
86+
renderOrgsItem(UserOrg orgs) {
87+
return GSYUserIconWidget(
88+
padding: const EdgeInsets.only(right: 5.0, left: 5.0),
89+
width: 30.0,
90+
height: 30.0,
91+
image: orgs.avatarUrl ?? GSYICons.DEFAULT_REMOTE_PIC,
92+
onPressed: () {
93+
NavigatorUtils.goPerson(context, orgs.login);
94+
});
95+
}
96+
97+
int length = orgList.length > 3 ? 3 : orgList.length;
98+
99+
list.add(new Text(GSYStrings.user_orgs_title + ":", style: GSYConstant.subLightSmallText));
100+
101+
for (int i = 0; i < length; i++) {
102+
list.add(renderOrgsItem(orgList[i]));
103+
}
104+
if (orgList.length > 3) {
105+
list.add(new RawMaterialButton(
106+
onPressed: () {
107+
NavigatorUtils.gotoCommonList(context, userInfo.login + " " + GSYStrings.user_orgs_title, "org", "user_orgs", userName: userInfo.login);
108+
},
109+
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
110+
padding: const EdgeInsets.only(right: 5.0, left: 5.0),
111+
constraints: const BoxConstraints(minWidth: 0.0, minHeight: 0.0),
112+
child: Icon(
113+
Icons.more_horiz,
114+
color: Color(GSYColors.white),
115+
size: 18.0,
116+
)));
117+
}
118+
return Row(children: list);
119+
}
120+
73121
_renderChart(context) {
74122
double height = 140.0;
75-
double width = 3 * MediaQuery.of(context).size.width / 2;
76-
if(userInfo.login != null && userInfo.type == "Organization") {
123+
double width = 3 * MediaQuery
124+
.of(context)
125+
.size
126+
.width / 2;
127+
if (userInfo.login != null && userInfo.type == "Organization") {
77128
return new Container();
78129
}
79130
return (userInfo.login != null)
80131
? new Card(
81-
margin: EdgeInsets.only(top: 0.0, left: 10.0, right: 10.0, bottom: 10.0),
82-
color: Colors.white,
83-
child: new SingleChildScrollView(
84-
scrollDirection: Axis.horizontal,
85-
child: new Container(
86-
padding: EdgeInsets.only(left: 10.0, right: 10.0),
87-
width: width,
88-
height: height,
132+
margin: EdgeInsets.only(top: 0.0, left: 10.0, right: 10.0, bottom: 10.0),
133+
color: Colors.white,
134+
child: new SingleChildScrollView(
135+
scrollDirection: Axis.horizontal,
136+
child: new Container(
137+
padding: EdgeInsets.only(left: 10.0, right: 10.0),
138+
width: width,
139+
height: height,
89140

90-
///svg chart
91-
child: new SvgPicture.network(
92-
CommonUtils.getUserChartAddress(userInfo.login),
93-
width: width,
94-
height: height - 10,
95-
allowDrawingOutsideViewBox: true,
96-
placeholderBuilder: (BuildContext context) => new Container(
97-
height: height,
98-
width: width,
99-
child: Center(
100-
child: const SpinKitRipple(color: Color(GSYColors.primaryValue)),
101-
),
102-
),
103-
),
141+
///svg chart
142+
child: new SvgPicture.network(
143+
CommonUtils.getUserChartAddress(userInfo.login),
144+
width: width,
145+
height: height - 10,
146+
allowDrawingOutsideViewBox: true,
147+
placeholderBuilder: (BuildContext context) =>
148+
new Container(
149+
height: height,
150+
width: width,
151+
child: Center(
152+
child: const SpinKitRipple(color: Color(GSYColors.primaryValue)),
104153
),
105154
),
106-
)
155+
),
156+
),
157+
),
158+
)
107159
: new Container(
108-
height: height,
109-
child: Center(
110-
child: const SpinKitRipple(color: Color(GSYColors.primaryValue)),
111-
),
112-
);
160+
height: height,
161+
child: Center(
162+
child: const SpinKitRipple(color: Color(GSYColors.primaryValue)),
163+
),
164+
);
113165
}
114166

115167
@override
@@ -129,6 +181,7 @@ class UserHeaderItem extends StatelessWidget {
129181
new Row(
130182
crossAxisAlignment: CrossAxisAlignment.start,
131183
children: <Widget>[
184+
132185
///用户头像
133186
new RawMaterialButton(
134187
onPressed: () {
@@ -156,6 +209,7 @@ class UserHeaderItem extends StatelessWidget {
156209
children: <Widget>[
157210
new Row(
158211
children: <Widget>[
212+
159213
///用户名
160214
new Text(userInfo.login ?? "", style: GSYConstant.largeTextWhiteBold),
161215
_getNotifyIcon(context, notifyColor),
@@ -189,7 +243,7 @@ class UserHeaderItem extends StatelessWidget {
189243
),
190244
new Container(
191245

192-
///用户博客
246+
///用户博客
193247
child: new RawMaterialButton(
194248
onPressed: () {
195249
if (userInfo.blog != null) {
@@ -211,6 +265,9 @@ class UserHeaderItem extends StatelessWidget {
211265
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
212266
alignment: Alignment.topLeft),
213267

268+
///组织
269+
_renderOrgs(context, orgList),
270+
214271
///用户描述
215272
new Container(
216273
child: new Text(
@@ -233,39 +290,40 @@ class UserHeaderItem extends StatelessWidget {
233290
_getBottomItem(
234291
GSYStrings.user_tab_repos,
235292
userInfo.public_repos,
236-
() {
293+
() {
237294
NavigatorUtils.gotoCommonList(context, userInfo.login, "repository", "user_repos", userName: userInfo.login);
238295
},
239296
),
240297
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
241298
_getBottomItem(
242299
GSYStrings.user_tab_fans,
243300
userInfo.followers,
244-
() {
301+
() {
245302
NavigatorUtils.gotoCommonList(context, userInfo.login, "user", "follower", userName: userInfo.login);
246303
},
247304
),
248305
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
249306
_getBottomItem(
250307
GSYStrings.user_tab_focus,
251308
userInfo.following,
252-
() {
309+
() {
253310
NavigatorUtils.gotoCommonList(context, userInfo.login, "user", "followed", userName: userInfo.login);
254311
},
255312
),
256313
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
257314
_getBottomItem(
258315
GSYStrings.user_tab_star,
259316
userInfo.starred,
260-
() {
317+
() {
261318
NavigatorUtils.gotoCommonList(context, userInfo.login, "repository", "user_star", userName: userInfo.login);
262319
},
263320
),
264321
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
265322
_getBottomItem(
266323
GSYStrings.user_tab_honor,
267324
beStaredCount,
268-
() {},
325+
() {
326+
},
269327
),
270328
],
271329
),

lib/widget/UserItem.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:gsy_github_app_flutter/common/model/User.dart';
3+
import 'package:gsy_github_app_flutter/common/model/UserOrg.dart';
34
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
45
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
56

@@ -58,4 +59,9 @@ class UserItemViewModel {
5859
userName = user.login;
5960
userPic = user.avatar_url;
6061
}
62+
63+
UserItemViewModel.fromOrgMap(UserOrg org) {
64+
userName = org.login;
65+
userPic = org.avatarUrl;
66+
}
6167
}

0 commit comments

Comments
 (0)