X Tutup
Skip to content

Commit 7145305

Browse files
committed
commonlist
1 parent ef42178 commit 7145305

File tree

5 files changed

+279
-9
lines changed

5 files changed

+279
-9
lines changed

lib/common/dao/ReposDao.dart

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,68 @@ class ReposDao {
179179
return new DataResult(null, res.result);
180180
}
181181

182+
/**
183+
* 获取当前仓库所有订阅用户
184+
*/
185+
static getRepositoryWatcherDao(userName, reposName, page) async {}
186+
187+
/**
188+
* 获取当前仓库所有star用户
189+
*/
190+
static getRepositoryStarDao(userName, reposName, page) async {}
191+
192+
/**
193+
* 获取仓库的fork分支
194+
*/
195+
static getRepositoryForksDao(userName, reposName, page) async {}
196+
197+
/**
198+
* 获取当前仓库所有star用户
199+
*/
200+
static getStarRepositoryDao(userName, page, sort) async {}
201+
202+
/**
203+
* 用户的仓库
204+
*/
205+
static getUserRepositoryDao(userName, page, sort) async {
206+
String url = Address.userRepos(userName, sort) + Address.getPageParams("&", page);
207+
var res = await HttpManager.netFetch(url, null, null, null);
208+
if (res != null && res.result && res.data.length > 0) {
209+
List<ReposViewModel> list = new List();
210+
var dataList = res.data;
211+
if (dataList == null || dataList.length == 0) {
212+
return new DataResult(null, false);
213+
}
214+
for (int i = 0; i < dataList.length; i++) {
215+
var data = dataList[i];
216+
ReposViewModel reposViewModel = new ReposViewModel();
217+
reposViewModel.ownerName = data["owner"]["login"];
218+
reposViewModel.ownerPic = data["owner"]["avatar_url"];
219+
reposViewModel.repositoryName = data["name"];
220+
reposViewModel.repositoryStar = data["watchers_count"].toString();
221+
reposViewModel.repositoryFork = data["forks_count"].toString();
222+
reposViewModel.repositoryWatch = data["open_issues"].toString();
223+
reposViewModel.repositoryType = data["language"] != null ? data["language"] : '---';
224+
reposViewModel.repositoryDes = data["description"] != null ? data["description"] : '---';
225+
list.add(reposViewModel);
226+
}
227+
return new DataResult(list, true);
228+
} else {
229+
return new DataResult(null, false);
230+
}
231+
}
232+
182233
/**
183234
* 创建仓库的fork分支
184235
*/
185236
static createForkDao(userName, reposName) async {
186237
String url = Address.createFork(userName, reposName);
187-
var res = await HttpManager.netFetch(url, null, null, new Options(method: "POST"));
238+
var res = await HttpManager.netFetch(url, null, null, new Options(method: "POST", contentType: ContentType.TEXT));
188239
return new DataResult(null, res.result);
189240
}
241+
242+
/**
243+
* 获取当前仓库所有分支
244+
*/
245+
static getBranchesDao(userName, reposName) async {}
190246
}

lib/common/utils/NavigatorUtils.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:gsy_github_app_flutter/page/CommonListPage.dart';
23
import 'package:gsy_github_app_flutter/page/HomePage.dart';
34
import 'package:gsy_github_app_flutter/page/IssueDetailPage.dart';
45
import 'package:gsy_github_app_flutter/page/LoginPage.dart';
@@ -45,4 +46,18 @@ class NavigatorUtils {
4546
static goIssueDetail(BuildContext context, String userName, String reposName, String num) {
4647
Navigator.push(context, new MaterialPageRoute(builder: (context) => new IssueDetailPage(userName, reposName, num)));
4748
}
49+
50+
///通用列表
51+
static gotoCommonList(BuildContext context, String title, String showType, String dataType, {String userName, String reposName}) {
52+
Navigator.push(
53+
context,
54+
new MaterialPageRoute(
55+
builder: (context) => new CommonListPage(
56+
title,
57+
showType,
58+
dataType,
59+
userName: userName,
60+
reposName: reposName,
61+
)));
62+
}
4863
}

