Skip to content

Commit d1619c5

Browse files
committed
notify model
1 parent ec2c98f commit d1619c5

8 files changed

Lines changed: 147 additions & 36 deletions

File tree

‎lib/common/dao/ReposDao.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ class ReposDao {
452452
var res = await getRepositoryReleaseDao("CarGuo", 'GSYGithubAppFlutter', 1, needHtml: false);
453453
if (res != null && res.result && res.data.length > 0) {
454454
//github只能有release的versionName,没有code,囧
455-
String versionName = res.data[0].actionTitle;
455+
String versionName = res.data[0].title;
456456
if (versionName != null) {
457457
if (Config.DEBUG) {
458458
print("versionName " + versionName);
@@ -471,7 +471,7 @@ class ReposDao {
471471
print("newsHad " + result.toString());
472472
}
473473
if (result > 0) {
474-
CommonUtils.showUpdateDialog(context, res.data[0].actionTitle + ": " + res.data[0].body);
474+
CommonUtils.showUpdateDialog(context, res.data[0].title + ": " + res.data[0].body);
475475
} else {
476476
if (showTip) Fluttertoast.showToast(msg: GSYStrings.app_not_new_version);
477477
}

‎lib/common/dao/UserDao.dart‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import 'package:gsy_github_app_flutter/common/config/Config.dart';
66
import 'package:gsy_github_app_flutter/common/config/ignoreConfig.dart';
77
import 'package:gsy_github_app_flutter/common/dao/DaoResult.dart';
88
import 'package:gsy_github_app_flutter/common/local/LocalStorage.dart';
9+
import 'package:gsy_github_app_flutter/common/model/Notification.dart';
910
import 'package:gsy_github_app_flutter/common/model/User.dart';
1011
import 'package:gsy_github_app_flutter/common/net/Address.dart';
1112
import 'package:gsy_github_app_flutter/common/net/Api.dart';
1213
import 'package:gsy_github_app_flutter/common/redux/UserRedux.dart';
13-
import 'package:gsy_github_app_flutter/widget/EventItem.dart';
1414
import 'package:redux/redux.dart';
1515

1616
class UserDao {
@@ -176,13 +176,13 @@ class UserDao {
176176
String url = Address.getNotifation(all, participating) + Address.getPageParams(tag, page);
177177
var res = await HttpManager.netFetch(url, null, null, null);
178178
if (res != null && res.result) {
179-
List<EventViewModel> list = new List();
179+
List<Notification> list = new List();
180180
var data = res.data;
181181
if (data == null || data.length == 0) {
182182
return new DataResult([], true);
183183
}
184184
for (int i = 0; i < data.length; i++) {
185-
list.add(EventViewModel.fromNotify(data[i]));
185+
list.add(Notification.fromJson(data[i]));
186186
}
187187
return new DataResult(list, true);
188188
} else {

‎lib/common/model/Notification.dart‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'package:gsy_github_app_flutter/common/model/NotificationSubject.dart';
2+
import 'package:gsy_github_app_flutter/common/model/Repository.dart';
3+
import 'package:json_annotation/json_annotation.dart';
4+
5+
/**
6+
* Created by guoshuyu
7+
* Date: 2018-07-31
8+
*/
9+
10+
part 'Notification.g.dart';
11+
12+
@JsonSerializable()
13+
class Notification extends Object with _$NotificationSerializerMixin {
14+
String id;
15+
bool unread;
16+
String reason;
17+
@JsonKey(name: "updated_at")
18+
DateTime updateAt;
19+
@JsonKey(name: "last_read_at")
20+
DateTime lastReadAt;
21+
Repository repository;
22+
NotificationSubject subject;
23+
24+
Notification(this.id, this.unread, this.reason, this.updateAt, this.lastReadAt, this.repository, this.subject);
25+
26+
factory Notification.fromJson(Map<String, dynamic> json) => _$NotificationFromJson(json);
27+
}

‎lib/common/model/Notification.g.dart‎

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
3+
/**
4+
* Created by guoshuyu
5+
* Date: 2018-07-31
6+
*/
7+
8+
part 'NotificationSubject.g.dart';
9+
10+
@JsonSerializable()
11+
class NotificationSubject extends Object with _$NotificationSubjectSerializerMixin {
12+
String title;
13+
String url;
14+
String type;
15+
16+
NotificationSubject(this.title, this.url, this.type);
17+
18+
factory NotificationSubject.fromJson(Map<String, dynamic> json) => _$NotificationSubjectFromJson(json);
19+
}

‎lib/common/model/NotificationSubject.g.dart‎

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/page/NotifyPage.dart‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
88
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
99
import 'package:gsy_github_app_flutter/widget/GSYSelectItemWidget.dart';
1010
import 'package:gsy_github_app_flutter/widget/GSYTitleBar.dart';
11+
import 'package:gsy_github_app_flutter/common/model/Notification.dart' as Model;
1112

1213
/**
1314
* 通知消息
@@ -29,18 +30,18 @@ class _NotifyPageState extends GSYListState<NotifyPage> {
2930
_NotifyPageState();
3031

3132
_renderEventItem(index) {
32-
EventViewModel eventViewModel = pullLoadWidgetControl.dataList[index];
33+
Model.Notification notification = pullLoadWidgetControl.dataList[index];
34+
EventViewModel eventViewModel = EventViewModel.fromNotify(notification);
3335
return new EventItem(eventViewModel, onPressed: () {
34-
var eventMap = eventViewModel.eventMap;
35-
if (eventMap["unread"]) {
36-
UserDao.setNotificationAsReadDao(eventMap["id"].toString());
36+
if (notification.unread) {
37+
UserDao.setNotificationAsReadDao(notification.id.toString());
3738
}
38-
if (eventMap["subject"]["type"] == 'Issue') {
39-
String url = eventMap["subject"]["url"];
39+
if (notification.subject.type == 'Issue') {
40+
String url = notification.subject.url;
4041
List<String> tmp = url.split("/");
4142
String number = tmp[tmp.length - 1];
42-
String userName = eventMap["repository"]["owner"]["login"];
43-
String reposName = eventMap["repository"]["name"];
43+
String userName = notification.repository.owner.login;
44+
String reposName = notification.repository.name;
4445
NavigatorUtils.goIssueDetail(context, userName, reposName, number, needRightLocalIcon: true).then((res) {
4546
showRefreshLoading();
4647
});

‎lib/widget/EventItem.dart‎

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:gsy_github_app_flutter/common/utils/EventUtils.dart';
77
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
88
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
99
import 'package:gsy_github_app_flutter/widget/GSYUserIconWidget.dart';
10+
import 'package:gsy_github_app_flutter/common/model/Notification.dart' as Model;
1011

1112
/**
1213
* 事件Item
@@ -27,23 +28,23 @@ class EventItem extends StatelessWidget {
2728
Widget des = (eventViewModel.actionDes == null || eventViewModel.actionDes.length == 0)
2829
? new Container()
2930
: new Container(
30-
child: new Text(
31-
eventViewModel.actionDes,
32-
style: GSYConstant.subSmallText,
33-
maxLines: 3,
34-
),
35-
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
36-
alignment: Alignment.topLeft);
31+
child: new Text(
32+
eventViewModel.actionDes,
33+
style: GSYConstant.subSmallText,
34+
maxLines: 3,
35+
),
36+
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
37+
alignment: Alignment.topLeft);
3738

3839
Widget userImage = (needImage)
3940
? new GSYUserIconWidget(
40-
padding: const EdgeInsets.only(top: 0.0, right: 5.0, left: 0.0),
41-
width: 30.0,
42-
height: 30.0,
43-
image: eventViewModel.actionUserPic,
44-
onPressed: () {
45-
NavigatorUtils.goPerson(context, eventViewModel.actionUser);
46-
})
41+
padding: const EdgeInsets.only(top: 0.0, right: 5.0, left: 0.0),
42+
width: 30.0,
43+
height: 30.0,
44+
image: eventViewModel.actionUserPic,
45+
onPressed: () {
46+
NavigatorUtils.goPerson(context, eventViewModel.actionUser);
47+
})
4748
: Container();
4849
return new Container(
4950
child: new GSYCardItem(
@@ -79,7 +80,6 @@ class EventViewModel {
7980
String actionDes;
8081
String actionTime;
8182
String actionTarget;
82-
var eventMap;
8383

8484
EventViewModel.fromEventMap(Event event) {
8585
actionTime = CommonUtils.getNewsTimeStr(event.createdAt);
@@ -97,13 +97,12 @@ class EventViewModel {
9797
actionTarget = eventMap.commit.message;
9898
}
9999

100-
EventViewModel.fromNotify(eventMap) {
101-
actionTime = CommonUtils.getNewsTimeStr(DateTime.parse(eventMap["updated_at"]));
102-
actionUser = eventMap["repository"]["full_name"];
103-
String type = eventMap["subject"]["type"];
104-
String status = eventMap["unread"] ? GSYStrings.notify_unread : GSYStrings.notify_readed;
105-
actionDes = eventMap["reason"] + "${GSYStrings.notify_type}:$type,${GSYStrings.notify_status}:$status";
106-
actionTarget = eventMap["subject"]["title"];
107-
this.eventMap = eventMap;
100+
EventViewModel.fromNotify(Model.Notification eventMap) {
101+
actionTime = CommonUtils.getNewsTimeStr(eventMap.updateAt);
102+
actionUser = eventMap.repository.fullName;
103+
String type = eventMap.subject.type;
104+
String status = eventMap.unread ? GSYStrings.notify_unread : GSYStrings.notify_readed;
105+
actionDes = eventMap.reason + "${GSYStrings.notify_type}:$type,${GSYStrings.notify_status}:$status";
106+
actionTarget = eventMap.subject.title;
108107
}
109108
}

0 commit comments

Comments
 (0)