X Tutup
Skip to content

Commit b2d964b

Browse files
committed
增加组织
1 parent ed9e2a0 commit b2d964b

File tree

6 files changed

+76
-19
lines changed

6 files changed

+76
-19
lines changed

lib/common/dao/UserDao.dart

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ class UserDao {
7979
res = await HttpManager.netFetch(Address.getUserInfo(userName), null, null, null);
8080
}
8181
if (res != null && res.result) {
82-
var countRes = await getUserStaredCountNet(res.data["login"]);
8382
String starred = "---";
84-
if (countRes.result) {
85-
starred = countRes.data;
83+
if(res.data["type"] != "Organization") {
84+
var countRes = await getUserStaredCountNet(res.data["login"]);
85+
if (countRes.result) {
86+
starred = countRes.data;
87+
}
8688
}
8789
User user = User.fromJson(res.data);
8890
user.starred = starred;
@@ -215,4 +217,25 @@ class UserDao {
215217
var res = await HttpManager.netFetch(url, null, null, new Options(method: !followed ? "PUT" : "DELETE"), noTip: true);
216218
return new DataResult(res.data, res.result);
217219
}
220+
221+
/**
222+
* 组织成员
223+
*/
224+
static getMemberDao(userName, page) async {
225+
String url = Address.getMember(userName) + Address.getPageParams("?", page);
226+
var res = await HttpManager.netFetch(url, null, null, null);
227+
if (res != null && res.result) {
228+
List<UserItemViewModel> list = new List();
229+
var data = res.data;
230+
if (data == null || data.length == 0) {
231+
return new DataResult(null, false);
232+
}
233+
for (int i = 0; i < data.length; i++) {
234+
list.add(new UserItemViewModel(data[i]['login'], data[i]["avatar_url"]));
235+
}
236+
return new DataResult(list, true);
237+
} else {
238+
return new DataResult(null, false);
239+
}
240+
}
218241
}

lib/common/style/GSYStyle.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ class GSYStrings {
220220
static const String user_tab_focus = "关注";
221221
static const String user_tab_star = "星标";
222222
static const String user_tab_honor = "荣耀";
223+
static const String user_dynamic_group = "组织成员";
223224
static const String user_dynamic_title = "个人动态";
225+
static const String user_focus = "已关注";
226+
static const String user_un_focus = "关注";
227+
static const String user_focus_no_support = "不支持关注组织。";
224228

225229
static const String repos_tab_readme = "详情";
226230
static const String repos_tab_info = "动态";

lib/page/PersonPage.dart

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import 'dart:async';
22

33
import 'package:flutter/material.dart';
4+
import 'package:fluttertoast/fluttertoast.dart';
45
import 'package:gsy_github_app_flutter/common/dao/EventDao.dart';
56
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
67
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
78
import 'package:gsy_github_app_flutter/common/model/User.dart';
9+
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
810
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
11+
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
912
import 'package:gsy_github_app_flutter/widget/EventItem.dart';
1013
import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
1114
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
1215
import 'package:gsy_github_app_flutter/widget/UserHeader.dart';
16+
import 'package:gsy_github_app_flutter/widget/UserItem.dart';
1317

1418
/**
1519
* 个人详情
@@ -56,7 +60,7 @@ class _PersonState extends GSYListState<PersonPage> {
5660
} else {
5761
return null;
5862
}
59-
var res = await EventDao.getEventDao(_getUserName(), page: page);
63+
var res = await _getDataLogic();
6064
if (res != null && res.result) {
6165
pullLoadWidgetControl.dataList.clear();
6266
setState(() {
@@ -79,7 +83,7 @@ class _PersonState extends GSYListState<PersonPage> {
7983
_getFocusStatus() async {
8084
var focusRes = await UserDao.checkFollowDao(userName);
8185
setState(() {
82-
focus = (focusRes != null && focusRes.result) ? "已关注" : "关注";
86+
focus = (focusRes != null && focusRes.result) ? GSYStrings.user_focus : GSYStrings.user_un_focus;
8387
focusStatus = (focusRes != null && focusRes.result);
8488
});
8589
}
@@ -88,7 +92,13 @@ class _PersonState extends GSYListState<PersonPage> {
8892
if (index == 0) {
8993
return new UserHeaderItem(userInfo, beStaredCount);
9094
}
91-
return new EventItem(pullLoadWidgetControl.dataList[index - 1]);
95+
if (userInfo.type == "Organization") {
96+
return new UserItem(pullLoadWidgetControl.dataList[index - 1], onPressed: () {
97+
NavigatorUtils.goPerson(context, pullLoadWidgetControl.dataList[index - 1].userName);
98+
});
99+
} else {
100+
return new EventItem(pullLoadWidgetControl.dataList[index - 1]);
101+
}
92102
}
93103

94104
_getUserName() {
@@ -98,6 +108,13 @@ class _PersonState extends GSYListState<PersonPage> {
98108
return userInfo.login;
99109
}
100110

111+
_getDataLogic() async {
112+
if (userInfo.type == "Organization") {
113+
return await UserDao.getMemberDao(_getUserName(), page);
114+
}
115+
return await EventDao.getEventDao(_getUserName(), page: page);
116+
}
117+
101118
@override
102119
bool get wantKeepAlive => true;
103120

@@ -106,7 +123,7 @@ class _PersonState extends GSYListState<PersonPage> {
106123

107124
@override
108125
requestLoadMore() async {
109-
return await EventDao.getEventDao(_getUserName(), page: page);
126+
return await _getDataLogic();
110127
}
111128

112129
@override
@@ -127,6 +144,10 @@ class _PersonState extends GSYListState<PersonPage> {
127144
if (focus == '') {
128145
return;
129146
}
147+
if(userInfo.type == "Organization") {
148+
Fluttertoast.showToast(msg: GSYStrings.user_focus_no_support);
149+
return;
150+
}
130151
CommonUtils.showLoadingDialog(context);
131152
UserDao.doFollowDao(userName, focusStatus).then((res) {
132153
Navigator.pop(context);

lib/widget/ReposHeaderItem.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ class ReposHeaderItem extends StatelessWidget {
7373
new RawMaterialButton(
7474
constraints: new BoxConstraints(minWidth: 0.0, minHeight: 0.0),
7575
padding: new EdgeInsets.all(0.0),
76-
onPressed: () {},
76+
onPressed: () {
77+
NavigatorUtils.goPerson(context, reposHeaderViewModel.ownerName);
78+
},
7779
child: new Text(reposHeaderViewModel.ownerName, style: GSYConstant.normalTextMitWhiteBold),
7880
),
7981
new Text(" /", style: GSYConstant.normalTextMitWhiteBold),

lib/widget/ReposItem.dart

Lines changed: 17 additions & 10 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/style/GSYStyle.dart';
3+
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
34
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
45
import 'package:gsy_github_app_flutter/widget/GSYIConText.dart';
56

@@ -45,16 +46,22 @@ class ReposItem extends StatelessWidget {
4546
new Row(
4647
crossAxisAlignment: CrossAxisAlignment.start,
4748
children: <Widget>[
48-
new ClipOval(
49-
child: new FadeInImage.assetNetwork(
50-
placeholder: "static/images/logo.png",
51-
//预览图
52-
fit: BoxFit.fitWidth,
53-
image: reposViewModel.ownerPic,
54-
width: 40.0,
55-
height: 40.0,
56-
),
57-
),
49+
new RawMaterialButton(
50+
constraints: new BoxConstraints(minWidth: 0.0, minHeight: 0.0),
51+
padding: new EdgeInsets.all(0.0),
52+
onPressed: () {
53+
NavigatorUtils.goPerson(context, reposViewModel.ownerName);
54+
},
55+
child: new ClipOval(
56+
child: new FadeInImage.assetNetwork(
57+
placeholder: "static/images/logo.png",
58+
//预览图
59+
fit: BoxFit.fitWidth,
60+
image: reposViewModel.ownerPic,
61+
width: 40.0,
62+
height: 40.0,
63+
),
64+
)),
5865
new Padding(padding: EdgeInsets.all(10.0)),
5966
new Expanded(
6067
child: new Column(

lib/widget/UserHeader.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class UserHeaderItem extends StatelessWidget {
179179
)),
180180
new Container(
181181
child: new Text(
182-
GSYStrings.user_dynamic_title,
182+
(userInfo.type == "Organization") ? GSYStrings.user_dynamic_group : GSYStrings.user_dynamic_title,
183183
style: GSYConstant.normalTextBold,
184184
overflow: TextOverflow.ellipsis,
185185
),

0 commit comments

Comments
 (0)
X Tutup