Skip to content

Commit c7e7c4d

Browse files
committed
issuedetail
1 parent b04ce90 commit c7e7c4d

8 files changed

Lines changed: 314 additions & 16 deletions

File tree

‎lib/common/dao/IssueDao.dart‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:gsy_github_app_flutter/common/dao/DaoResult.dart';
22
import 'package:gsy_github_app_flutter/common/net/Address.dart';
33
import 'package:gsy_github_app_flutter/common/net/Api.dart';
4+
import 'package:gsy_github_app_flutter/widget/IssueHeaderItem.dart';
45
import 'package:gsy_github_app_flutter/widget/IssueItem.dart';
56

67
/**
@@ -68,4 +69,40 @@ class IssueDao {
6869
return new DataResult(null, false);
6970
}
7071
}
72+
73+
/**
74+
* issue的详请
75+
*/
76+
static getIssueInfoDao(userName, repository, number) async {
77+
String url = Address.getIssueInfo(userName, repository, number);
78+
//{"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}
79+
var res = await HttpManager.netFetch(url, null, null, null);
80+
if (res != null && res.result) {
81+
return new DataResult(IssueHeaderViewModel.fromMap(res.data), true);
82+
} else {
83+
return new DataResult(null, false);
84+
}
85+
}
86+
87+
/**
88+
* issue的详请列表
89+
*/
90+
static getIssueCommentDao(userName, repository, number, {page: 0}) async {
91+
String url = Address.getIssueComment(userName, repository, number) + Address.getPageParams("?", page);
92+
//{"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}
93+
var res = await HttpManager.netFetch(url, null, null, null);
94+
if (res != null && res.result) {
95+
List<IssueItemViewModel> list = new List();
96+
var data = res.data;
97+
if (data == null || data.length == 0) {
98+
return new DataResult(null, false);
99+
}
100+
for (int i = 0; i < data.length; i++) {
101+
list.add(IssueItemViewModel.fromMap(data[i], needTitle: false));
102+
}
103+
return new DataResult(list, true);
104+
} else {
105+
return new DataResult(null, false);
106+
}
107+
}
71108
}

