Skip to content

Commit a87de60

Browse files
committed
增加issue搜索
1 parent 169532c commit a87de60

3 files changed

Lines changed: 61 additions & 8 deletions

File tree

‎lib/common/dao/IssueDao.dart‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:gsy_github_app_flutter/common/net/Api.dart';
44
import 'package:gsy_github_app_flutter/widget/IssueItem.dart';
55

66
/**
7+
* Issue相关
78
* Created by guoshuyu
89
* Date: 2018-07-19
910
*/
@@ -35,4 +36,36 @@ class IssueDao {
3536
return new DataResult(null, false);
3637
}
3738
}
39+
40+
/**
41+
* 搜索仓库issue
42+
* @param q 搜索关键字
43+
* @param name 用户名
44+
* @param reposName 仓库名
45+
* @param page
46+
* @param state 问题状态,all open closed
47+
*/
48+
static searchRepositoryIssue(q, name, reposName, state, {page = 1}) async {
49+
String qu;
50+
if (state == null || state == 'all') {
51+
qu = q + "+repo%3A${name}%2F${reposName}";
52+
} else {
53+
qu = q + "+repo%3A${name}%2F${reposName}+state%3A${state}";
54+
}
55+
String url = Address.repositoryIssueSearch(qu) + Address.getPageParams("&", page);
56+
var res = await HttpManager.netFetch(url, null, null, null);
57+
if (res != null && res.result) {
58+
List<IssueItemViewModel> list = new List();
59+
var data = res.data["items"];
60+
if (data == null || data.length == 0) {
61+
return new DataResult(null, false);
62+
}
63+
for (int i = 0; i < data.length; i++) {
64+
list.add(IssueItemViewModel.fromMap(data[i]));
65+
}
66+
return new DataResult(list, true);
67+
} else {
68+
return new DataResult(null, false);
69+
}
70+
}
3871
}

‎lib/page/RepositoryDetailIssueList.dart‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ class _RepositoryDetailIssuePageState extends GSYListState<RepositoryDetailIssue
2929

3030
final String reposName;
3131

32+
String searchText;
3233
String issueState;
34+
int selectIndex;
3335

3436
_RepositoryDetailIssuePageState(this.userName, this.reposName);
3537

@@ -41,7 +43,7 @@ class _RepositoryDetailIssuePageState extends GSYListState<RepositoryDetailIssue
4143
);
4244
}
4345

44-
_resolveSelectIndex(selectIndex) {
46+
_resolveSelectIndex() {
4547
clearData();
4648
switch (selectIndex) {
4749
case 0:
@@ -57,6 +59,13 @@ class _RepositoryDetailIssuePageState extends GSYListState<RepositoryDetailIssue
5759
showRefreshLoading();
5860
}
5961

62+
_getDataLogic(String searchString) async {
63+
if (searchString == null || searchString.trim().length == 0) {
64+
return await IssueDao.getRepositoryIssueDao(userName, reposName, issueState, page: page);
65+
}
66+
return await IssueDao.searchRepositoryIssue(searchString, userName, reposName, this.issueState, page: this.page);
67+
}
68+
6069
@override
6170
bool get wantKeepAlive => true;
6271

@@ -68,12 +77,12 @@ class _RepositoryDetailIssuePageState extends GSYListState<RepositoryDetailIssue
6877

6978
@override
7079
requestLoadMore() async {
71-
return await IssueDao.getRepositoryIssueDao(userName, reposName, issueState, page: page);
80+
return await _getDataLogic(this.searchText);
7281
}
7382

7483
@override
7584
requestRefresh() async {
76-
return await IssueDao.getRepositoryIssueDao(userName, reposName, issueState, page: page);
85+
return await _getDataLogic(this.searchText);
7786
}
7887

7988
@override
@@ -83,15 +92,20 @@ class _RepositoryDetailIssuePageState extends GSYListState<RepositoryDetailIssue
8392
backgroundColor: Color(GSYColors.mainBackgroundColor),
8493
appBar: new AppBar(
8594
leading: new Container(),
86-
flexibleSpace: GSYSearchInputWidget((value){}),
95+
flexibleSpace: GSYSearchInputWidget((value) {
96+
this.searchText = value;
97+
}, (value) {
98+
_resolveSelectIndex();
99+
}),
87100
elevation: 0.0,
88101
backgroundColor: Color(GSYColors.mainBackgroundColor),
89102
bottom: new GSYSelectItemWidget([
90103
GSYStrings.repos_tab_issue_all,
91104
GSYStrings.repos_tab_issue_open,
92105
GSYStrings.repos_tab_issue_closed,
93106
], (selectIndex) {
94-
_resolveSelectIndex(selectIndex);
107+
this.selectIndex = selectIndex;
108+
_resolveSelectIndex();
95109
}),
96110
),
97111
body: GSYPullLoadWidget(

‎lib/widget/GSYSearchInputWidget.dart‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@ import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
77
* Date: 2018-07-20
88
*/
99
class GSYSearchInputWidget extends StatelessWidget {
10+
11+
final ValueChanged<String> onChanged;
12+
1013
final ValueChanged<String> onSubmitted;
1114

12-
GSYSearchInputWidget(this.onSubmitted);
15+
GSYSearchInputWidget(this.onChanged, this.onSubmitted);
1316

1417
@override
1518
Widget build(BuildContext context) {
1619
return new Container(
17-
decoration: new BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(4.0)),
18-
color: Colors.white, border: new Border.all(color: Color(GSYColors.subTextColor), width: 0.3)),
20+
decoration: new BoxDecoration(
21+
borderRadius: BorderRadius.all(Radius.circular(4.0)),
22+
color: Colors.white,
23+
border: new Border.all(color: Color(GSYColors.subTextColor), width: 0.3)),
1924
padding: new EdgeInsets.only(left: 20.0, top: 12.0, right: 20.0, bottom: 12.0),
2025
child: new TextField(
2126
autofocus: false,
@@ -24,6 +29,7 @@ class GSYSearchInputWidget extends StatelessWidget {
2429
hintStyle: GSYConstant.middleSubText,
2530
),
2631
style: GSYConstant.middleText,
32+
onChanged: onChanged,
2733
onSubmitted: onSubmitted),
2834
);
2935
}

0 commit comments

Comments
 (0)