Skip to content

Commit 105639a

Browse files
committed
my page list
1 parent 2633ae1 commit 105639a

6 files changed

Lines changed: 102 additions & 21 deletions

File tree

‎lib/common/dao/EventDao.dart‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,26 @@ class EventDao {
3434
return null;
3535
}
3636
}
37+
38+
/**
39+
* 用户行为事件
40+
*/
41+
static getEventDao(userName, {page = 0}) async {
42+
String url = Address.getEvent(userName) + Address.getPageParams("?", page);
43+
var res = await HttpManager.netFetch(url, null, null, null);
44+
if (res != null && res.result) {
45+
List<EventViewModel> list = new List();
46+
var data = res.data;
47+
if (data == null || data.length == 0) {
48+
return null;
49+
}
50+
for (int i = 0; i < data.length; i++) {
51+
list.add(EventViewModel.fromEventMap(data[i]));
52+
}
53+
return list;
54+
} else {
55+
return null;
56+
}
57+
}
58+
3759
}

‎lib/common/style/GSYStyle.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ class GSYStrings {
208208
static const String user_tab_focus = "关注";
209209
static const String user_tab_star = "星标";
210210
static const String user_tab_honor = "荣耀";
211+
static const String user_dynamic_title = "个人动态";
211212
}
212213

