X Tutup
Skip to content

Commit ff6520d

Browse files
committed
add notify
1 parent 6b86263 commit ff6520d

File tree

9 files changed

+175
-10
lines changed

9 files changed

+175
-10
lines changed

lib/common/dao/UserDao.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:gsy_github_app_flutter/common/model/User.dart';
99
import 'package:gsy_github_app_flutter/common/net/Address.dart';
1010
import 'package:gsy_github_app_flutter/common/net/Api.dart';
1111
import 'package:gsy_github_app_flutter/common/redux/UserRedux.dart';
12+
import 'package:gsy_github_app_flutter/widget/EventItem.dart';
1213
import 'package:gsy_github_app_flutter/widget/UserItem.dart';
1314
import 'package:redux/redux.dart';
1415

@@ -163,4 +164,26 @@ class UserDao {
163164
return new DataResult(null, false);
164165
}
165166
}
167+
168+
/**
169+
* 获取用户相关通知
170+
*/
171+
static getNotifyDao(bool all, bool participating, page) async {
172+
String tag = (!all && !participating) ? '?' : "&";
173+
String url = Address.getNotifation(all, participating) + Address.getPageParams(tag, page);
174+
var res = await HttpManager.netFetch(url, null, null, null);
175+
if (res != null && res.result) {
176+
List<EventViewModel> list = new List();
177+
var data = res.data;
178+
if (data == null || data.length == 0) {
179+
return new DataResult(null, false);
180+
}
181+
for (int i = 0; i < data.length; i++) {
182+
list.add(EventViewModel.fromNotify(data[i]));
183+
}
184+
return new DataResult(list, true);
185+
} else {
186+
return new DataResult(null, false);
187+
}
188+
}
166189
}

lib/common/style/GSYStyle.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,17 @@ class GSYStrings {
249249
static const String issue_edit_issue_title_not_be_null = "标题不能为空";
250250
static const String issue_edit_issue_title_tip = "请输入标题";
251251
static const String issue_edit_issue_content_tip = "请输入内容";
252+
253+
254+
static const String notify_title = "通知";
255+
static const String notify_tab_all = "所有";
256+
static const String notify_tab_part = "参与";
257+
static const String notify_tab_unread = "未读";
258+
static const String notify_unread = "未读";
259+
static const String notify_readed = "已读";
260+
static const String notify_status = "状态";
261+
static const String notify_type = "类型";
262+
252263
}
253264

254265
class GSYICons {
@@ -273,8 +284,10 @@ class GSYICons {
273284
static const IconData USER_ITEM_COMPANY = const IconData(0xe63e, fontFamily: GSYICons.FONT_FAMILY);
274285
static const IconData USER_ITEM_LOCATION = const IconData(0xe7e6, fontFamily: GSYICons.FONT_FAMILY);
275286
static const IconData USER_ITEM_LINK = const IconData(0xe670, fontFamily: GSYICons.FONT_FAMILY);
287+
static const IconData USER_NOTIFY = const IconData(0xe600, fontFamily: GSYICons.FONT_FAMILY);
276288

277289
static const IconData ISSUE_ITEM_ISSUE = const IconData(0xe661, fontFamily: GSYICons.FONT_FAMILY);
278290
static const IconData ISSUE_ITEM_COMMENT = const IconData(0xe6ba, fontFamily: GSYICons.FONT_FAMILY);
279291
static const IconData ISSUE_ITEM_ADD = const IconData(0xe662, fontFamily: GSYICons.FONT_FAMILY);
292+
280293
}

lib/common/utils/NavigatorUtils.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import 'dart:async';
2+
13
import 'package:flutter/material.dart';
24
import 'package:gsy_github_app_flutter/page/CodeDetailPage.dart';
35
import 'package:gsy_github_app_flutter/page/CommonListPage.dart';
46
import 'package:gsy_github_app_flutter/page/HomePage.dart';
57
import 'package:gsy_github_app_flutter/page/IssueDetailPage.dart';
68
import 'package:gsy_github_app_flutter/page/LoginPage.dart';
9+
import 'package:gsy_github_app_flutter/page/NotifyPage.dart';
710
import 'package:gsy_github_app_flutter/page/PersonPage.dart';
811
import 'package:gsy_github_app_flutter/page/RepositoryDetailPage.dart';
912

@@ -39,8 +42,8 @@ class NavigatorUtils {
3942
}
4043

4144
///仓库详情
42-
static goReposDetail(BuildContext context, String userName, String reposName) {
43-
Navigator.push(context, new MaterialPageRoute(builder: (context) => new RepositoryDetailPage(userName, reposName)));
45+
static Future<Null> goReposDetail(BuildContext context, String userName, String reposName) {
46+
return Navigator.push(context, new MaterialPageRoute(builder: (context) => new RepositoryDetailPage(userName, reposName)));
4447
}
4548

4649
///issue详情
@@ -76,4 +79,9 @@ class NavigatorUtils {
7679
branch: branch,
7780
)));
7881
}
82+
83+
///仓库详情通知
84+
static Future<Null> goNotifyPage(BuildContext context) {
85+
return Navigator.push(context, new MaterialPageRoute(builder: (context) => new NotifyPage()));
86+
}
7987
}

