mirror of
https://github.com/pd4d10/git-touch.git
synced 2026-04-30 19:37:35 -05:00
feat: style of home and notification screen
This commit is contained in:
@@ -1,201 +1,180 @@
|
||||
import '../utils.dart';
|
||||
import '../models/event.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
// import '../issue.dart';
|
||||
// import '../user.dart';
|
||||
|
||||
// class Strong extends StatelessWidget {
|
||||
// final String text;
|
||||
|
||||
// @override
|
||||
// build(context) {
|
||||
// return TextSpan(
|
||||
// text: text,
|
||||
// style: TextStyle(
|
||||
// fontWeight: FontWeight.bold,
|
||||
// color: Color(0xff24292e),
|
||||
// ),
|
||||
// // recognizer: recognizer,
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
class _Avatar extends StatelessWidget {
|
||||
final String url;
|
||||
_Avatar(this.url);
|
||||
|
||||
@override
|
||||
build(context) {
|
||||
return CircleAvatar(
|
||||
backgroundImage: NetworkImage(url),
|
||||
radius: 24.0,
|
||||
);
|
||||
}
|
||||
}
|
||||
import 'package:git_flux/screens/screens.dart';
|
||||
import 'package:git_flux/utils/utils.dart';
|
||||
|
||||
/// Events types:
|
||||
///
|
||||
/// https://developer.github.com/v3/activity/events/types/#event-types--payloads
|
||||
class EventItem extends StatelessWidget {
|
||||
final Event event;
|
||||
EventItem(this.event);
|
||||
|
||||
Widget getEventItemByType(BuildContext context) {
|
||||
TextSpan _buildEvent(BuildContext context) {
|
||||
switch (event.type) {
|
||||
case 'IssuesEvent':
|
||||
return RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: CupertinoColors.black),
|
||||
children: [
|
||||
_user(event, context),
|
||||
TextSpan(text: ' ${event.payload['action']} issue '),
|
||||
_strong(event.repo.name),
|
||||
TextSpan(
|
||||
text: '#' + event.payload['issue']['number'].toString(),
|
||||
),
|
||||
TextSpan(
|
||||
text: event.payload['issue']['title'],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
return TextSpan(children: [
|
||||
TextSpan(text: ' ${event.payload['action']} issue '),
|
||||
_buildIssue(context),
|
||||
TextSpan(text: ' at '),
|
||||
_buildRepo(context),
|
||||
]);
|
||||
case 'PushEvent':
|
||||
return RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: CupertinoColors.black),
|
||||
children: [
|
||||
_user(event, context),
|
||||
TextSpan(text: ' pushed to '),
|
||||
TextSpan(
|
||||
text: event.payload['ref'],
|
||||
style: TextStyle(color: CupertinoColors.activeBlue),
|
||||
),
|
||||
TextSpan(text: ' in '),
|
||||
_strong(event.repo.name),
|
||||
TextSpan(text: '')
|
||||
],
|
||||
return TextSpan(children: [
|
||||
TextSpan(text: ' pushed to '),
|
||||
TextSpan(
|
||||
text: event.payload['ref'],
|
||||
style: TextStyle(color: CupertinoColors.activeBlue),
|
||||
),
|
||||
);
|
||||
TextSpan(text: ' at '),
|
||||
_buildRepo(context),
|
||||
TextSpan(text: '')
|
||||
]);
|
||||
case 'PullRequestEvent':
|
||||
return RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: CupertinoColors.black),
|
||||
children: [
|
||||
_user(event, context),
|
||||
TextSpan(text: ' ${event.payload['action']} pull request '),
|
||||
_strong(event.repo.name),
|
||||
TextSpan(text: '#' + event.payload['number'].toString()),
|
||||
TextSpan(text: event.payload['pull_request']['title'])
|
||||
],
|
||||
),
|
||||
);
|
||||
return TextSpan(children: [
|
||||
TextSpan(text: ' ${event.payload['action']} pull request '),
|
||||
_buildPullRequest(context),
|
||||
TextSpan(text: ' at '),
|
||||
_buildRepo(context),
|
||||
]);
|
||||
case 'PullRequestReviewCommentEvent':
|
||||
return TextSpan(children: [
|
||||
TextSpan(text: ' reviewed pull request '),
|
||||
_buildPullRequest(context),
|
||||
TextSpan(text: ' at '),
|
||||
_buildRepo(context),
|
||||
]);
|
||||
case 'WatchEvent':
|
||||
return RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: CupertinoColors.black),
|
||||
children: [
|
||||
_user(event, context),
|
||||
TextSpan(text: ' ${event.payload['action']} '),
|
||||
_strong(event.repo.name),
|
||||
],
|
||||
),
|
||||
);
|
||||
return TextSpan(children: [
|
||||
TextSpan(text: ' ${event.payload['action']} '),
|
||||
_buildRepo(context)
|
||||
]);
|
||||
case 'IssueCommentEvent':
|
||||
return TextSpan(children: [
|
||||
TextSpan(text: ' commented on issue '),
|
||||
_buildIssue(context),
|
||||
TextSpan(text: ' at '),
|
||||
_buildRepo(context),
|
||||
// TextSpan(text: event.payload['comment']['body'])
|
||||
]);
|
||||
default:
|
||||
return Text(
|
||||
'Not implement yet',
|
||||
return TextSpan(
|
||||
text: 'Type ${event.type} Not implement yet',
|
||||
style: TextStyle(color: CupertinoColors.destructiveRed),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _buildOriginalComment() {
|
||||
switch (event.type) {
|
||||
case 'IssueCommentEvent':
|
||||
return event.payload['comment']['body'];
|
||||
case 'IssuesEvent':
|
||||
return event.payload['issue']['title'];
|
||||
case 'PullRequestEvent':
|
||||
return event.payload['pull_request']['title'];
|
||||
case 'PullRequestReviewCommentEvent':
|
||||
return event.payload['comment']['body'];
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
String _buildComment() {
|
||||
return _buildOriginalComment();
|
||||
}
|
||||
|
||||
TextSpan _buildLink(BuildContext context, String text, Function handle) {
|
||||
return TextSpan(
|
||||
text: text,
|
||||
style: TextStyle(color: Color(0xff0366d6)),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
Navigator.of(context).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) {
|
||||
return handle();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
TextSpan _buildRepo(BuildContext context) {
|
||||
return _buildLink(context, event.repo.name, () => RepoScreen());
|
||||
}
|
||||
|
||||
TextSpan _buildIssue(BuildContext context) {
|
||||
return _buildLink(context,
|
||||
'#' + event.payload['issue']['number'].toString(), () => UserScreen());
|
||||
}
|
||||
|
||||
TextSpan _buildPullRequest(BuildContext context) {
|
||||
return _buildLink(
|
||||
context,
|
||||
'#' + event.payload['pull_request']['number'].toString(),
|
||||
() => UserScreen());
|
||||
}
|
||||
|
||||
IconData _buildIconData(BuildContext context) {
|
||||
switch (event.type) {
|
||||
case 'IssueCommentEvent':
|
||||
return Octicons.comment_discussion;
|
||||
case 'IssuesEvent':
|
||||
return Octicons.issue_opened;
|
||||
case 'PullRequestEvent':
|
||||
return Octicons.git_pull_request;
|
||||
case 'PushEvent':
|
||||
return Octicons.repo_push;
|
||||
case 'WatchEvent':
|
||||
return Octicons.star;
|
||||
default:
|
||||
return Octicons.octoface;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
build(context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 16.0),
|
||||
padding: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(width: 1.0, color: Color(0xFFFFFFFFFF)),
|
||||
left: BorderSide(width: 1.0, color: Color(0xFFFFFFFFFF)),
|
||||
right: BorderSide(width: 1.0, color: Color(0xFFFF000000)),
|
||||
bottom: BorderSide(width: 1.0, color: Color(0xFFFF000000)),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
_Avatar(event.actor.avatarUrl),
|
||||
Expanded(child: getEventItemByType(context)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
TextSpan _strong(String text, [GestureRecognizer recognizer]) {
|
||||
return TextSpan(
|
||||
text: text,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xff24292e),
|
||||
),
|
||||
recognizer: recognizer,
|
||||
);
|
||||
}
|
||||
|
||||
TextSpan _user(Event event, context) {
|
||||
return _strong(
|
||||
event.actor.login,
|
||||
// TapGestureRecognizer()
|
||||
// ..onTap = () {
|
||||
// Navigator.of(context).push(
|
||||
// CupertinoPageRoute(
|
||||
// builder: (context) {
|
||||
// return IosUserPage(event.actor, event.avatar);
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
);
|
||||
}
|
||||
|
||||
class IssuesEvent extends StatelessWidget {
|
||||
final Event event;
|
||||
IssuesEvent(this.event);
|
||||
|
||||
@override
|
||||
build(context) {
|
||||
return RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: CupertinoColors.black),
|
||||
children: [
|
||||
_user(event, context),
|
||||
TextSpan(text: ' ${event.payload['action']} issue '),
|
||||
_strong(event.repo.name),
|
||||
TextSpan(
|
||||
text: '#' + event.payload['issue']['number'].toString(),
|
||||
border: Border(
|
||||
bottom: BorderSide(color: CupertinoColors.lightBackgroundGray))),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
CircleAvatar(
|
||||
backgroundColor: Colors.transparent,
|
||||
backgroundImage: NetworkImage(event.actor.avatarUrl),
|
||||
radius: 16,
|
||||
),
|
||||
Padding(padding: EdgeInsets.only(left: 10)),
|
||||
Expanded(
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: Color(0xff24292e), height: 1.2),
|
||||
children: <TextSpan>[
|
||||
_buildLink(
|
||||
context, event.actor.login, () => UserScreen()),
|
||||
_buildEvent(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(padding: EdgeInsets.only(left: 10)),
|
||||
Icon(_buildIconData(context),
|
||||
color: CupertinoColors.inactiveGray),
|
||||
],
|
||||
),
|
||||
TextSpan(
|
||||
text: event.payload['issue']['title'],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class IssueCommentEvent extends StatelessWidget {
|
||||
final Event event;
|
||||
IssueCommentEvent(this.event);
|
||||
|
||||
@override
|
||||
build(context) {
|
||||
return RichText(
|
||||
text: TextSpan(
|
||||
style: TextStyle(color: CupertinoColors.black),
|
||||
children: [
|
||||
_user(event, context),
|
||||
TextSpan(text: ' commented on issue '),
|
||||
_strong(event.repo.name),
|
||||
TextSpan(text: '#' + event.payload['issue']['number'].toString()),
|
||||
TextSpan(text: event.payload['comment']['body'])
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 42, top: 8),
|
||||
child: Text(_buildComment(),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: Color(0xffaaaaaa))))
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_flux/utils.dart';
|
||||
import 'package:git_flux/utils/utils.dart';
|
||||
|
||||
Future queryUser(String login) async {
|
||||
var data = await query('''
|
||||
|
||||
Reference in New Issue
Block a user