forked from CarGuo/gsy_github_app_flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrendPage.dart
More file actions
211 lines (191 loc) · 6.29 KB
/
TrendPage.dart
File metadata and controls
211 lines (191 loc) · 6.29 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
import 'package:gsy_github_app_flutter/common/redux/GSYState.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/NavigatorUtils.dart';
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
import 'package:gsy_github_app_flutter/widget/GSYListState.dart';
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
import 'package:gsy_github_app_flutter/widget/ReposItem.dart';
import 'package:redux/redux.dart';
/**
* 主页趋势tab页
* Created by guoshuyu
* Date: 2018-07-16
*/
class TrendPage extends StatefulWidget {
@override
_TrendPageState createState() => _TrendPageState();
}
class _TrendPageState extends State<TrendPage> with AutomaticKeepAliveClientMixin<TrendPage>, GSYListState<TrendPage> {
static TrendTypeModel selectTime = null;
static TrendTypeModel selectType = null;
_renderItem(e) {
ReposViewModel reposViewModel = ReposViewModel.fromTrendMap(e);
return new ReposItem(reposViewModel, onPressed: () {
NavigatorUtils.goReposDetail(context, reposViewModel.ownerName, reposViewModel.repositoryName);
});
}
_renderHeader(Store<GSYState> store) {
if (selectType == null && selectType == null) {
return Container();
}
return new GSYCardItem(
color: store.state.themeData.primaryColor,
margin: EdgeInsets.all(10.0),
shape: new RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
child: new Padding(
padding: new EdgeInsets.only(left: 0.0, top: 5.0, right: 0.0, bottom: 5.0),
child: new Row(
children: <Widget>[
_renderHeaderPopItem(selectTime.name, trendTime(context), (TrendTypeModel result) {
if (isLoading) {
Fluttertoast.showToast(msg: CommonUtils.getLocale(context).loading_text);
return;
}
setState(() {
selectTime = result;
});
showRefreshLoading();
}),
new Container(height: 10.0, width: 0.5, color: Color(GSYColors.white)),
_renderHeaderPopItem(selectType.name, trendType(context), (TrendTypeModel result) {
if (isLoading) {
Fluttertoast.showToast(msg: CommonUtils.getLocale(context).loading_text);
return;
}
setState(() {
selectType = result;
});
showRefreshLoading();
}),
],
),
),
);
}
_renderHeaderPopItem(String data, List<TrendTypeModel> list, PopupMenuItemSelected<TrendTypeModel> onSelected) {
return new Expanded(
child: new PopupMenuButton<TrendTypeModel>(
child: new Center(child: new Text(data, style: GSYConstant.middleTextWhite)),
onSelected: onSelected,
itemBuilder: (BuildContext context) {
return _renderHeaderPopItemChild(list);
},
),
);
}
_renderHeaderPopItemChild(List<TrendTypeModel> data) {
List<PopupMenuEntry<TrendTypeModel>> list = new List();
for (TrendTypeModel item in data) {
list.add(PopupMenuItem<TrendTypeModel>(
value: item,
child: new Text(item.name),
));
}
return list;
}
@override
Future<Null> handleRefresh() async {
if (isLoading) {
return null;
}
isLoading = true;
page = 1;
await ReposDao.getTrendDao(_getStore(), since: selectTime.value, languageType: selectType.value);
setState(() {
pullLoadWidgetControl.needLoadMore = false;
});
isLoading = false;
return null;
}
@override
requestRefresh() async {
return null;
}
@override
requestLoadMore() async {
return null;
}
@override
bool get isRefreshFirst => false;
@override
void didChangeDependencies() {
pullLoadWidgetControl.dataList = _getStore().state.trendList;
if (pullLoadWidgetControl.dataList.length == 0) {
setState(() {
selectTime = trendTime(context)[0];
selectType = trendType(context)[0];
});
showRefreshLoading();
}
super.didChangeDependencies();
}
@override
void dispose() {
super.dispose();
clearData();
}
Store<GSYState> _getStore() {
return StoreProvider.of(context);
}
@override
Widget build(BuildContext context) {
super.build(context); // See AutomaticKeepAliveClientMixin.
return new StoreBuilder<GSYState>(
builder: (context, store) {
return new Scaffold(
backgroundColor: Color(GSYColors.mainBackgroundColor),
appBar: new AppBar(
flexibleSpace: _renderHeader(store),
backgroundColor: Color(GSYColors.mainBackgroundColor),
leading: new Container(),
elevation: 0.0,
),
body: GSYPullLoadWidget(
pullLoadWidgetControl,
(BuildContext context, int index) => _renderItem(pullLoadWidgetControl.dataList[index]),
handleRefresh,
onLoadMore,
refreshKey: refreshIndicatorKey,
),
);
},
);
}
}
class TrendTypeModel {
final String name;
final String value;
TrendTypeModel(this.name, this.value);
}
trendTime(BuildContext context) {
return [
new TrendTypeModel(CommonUtils.getLocale(context).trend_day, "daily"),
new TrendTypeModel(CommonUtils.getLocale(context).trend_week, "weekly"),
new TrendTypeModel(CommonUtils.getLocale(context).trend_month, "monthly"),
];
}
trendType(BuildContext context) {
return [
TrendTypeModel(CommonUtils.getLocale(context).trend_all, null),
TrendTypeModel("Java", "Java"),
TrendTypeModel("Kotlin", "Kotlin"),
TrendTypeModel("Dart", "Dart"),
TrendTypeModel("Objective-C", "Objective-C"),
TrendTypeModel("Swift", "Swift"),
TrendTypeModel("JavaScript", "JavaScript"),
TrendTypeModel("PHP", "PHP"),
TrendTypeModel("Go", "Go"),
TrendTypeModel("C++", "C++"),
TrendTypeModel("C", "C"),
TrendTypeModel("HTML", "HTML"),
TrendTypeModel("CSS", "CSS"),
];
}