Skip to content

Commit ec2c98f

Browse files
committed
user model
1 parent eff903f commit ec2c98f

7 files changed

Lines changed: 33 additions & 32 deletions

File tree

‎lib/common/dao/ReposDao.dart‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import 'package:get_version/get_version.dart';
77
import 'package:gsy_github_app_flutter/common/config/Config.dart';
88
import 'package:gsy_github_app_flutter/common/dao/DaoResult.dart';
99
import 'package:gsy_github_app_flutter/common/model/Event.dart';
10+
import 'package:gsy_github_app_flutter/common/model/FileModel.dart';
1011
import 'package:gsy_github_app_flutter/common/model/PushCommit.dart';
1112
import 'package:gsy_github_app_flutter/common/model/Release.dart';
1213
import 'package:gsy_github_app_flutter/common/model/RepoCommit.dart';
1314
import 'package:gsy_github_app_flutter/common/model/Repository.dart';
15+
import 'package:gsy_github_app_flutter/common/model/User.dart';
1416
import 'package:gsy_github_app_flutter/common/net/Address.dart';
1517
import 'package:gsy_github_app_flutter/common/net/Api.dart';
1618
import 'package:gsy_github_app_flutter/common/net/trending/GithubTrending.dart';
1719
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
1820
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
19-
import 'package:gsy_github_app_flutter/page/RepositoryFileListPage.dart';
20-
import 'package:gsy_github_app_flutter/widget/UserItem.dart';
2121
import 'package:pub_semver/pub_semver.dart';
2222