lib/page/NotifyPage.dart

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
3+
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
4+
import 'package:gsy_github_app_flutter/widget/EventItem.dart';
5+
import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
6+
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
7+
import 'package:gsy_github_app_flutter/widget/GSYSelectItemWidget.dart';
8+
9+
/**
10+
* Created by guoshuyu
11+
* Date: 2018-07-24
12+
*/
13+
14+
class NotifyPage extends StatefulWidget {
15+
NotifyPage();
16+
17+
@override
18+
_NotifyPageState createState() => _NotifyPageState();
19+
}
20+
21+
// ignore: mixin_inherits_from_not_object
22+
class _NotifyPageState extends GSYListState<NotifyPage> {
23+
int selectIndex;
24+
25+
_NotifyPageState();
26+
27+
_renderEventItem(index) {
28+
EventViewModel eventViewModel = pullLoadWidgetControl.dataList[index];
29+
return new EventItem(
30+
eventViewModel,
31+
onPressed: () {},
32+
);
33+
}
34+
35+
_resolveSelectIndex() {
36+
clearData();
37+
showRefreshLoading();
38+
}
39+
40+
_getDataLogic() async {
41+
return await UserDao.getNotifyDao(selectIndex == 2, selectIndex == 1, page);
42+
}
43+
44+
@override
45+
bool get wantKeepAlive => true;
46+
47+
@override
48+
bool get needHeader => false;
49+
50+
@override
51+
bool get isRefreshFirst => true;
52+
53+
@override
54+
requestLoadMore() async {
55+
return await _getDataLogic();
56+
}
57+
58+
@override
59+
requestRefresh() async {
60+
return await _getDataLogic();
61+
}
62+
63+
@override
64+
Widget build(BuildContext context) {
65+
super.build(context); // See AutomaticKeepAliveClientMixin.
66+
return new Scaffold(
67+
backgroundColor: Color(GSYColors.mainBackgroundColor),
68+
appBar: new AppBar(
69+
title: new Text(GSYStrings.notify_title),
70+
bottom: new GSYSelectItemWidget(
71+
[
72+
GSYStrings.notify_tab_unread,
73+
GSYStrings.notify_tab_part,
74+
GSYStrings.notify_tab_all,
75+
],
76+
(selectIndex) {
77+
this.selectIndex = selectIndex;
78+
_resolveSelectIndex();
79+
},
80+
elevation: 0.0,
81+
),
82+
elevation: 4.0,
83+
),
84+
body: GSYPullLoadWidget(
85+
pullLoadWidgetControl,
86+
(BuildContext context, int index) => _renderEventItem(index),
87+
handleRefresh,
88+
onLoadMore,
89+
refreshKey: refreshIndicatorKey,
90+
),
91+
);
92+
}
93+
}