‎lib/common/utils/EventUtils.dart‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ class EventUtils {
4141
actionStr = event["payload"]["action"] + " repository from an installation ";
4242
break;
4343
case "IssueCommentEvent":
44-
actionStr =
45-
event["payload"]["action"] + " comment on issue " + event["payload"]["issue"]["number"].toString() + " in " + event["repo"]["name"];
44+
actionStr = event["payload"]["action"] + " comment on issue " + event["payload"]["issue"]["number"].toString() + " in " + event["repo"]["name"];
4645
des = event["payload"]["comment"]["body"];
4746
break;
4847
case "IssuesEvent":
49-
actionStr =
50-
event["payload"]["action"] + " issue " + event["payload"]["issue"]["number"].toString().toString() + " in " + event["repo"]["name"];
48+
actionStr = event["payload"]["action"] + " issue " + event["payload"]["issue"]["number"].toString().toString() + " in " + event["repo"]["name"];
5149
des = event["payload"]["issue"]["title"];
5250
break;
5351

@@ -173,6 +171,7 @@ class EventUtils {
173171
});
174172
}
175173
});*/
174+
NavigatorUtils.goIssueDetail(context, owner, repositoryName, event["payload"]["issue"]["number"].toString());
176175
break;
177176
default:
178177
if (fullName.toLowerCase() == currentRepository.toLowerCase()) {

‎lib/common/utils/NavigatorUtils.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/page/HomePage.dart';
3+
import 'package:gsy_github_app_flutter/page/IssueDetailPage.dart';
34
import 'package:gsy_github_app_flutter/page/LoginPage.dart';
45
import 'package:gsy_github_app_flutter/page/PersonPage.dart';
56
import 'package:gsy_github_app_flutter/page/RepositoryDetailPage.dart';
@@ -39,4 +40,9 @@ class NavigatorUtils {
3940
static goReposDetail(BuildContext context, String userName, String reposName) {
4041
Navigator.push(context, new MaterialPageRoute(builder: (context) => new RepositoryDetailPage(userName, reposName)));
4142
}
43+
44+
///issue详情
45+
static goIssueDetail(BuildContext context, String userName, String reposName, String num) {
46+
Navigator.push(context, new MaterialPageRoute(builder: (context) => new IssueDetailPage(userName, reposName, num)));
47+
}
4248
}

‎lib/page/IssueDetailPage.dart‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:gsy_github_app_flutter/common/dao/IssueDao.dart';
3+
import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
4+
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
5+
import 'package:gsy_github_app_flutter/widget/IssueHeaderItem.dart';
6+
import 'package:gsy_github_app_flutter/widget/IssueItem.dart';
7+
8+
/**
9+
* Created by guoshuyu
10+
* on 2018/7/21.
11+
*/
12+
13+
class IssueDetailPage extends StatefulWidget {
14+
final String userName;
15+
16+
final String reposName;
17+
18+
final String issueNum;
19+
20+
IssueDetailPage(this.userName, this.reposName, this.issueNum);
21+
22+
@override
23+
_IssueDetailPageState createState() => _IssueDetailPageState(issueNum, userName, reposName);
24+
}
25+
26+
// ignore: mixin_inherits_from_not_object
27+
class _IssueDetailPageState extends GSYListState<IssueDetailPage> {
28+
final String userName;
29+
30+
final String reposName;
31+
32+
final String issueNum;
33+
34+
int selectIndex = 0;
35+
36+
IssueHeaderViewModel issueHeaderViewModel = new IssueHeaderViewModel();
37+
38+
_IssueDetailPageState(this.issueNum, this.userName, this.reposName);
39+
40+
_renderEventItem(index) {
41+
if (index == 0) {
42+
return new IssueHeaderItem(issueHeaderViewModel, onPressed: () {});
43+
}
44+
IssueItemViewModel issueItemViewModel = pullLoadWidgetControl.dataList[index - 1];
45+
return new IssueItem(
46+
issueItemViewModel,
47+
hideBottom: true,
48+
limitComment: false,
49+
onPressed: () {},
50+
);
51+
}
52+
53+
_getDataLogic() async {
54+
if (page <= 1) {
55+
var res = await IssueDao.getIssueInfoDao(userName, reposName, issueNum);
56+
if (res != null && res.result) {
57+
setState(() {
58+
issueHeaderViewModel = res.data;
59+
});
60+
}
61+
}
62+
return await IssueDao.getIssueCommentDao(userName, reposName, issueNum, page: page);
63+
}
64+
65+
@override
66+
bool get wantKeepAlive => true;
67+
68+
@override
69+
requestRefresh() async {
70+
return await _getDataLogic();
71+
}
72+
73+
@override
74+
requestLoadMore() async {
75+
return await _getDataLogic();
76+
}
77+
78+
@override
79+
bool get isRefreshFirst => true;
80+
81+
@override
82+
bool get needHeader => true;
83+
84+
@override
85+
Widget build(BuildContext context) {
86+
super.build(context); // See AutomaticKeepAliveClientMixin.
87+
return new Scaffold(
88+
appBar: new AppBar(
89+
title: new Text(
90+
reposName,
91+
maxLines: 1,
92+
overflow: TextOverflow.ellipsis,
93+
)),
94+
body: GSYPullLoadWidget(
95+
pullLoadWidgetControl,
96+
(BuildContext context, int index) => _renderEventItem(index),
97+
handleRefresh,
98+
onLoadMore,
99+
refreshKey: refreshIndicatorKey,
100+
),
101+
);
102+
}
103+
}

‎lib/page/LoginPage.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:gsy_github_app_flutter/common/config/Config.dart';
33
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
44
import 'package:gsy_github_app_flutter/common/local/LocalStorage.dart';
55
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
6+
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
67
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
78
import 'package:gsy_github_app_flutter/widget/GSYFlexButton.dart';
89
import 'package:gsy_github_app_flutter/widget/GSYInputWidget.dart';
@@ -97,10 +98,11 @@ class _LoginPageState extends State<LoginPage> {
9798
if (_password == null || _password.length == 0) {
9899
return;
99100
}
101+
CommonUtils.showLoadingDialog(context);
100102
UserDao.login(_userName, _password, (data) {
103+
Navigator.pop(context);
101104
if (data != null && data.result == true) {
102105
NavigatorUtils.goHome(context);
103-
//Fluttertoast.showToast(msg: GSYStrings.login_success);
104106
}
105107
});
106108
},

‎lib/page/RepositoryDetailIssueListPage.dart‎

Lines changed: 4 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/IssueDao.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/GSYListState.dart';
56
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
67
import 'package:gsy_github_app_flutter/widget/GSYSearchInputWidget.dart';
@@ -39,7 +40,9 @@ class _RepositoryDetailIssuePageState extends GSYListState<RepositoryDetailIssue
3940
IssueItemViewModel issueItemViewModel = pullLoadWidgetControl.dataList[index];
4041
return new IssueItem(
4142
issueItemViewModel,
42-
onPressed: () {},
43+
onPressed: () {
44+
NavigatorUtils.goIssueDetail(context, userName, reposName, issueItemViewModel.number);
45+
},
4346
);
4447
}
4548

