Repository navigation
Expand file tree
/
Copy pathEventItem.dart
More file actions
108 lines (98 loc) · 4.1 KB
/
Copy pathEventItem.dart
File metadata and controls
108 lines (98 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import 'package:flutter/material.dart';
import 'package:gsy_github_app_flutter/common/model/Event.dart';
import 'package:gsy_github_app_flutter/common/model/RepoCommit.dart';
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
import 'package:gsy_github_app_flutter/common/utils/EventUtils.dart';
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
import 'package:gsy_github_app_flutter/widget/GSYUserIconWidget.dart';
import 'package:gsy_github_app_flutter/common/model/Notification.dart' as Model;
/**
* 事件Item
* Created by guoshuyu
* Date: 2018-07-16
*/
class EventItem extends StatelessWidget {
final EventViewModel eventViewModel;
final VoidCallback onPressed;
final bool needImage;
EventItem(this.eventViewModel, {this.onPressed, this.needImage = true}) : super();
@override
Widget build(BuildContext context) {
Widget des = (eventViewModel.actionDes == null || eventViewModel.actionDes.length == 0)
? new Container()
: new Container(
child: new Text(
eventViewModel.actionDes,
style: GSYConstant.smallSubText,
maxLines: 3,
),
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
alignment: Alignment.topLeft);
Widget userImage = (needImage)
? new GSYUserIconWidget(
padding: const EdgeInsets.only(top: 0.0, right: 5.0, left: 0.0),
width: 30.0,
height: 30.0,
image: eventViewModel.actionUserPic,
onPressed: () {
NavigatorUtils.goPerson(context, eventViewModel.actionUser);
})
: Container();
return new Container(
child: new GSYCardItem(
child: new FlatButton(
onPressed: onPressed,
child: new Padding(
padding: new EdgeInsets.only(left: 0.0, top: 10.0, right: 0.0, bottom: 10.0),
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Row(
children: <Widget>[
userImage,
new Expanded(child: new Text(eventViewModel.actionUser, style: GSYConstant.smallTextBold)),
new Text(eventViewModel.actionTime, style: GSYConstant.smallSubText),
],
),
new Container(
child: new Text(eventViewModel.actionTarget, style: GSYConstant.smallTextBold),
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
alignment: Alignment.topLeft),
des,
],
),
))),
);
}
}
class EventViewModel {
String actionUser;
String actionUserPic;
String actionDes;
String actionTime;
String actionTarget;
EventViewModel.fromEventMap(Event event) {
actionTime = CommonUtils.getNewsTimeStr(event.createdAt);
actionUser = event.actor.login;
actionUserPic = event.actor.avatar_url;
var other = EventUtils.getActionAndDes(event);
actionDes = other["des"];
actionTarget = other["actionStr"];
}
EventViewModel.fromCommitMap(RepoCommit eventMap) {
actionTime = CommonUtils.getNewsTimeStr(eventMap.commit.committer.date);
actionUser = eventMap.commit.committer.name;
actionDes = "sha:" + eventMap.sha;
actionTarget = eventMap.commit.message;
}
EventViewModel.fromNotify(BuildContext context, Model.Notification eventMap) {
actionTime = CommonUtils.getNewsTimeStr(eventMap.updateAt);
actionUser = eventMap.repository.fullName;
String type = eventMap.subject.type;
String status = eventMap.unread ? CommonUtils.getLocale(context).notify_unread : CommonUtils.getLocale(context).notify_readed;
actionDes = eventMap.reason + "${CommonUtils.getLocale(context).notify_type}:$type,${CommonUtils.getLocale(context).notify_status}:$status";
actionTarget = eventMap.subject.title;
}
}