Skip to content

Commit 2ca3ae3

Browse files
committed
add issueList
1 parent 345a4f8 commit 2ca3ae3

6 files changed

Lines changed: 351 additions & 1 deletion

File tree

‎lib/common/dao/IssueDao.dart‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'package:gsy_github_app_flutter/common/dao/DaoResult.dart';
2+
import 'package:gsy_github_app_flutter/common/net/Address.dart';
3+
import 'package:gsy_github_app_flutter/common/net/Api.dart';
4+
import 'package:gsy_github_app_flutter/widget/IssueItem.dart';
5+
6+
/**
7+
* Created by guoshuyu
8+
* Date: 2018-07-19
9+
*/
10+
11+
class IssueDao {
12+
/**
13+
* 获取仓库issue
14+
* @param page
15+
* @param userName
16+
* @param repository
17+
* @param state issue状态
18+
* @param sort 排序类型 created updated等
19+
* @param direction 正序或者倒序
20+
*/
21+
static getRepositoryIssueDao(userName, repository, state, {sort, direction, page = 0}) async {
22+
String url = Address.getReposIssue(userName, repository, state, sort, direction) + Address.getPageParams("&", page);
23+
var res = await HttpManager.netFetch(url, null, {"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}, null);
24+
if (res != null && res.result) {
25+
List<IssueItemViewModel> list = new List();
26+
var data = res.data;
27+
if (data == null || data.length == 0) {
28+
return new DataResult(null, false);
29+
}
30+
for (int i = 0; i < data.length; i++) {
31+
list.add(IssueItemViewModel.fromMap(data[i]));
32+
}
33+
return new DataResult(list, true);
34+
} else {
35+
return new DataResult(null, false);
36+
}
37+
}
38+
}

‎lib/common/style/GSYStyle.dart‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class GSYStrings {
221221
static const String repos_tab_info = "动态";
222222
static const String repos_tab_file = "文件";
223223
static const String repos_tab_issue = "ISSUE";
224+
static const String repos_issue_search = "搜索";
224225
}
225226

226227
class GSYICons {
@@ -243,4 +244,7 @@ class GSYICons {
243244
static IconData USER_ITEM_COMPANY = new IconData(0xe63e, fontFamily: GSYICons.FONT_FAMILY);
244245
static IconData USER_ITEM_LOCATION = new IconData(0xe7e6, fontFamily: GSYICons.FONT_FAMILY);
245246
static IconData USER_ITEM_LINK = new IconData(0xe670, fontFamily: GSYICons.FONT_FAMILY);
247+
248+
static IconData ISSUE_ITEM_ISSUE = new IconData(0xe661, fontFamily: GSYICons.FONT_FAMILY);
249+
static IconData ISSUE_ITEM_COMMENT = new IconData(0xe6ba, fontFamily: GSYICons.FONT_FAMILY);
246250
}

‎lib/common/utils/CommonUtils.dart‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,18 @@ class CommonUtils {
3636
return getDateStr(date);
3737
}
3838
}
39+
40+
static getFullName(String repository_url) {
41+
if (repository_url != null && repository_url.substring(repository_url.length - 1) == "/") {
42+
repository_url = repository_url.substring(0, repository_url.length - 1);
43+
}
44+
String fullName = '';
45+
if (repository_url != null) {
46+
List<String> splicurl = repository_url.split("/");
47+
if (splicurl.length > 2) {
48+
fullName = splicurl[splicurl.length - 2] + "/" + splicurl[splicurl.length - 1];
49+
}
50+
}
51+
return fullName;
52+
}
3953
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
import 'dart:async';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:gsy_github_app_flutter/common/config/Config.dart';
5+
import 'package:gsy_github_app_flutter/common/dao/IssueDao.dart';
6+
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
7+
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
8+
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
9+
import 'package:gsy_github_app_flutter/widget/IssueItem.dart';
10+
11+
/**
12+
* 仓库详情issue列表
13+
* Created by guoshuyu
14+
* Date: 2018-07-19
15+
*/
16+
class RepositoryDetailIssuePage extends StatefulWidget {
17+
final String userName;
18+
19+
final String reposName;
20+
21+
RepositoryDetailIssuePage(this.userName, this.reposName);
22+
23+
@override
24+
_RepositoryDetailIssuePageState createState() => _RepositoryDetailIssuePageState(userName, reposName);
25+
}
26+
27+
// ignore: mixin_inherits_from_not_object
28+
class _RepositoryDetailIssuePageState extends State<RepositoryDetailIssuePage> with AutomaticKeepAliveClientMixin {
29+
final String userName;
30+
31+
final String reposName;
32+
33+
String issueState;
34+
35+
bool isLoading = false;
36+
37+
int page = 1;
38+
39+
final List dataList = new List();
40+
41+
final GSYPullLoadWidgetControl pullLoadWidgetControl = new GSYPullLoadWidgetControl();
42+
43+
_RepositoryDetailIssuePageState(this.userName, this.reposName);
44+
45+
Future<Null> _handleRefresh() async {
46+
if (isLoading) {
47+
return null;
48+
}
49+
isLoading = true;
50+
page = 1;
51+
var res = await IssueDao.getRepositoryIssueDao(userName, reposName, issueState, page: page);
52+
if (res != null && res.result) {
53+
pullLoadWidgetControl.dataList.clear();
54+
setState(() {
55+
pullLoadWidgetControl.dataList.addAll(res.data);
56+
});
57+
}
58+
setState(() {
59+
pullLoadWidgetControl.needLoadMore = (res != null && res.data != null && res.data.length == Config.PAGE_SIZE);
60+
});
61+
isLoading = false;
62+
return null;
63+
}
64+
65+
Future<Null> _onLoadMore() async {
66+
if (isLoading) {
67+
return null;
68+
}
69+
isLoading = true;
70+
page++;
71+
var res = await IssueDao.getRepositoryIssueDao(userName, reposName, issueState, page: page);
72+
if (res != null && res.result) {
73+
setState(() {
74+
pullLoadWidgetControl.dataList.addAll(res.data);
75+
});
76+
}
77+
setState(() {
78+
pullLoadWidgetControl.needLoadMore = (res != null && res.data != null && res.data.length == Config.PAGE_SIZE);
79+
});
80+
isLoading = false;
81+
return null;
82+
}
83+
84+
_renderEventItem(index) {
85+
IssueItemViewModel issueItemViewModel = pullLoadWidgetControl.dataList[index];
86+
return new IssueItem(
87+
issueItemViewModel,
88+
onPressed: () {},
89+
);
90+
}
91+
92+
@override
93+
bool get wantKeepAlive => true;
94+
95+
@override
96+
void initState() {
97+
super.initState();
98+
pullLoadWidgetControl.needHeader = false;
99+
pullLoadWidgetControl.dataList = dataList;
100+
if (pullLoadWidgetControl.dataList.length == 0) {
101+
_handleRefresh();
102+
}
103+
}
104+
105+
@override
106+
void didChangeDependencies() {
107+
super.didChangeDependencies();
108+
}
109+
110+
@override
111+
Widget build(BuildContext context) {
112+
super.build(context); // See AutomaticKeepAliveClientMixin.
113+
return new Scaffold(
114+
appBar: new AppBar(
115+
backgroundColor: Colors.white,
116+
leading: new Column(
117+
children: <Widget>[
118+
new Container(
119+
child: new TextField(
120+
autofocus: true,
121+
decoration: new InputDecoration.collapsed(
122+
hintText: GSYStrings.repos_issue_search,
123+
hintStyle: GSYConstant.subSmallText,
124+
),
125+
style: GSYConstant.smallText,
126+
onSubmitted: (result) {}),
127+
),
128+
new GSYCardItem(
129+
color: Color(GSYColors.primaryValue),
130+
margin: EdgeInsets.all(10.0),
131+
shape: new RoundedRectangleBorder(
132+
borderRadius: BorderRadius.all(Radius.circular(4.0)),
133+
),
134+
child: new Padding(
135+
padding: new EdgeInsets.only(left: 10.0, top: 5.0, right: 10.0, bottom: 5.0),
136+
child: new Row(
137+
children: <Widget>[
138+
new Expanded(
139+
child: new Text(
140+
"Ffff",
141+
style: GSYConstant.middleTextWhite,
142+
)),
143+
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
144+
new Expanded(
145+
child: new Text(
146+
"Ffff",
147+
style: GSYConstant.middleTextWhite,
148+
)),
149+
new Container(width: 0.3, height: 40.0, color: Color(GSYColors.subLightTextColor)),
150+
new Expanded(
151+
child: new Text(
152+
"Ffff",
153+
style: GSYConstant.middleTextWhite,
154+
)),
155+
],
156+
)))
157+
],
158+
),
159+
),
160+
body: GSYPullLoadWidget(pullLoadWidgetControl, (BuildContext context, int index) => _renderEventItem(index), _handleRefresh, _onLoadMore),
161+
);
162+
}
163+
}

‎lib/page/RepositoryDetailPage.dart‎

Lines changed: 2 additions & 1 deletion
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/dao/ReposDao.dart';
33
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
4+
import 'package:gsy_github_app_flutter/page/RepositoryDetailIssueList.dart';
45
import 'package:gsy_github_app_flutter/page/RepositoryDetailReadmePage.dart';
56
import 'package:gsy_github_app_flutter/page/RepostoryDetailInfoPage.dart';
67
import 'package:gsy_github_app_flutter/widget/GSYIConText.dart';
@@ -139,7 +140,7 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
139140
new RepositoryDetailReadmePage(),
140141
new ReposDetailInfoPage(reposDetailInfoPageControl, userName, reposName),
141142
new Icon(GSYICons.MAIN_DT),
142-
new Icon(GSYICons.MAIN_DT),
143+
new RepositoryDetailIssuePage(userName, reposName)
143144
],
144145
backgroundColor: GSYColors.primarySwatch,
145146
indicatorColor: Colors.white,

‎lib/widget/IssueItem.dart‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
3+
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
4+
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
5+
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
6+
import 'package:gsy_github_app_flutter/widget/GSYIConText.dart';
7+
8+
/**
9+
* Issue相关item
10+
* Created by guoshuyu
11+
* Date: 2018-07-19
12+
*/
13+
class IssueItem extends StatelessWidget {
14+
final IssueItemViewModel issueItemViewModel;
15+
16+
final VoidCallback onPressed;
17+
18+
final bool needBottom;
19+
20+
IssueItem(this.issueItemViewModel, {this.onPressed, this.needBottom = false});
21+
22+
@override
23+
Widget build(BuildContext context) {
24+
Widget bottomContainer = (needBottom)
25+
? new Container()
26+
: new Row(
27+
children: <Widget>[
28+
new GSYIConText(
29+
GSYICons.ISSUE_ITEM_ISSUE,
30+
issueItemViewModel.state,
31+
GSYConstant.subSmallText,
32+
issueItemViewModel.state == "open" ? Colors.green : Colors.red,
33+
15.0,
34+
padding: 2.0,
35+
),
36+
new Padding(padding: new EdgeInsets.all(2.0)),
37+
new Expanded(
38+
child: new Text(issueItemViewModel.issueTag, style: GSYConstant.subSmallText),
39+
),
40+
new GSYIConText(
41+
GSYICons.ISSUE_ITEM_COMMENT,
42+
issueItemViewModel.commentCount,
43+
GSYConstant.subSmallText,
44+
Color(GSYColors.subTextColor),
45+
15.0,
46+
padding: 2.0,
47+
),
48+
],
49+
);
50+
return new GSYCardItem(
51+
child: new FlatButton(
52+
padding: new EdgeInsets.all(0.0),
53+
onPressed: onPressed,
54+
child: new Padding(
55+
padding: new EdgeInsets.only(left: 5.0, top: 5.0, right: 10.0, bottom: 8.0),
56+
child: new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
57+
new IconButton(
58+
icon: new ClipOval(
59+
child: new FadeInImage.assetNetwork(
60+
placeholder: "static/images/logo.png",
61+
//预览图
62+
fit: BoxFit.fitWidth,
63+
image: issueItemViewModel.actionUserPic,
64+
width: 30.0,
65+
height: 30.0,
66+
),
67+
),
68+
onPressed: () {}),
69+
new Expanded(
70+
child: Column(
71+
mainAxisSize: MainAxisSize.min,
72+
children: <Widget>[
73+
new Row(
74+
children: <Widget>[
75+
new Expanded(child: new Text(issueItemViewModel.actionUser, style: GSYConstant.smallTextBold)),
76+
new Text(
77+
issueItemViewModel.actionTime,
78+
style: GSYConstant.subSmallText,
79+
maxLines: 2,
80+
overflow: TextOverflow.ellipsis,
81+
),
82+
],
83+
),
84+
new Padding(
85+
padding: new EdgeInsets.only(left: 0.0, top: 2.0, right: 0.0, bottom: 0.0),
86+
),
87+
new Container(
88+
child: new Text(
89+
issueItemViewModel.issueComment,
90+
style: GSYConstant.smallTextBold,
91+
maxLines: 2,
92+
),
93+
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
94+
alignment: Alignment.topLeft),
95+
new Padding(
96+
padding: new EdgeInsets.only(left: 0.0, top: 2.0, right: 0.0, bottom: 0.0),
97+
),
98+
bottomContainer,
99+
],
100+
),
101+
),
102+
]),
103+
),
104+
),
105+
);
106+
}
107+
}
108+
109+
class IssueItemViewModel {
110+
String actionTime = "---";
111+
String actionUser = "---";
112+
String actionUserPic = "---";
113+
String issueComment = "---";
114+
String commentCount = "---";
115+
String state = "---";
116+
String issueTag = "---";
117+
118+
IssueItemViewModel();
119+
120+
IssueItemViewModel.fromMap(issueMap) {
121+
String fullName = CommonUtils.getFullName(issueMap["repository_url"]);
122+
actionTime = CommonUtils.getNewsTimeStr(DateTime.parse(issueMap["created_at"]));
123+
actionUser = issueMap["user"]["login"];
124+
actionUserPic = issueMap["user"]["avatar_url"];
125+
issueComment = fullName + "- " + issueMap["title"];
126+
commentCount = issueMap["comments"].toString();
127+
state = issueMap["state"];
128+
issueTag = "#" + issueMap["number"].toString();
129+
}
130+
}

0 commit comments

Comments
 (0)