‎lib/widget/IssueHeaderItem.dart‎

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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 详情头
10+
* Created by guoshuyu
11+
* on 2018/7/21.
12+
*/
13+
14+
class IssueHeaderItem extends StatelessWidget {
15+
final IssueHeaderViewModel issueHeaderViewModel;
16+
17+
final VoidCallback onPressed;
18+
19+
IssueHeaderItem(this.issueHeaderViewModel, {this.onPressed});
20+
21+
@override
22+
Widget build(BuildContext context) {
23+
Color issueStateColor = issueHeaderViewModel.state == "open" ? Colors.green : Colors.red;
24+
Widget bottomContainer = new Row(
25+
children: <Widget>[
26+
new GSYIConText(
27+
GSYICons.ISSUE_ITEM_ISSUE,
28+
issueHeaderViewModel.state,
29+
TextStyle(
30+
color: issueStateColor,
31+
fontSize: GSYConstant.smallTextSize,
32+
),
33+
issueStateColor,
34+
15.0,
35+
padding: 2.0,
36+
),
37+
new Padding(padding: new EdgeInsets.all(2.0)),
38+
new Text(issueHeaderViewModel.issueTag, style: GSYConstant.smallTextWhite),
39+
new Padding(padding: new EdgeInsets.all(2.0)),
40+
new GSYIConText(
41+
GSYICons.ISSUE_ITEM_COMMENT,
42+
issueHeaderViewModel.commentCount,
43+
GSYConstant.smallTextWhite,
44+
Color(GSYColors.white),
45+
15.0,
46+
padding: 2.0,
47+
),
48+
],
49+
);
50+
return new GSYCardItem(
51+
color: Color(GSYColors.primaryValue),
52+
child: new FlatButton(
53+
padding: new EdgeInsets.all(0.0),
54+
onPressed: onPressed,
55+
child: new Padding(
56+
padding: new EdgeInsets.all(10.0),
57+
child: new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
58+
new IconButton(
59+
icon: new ClipOval(
60+
child: new FadeInImage.assetNetwork(
61+
placeholder: "static/images/logo.png",
62+
//预览图
63+
fit: BoxFit.fitWidth,
64+
image: issueHeaderViewModel.actionUserPic,
65+
width: 80.0,
66+
height: 80.0,
67+
),
68+
),
69+
onPressed: () {
70+
NavigatorUtils.goPerson(context, issueHeaderViewModel.actionUser);
71+
}),
72+
new Expanded(
73+
child: Column(
74+
mainAxisSize: MainAxisSize.min,
75+
children: <Widget>[
76+
new Row(
77+
children: <Widget>[
78+
new Expanded(child: new Text(issueHeaderViewModel.actionUser, style: GSYConstant.normalTextWhite)),
79+
new Text(
80+
issueHeaderViewModel.actionTime,
81+
style: GSYConstant.subSmallText,
82+
maxLines: 2,
83+
overflow: TextOverflow.ellipsis,
84+
),
85+
],
86+
),
87+
new Padding(padding: new EdgeInsets.all(2.0)),
88+
bottomContainer,
89+
new Container(
90+
child: new Text(
91+
issueHeaderViewModel.issueComment,
92+
style: GSYConstant.smallTextWhite,
93+
maxLines: 2,
94+
),
95+
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
96+
alignment: Alignment.topLeft),
97+
new Padding(
98+
padding: new EdgeInsets.only(left: 0.0, top: 2.0, right: 0.0, bottom: 0.0),
99+
),
100+
],
101+
),
102+
),
103+
]),
104+
),
105+
),
106+
);
107+
}
108+
}
109+
110+
class IssueHeaderViewModel {
111+
String actionTime = "---";
112+
String actionUser = "---";
113+
String actionUserPic = "---";
114+
String closed_by = "---";
115+
bool locked = false;
116+
String issueComment = "---";
117+
String issueDesHtml = "---";
118+
String commentCount = "---";
119+
String state = "---";
120+
String issueDes = "---";
121+
String issueTag = "---";
122+
123+
IssueHeaderViewModel();
124+
125+
IssueHeaderViewModel.fromMap(issueMap) {
126+
actionTime = CommonUtils.getNewsTimeStr(DateTime.parse(issueMap["created_at"]));
127+
actionUser = issueMap["user"]["login"];
128+
actionUserPic = issueMap["user"]["avatar_url"];
129+
closed_by = issueMap["closed_by"] != null ? issueMap["closed_by"]["login"] : "";
130+
locked = issueMap["locked"];
131+
issueComment = issueMap["title"];
132+
issueDesHtml = issueMap["body_html"] != null ? issueMap["body_html"] : "";
133+
commentCount = issueMap["comments"].toString() + "";
134+
state = issueMap["state"];
135+
issueDes = issueMap["body"] != null ? ": \n" + issueMap["body"] : '';
136+
issueTag = "#" + issueMap["number"].toString();
137+
}
138+
}

0 commit comments

Comments
 (0)