213214
class GSYICons {

‎lib/common/utils/EventUtils.dart‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,23 @@ class EventUtils {
8181
String descSpan = '';
8282

8383
int count = event["comments"];
84-
int maxLines = 4;
85-
int max = (count > maxLines) ? maxLines - 1 : count;
84+
if(count != null) {
85+
int maxLines = 4;
86+
int max = (count != null && count > maxLines) ? maxLines - 1 : count;
8687

87-
for (int i = 0; i < max; i++) {
88-
var commit = event["payload"]["comment"].get(i);
89-
if (i != 0) {
90-
descSpan += ("\n");
88+
for (int i = 0; i < max; i++) {
89+
var commit = event["payload"]["comment"].get(i);
90+
if (i != 0) {
91+
descSpan += ("\n");
92+
}
93+
String sha = commit["sha"].substring(0, 7);
94+
descSpan += sha;
95+
descSpan += " ";
96+
descSpan += commit["message"];
97+
}
98+
if (count > maxLines) {
99+
descSpan = descSpan + "\n" + "...";
91100
}
92-
String sha = commit["sha"].substring(0, 7);
93-
descSpan += sha;
94-
descSpan += " ";
95-
descSpan += commit["message"];
96-
}
97-
if (count > maxLines) {
98-
descSpan = descSpan + "\n" + "...";
99101
}
100102
break;
101103
case "ReleaseEvent":

‎lib/page/MyPage.dart‎

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
21
import 'dart:async';
2+
import 'dart:math';
33

44
import 'package:flutter/material.dart';
55
import 'package:flutter_redux/flutter_redux.dart';
6+
import 'package:gsy_github_app_flutter/common/config/Config.dart';
7+
import 'package:gsy_github_app_flutter/common/dao/EventDao.dart';
68
import 'package:gsy_github_app_flutter/common/redux/GSYState.dart';
9+
import 'package:gsy_github_app_flutter/widget/EventItem.dart';
710
import 'package:gsy_github_app_flutter/widget/GSYPullLoadWidget.dart';
811
import 'package:gsy_github_app_flutter/widget/UserHeader.dart';
912
import 'package:redux/redux.dart';
13+
1014
class MyPage extends StatefulWidget {
1115
@override
1216
_MyPageState createState() => _MyPageState();
1317
}
1418

1519
// ignore: mixin_inherits_from_not_object
16-
class _MyPageState extends State<MyPage> with AutomaticKeepAliveClientMixin {
17-
20+
class _MyPageState extends State<MyPage> with AutomaticKeepAliveClientMixin {
1821
bool isLoading = false;
1922

2023
int page = 1;
@@ -24,23 +27,62 @@ class _MyPageState extends State<MyPage> with AutomaticKeepAliveClientMixin {
2427
final GSYPullLoadWidgetControl pullLoadWidgetControl = new GSYPullLoadWidgetControl();
2528

2629
Future<Null> _handleRefresh() async {
30+
if (isLoading) {
31+
return null;
32+
}
33+
isLoading = true;
34+
page = 1;
35+
var result = await EventDao.getEventDao(_getUserName(), page: page);
36+
if (result != null && result.length > 0) {
37+
pullLoadWidgetControl.dataList.clear();
38+
setState(() {
39+
pullLoadWidgetControl.dataList.addAll(result);
40+
});
41+
}
42+
setState(() {
43+
pullLoadWidgetControl.needLoadMore = (result != null && result.length == Config.PAGE_SIZE);
44+
});
45+
isLoading = false;
2746
return null;
2847
}
2948

3049
Future<Null> _onLoadMore() async {
50+
if (isLoading) {
51+
return null;
52+
}
53+
isLoading = true;
54+
page++;
55+
var result = await EventDao.getEventDao(_getUserName(), page: page);
56+
if (result != null && result.length > 0) {
57+
setState(() {
58+
pullLoadWidgetControl.dataList.addAll(result);
59+
});
60+
}
61+
setState(() {
62+
pullLoadWidgetControl.needLoadMore = (result != null);
63+
});
64+
isLoading = false;
3165
return null;
3266
}
3367

3468
_renderEventItem(userInfo, index) {
35-
if(index == 0) {
69+
if (index == 0) {
3670
return new UserHeaderItem(userInfo);
3771
}
72+
return new EventItem(pullLoadWidgetControl.dataList[index - 1]);
3873
}
3974

4075
Store<GSYState> _getStore() {
4176
return StoreProvider.of(context);
4277
}
4378

79+
_getUserName() {
80+
if (_getStore().state.userInfo == null) {
81+
return null;
82+
}
83+
return _getStore().state.userInfo.login;
84+
}
85+
4486
@override
4587
bool get wantKeepAlive => true;
4688

@@ -52,15 +94,19 @@ class _MyPageState extends State<MyPage> with AutomaticKeepAliveClientMixin {
5294

5395
@override
5496
void didChangeDependencies() {
97+
pullLoadWidgetControl.dataList = dataList;
98+
if (pullLoadWidgetControl.dataList.length == 0) {
99+
_handleRefresh();
100+
}
55101
super.didChangeDependencies();
56102
}
57103

58104
@override
59105
Widget build(BuildContext context) {
60106
return new StoreBuilder<GSYState>(
61107
builder: (context, store) {
62-
return GSYPullLoadWidget(pullLoadWidgetControl, (BuildContext context, int index) => _renderEventItem(store.state.userInfo, index),
63-
_handleRefresh, _onLoadMore);
108+
return GSYPullLoadWidget(
109+
pullLoadWidgetControl, (BuildContext context, int index) => _renderEventItem(store.state.userInfo, index), _handleRefresh, _onLoadMore);
64110
},
65111
);
66112
}

‎lib/widget/GSYPullLoadWidget.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ class _GSYPullLoadWidgetState extends State<GSYPullLoadWidget> {
6262
child: new ListView.builder(
6363
physics: const AlwaysScrollableScrollPhysics(),
6464
itemBuilder: (context, index) {
65-
if (index == control.dataList.length && control.dataList.length != 0) {
65+
if (!control.needHeader && index == control.dataList.length && control.dataList.length != 0) {
66+
return _buildProgressIndicator();
67+
} else if (control.needHeader && index == _getListCount() - 1 && control.dataList.length != 0) {
6668
return _buildProgressIndicator();
6769
} else {
6870
return itemBuilder(context, index);

‎lib/widget/UserHeader.dart‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,15 @@ class UserHeaderItem extends StatelessWidget {
130130
),
131131
],
132132
),
133-
))
133+
)),
134+
new Container(
135+
child: new Text(
136+
GSYStrings.user_dynamic_title,
137+
style: GSYConstant.normalTextBold,
138+
overflow: TextOverflow.ellipsis,
139+
),
140+
margin: new EdgeInsets.only(top: 15.0, bottom: 15.0, left: 12.0),
141+
alignment: Alignment.topLeft),
134142
],
135143
);
136144
}

0 commit comments

Comments
 (0)