Skip to content

Commit 8d98254

Browse files
committed
repos model
1 parent 0af5a7c commit 8d98254

8 files changed

Lines changed: 72 additions & 23 deletions

File tree

‎lib/common/dao/ReposDao.dart‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import 'package:gsy_github_app_flutter/page/RepositoryFileListPage.dart';
1818
import 'package:gsy_github_app_flutter/widget/PushCoedItem.dart';
1919
import 'package:gsy_github_app_flutter/widget/PushHeader.dart';
2020
import 'package:gsy_github_app_flutter/widget/ReleaseItem.dart';
21-
import 'package:gsy_github_app_flutter/widget/ReposHeaderItem.dart';
2221
import 'package:gsy_github_app_flutter/widget/UserItem.dart';
2322
import 'package:pub_semver/pub_semver.dart';
2423

@@ -64,7 +63,7 @@ class ReposDao {
6463
if (data == null || data.length == 0) {
6564
return new DataResult(null, false);
6665
}
67-
return new DataResult(ReposHeaderViewModel.fromHttpMap(reposName, userName, data), true);
66+
return new DataResult(Repository.fromJson(data), true);
6867
} else {
6968
return new DataResult(null, false);
7069
}

‎lib/common/model/License.dart‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Created by guoshuyu
3+
* Date: 2018-07-31
4+
*/
5+
import 'package:json_annotation/json_annotation.dart';
6+
7+
/**
8+
* Created by guoshuyu
9+
* Date: 2018-07-31
10+
*/
11+
12+
part 'License.g.dart';
13+
14+
@JsonSerializable()
15+
class License extends Object with _$LicenseSerializerMixin {
16+
17+
String name;
18+
19+
License(this.name);
20+
21+
factory License.fromJson(Map<String, dynamic> json) => _$LicenseFromJson(json);
22+
}

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

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

‎lib/common/model/Repository.dart‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:gsy_github_app_flutter/common/model/License.dart';
12
import 'package:gsy_github_app_flutter/common/model/RepositoryPermissions.dart';
23
import 'package:gsy_github_app_flutter/common/model/User.dart';
34
import 'package:json_annotation/json_annotation.dart';
@@ -86,6 +87,8 @@ class Repository extends Object with _$RepositorySerializerMixin {
8687

8788
User owner;
8889

90+
License license;
91+
8992
Repository parent;
9093

9194
RepositoryPermissions permissions;
@@ -98,6 +101,7 @@ class Repository extends Object with _$RepositorySerializerMixin {
98101
this.htmlUrl,
99102
this.description,
100103
this.language,
104+
this.license,
101105
this.defaultBranch,
102106
this.createdAt,
103107
this.updatedAt,
@@ -127,4 +131,6 @@ class Repository extends Object with _$RepositorySerializerMixin {
127131
/// from a map. We pass the map to the generated _$UserFromJson constructor.
128132
/// The constructor is named after the source class, in this case User.
129133
factory Repository.fromJson(Map<String, dynamic> json) => _$RepositoryFromJson(json);
134+
135+
Repository.empty();
130136
}

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

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

‎lib/page/RepositoryDetailPage.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
6565
var result = await ReposDao.getRepositoryDetailDao(userName, reposName, branchControl.currentBranch);
6666
if (result != null && result.result) {
6767
setState(() {
68-
reposDetailInfoPageControl.reposHeaderViewModel = result.data;
68+
reposDetailInfoPageControl.repository = result.data;
6969
});
7070
}
7171
}
@@ -93,8 +93,8 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
9393
}
9494

9595
_refresh() {
96-
this._getReposStatus();
9796
this._getReposDetail();
97+
this._getReposStatus();
9898
}
9999