lib/widget/EventItem.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class EventItem extends StatelessWidget {
3434

3535
Widget userImage = (needImage)
3636
? new IconButton(
37-
padding: EdgeInsets.only(top: 0.0, left: 0.0, bottom: 0.0, right: 10.0),
37+
padding: EdgeInsets.only(top: 0.0, left: 0.0, bottom: 0.0, right: 10.0),
3838
icon: new ClipOval(
3939
child: new FadeInImage.assetNetwork(
4040
placeholder: "static/images/logo.png",
@@ -102,4 +102,14 @@ class EventViewModel {
102102
actionTarget = eventMap["commit"]["message"];
103103
this.eventMap = eventMap;
104104
}
105+
106+
EventViewModel.fromNotify(eventMap) {
107+
actionTime = CommonUtils.getNewsTimeStr(DateTime.parse(eventMap["created_at"]));
108+
actionUser = eventMap["repository"]["full_name"];
109+
String type = eventMap["subject"]["type"];
110+
String status = eventMap["unread"] ? GSYStrings.notify_unread : GSYStrings.notify_readed;
111+
actionDes = eventMap["reason"] + "${GSYStrings.notify_type}:$type,${GSYStrings.notify_status}:$status";
112+
actionTarget = eventMap["subject.title"];
113+
this.eventMap = eventMap;
114+
}
105115
}

lib/widget/GSYCardItem.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ class GSYCardItem extends StatelessWidget {
1111
final EdgeInsets margin;
1212
final Color color;
1313
final RoundedRectangleBorder shape;
14+
final double elevation;
1415

15-
GSYCardItem({@required this.child, this.margin, this.color, this.shape});
16+
GSYCardItem({@required this.child, this.margin, this.color, this.shape, this.elevation = 5.0});
1617

1718
@override
1819
Widget build(BuildContext context) {
@@ -28,6 +29,6 @@ class GSYCardItem extends StatelessWidget {
2829
if (color == null) {
2930
color = new Color(GSYColors.cardWhite);
3031
}
31-
return new Card(elevation: 5.0, shape: shape, color: color, margin: margin, child: child);
32+
return new Card(elevation: elevation, shape: shape, color: color, margin: margin, child: child);
3233
}
3334
}

lib/widget/GSYSelectItemWidget.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ class GSYSelectItemWidget extends StatefulWidget implements PreferredSizeWidget
1414
final List<String> itemNames;
1515

1616
final SelectItemChanged selectItemChanged;
17+
final double elevation;
1718

18-
GSYSelectItemWidget(this.itemNames, this.selectItemChanged);
19+
GSYSelectItemWidget(this.itemNames, this.selectItemChanged, {this.elevation = 5.0});
1920

2021
@override
21-
_GSYSelectItemWidgetState createState() => _GSYSelectItemWidgetState(selectItemChanged, itemNames);
22+
_GSYSelectItemWidgetState createState() => _GSYSelectItemWidgetState(selectItemChanged, itemNames, elevation);
2223

2324
@override
2425
Size get preferredSize {
@@ -33,7 +34,9 @@ class _GSYSelectItemWidgetState extends State<GSYSelectItemWidget> {
3334

3435
final SelectItemChanged selectItemChanged;
3536

36-
_GSYSelectItemWidgetState(this.selectItemChanged, this.itemNames);
37+
final double elevation;
38+
39+
_GSYSelectItemWidgetState(this.selectItemChanged, this.itemNames, this.elevation);
3740

3841
_renderItem(String name, int index) {
3942
var style = index == selectIndex ? GSYConstant.middleTextWhite : GSYConstant.middleSubText;
@@ -73,6 +76,7 @@ class _GSYSelectItemWidgetState extends State<GSYSelectItemWidget> {
7376
@override
7477
Widget build(BuildContext context) {
7578
return new GSYCardItem(
79+
elevation: elevation,
7680
color: Color(GSYColors.primaryValue),
7781
margin: EdgeInsets.all(10.0),
7882
shape: new RoundedRectangleBorder(

lib/widget/ReposHeaderItem.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ReposHeaderItem extends StatelessWidget {
8383
),
8484
new Padding(padding: new EdgeInsets.all(5.0)),
8585
new Container(
86-
child: new Text(reposHeaderViewModel.repositoryDes, style: GSYConstant.subSmallText),
86+
child: new Text(reposHeaderViewModel.repositoryDes != null ? reposHeaderViewModel.repositoryDes : "---", style: GSYConstant.subSmallText),
8787
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
8888
alignment: Alignment.topLeft),
8989
new Container(

lib/widget/UserHeader.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,20 @@ class UserHeaderItem extends StatelessWidget {
5858
child: new Column(
5959
crossAxisAlignment: CrossAxisAlignment.start,
6060
children: <Widget>[
61-
new Text(userInfo.login == null ? "" : userInfo.login, style: GSYConstant.largeTextWhiteBold),
61+
new Row(
62+
children: <Widget>[
63+
new Text(userInfo.login == null ? "" : userInfo.login, style: GSYConstant.largeTextWhiteBold),
64+
new IconButton(
65+
icon: new Icon(
66+
GSYICons.USER_NOTIFY,
67+
color: Colors.blue,
68+
size: 18.0,
69+
),
70+
onPressed: () {
71+
NavigatorUtils.goNotifyPage(context);
72+
}),
73+
],
74+
),
6275
new Text(userInfo.name == null ? "" : userInfo.name, style: GSYConstant.subLightSmallText),
6376
new GSYIConText(
6477
GSYICons.USER_ITEM_COMPANY,

0 commit comments

Comments
 (0)
X Tutup