lib/page/CommonListPage.dart

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
3+
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
4+
import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
5+
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
6+
import 'package:gsy_github_app_flutter/widget/ReposItem.dart';
7+
8+
/**
9+
* 通用list
10+
* Created by guoshuyu
11+
* on 2018/7/22.
12+
*/
13+
14+
class CommonListPage extends StatefulWidget {
15+
final String userName;
16+
17+
final String reposName;
18+
19+
final String showType;
20+
21+
final String dataType;
22+
23+
final String title;
24+
25+
CommonListPage(this.title, this.showType, this.dataType, {this.userName, this.reposName});
26+
27+
@override
28+
_CommonListPageState createState() => _CommonListPageState(this.title, this.showType, this.dataType, this.userName, this.reposName);
29+
}
30+
31+
// ignore: mixin_inherits_from_not_object
32+
class _CommonListPageState extends GSYListState<CommonListPage> {
33+
final String userName;
34+
35+
final String reposName;
36+
37+
final String title;
38+
39+
final String showType;
40+
41+
final String dataType;
42+
43+
_CommonListPageState(this.title, this.showType, this.dataType, this.userName, this.reposName);
44+
45+
_renderItem(index) {
46+
var data = pullLoadWidgetControl.dataList[index];
47+
switch (showType) {
48+
case 'repository':
49+
return new ReposItem(data, onPressed: () {
50+
NavigatorUtils.goReposDetail(context, data.ownerName, data.repositoryName);
51+
});
52+
case 'user':
53+
return null;
54+
case 'org':
55+
return null;
56+
case 'issue':
57+
return null;
58+
case 'release':
59+
return null;
60+
case 'notify':
61+
return null;
62+
}
63+
}
64+
65+
_getDataLogic() async {
66+
switch (dataType) {
67+
case 'follower':
68+
return null;
69+
case 'followed':
70+
return null;
71+
case 'user_repos':
72+
return await ReposDao.getUserRepositoryDao(userName, page, null);
73+
case 'user_star':
74+
return null;
75+
case 'repo_star':
76+
return null;
77+
case 'repo_watcher':
78+
return null;
79+
case 'repo_fork':
80+
return null;
81+
case 'repo_release':
82+
return null;
83+
case 'repo_tag':
84+
return null;
85+
case 'notify':
86+
return null;
87+
case 'history':
88+
return null;
89+
case 'topics':
90+
return null;
91+
case 'user_be_stared':
92+
return null;
93+
case 'user_orgs':
94+
return null;
95+
}
96+
}
97+
98+
@override
99+
bool get wantKeepAlive => true;
100+
101+
@override
102+
requestRefresh() async {
103+
return await _getDataLogic();
104+
}
105+
106+
@override
107+
requestLoadMore() async {
108+
return await _getDataLogic();
109+
}
110+
111+
@override
112+
bool get isRefreshFirst => true;
113+
114+
@override
115+
bool get needHeader => true;
116+
117+
@override
118+
Widget build(BuildContext context) {
119+
super.build(context); // See AutomaticKeepAliveClientMixin.
120+
return new Scaffold(
121+
appBar: new AppBar(
122+
title: new Text(
123+
title,
124+
maxLines: 1,
125+
overflow: TextOverflow.ellipsis,
126+
)),
127+
body: GSYPullLoadWidget(
128+
pullLoadWidgetControl,
129+
(BuildContext context, int index) => _renderItem(index),
130+
handleRefresh,
131+
onLoadMore,
132+
refreshKey: refreshIndicatorKey,
133+
),
134+
);
135+
}
136+
}

lib/page/RepositoryDetailIssueListPage.dart

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'package:flutter/material.dart';
2+
import 'package:fluttertoast/fluttertoast.dart';
23
import 'package:gsy_github_app_flutter/common/dao/IssueDao.dart';
34
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
5+
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
46
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
57
import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
68
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
@@ -69,6 +71,39 @@ class _RepositoryDetailIssuePageState extends GSYListState<RepositoryDetailIssue
6971
return await IssueDao.searchRepositoryIssue(searchString, userName, reposName, this.issueState, page: this.page);
7072
}
7173