100100
_renderBranchPopItem(String data, List<String> list, onSelected) {

‎lib/page/RepostoryDetailInfoPage.dart‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
33
import 'package:gsy_github_app_flutter/common/model/RepoCommit.dart';
4+
import 'package:gsy_github_app_flutter/common/model/Repository.dart';
45
import 'package:gsy_github_app_flutter/common/utils/EventUtils.dart';
56
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
67
import 'package:gsy_github_app_flutter/page/RepositoryDetailPage.dart';
@@ -22,7 +23,7 @@ class ReposDetailInfoPage extends StatefulWidget {
2223

2324
final BranchControl branchControl;
2425

25-
ReposDetailInfoPage(this.reposDetailInfoPageControl, this.userName, this.reposName, this.branchControl, { Key key }) : super(key: key);
26+
ReposDetailInfoPage(this.reposDetailInfoPageControl, this.userName, this.reposName, this.branchControl, {Key key}) : super(key: key);
2627

2728
@override
2829
ReposDetailInfoPageState createState() => ReposDetailInfoPageState(reposDetailInfoPageControl, userName, reposName, branchControl);
@@ -44,7 +45,7 @@ class ReposDetailInfoPageState extends GSYListState<ReposDetailInfoPage> {
4445

4546
_renderEventItem(index) {
4647
if (index == 0) {
47-
return new ReposHeaderItem(reposDetailInfoPageControl.reposHeaderViewModel, (index) {
48+
return new ReposHeaderItem(ReposHeaderViewModel.fromHttpMap(userName, reposName, reposDetailInfoPageControl.repository), (index) {
4849
selectIndex = index;
4950
clearData();
5051
showRefreshLoading();
@@ -109,5 +110,5 @@ class ReposDetailInfoPageState extends GSYListState<ReposDetailInfoPage> {
109110
}
110111

111112
class ReposDetailInfoPageControl {
112-
ReposHeaderViewModel reposHeaderViewModel = new ReposHeaderViewModel();
113+
Repository repository = Repository.empty();
113114
}

‎lib/widget/ReposHeaderItem.dart‎

Lines changed: 17 additions & 16 deletions
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/Repository.dart';
23
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
34
import 'package:gsy_github_app_flutter/common/utils/CommonUtils.dart';
45
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
@@ -185,23 +186,23 @@ class ReposHeaderViewModel {
185186

186187
ReposHeaderViewModel();
187188

188-
ReposHeaderViewModel.fromHttpMap(reposName, ownerName, map) {
189+
ReposHeaderViewModel.fromHttpMap(ownerName, reposName, Repository map) {
189190
this.ownerName = ownerName;
190-
this.ownerPic = map["owner"]["avatar_url"];
191+
this.ownerPic = map.owner.avatar_url;
191192
this.repositoryName = reposName;
192-
this.repositoryStar = map["watchers_count"] != null ? map["watchers_count"].toString() : "";
193-
this.repositoryFork = map["forks_count"] != null ? map["forks_count"].toString() : "";
194-
this.repositoryWatch = map["subscribers_count"] != null ? map["subscribers_count"].toString() : "";
195-
this.repositoryIssue = map["open_issues_count"] != null ? map["open_issues_count"].toString() : "";
196-
this.repositoryIssueClose = map["closed_issues_count"] != null ? map["closed_issues_count"].toString() : "";
197-
this.repositoryIssueAll = map["all_issues_count"] != null ? map["all_issues_count"].toString() : "";
198-
this.repositorySize = ((map["size"] / 1024.0)).toString().substring(0, 3) + "M";
199-
this.repositoryType = map["language"];
200-
this.repositoryDes = map["description"];
201-
this.repositoryIsFork = map["fork"];
202-
this.license = map["license"] != null ? map["license"]["name"] : "";
203-
this.repositoryParentName = map["parent"] != null ? map["parent"]["full_name"] : null;
204-
this.created_at = CommonUtils.getNewsTimeStr(DateTime.parse(map["created_at"]));
205-
this.push_at = CommonUtils.getNewsTimeStr(DateTime.parse(map["pushed_at"]));
193+
this.repositoryStar = map.watchersCount != null ? map.watchersCount.toString() : "";
194+
this.repositoryFork = map.forksCount != null ? map.forksCount.toString() : "";
195+
this.repositoryWatch = map.subscribersCount != null ? map.subscribersCount.toString() : "";
196+
this.repositoryIssue = map.openIssuesCount != null ? map.openIssuesCount.toString() : "";
197+
//this.repositoryIssueClose = map.closedIssuesCount != null ? map.closed_issues_count.toString() : "";
198+
//this.repositoryIssueAll = map.all_issues_count != null ? map.all_issues_count.toString() : "";
199+
this.repositorySize = ((map.size / 1024.0)).toString().substring(0, 3) + "M";
200+
this.repositoryType = map.language;
201+
this.repositoryDes = map.description;
202+
this.repositoryIsFork = map.fork;
203+
this.license = map.license != null ? map.license.name : "";
204+
this.repositoryParentName = map.parent != null ? map.parent.fullName : null;
205+
this.created_at = CommonUtils.getNewsTimeStr(map.createdAt);
206+
this.push_at = CommonUtils.getNewsTimeStr(map.pushedAt);
206207
}
207208
}

0 commit comments

Comments
 (0)