Skip to content

Commit a24ccfa

Browse files
committed
♿️Add chrome custom tab for issues,pull request detail
♻️ code refactor
1 parent e4514da commit a24ccfa

File tree

13 files changed

+307
-111
lines changed

13 files changed

+307
-111
lines changed

lib/bloc/User/User_model.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,13 @@ class RepositoriesNode extends Equatable {
361361
this.owner,
362362
this.languages,
363363
this.stargazers,
364+
this.url,
364365
this.type});
365366

366367
final String name;
367368
final String description;
368369
final Owner owner;
370+
final String url;
369371
final Languages languages;
370372
final Followers stargazers;
371373
final String type;
@@ -377,6 +379,7 @@ class RepositoriesNode extends Equatable {
377379

378380
factory RepositoriesNode.fromJson(Map<String, dynamic> json) =>
379381
RepositoriesNode(
382+
url:json["url"] == null ? null : json["url"],
380383
name: json["name"] == null ? null : json["name"],
381384
description: json["description"] == null ? null : json["description"],
382385
owner: json["owner"] == null ? null : Owner.fromJson(json["owner"]),
@@ -392,6 +395,7 @@ class RepositoriesNode extends Equatable {
392395
Map<String, dynamic> toJson() => {
393396
"name": name == null ? null : name,
394397
"owner": owner == null ? null : owner.toJson(),
398+
"url": url == null ? null : url,
395399
"stargazers": stargazers == null ? null : stargazers.toJson(),
396400
};
397401
Map<String, dynamic> toDbJson() => {

lib/bloc/issues/issues_model.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:flutter_github_connect/bloc/User/User_model.dart';
12
import 'package:flutter_github_connect/bloc/notification/notification_model.dart';
23
import 'package:flutter_github_connect/bloc/search/model/search_userModel.dart';
34
import 'package:flutter_github_connect/model/page_info_model.dart';
@@ -96,7 +97,7 @@ class IssuesModel {
9697
bool closed;
9798
String authorAssociation;
9899
Author author;
99-
Repository repository;
100+
RepositoriesNode repository;
100101
Labels labels;
101102
String closedAt;
102103
String type;
@@ -128,7 +129,7 @@ class IssuesModel {
128129
author =
129130
json['author'] != null ? new Author.fromJson(json['author']) : null;
130131
repository = json['repository'] != null
131-
? new Repository.fromJson(json['repository'])
132+
? new RepositoriesNode.fromJson(json['repository'])
132133
: null;
133134
labels =
134135
json['labels'] != null ? new Labels.fromJson(json['labels']) : null;
@@ -162,20 +163,31 @@ class Author {
162163
String login;
163164
String avatarUrl;
164165
String url;
166+
String name;
165167

166168
Author({this.login, this.avatarUrl, this.url});
167169

168170
Author.fromJson(Map<String, dynamic> json) {
169171
login = json['login'];
170172
avatarUrl = json['avatarUrl'];
171173
url = json['url'];
174+
name = json['name'];
172175
}
173176

174177
Map<String, dynamic> toJson() {
175178
final Map<String, dynamic> data = new Map<String, dynamic>();
176179
data['login'] = this.login;
177180
data['avatarUrl'] = this.avatarUrl;
178181
data['url'] = this.url;
182+
data['name'] = this.name;
179183
return data;
180184
}
185+
UserModel toUserModel() {
186+
return UserModel(
187+
login: this.login,
188+
avatarUrl: this.avatarUrl,
189+
name: this.name,
190+
url: this.url
191+
);
192+
}
181193
}

lib/helper/utility.dart

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import 'package:flutter/foundation.dart';
2+
import 'package:flutter/material.dart';
13
import 'package:intl/intl.dart';
24
import 'package:share/share.dart';
35
import 'package:url_launcher/url_launcher.dart';
6+
import 'package:flutter_custom_tabs/flutter_custom_tabs.dart' as custom;
47

58
class Utility {
69
Utility._internal();
@@ -20,20 +23,23 @@ class Utility {
2023
}
2124
}
2225

23-
static share(String message){
24-
Share.share(message,);
26+
static share(String message) {
27+
Share.share(
28+
message,
29+
);
2530
}
31+
2632
static String getPassedTime(String date) {
2733
if (date == null || date.isEmpty) {
2834
return '';
2935
}
3036
String msg = '';
3137
var dt = DateTime.parse(date).toLocal();
32-
38+
3339
if (DateTime.now().toLocal().isBefore(dt)) {
3440
return DateFormat.jm().format(DateTime.parse(date).toLocal()).toString();
3541
}
36-
42+
3743
var dur = DateTime.now().toLocal().difference(dt);
3844
if (dur.inDays > 0) {
3945
msg = '${dur.inDays} d';
@@ -49,4 +55,31 @@ class Utility {
4955
}
5056
return msg;
5157
}
58+
59+
static void launchURL(BuildContext context, String url) async {
60+
if(url == null){
61+
return;
62+
}
63+
try {
64+
await custom.launch(
65+
url,
66+
option: new custom.CustomTabsOption(
67+
toolbarColor: Theme.of(context).primaryColor,
68+
enableDefaultShare: true,
69+
enableUrlBarHiding: true,
70+
showPageTitle: true,
71+
animation: new custom.CustomTabsAnimation.slideIn(),
72+
extraCustomTabs: <String>[
73+
// ref. https://play.google.com/store/apps/details?id=org.mozilla.firefox
74+
'org.mozilla.firefox',
75+
// ref. https://play.google.com/store/apps/details?id=com.microsoft.emmx
76+
'com.microsoft.emmx',
77+
],
78+
),
79+
);
80+
} catch (e) {
81+
// An exception is thrown if browser app is not installed on Android device.
82+
debugPrint(e.toString());
83+
}
84+
}
5285
}

lib/resources/grapgqlApi/graphql_query_api.dart

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Apis {
4242
isViewer
4343
location
4444
login
45-
organizationVerifiedDomainEmails(login: $login)
45+
#organizationVerifiedDomainEmails(login: $login)
4646
pinnedItemsRemaining
4747
projectsResourcePath
4848
projectsUrl
@@ -170,10 +170,10 @@ class Apis {
170170
''';
171171

172172
static String search =
173-
r'''query userInfo($query: String!, $type:SearchType!,$endCursor: String) {
173+
r'''query userInfo($query: String!, $type: SearchType!, $endCursor: String) {
174174
search(query: $query, first: 30, type: $type, after: $endCursor) {
175-
pageInfo{
176-
endCursor
175+
pageInfo {
176+
endCursor
177177
}
178178
userCount
179179
nodes {
@@ -185,42 +185,40 @@ class Apis {
185185
bio
186186
login
187187
}
188-
# ... on Organization {
189-
# name
190-
# avatarUrl
191-
# login
192-
# }
193188
... on Issue {
194189
__typename
195190
url
196191
title
197192
number
198193
closed
199194
closedAt
195+
createdAt
200196
repository {
201197
name
202-
owner{
203-
login
198+
url
199+
owner {
200+
login
204201
}
205202
}
206-
labels(first: 10) {
203+
labels(first: 10) {
207204
__typename
208205
nodes {
209-
color
210-
name
211-
}
212-
}
206+
color
207+
name
208+
}
209+
}
213210
author {
214211
login
215212
avatarUrl
216213
url
217214
}
218215
state
219-
}
216+
}
220217
... on Repository {
221218
__typename
222219
id
223220
name
221+
url
224222
description
225223
stargazers {
226224
totalCount
@@ -240,7 +238,7 @@ class Apis {
240238
}
241239
... on PullRequest {
242240
__typename
243-
url
241+
url
244242
number
245243
closed
246244
title
@@ -251,6 +249,7 @@ class Apis {
251249
}
252250
repository {
253251
nameWithOwner
252+
url
254253
}
255254
state
256255
closedAt
@@ -263,7 +262,8 @@ class Apis {
263262
}
264263
}
265264
}
266-
}''';
265+
}
266+
''';
267267

268268
static const String userName = r'''query {
269269
viewer {

lib/ui/page/pullRequest/pull_request_screen.dart

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import 'package:get_it/get_it.dart';
1010
class PullRequestScreen extends StatelessWidget {
1111
final UserPullRequests pullRequest;
1212
final ScrollController controller;
13-
const PullRequestScreen({Key key, this.pullRequest, this.controller})
14-
: super(key: key);
15-
Widget _pullRequestTile(context, Node model, String username,
16-
{bool isCommented = false}) {
13+
const PullRequestScreen({Key key, this.pullRequest, this.controller}) : super(key: key);
14+
Widget _pullRequestTile(context, Node model, String username, {bool isCommented = false}) {
1715
final double widthOffset = 58.0;
1816
return GCard(
1917
color: Theme.of(context).colorScheme.surface,
@@ -62,8 +60,7 @@ class PullRequestScreen extends StatelessWidget {
6260
width: MediaQuery.of(context).size.width - widthOffset,
6361
alignment: Alignment.bottomRight,
6462
child: Text(
65-
Utility.getPassedTime(model.createdAt.toString()) +
66-
" ago",
63+
Utility.getPassedTime(model.createdAt.toString()) + " ago",
6764
style: Theme.of(context).textTheme.subtitle2,
6865
),
6966
)
@@ -73,9 +70,7 @@ class PullRequestScreen extends StatelessWidget {
7370
],
7471
).vP16)
7572
.ripple(() {
76-
Utility.launchTo(
77-
model.url,
78-
);
73+
Utility.launchURL(context, model.url);
7974
});
8075
}
8176

@@ -129,10 +124,8 @@ class PullRequestScreen extends StatelessWidget {
129124
return Column(
130125
children: <Widget>[
131126
// Text(model.type.toString()),
132-
_pullRequestTile(context, model, snapshot.data ?? "",
133-
isCommented: true),
134-
if (pullRequest.nodes.last != model)
135-
Divider(height: 1, indent: 50),
127+
_pullRequestTile(context, model, snapshot.data ?? "", isCommented: true),
128+
if (pullRequest.nodes.last != model) Divider(height: 1, indent: 50),
136129
],
137130
);
138131
},

lib/ui/page/repo/commit/commit_screen.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ class CommitScreen extends StatelessWidget {
149149
decoration: TextDecoration.underline,
150150
),
151151
).ripple(() {
152-
Utility.launchTo(model.url);
152+
// Utility.launchTo(model.url);
153+
Utility.launchURL(context, model.url);
153154
Navigator.pop(context);
154155
}),
155156
],

lib/ui/page/repo/repo_detail_screen.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ class RepoDetailScreen extends StatelessWidget {
185185
}
186186
),
187187
_getUtilRos(context, "Browse Code", icon: null, onPressed: (){
188-
Utility.launchTo("https://github.com/${model.owner.login}/${model.name}");
188+
Utility.launchURL(context,"https://github.com/${model.owner.login}/${model.name}");
189+
// Utility.launchTo("https://github.com/${model.owner.login}/${model.name}");
189190
}),
190191
],
191192
),

0 commit comments

Comments
 (0)