Skip to content

Commit 625f49c

Browse files
committed
repos issue list
1 parent 9050f49 commit 625f49c

File tree

6 files changed

+139
-61
lines changed

6 files changed

+139
-61
lines changed

lib/common/ab/provider/repos/RepositoryIssueDbProvider.dart

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import 'dart:async';
2+
import 'dart:convert';
3+
14
import 'package:gsy_github_app_flutter/common/ab/SqlProvider.dart';
5+
import 'package:gsy_github_app_flutter/common/model/Issue.dart';
6+
import 'package:sqflite/sqflite.dart';
27

38
/**
49
* 仓库issue表
@@ -18,7 +23,9 @@ class RepositoryIssueDbProvider extends BaseDbProvider {
1823
final String columnState = "state";
1924
final String columnData = "data";
2025

21-
Map<String, dynamic> toMap() {
26+
RepositoryIssueDbProvider();
27+
28+
Map<String, dynamic> toMap(String fullName, String state, String data) {
2229
Map<String, dynamic> map = {columnFullName: fullName, columnState: state, columnData: data};
2330
if (id != null) {
2431
map[columnId] = id;
@@ -34,10 +41,57 @@ class RepositoryIssueDbProvider extends BaseDbProvider {
3441
}
3542

3643
@override
37-
tableSqlString() {}
44+
tableSqlString() {
45+
return tableBaseString(name, columnId) +
46+
'''
47+
$columnFullName text not null,
48+
$columnState text not null,
49+
$columnData text not null)
50+
''';
51+
}
3852

3953
@override
4054
tableName() {
4155
return name;
4256
}
43-
}
57+
58+
Future _getProvider(Database db, String fullName, String state) async {
59+
List<Map<String, dynamic>> maps = await db.query(name,
60+
columns: [columnId, columnFullName, columnState, columnData],
61+
where: "$columnFullName = ? and $columnState = ?",
62+
whereArgs: [fullName, state]);
63+
if (maps.length > 0) {
64+
RepositoryIssueDbProvider provider = RepositoryIssueDbProvider.fromMap(maps.first);
65+
return provider;
66+
}
67+
return null;
68+
}
69+
70+
///插入到数据库
71+
Future insert(String fullName, String state, String dataMapString) async {
72+
Database db = await getDataBase();
73+
var provider = await _getProvider(db, fullName, state);
74+
if (provider != null) {
75+
await db.delete(name, where: "$columnFullName = ? and $columnState = ?", whereArgs: [fullName, state]);
76+
}
77+
return await db.insert(name, toMap(fullName, state, dataMapString));
78+
}
79+
80+
///获取事件数据
81+
Future<List<Issue>> getData(String fullName, String branch) async {
82+
Database db = await getDataBase();
83+
84+
var provider = await _getProvider(db, fullName, branch);
85+
if (provider != null) {
86+
List<Issue> list = new List();
87+
List<dynamic> eventMap = json.decode(provider.data);
88+
if (eventMap.length > 0) {
89+
for (var item in eventMap) {
90+
list.add(Issue.fromJson(item));
91+
}
92+
}
93+
return list;
94+
}
95+
return null;
96+
}
97+
}

lib/common/dao/IssueDao.dart

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import 'dart:convert';
12
import 'dart:io';
23

34
import 'package:dio/dio.dart';
5+
import 'package:gsy_github_app_flutter/common/ab/provider/repos/RepositoryIssueDbProvider.dart';
46
import 'package:gsy_github_app_flutter/common/dao/DaoResult.dart';
57
import 'package:gsy_github_app_flutter/common/model/Issue.dart';
68
import 'package:gsy_github_app_flutter/common/net/Address.dart';
@@ -22,22 +24,41 @@ class IssueDao {
2224
* @param sort 排序类型 created updated等
2325
* @param direction 正序或者倒序
2426
*/
25-
static getRepositoryIssueDao(userName, repository, state, {sort, direction, page = 0}) async {
26-
String url = Address.getReposIssue(userName, repository, state, sort, direction) + Address.getPageParams("&", page);
27-
var res = await HttpManager.netFetch(url, null, {"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}, null);
28-
if (res != null && res.result) {
29-
List<Issue> list = new List();
30-
var data = res.data;
31-
if (data == null || data.length == 0) {
27+
static getRepositoryIssueDao(userName, repository, state, {sort, direction, page = 0, needDb = false}) async {
28+
String fullName = userName + "/" + repository;
29+
String dbState = state ?? "*";
30+
RepositoryIssueDbProvider provider = new RepositoryIssueDbProvider();
31+
32+
next() async {
33+
String url = Address.getReposIssue(userName, repository, state, sort, direction) + Address.getPageParams("&", page);
34+
var res = await HttpManager.netFetch(url, null, {"Accept": 'application/vnd.github.html,application/vnd.github.VERSION.raw'}, null);
35+
if (res != null && res.result) {
36+
List<Issue> list = new List();
37+
var data = res.data;
38+
if (data == null || data.length == 0) {
39+
return new DataResult(null, false);
40+
}
41+
for (int i = 0; i < data.length; i++) {
42+
list.add(Issue.fromJson(data[i]));
43+
}
44+
if (needDb) {
45+
provider.insert(fullName, dbState, json.encode(data));
46+
}
47+
return new DataResult(list, true);
48+
} else {
3249
return new DataResult(null, false);
3350
}
34-
for (int i = 0; i < data.length; i++) {
35-
list.add(Issue.fromJson(data[i]));
51+
}
52+
53+
if (needDb) {
54+
List<Issue> list = await provider.getData(fullName, dbState);
55+
if (list == null) {
56+
return await next();
3657
}
37-
return new DataResult(list, true);
38-
} else {
39-
return new DataResult(null, false);
58+
DataResult dataResult = new DataResult(list, true, next: next());
59+
return dataResult;
4060
}
61+
return await next();
4162
}
4263

4364
/**
@@ -139,8 +160,8 @@ class IssueDao {
139160
*/
140161
static lockIssueDao(userName, repository, number, locked) async {
141162
String url = Address.lockIssue(userName, repository, number);
142-
var res = await HttpManager.netFetch(
143-
url, null, {"Accept": 'application/vnd.github.VERSION.full+json'}, new Options(method: locked ? "DELETE" : 'PUT', contentType: ContentType.TEXT),
163+
var res = await HttpManager.netFetch(url, null, {"Accept": 'application/vnd.github.VERSION.full+json'},
164+
new Options(method: locked ? "DELETE" : 'PUT', contentType: ContentType.TEXT),
144165
noTip: true);
145166
if (res != null && res.result) {
146167
return new DataResult(res.data, true);

lib/common/utils/CommonUtils.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class CommonUtils {
2929
static final double DAYS_LIMIT = 30 * HOURS_LIMIT;
3030

3131
static String getDateStr(DateTime date) {
32+
if (date == null || date.toString() == null) {
33+
return "";
34+
} else if (date.toString().length < 10) {
35+
return date.toString();
36+
}
3237
return date.toString().substring(0, 10);
3338
}
3439

lib/page/PersonPage.dart

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ class _PersonState extends GSYListState<PersonPage> {
5151
_PersonState(this.userName);
5252

5353
_resolveUserInfo(res) {
54-
setState(() {
55-
userInfo = res.data;
56-
titleOptionControl.url = res.data.html_url;
57-
});
54+
if (isShow) {
55+
setState(() {
56+
userInfo = res.data;
57+
titleOptionControl.url = res.data.html_url;
58+
});
59+
}
5860
}
5961

6062
@override
@@ -64,6 +66,7 @@ class _PersonState extends GSYListState<PersonPage> {
6466
}
6567
isLoading = true;
6668
page = 1;
69+
6770
///从Dao中获取数据
6871
///如果第一次返回的是网络数据,next为空
6972
///如果返回的是数据库数据,next不为空
@@ -92,20 +95,24 @@ class _PersonState extends GSYListState<PersonPage> {
9295
_getFocusStatus();
9396
ReposDao.getUserRepository100StatusDao(_getUserName()).then((res) {
9497
if (res != null && res.result) {
95-
setState(() {
96-
beStaredCount = res.data.toString();
97-
});
98+
if (isShow) {
99+
setState(() {
100+
beStaredCount = res.data.toString();
101+
});
102+
}
98103
}
99104
});
100105
return null;
101106
}
102107

103108
_getFocusStatus() async {
104109
var focusRes = await UserDao.checkFollowDao(userName);
105-
setState(() {
106-
focus = (focusRes != null && focusRes.result) ? GSYStrings.user_focus : GSYStrings.user_un_focus;
107-
focusStatus = (focusRes != null && focusRes.result);
108-
});
110+
if (isShow) {
111+
setState(() {
112+
focus = (focusRes != null && focusRes.result) ? GSYStrings.user_focus : GSYStrings.user_un_focus;
113+
focusStatus = (focusRes != null && focusRes.result);
114+
});
115+
}
109116
}
110117

111118
_renderEventItem(index) {

lib/page/RepositoryDetailIssueListPage.dart

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,44 +66,35 @@ class _RepositoryDetailIssuePageState extends GSYListState<RepositoryDetailIssue
6666

6767
_getDataLogic(String searchString) async {
6868
if (searchString == null || searchString.trim().length == 0) {
69-
return await IssueDao.getRepositoryIssueDao(userName, reposName, issueState, page: page);
69+
return await IssueDao.getRepositoryIssueDao(userName, reposName, issueState, page: page, needDb: page <= 1);
7070
}
7171
return await IssueDao.searchRepositoryIssue(searchString, userName, reposName, this.issueState, page: this.page);
7272
}
7373

7474
_createIssue() {
7575
String title = "";
7676
String content = "";
77-
CommonUtils.showEditDialog(
78-
context,
79-
GSYStrings.issue_edit_issue,
80-
(titleValue) {
81-
title = titleValue;
82-
},
83-
(contentValue) {
84-
content = contentValue;
85-
},
86-
() {
87-
if (title == null || title.trim().length == 0) {
88-
Fluttertoast.showToast(msg: GSYStrings.issue_edit_issue_title_not_be_null);
89-
return;
90-
}
91-
if (content == null || content.trim().length == 0) {
92-
Fluttertoast.showToast(msg: GSYStrings.issue_edit_issue_content_not_be_null);
93-
return;
94-
}
95-
CommonUtils.showLoadingDialog(context);
96-
//提交修改
97-
IssueDao.createIssueDao(userName, reposName, {"title": title, "body": content}).then((result) {
98-
showRefreshLoading();
99-
Navigator.pop(context);
100-
Navigator.pop(context);
101-
});
102-
},
103-
needTitle: true,
104-
titleController: new TextEditingController(),
105-
valueController: new TextEditingController()
106-
);
77+
CommonUtils.showEditDialog(context, GSYStrings.issue_edit_issue, (titleValue) {
78+
title = titleValue;
79+
}, (contentValue) {
80+
content = contentValue;
81+
}, () {
82+
if (title == null || title.trim().length == 0) {
83+
Fluttertoast.showToast(msg: GSYStrings.issue_edit_issue_title_not_be_null);
84+
return;
85+
}
86+
if (content == null || content.trim().length == 0) {
87+
Fluttertoast.showToast(msg: GSYStrings.issue_edit_issue_content_not_be_null);
88+
return;
89+
}
90+
CommonUtils.showLoadingDialog(context);
91+
//提交修改
92+
IssueDao.createIssueDao(userName, reposName, {"title": title, "body": content}).then((result) {
93+
showRefreshLoading();
94+
Navigator.pop(context);
95+
Navigator.pop(context);
96+
});
97+
}, needTitle: true, titleController: new TextEditingController(), valueController: new TextEditingController());
10798
}
10899

109100
@override
@@ -145,7 +136,7 @@ class _RepositoryDetailIssuePageState extends GSYListState<RepositoryDetailIssue
145136
this.searchText = value;
146137
}, (value) {
147138
_resolveSelectIndex();
148-
}, (){
139+
}, () {
149140
_resolveSelectIndex();
150141
}),
151142
elevation: 0.0,

lib/widget/UserHeader.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class UserHeaderItem extends StatelessWidget {
9191
placeholder: GSYICons.DEFAULT_USER_ICON,
9292
//预览图
9393
fit: BoxFit.fitWidth,
94-
image: userInfo.avatar_url == null ? "http://null" : userInfo.avatar_url,
94+
image:userInfo.avatar_url ?? GSYICons.DEFAULT_REMOTE_PIC,
9595
width: 80.0,
9696
height: 80.0,
9797
),

0 commit comments

Comments
 (0)