74+
_createIssue() {
75+
String title = "";
76+
String content = "";
77+
CommonUtils.showEditDialog(
78+
context,
79+
GSYStrings.issue_edit_issue,
80+
(titleValue) {
81+
title = titleValue;
82+
},
83+
(contentValue) {
84+
content = contentValue;
85+
},
86+
() {
87+
if (title == null || title.trim().length == 0) {
88+
Fluttertoast.showToast(msg: GSYStrings.issue_edit_issue_title_not_be_null);
89+
return;
90+
}
91+
if (content == null || content.trim().length == 0) {
92+
Fluttertoast.showToast(msg: GSYStrings.issue_edit_issue_content_not_be_null);
93+
return;
94+
}
95+
CommonUtils.showLoadingDialog(context);
96+
//提交修改
97+
IssueDao.createIssueDao(userName, reposName, {"title": title, "body": content}).then((result) {
98+
showRefreshLoading();
99+
Navigator.pop(context);
100+
Navigator.pop(context);
101+
});
102+
},
103+
needTitle: true,
104+
);
105+
}
106+
72107
@override
73108
bool get wantKeepAlive => true;
74109

@@ -98,7 +133,9 @@ class _RepositoryDetailIssuePageState extends GSYListState<RepositoryDetailIssue
98133
size: 55.0,
99134
color: Color(GSYColors.textWhite),
100135
),
101-
onPressed: () {}),
136+
onPressed: () {
137+
_createIssue();
138+
}),
102139
backgroundColor: Color(GSYColors.mainBackgroundColor),
103140
appBar: new AppBar(
104141
leading: new Container(),

lib/widget/UserHeader.dart

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:gsy_github_app_flutter/common/model/User.dart';
33
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
4+
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
45
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
56
import 'package:gsy_github_app_flutter/widget/GSYIConText.dart';
67

@@ -13,10 +14,13 @@ class UserHeaderItem extends StatelessWidget {
1314

1415
UserHeaderItem(this.userInfo);
1516

16-
_getBottomItem(String title, var value) {
17+
_getBottomItem(String title, var value, onPressed) {
1718
return new Expanded(
1819
child: new Center(
19-
child: new Text(title + "\n" + (value == null ? "" : value.toString()), textAlign: TextAlign.center, style: GSYConstant.subSmallText),
20+
child: new FlatButton(
21+
onPressed: onPressed,
22+
child: new Text(title + "\n" + (value == null ? "" : value.toString()), textAlign: TextAlign.center, style: GSYConstant.subSmallText),
23+
),
2024
),
2125
);
2226
}
@@ -101,15 +105,37 @@ class UserHeaderItem extends StatelessWidget {
101105
new Row(
102106
crossAxisAlignment: CrossAxisAlignment.start,
103107
children: <Widget>[
104-
_getBottomItem(GSYStrings.user_tab_repos, userInfo.public_repos),
108+
_getBottomItem(
109+
GSYStrings.user_tab_repos,
110+
userInfo.public_repos,
111+
() {
112+
NavigatorUtils.gotoCommonList(context, userInfo.login, "repository", "user_repos", userName: userInfo.login);
113+
},
114+
),
105115
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
106-
_getBottomItem(GSYStrings.user_tab_fans, userInfo.followers),
116+
_getBottomItem(
117+
GSYStrings.user_tab_fans,
118+
userInfo.followers,
119+
() {},
120+
),
107121
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
108-
_getBottomItem(GSYStrings.user_tab_focus, userInfo.following),
122+
_getBottomItem(
123+
GSYStrings.user_tab_focus,
124+
userInfo.following,
125+
() {},
126+
),
109127
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
110-
_getBottomItem(GSYStrings.user_tab_star, "---"),
128+
_getBottomItem(
129+
GSYStrings.user_tab_star,
130+
"---",
131+
() {},
132+
),
111133
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
112-
_getBottomItem(GSYStrings.user_tab_honor, "---"),
134+
_getBottomItem(
135+
GSYStrings.user_tab_honor,
136+
"---",
137+
() {},
138+
),
113139
],
114140
),
115141
],

0 commit comments

Comments
 (0)
X Tutup