mirror of
https://github.com/pd4d10/git-touch.git
synced 2026-05-01 03:47:36 -05:00
feat: style of home and notification screen
This commit is contained in:
72
lib/utils/github.dart
Normal file
72
lib/utils/github.dart
Normal file
@@ -0,0 +1,72 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:github/server.dart';
|
||||
export 'package:github/server.dart';
|
||||
import '../token.dart';
|
||||
|
||||
var ghClient = createGitHubClient(auth: Authentication.withToken(token));
|
||||
|
||||
final prefix = 'https://api.github.com';
|
||||
final endpoint = '/graphql';
|
||||
|
||||
Future<dynamic> getWithCredentials(String url) async {
|
||||
final res = await http.get(
|
||||
prefix + url,
|
||||
headers: {HttpHeaders.authorizationHeader: 'token $token'},
|
||||
);
|
||||
final data = json.decode(res.body);
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<dynamic> postWithCredentials(String url, String body) async {
|
||||
final res = await http.post(
|
||||
prefix + url,
|
||||
headers: {HttpHeaders.authorizationHeader: 'token $token'},
|
||||
body: body,
|
||||
);
|
||||
final data = json.decode(res.body);
|
||||
return data;
|
||||
}
|
||||
|
||||
Future<dynamic> query(String query) async {
|
||||
final data =
|
||||
await postWithCredentials('/graphql', json.encode({'query': query}));
|
||||
if (data['errors'] != null) {
|
||||
throw new Exception(data['errors'].toString());
|
||||
}
|
||||
print(data);
|
||||
return data['data'];
|
||||
}
|
||||
|
||||
Future<List<Event>> fetchEvents(int page) async {
|
||||
List data = await getWithCredentials(
|
||||
'/users/pd4d10/received_events/public?page=$page',
|
||||
);
|
||||
return data.map<Event>((item) => Event.fromJSON(item)).toList();
|
||||
}
|
||||
|
||||
class NotificationGroup {
|
||||
String fullName;
|
||||
List<Notification> items = [];
|
||||
|
||||
NotificationGroup(this.fullName);
|
||||
}
|
||||
|
||||
Future<List<NotificationGroup>> fetchNotifications([int index = 0]) async {
|
||||
var data = await ghClient.activity
|
||||
.listNotifications(all: index == 2, participating: index == 1)
|
||||
.toList();
|
||||
|
||||
Map<String, NotificationGroup> groupMap = {};
|
||||
data.forEach((item) {
|
||||
String repo = item.repository.fullName;
|
||||
if (groupMap[repo] == null) {
|
||||
groupMap[repo] = NotificationGroup(repo);
|
||||
}
|
||||
|
||||
groupMap[repo].items.add(item);
|
||||
});
|
||||
return groupMap.values.toList();
|
||||
}
|
||||
203
lib/utils/octicons.dart
Normal file
203
lib/utils/octicons.dart
Normal file
@@ -0,0 +1,203 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Octicons {
|
||||
static const IconData alert = IconData(61696, fontFamily: 'Octicons');
|
||||
static const IconData archive = IconData(61697, fontFamily: 'Octicons');
|
||||
static const IconData arrow_down = IconData(61698, fontFamily: 'Octicons');
|
||||
static const IconData arrow_left = IconData(61699, fontFamily: 'Octicons');
|
||||
static const IconData arrow_right = IconData(61700, fontFamily: 'Octicons');
|
||||
static const IconData arrow_small_down =
|
||||
IconData(61701, fontFamily: 'Octicons');
|
||||
static const IconData arrow_small_left =
|
||||
IconData(61702, fontFamily: 'Octicons');
|
||||
static const IconData arrow_small_right =
|
||||
IconData(61703, fontFamily: 'Octicons');
|
||||
static const IconData arrow_small_up =
|
||||
IconData(61704, fontFamily: 'Octicons');
|
||||
static const IconData arrow_up = IconData(61705, fontFamily: 'Octicons');
|
||||
static const IconData beaker = IconData(61706, fontFamily: 'Octicons');
|
||||
static const IconData bell = IconData(61707, fontFamily: 'Octicons');
|
||||
static const IconData bold = IconData(61708, fontFamily: 'Octicons');
|
||||
static const IconData book = IconData(61709, fontFamily: 'Octicons');
|
||||
static const IconData bookmark = IconData(61710, fontFamily: 'Octicons');
|
||||
static const IconData briefcase = IconData(61711, fontFamily: 'Octicons');
|
||||
static const IconData broadcast = IconData(61712, fontFamily: 'Octicons');
|
||||
static const IconData browser = IconData(61713, fontFamily: 'Octicons');
|
||||
static const IconData bug = IconData(61714, fontFamily: 'Octicons');
|
||||
static const IconData calendar = IconData(61715, fontFamily: 'Octicons');
|
||||
static const IconData check = IconData(61716, fontFamily: 'Octicons');
|
||||
static const IconData checklist = IconData(61717, fontFamily: 'Octicons');
|
||||
static const IconData chevron_down = IconData(61718, fontFamily: 'Octicons');
|
||||
static const IconData chevron_left = IconData(61719, fontFamily: 'Octicons');
|
||||
static const IconData chevron_right = IconData(61720, fontFamily: 'Octicons');
|
||||
static const IconData chevron_up = IconData(61721, fontFamily: 'Octicons');
|
||||
static const IconData circle_slash = IconData(61722, fontFamily: 'Octicons');
|
||||
static const IconData circuit_board = IconData(61723, fontFamily: 'Octicons');
|
||||
static const IconData clippy = IconData(61724, fontFamily: 'Octicons');
|
||||
static const IconData clock = IconData(61725, fontFamily: 'Octicons');
|
||||
static const IconData cloud_download =
|
||||
IconData(61726, fontFamily: 'Octicons');
|
||||
static const IconData cloud_upload = IconData(61727, fontFamily: 'Octicons');
|
||||
static const IconData code = IconData(61728, fontFamily: 'Octicons');
|
||||
static const IconData comment = IconData(61729, fontFamily: 'Octicons');
|
||||
static const IconData comment_discussion =
|
||||
IconData(61730, fontFamily: 'Octicons');
|
||||
static const IconData credit_card = IconData(61731, fontFamily: 'Octicons');
|
||||
static const IconData dash = IconData(61732, fontFamily: 'Octicons');
|
||||
static const IconData dashboard = IconData(61733, fontFamily: 'Octicons');
|
||||
static const IconData database = IconData(61734, fontFamily: 'Octicons');
|
||||
static const IconData desktop_download =
|
||||
IconData(61735, fontFamily: 'Octicons');
|
||||
static const IconData device_camera = IconData(61736, fontFamily: 'Octicons');
|
||||
static const IconData device_camera_video =
|
||||
IconData(61737, fontFamily: 'Octicons');
|
||||
static const IconData device_desktop =
|
||||
IconData(61738, fontFamily: 'Octicons');
|
||||
static const IconData device_mobile = IconData(61739, fontFamily: 'Octicons');
|
||||
static const IconData diff = IconData(61740, fontFamily: 'Octicons');
|
||||
static const IconData diff_added = IconData(61741, fontFamily: 'Octicons');
|
||||
static const IconData diff_ignored = IconData(61742, fontFamily: 'Octicons');
|
||||
static const IconData diff_modified = IconData(61743, fontFamily: 'Octicons');
|
||||
static const IconData diff_removed = IconData(61744, fontFamily: 'Octicons');
|
||||
static const IconData diff_renamed = IconData(61745, fontFamily: 'Octicons');
|
||||
static const IconData ellipsis = IconData(61746, fontFamily: 'Octicons');
|
||||
static const IconData eye = IconData(61747, fontFamily: 'Octicons');
|
||||
static const IconData file = IconData(61748, fontFamily: 'Octicons');
|
||||
static const IconData file_binary = IconData(61749, fontFamily: 'Octicons');
|
||||
static const IconData file_code = IconData(61750, fontFamily: 'Octicons');
|
||||
static const IconData file_directory =
|
||||
IconData(61751, fontFamily: 'Octicons');
|
||||
static const IconData file_media = IconData(61752, fontFamily: 'Octicons');
|
||||
static const IconData file_pdf = IconData(61753, fontFamily: 'Octicons');
|
||||
static const IconData file_submodule =
|
||||
IconData(61754, fontFamily: 'Octicons');
|
||||
static const IconData file_symlink_directory =
|
||||
IconData(61755, fontFamily: 'Octicons');
|
||||
static const IconData file_symlink_file =
|
||||
IconData(61756, fontFamily: 'Octicons');
|
||||
static const IconData file_zip = IconData(61757, fontFamily: 'Octicons');
|
||||
static const IconData flame = IconData(61758, fontFamily: 'Octicons');
|
||||
static const IconData fold = IconData(61759, fontFamily: 'Octicons');
|
||||
static const IconData gear = IconData(61760, fontFamily: 'Octicons');
|
||||
static const IconData gift = IconData(61761, fontFamily: 'Octicons');
|
||||
static const IconData gist = IconData(61762, fontFamily: 'Octicons');
|
||||
static const IconData gist_secret = IconData(61763, fontFamily: 'Octicons');
|
||||
static const IconData git_branch = IconData(61764, fontFamily: 'Octicons');
|
||||
static const IconData git_commit = IconData(61765, fontFamily: 'Octicons');
|
||||
static const IconData git_compare = IconData(61766, fontFamily: 'Octicons');
|
||||
static const IconData git_merge = IconData(61767, fontFamily: 'Octicons');
|
||||
static const IconData git_pull_request =
|
||||
IconData(61768, fontFamily: 'Octicons');
|
||||
static const IconData globe = IconData(61769, fontFamily: 'Octicons');
|
||||
static const IconData grabber = IconData(61770, fontFamily: 'Octicons');
|
||||
static const IconData graph = IconData(61771, fontFamily: 'Octicons');
|
||||
static const IconData heart = IconData(61772, fontFamily: 'Octicons');
|
||||
static const IconData history = IconData(61773, fontFamily: 'Octicons');
|
||||
static const IconData home = IconData(61774, fontFamily: 'Octicons');
|
||||
static const IconData horizontal_rule =
|
||||
IconData(61775, fontFamily: 'Octicons');
|
||||
static const IconData hubot = IconData(61776, fontFamily: 'Octicons');
|
||||
static const IconData inbox = IconData(61777, fontFamily: 'Octicons');
|
||||
static const IconData info = IconData(61778, fontFamily: 'Octicons');
|
||||
static const IconData issue_closed = IconData(61779, fontFamily: 'Octicons');
|
||||
static const IconData issue_opened = IconData(61780, fontFamily: 'Octicons');
|
||||
static const IconData issue_reopened =
|
||||
IconData(61781, fontFamily: 'Octicons');
|
||||
static const IconData italic = IconData(61782, fontFamily: 'Octicons');
|
||||
static const IconData jersey = IconData(61783, fontFamily: 'Octicons');
|
||||
static const IconData kebab_horizontal =
|
||||
IconData(61784, fontFamily: 'Octicons');
|
||||
static const IconData kebab_vertical =
|
||||
IconData(61785, fontFamily: 'Octicons');
|
||||
static const IconData key = IconData(61786, fontFamily: 'Octicons');
|
||||
static const IconData keyboard = IconData(61787, fontFamily: 'Octicons');
|
||||
static const IconData law = IconData(61788, fontFamily: 'Octicons');
|
||||
static const IconData light_bulb = IconData(61789, fontFamily: 'Octicons');
|
||||
static const IconData link = IconData(61790, fontFamily: 'Octicons');
|
||||
static const IconData link_external = IconData(61791, fontFamily: 'Octicons');
|
||||
static const IconData list_ordered = IconData(61792, fontFamily: 'Octicons');
|
||||
static const IconData list_unordered =
|
||||
IconData(61793, fontFamily: 'Octicons');
|
||||
static const IconData location = IconData(61794, fontFamily: 'Octicons');
|
||||
static const IconData lock = IconData(61795, fontFamily: 'Octicons');
|
||||
static const IconData logo_gist = IconData(61796, fontFamily: 'Octicons');
|
||||
static const IconData logo_github = IconData(61797, fontFamily: 'Octicons');
|
||||
static const IconData mail = IconData(61798, fontFamily: 'Octicons');
|
||||
static const IconData mail_read = IconData(61799, fontFamily: 'Octicons');
|
||||
static const IconData mark_github = IconData(61800, fontFamily: 'Octicons');
|
||||
static const IconData markdown = IconData(61801, fontFamily: 'Octicons');
|
||||
static const IconData megaphone = IconData(61802, fontFamily: 'Octicons');
|
||||
static const IconData mention = IconData(61803, fontFamily: 'Octicons');
|
||||
static const IconData milestone = IconData(61804, fontFamily: 'Octicons');
|
||||
static const IconData mirror = IconData(61805, fontFamily: 'Octicons');
|
||||
static const IconData mortar_board = IconData(61806, fontFamily: 'Octicons');
|
||||
static const IconData mute = IconData(61807, fontFamily: 'Octicons');
|
||||
static const IconData no_newline = IconData(61808, fontFamily: 'Octicons');
|
||||
static const IconData note = IconData(61809, fontFamily: 'Octicons');
|
||||
static const IconData octoface = IconData(61810, fontFamily: 'Octicons');
|
||||
static const IconData organization = IconData(61811, fontFamily: 'Octicons');
|
||||
static const IconData package = IconData(61812, fontFamily: 'Octicons');
|
||||
static const IconData paintcan = IconData(61813, fontFamily: 'Octicons');
|
||||
static const IconData pencil = IconData(61814, fontFamily: 'Octicons');
|
||||
static const IconData person = IconData(61815, fontFamily: 'Octicons');
|
||||
static const IconData pin = IconData(61816, fontFamily: 'Octicons');
|
||||
static const IconData plug = IconData(61817, fontFamily: 'Octicons');
|
||||
static const IconData plus = IconData(61818, fontFamily: 'Octicons');
|
||||
static const IconData plus_small = IconData(61819, fontFamily: 'Octicons');
|
||||
static const IconData primitive_dot = IconData(61820, fontFamily: 'Octicons');
|
||||
static const IconData primitive_square =
|
||||
IconData(61821, fontFamily: 'Octicons');
|
||||
static const IconData project = IconData(61822, fontFamily: 'Octicons');
|
||||
static const IconData pulse = IconData(61823, fontFamily: 'Octicons');
|
||||
static const IconData question = IconData(61824, fontFamily: 'Octicons');
|
||||
static const IconData quote = IconData(61825, fontFamily: 'Octicons');
|
||||
static const IconData radio_tower = IconData(61826, fontFamily: 'Octicons');
|
||||
static const IconData reply = IconData(61827, fontFamily: 'Octicons');
|
||||
static const IconData repo = IconData(61828, fontFamily: 'Octicons');
|
||||
static const IconData repo_clone = IconData(61829, fontFamily: 'Octicons');
|
||||
static const IconData repo_force_push =
|
||||
IconData(61830, fontFamily: 'Octicons');
|
||||
static const IconData repo_forked = IconData(61831, fontFamily: 'Octicons');
|
||||
static const IconData repo_pull = IconData(61832, fontFamily: 'Octicons');
|
||||
static const IconData repo_push = IconData(61833, fontFamily: 'Octicons');
|
||||
static const IconData report = IconData(61834, fontFamily: 'Octicons');
|
||||
static const IconData rocket = IconData(61835, fontFamily: 'Octicons');
|
||||
static const IconData rss = IconData(61836, fontFamily: 'Octicons');
|
||||
static const IconData ruby = IconData(61837, fontFamily: 'Octicons');
|
||||
static const IconData screen_full = IconData(61838, fontFamily: 'Octicons');
|
||||
static const IconData screen_normal = IconData(61839, fontFamily: 'Octicons');
|
||||
static const IconData search = IconData(61840, fontFamily: 'Octicons');
|
||||
static const IconData server = IconData(61841, fontFamily: 'Octicons');
|
||||
static const IconData settings = IconData(61842, fontFamily: 'Octicons');
|
||||
static const IconData shield = IconData(61843, fontFamily: 'Octicons');
|
||||
static const IconData sign_in = IconData(61844, fontFamily: 'Octicons');
|
||||
static const IconData sign_out = IconData(61845, fontFamily: 'Octicons');
|
||||
static const IconData smiley = IconData(61846, fontFamily: 'Octicons');
|
||||
static const IconData squirrel = IconData(61847, fontFamily: 'Octicons');
|
||||
static const IconData star = IconData(61848, fontFamily: 'Octicons');
|
||||
static const IconData stop = IconData(61849, fontFamily: 'Octicons');
|
||||
static const IconData sync = IconData(61850, fontFamily: 'Octicons');
|
||||
static const IconData tag = IconData(61851, fontFamily: 'Octicons');
|
||||
static const IconData tasklist = IconData(61852, fontFamily: 'Octicons');
|
||||
static const IconData telescope = IconData(61853, fontFamily: 'Octicons');
|
||||
static const IconData terminal = IconData(61854, fontFamily: 'Octicons');
|
||||
static const IconData text_size = IconData(61855, fontFamily: 'Octicons');
|
||||
static const IconData three_bars = IconData(61856, fontFamily: 'Octicons');
|
||||
static const IconData thumbsdown = IconData(61857, fontFamily: 'Octicons');
|
||||
static const IconData thumbsup = IconData(61858, fontFamily: 'Octicons');
|
||||
static const IconData tools = IconData(61859, fontFamily: 'Octicons');
|
||||
static const IconData trashcan = IconData(61860, fontFamily: 'Octicons');
|
||||
static const IconData triangle_down = IconData(61861, fontFamily: 'Octicons');
|
||||
static const IconData triangle_left = IconData(61862, fontFamily: 'Octicons');
|
||||
static const IconData triangle_right =
|
||||
IconData(61863, fontFamily: 'Octicons');
|
||||
static const IconData triangle_up = IconData(61864, fontFamily: 'Octicons');
|
||||
static const IconData unfold = IconData(61865, fontFamily: 'Octicons');
|
||||
static const IconData unmute = IconData(61866, fontFamily: 'Octicons');
|
||||
static const IconData unverified = IconData(61867, fontFamily: 'Octicons');
|
||||
static const IconData verified = IconData(61868, fontFamily: 'Octicons');
|
||||
static const IconData versions = IconData(61869, fontFamily: 'Octicons');
|
||||
static const IconData watch = IconData(61870, fontFamily: 'Octicons');
|
||||
static const IconData x = IconData(61871, fontFamily: 'Octicons');
|
||||
static const IconData zap = IconData(61872, fontFamily: 'Octicons');
|
||||
}
|
||||
25
lib/utils/timeago.dart
Normal file
25
lib/utils/timeago.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'dart:core';
|
||||
|
||||
class TimeAgo {
|
||||
static String _ceil(double n) => n.ceil().toString();
|
||||
|
||||
static String _pluralize(double time, String unit) {
|
||||
if (time == 1) {
|
||||
return '${_ceil(time)} $unit ago';
|
||||
}
|
||||
return '${_ceil(time)} ${unit}s ago';
|
||||
}
|
||||
|
||||
static String format(DateTime time) {
|
||||
double diff =
|
||||
(DateTime.now().millisecondsSinceEpoch - time.millisecondsSinceEpoch) /
|
||||
1000;
|
||||
if (diff < 3600) {
|
||||
return _pluralize(diff / 60, 'minute');
|
||||
} else if (diff < 86400) {
|
||||
return _pluralize(diff / 3600, 'hour');
|
||||
} else {
|
||||
return _pluralize(diff / 86400, 'day');
|
||||
}
|
||||
}
|
||||
}
|
||||
3
lib/utils/utils.dart
Normal file
3
lib/utils/utils.dart
Normal file
@@ -0,0 +1,3 @@
|
||||
export 'github.dart';
|
||||
export 'octicons.dart';
|
||||
export 'timeago.dart';
|
||||
Reference in New Issue
Block a user