2323
/**
@@ -138,15 +138,15 @@ class ReposDao {
138138
if (text) {
139139
return new DataResult(res.data, true);
140140
}
141-
List<FileItemViewModel> list = new List();
141+
List<FileModel> list = new List();
142142
var data = res.data;
143143
if (data == null || data.length == 0) {
144144
return new DataResult(null, false);
145145
}
146-
List<FileItemViewModel> dirs = [];
147-
List<FileItemViewModel> files = [];
146+
List<FileModel> dirs = [];
147+
List<FileModel> files = [];
148148
for (int i = 0; i < data.length; i++) {
149-
FileItemViewModel file = FileItemViewModel.fromMap(data[i]);
149+
FileModel file = FileModel.fromJson(data[i]);
150150
if (file.type == 'file') {
151151
files.add(file);
152152
} else {
@@ -188,13 +188,13 @@ class ReposDao {
188188
String url = Address.getReposWatcher(userName, reposName) + Address.getPageParams("?", page);
189189
var res = await HttpManager.netFetch(url, null, null, null);
190190
if (res != null && res.result) {
191-
List<UserItemViewModel> list = new List();
191+
List<User> list = new List();
192192
var data = res.data;
193193
if (data == null || data.length == 0) {
194194
return new DataResult(null, false);
195195
}
196196
for (int i = 0; i < data.length; i++) {
197-
list.add(new UserItemViewModel(data[i]['login'], data[i]["avatar_url"]));
197+
list.add(new User.fromJson(data[i]));
198198
}
199199
return new DataResult(list, true);
200200
} else {
@@ -209,13 +209,13 @@ class ReposDao {
209209
String url = Address.getReposStar(userName, reposName) + Address.getPageParams("?", page);
210210
var res = await HttpManager.netFetch(url, null, null, null);
211211
if (res != null && res.result) {
212-
List<UserItemViewModel> list = new List();
212+
List<User> list = new List();
213213
var data = res.data;
214214
if (data == null || data.length == 0) {
215215
return new DataResult(null, false);
216216
}
217217
for (int i = 0; i < data.length; i++) {
218-
list.add(new UserItemViewModel(data[i]['login'], data[i]["avatar_url"]));
218+
list.add(new User.fromJson(data[i]));
219219
}
220220
return new DataResult(list, true);
221221
} else {
@@ -382,13 +382,13 @@ class ReposDao {
382382
}
383383
} else {
384384
if (res != null && res.result && res.data["items"] != null) {
385-
List<UserItemViewModel> list = new List();
385+
List<User> list = new List();
386386
var data = res.data["items"];
387387
if (data == null || data.length == 0) {
388388
return new DataResult(null, false);
389389
}
390390
for (int i = 0; i < data.length; i++) {
391-
list.add(new UserItemViewModel(data[i]['login'], data[i]["avatar_url"]));
391+
list.add(new User.fromJson(data[i]));
392392
}
393393
return new DataResult(list, true);
394394
} else {

‎lib/common/dao/UserDao.dart‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'package:gsy_github_app_flutter/common/net/Address.dart';
1111
import 'package:gsy_github_app_flutter/common/net/Api.dart';
1212
import 'package:gsy_github_app_flutter/common/redux/UserRedux.dart';
1313
import 'package:gsy_github_app_flutter/widget/EventItem.dart';
14-
import 'package:gsy_github_app_flutter/widget/UserItem.dart';
1514
import 'package:redux/redux.dart';
1615

1716
class UserDao {
@@ -134,13 +133,13 @@ class UserDao {
134133
String url = Address.getUserFollower(userName) + Address.getPageParams("?", page);
135134
var res = await HttpManager.netFetch(url, null, null, null);
136135
if (res != null && res.result) {
137-
List<UserItemViewModel> list = new List();
136+
List<User> list = new List();
138137
var data = res.data;
139138
if (data == null || data.length == 0) {
140139
return new DataResult(null, false);
141140
}
142141
for (int i = 0; i < data.length; i++) {
143-
list.add(new UserItemViewModel(data[i]['login'], data[i]["avatar_url"]));
142+
list.add(new User.fromJson(data[i]));
144143
}
145144
return new DataResult(list, true);
146145
} else {
@@ -155,13 +154,13 @@ class UserDao {
155154
String url = Address.getUserFollow(userName) + Address.getPageParams("?", page);
156155
var res = await HttpManager.netFetch(url, null, null, null);
157156
if (res != null && res.result) {
158-
List<UserItemViewModel> list = new List();
157+
List<User> list = new List();
159158
var data = res.data;
160159
if (data == null || data.length == 0) {
161160
return new DataResult(null, false);
162161
}
163162
for (int i = 0; i < data.length; i++) {
164-
list.add(new UserItemViewModel(data[i]['login'], data[i]["avatar_url"]));
163+
list.add(new User.fromJson(data[i]));
165164
}
166165
return new DataResult(list, true);
167166
} else {
@@ -234,13 +233,13 @@ class UserDao {
234233
String url = Address.getMember(userName) + Address.getPageParams("?", page);
235234
var res = await HttpManager.netFetch(url, null, null, null);
236235
if (res != null && res.result) {
237-
List<UserItemViewModel> list = new List();
236+
List<User> list = new List();
238237
var data = res.data;
239238
if (data == null || data.length == 0) {
240239
return new DataResult(null, false);
241240
}
242241
for (int i = 0; i < data.length; i++) {
243-
list.add(new UserItemViewModel(data[i]['login'], data[i]["avatar_url"]));
242+
list.add(new User.fromJson(data[i]));
244243
}
245244
return new DataResult(list, true);
246245
} else {

‎lib/page/CommonListPage.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class _CommonListPageState extends GSYListState<CommonListPage> {
5656
NavigatorUtils.goReposDetail(context, reposViewModel.ownerName, reposViewModel.repositoryName);
5757
});
5858
case 'user':
59-
return new UserItem(data, onPressed: () {
59+
return new UserItem(UserItemViewModel.fromMap(data), onPressed: () {
6060
NavigatorUtils.goPerson(context, data.userName);
6161
});
6262
case 'org':

‎lib/page/PersonPage.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ class _PersonState extends GSYListState<PersonPage> {
101101
return new UserHeaderItem(userInfo, beStaredCount);
102102
}
103103
if (userInfo.type == "Organization") {
104-
return new UserItem(pullLoadWidgetControl.dataList[index - 1], onPressed: () {
105-
NavigatorUtils.goPerson(context, pullLoadWidgetControl.dataList[index - 1].userName);
104+
return new UserItem(UserItemViewModel.fromMap(pullLoadWidgetControl.dataList[index - 1]), onPressed: () {
105+
NavigatorUtils.goPerson(context, UserItemViewModel.fromMap(pullLoadWidgetControl.dataList[index - 1]).userName);
106106
});
107107
} else {
108108
Event event = pullLoadWidgetControl.dataList[index - 1];

‎lib/page/RepositoryFileListPage.dart‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import 'dart:io';
2-
31
import 'package:flutter/material.dart';
42
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
3+
import 'package:gsy_github_app_flutter/common/model/FileModel.dart';
54
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
65
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
7-
import 'package:gsy_github_app_flutter/common/utils/HtmlUtils.dart';
86
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
97
import 'package:gsy_github_app_flutter/page/RepositoryDetailPage.dart';
108
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
@@ -49,7 +47,7 @@ class RepositoryDetailFileListPageState extends GSYListState<RepositoryDetailFil
4947

5048
///渲染文件item
5149
_renderEventItem(index) {
52-
FileItemViewModel fileItemViewModel = pullLoadWidgetControl.dataList[index];
50+
FileItemViewModel fileItemViewModel = FileItemViewModel.fromMap(pullLoadWidgetControl.dataList[index]);
5351
IconData iconData = (fileItemViewModel.type == "file") ? GSYICons.REPOS_ITEM_FILE : GSYICons.REPOS_ITEM_DIR;
5452
Widget trailing = (fileItemViewModel.type == "file") ? null : new Icon(GSYICons.REPOS_ITEM_NEXT, size: 14.0);
5553
return new GSYCardItem(
@@ -187,8 +185,8 @@ class FileItemViewModel {
187185

188186
FileItemViewModel();
189187

190-
FileItemViewModel.fromMap(map) {
191-
name = map["name"];
192-
type = map["type"];
188+
FileItemViewModel.fromMap(FileModel map) {
189+
name = map.name;
190+
type = map.type;
193191
}
194192
}

‎lib/page/SearchPage.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class _SearchPageState extends GSYListState<SearchPage> {
3636
NavigatorUtils.goReposDetail(context, reposViewModel.ownerName, reposViewModel.repositoryName);
3737
});
3838
} else if (selectIndex == 1) {
39-
return new UserItem(data, onPressed: () {
40-
NavigatorUtils.goPerson(context, data.userName);
39+
return new UserItem(UserItemViewModel.fromMap(data), onPressed: () {
40+
NavigatorUtils.goPerson(context, UserItemViewModel.fromMap(data).userName);
4141
});
4242
}
4343
}

‎lib/widget/UserItem.dart‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:gsy_github_app_flutter/common/model/User.dart';
23
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
34
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
45

@@ -53,5 +54,8 @@ class UserItemViewModel {
5354
String userPic;
5455
String userName;
5556

56-
UserItemViewModel(this.userName, this.userPic);
57+
UserItemViewModel.fromMap(User user) {
58+
userName = user.login;
59+
userPic = user.avatar_url;
60+
}
5761
}

0 commit comments

Comments
 (0)