mirror of
https://github.com/pd4d10/git-touch.git
synced 2026-11-19 17:48:59 -06:00
feat: add android notification screen
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_flux/utils/utils.dart';
|
||||
import 'news.dart';
|
||||
import 'notifications.dart';
|
||||
|
||||
class AndroidHome extends StatefulWidget {
|
||||
@override
|
||||
@@ -15,6 +16,8 @@ class _AndroidHomeState extends State<AndroidHome> {
|
||||
switch (active) {
|
||||
case 0:
|
||||
return NewsScreen();
|
||||
case 1:
|
||||
return NotificationScreen();
|
||||
default:
|
||||
return Text('d');
|
||||
}
|
||||
|
||||
@@ -19,7 +19,15 @@ class NewsScreenState extends State<NewsScreen> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('News')),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: refresh,
|
||||
onRefresh: () async {
|
||||
await refresh();
|
||||
// Scaffold.of(context).showSnackBar(SnackBar(
|
||||
// content: Container(
|
||||
// child: Text('data'),
|
||||
// padding: EdgeInsets.only(bottom: 10),
|
||||
// )
|
||||
// ));
|
||||
},
|
||||
child: ListView.builder(
|
||||
controller: controller,
|
||||
itemCount: events.length + 1,
|
||||
|
||||
@@ -1 +1,96 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:core';
|
||||
import 'package:flutter/material.dart' hide Notification;
|
||||
import 'package:flutter/cupertino.dart' hide Notification;
|
||||
import 'package:git_flux/providers/notification.dart';
|
||||
import 'package:git_flux/widgets/notification_item.dart';
|
||||
import 'package:git_flux/utils/utils.dart';
|
||||
|
||||
class NotificationGroup {
|
||||
String fullName;
|
||||
List<Notification> items = [];
|
||||
|
||||
NotificationGroup(this.fullName);
|
||||
}
|
||||
|
||||
class NotificationScreen extends StatefulWidget {
|
||||
@override
|
||||
NotificationScreenState createState() => NotificationScreenState();
|
||||
}
|
||||
|
||||
class NotificationScreenState extends State<NotificationScreen> {
|
||||
int active = 0;
|
||||
bool loading = false;
|
||||
List<NotificationGroup> groups = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Future.delayed(Duration(seconds: 0)).then((_) {
|
||||
_onSwitchTab(context, 0);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildGroupItem(BuildContext context, int index) {
|
||||
var group = groups[index];
|
||||
|
||||
return Container(
|
||||
// padding: EdgeInsets.all(10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 10, left: 4, bottom: 4),
|
||||
color: CupertinoColors.extraLightBackgroundGray,
|
||||
child: Text(
|
||||
group.fullName,
|
||||
style: TextStyle(color: CupertinoColors.black),
|
||||
),
|
||||
),
|
||||
Column(
|
||||
children: group.items
|
||||
.map((item) => NotificationItem(item: item))
|
||||
.toList())
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onSwitchTab(BuildContext context, int index) async {
|
||||
setState(() {
|
||||
active = index;
|
||||
loading = true;
|
||||
});
|
||||
|
||||
var ns = await ghClient.activity
|
||||
.listNotifications(all: index == 2, participating: index == 1)
|
||||
.toList();
|
||||
|
||||
NotificationProvider.of(context).countUpdate.add(ns.length);
|
||||
|
||||
Map<String, NotificationGroup> groupMap = {};
|
||||
ns.forEach((item) {
|
||||
String repo = item.repository.fullName;
|
||||
if (groupMap[repo] == null) {
|
||||
groupMap[repo] = NotificationGroup(repo);
|
||||
}
|
||||
|
||||
groupMap[repo].items.add(item);
|
||||
});
|
||||
|
||||
setState(() {
|
||||
groups = groupMap.values.toList();
|
||||
loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('Notification')),
|
||||
body: ListView.builder(
|
||||
itemCount: groups.length,
|
||||
itemBuilder: _buildGroupItem,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ class NewsScreenState extends State<NewsScreen> {
|
||||
slivers: <Widget>[
|
||||
CupertinoSliverNavigationBar(
|
||||
largeTitle: const Text('News'),
|
||||
trailing: Icon(Octicons.settings),
|
||||
// trailing: Icon(Octicons.settings),
|
||||
),
|
||||
CupertinoSliverRefreshControl(
|
||||
onRefresh: refresh,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import 'dart:core';
|
||||
import 'package:flutter/material.dart' hide Notification;
|
||||
import 'package:flutter/cupertino.dart' hide Notification;
|
||||
import 'package:git_flux/providers/notification.dart';
|
||||
import 'package:git_flux/screens/screens.dart';
|
||||
import 'package:git_flux/widgets/notification_item.dart';
|
||||
import 'package:git_flux/utils/utils.dart';
|
||||
|
||||
class NotificationGroup {
|
||||
@@ -30,86 +29,6 @@ class NotificationScreenState extends State<NotificationScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildRoute(Notification item) {
|
||||
String type = item.subject.type;
|
||||
switch (type) {
|
||||
case 'Issue':
|
||||
case 'PullRequest':
|
||||
// return IssueScreen(item.repository.);
|
||||
default:
|
||||
throw new Exception('Unhandled notification type: $type');
|
||||
}
|
||||
}
|
||||
|
||||
IconData _buildIconData(String type) {
|
||||
switch (type) {
|
||||
case 'Issue':
|
||||
return Octicons.issue_opened;
|
||||
// color: Color.fromRGBO(0x28, 0xa7, 0x45, 1),
|
||||
case 'PullRequest':
|
||||
return Octicons.git_pull_request;
|
||||
// color: Color.fromRGBO(0x6f, 0x42, 0xc1, 1),
|
||||
default:
|
||||
throw new Exception('Unhandled icon type: $type');
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildItem(BuildContext context, Notification item) {
|
||||
return Material(
|
||||
child: InkWell(
|
||||
splashColor: Colors.transparent,
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
CupertinoPageRoute(builder: (context) => _buildRoute(item)),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Icon(_buildIconData(item.subject.type),
|
||||
color: CupertinoColors.inactiveGray),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.grey))),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(item.subject.title,
|
||||
style: TextStyle(height: 1)),
|
||||
Padding(padding: EdgeInsets.only(top: 4)),
|
||||
Text(TimeAgo.format(item.updatedAt),
|
||||
style: TextStyle(fontSize: 12))
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Icon(
|
||||
CupertinoIcons.right_chevron,
|
||||
color: CupertinoColors.inactiveGray,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildGroupItem(BuildContext context, int index) {
|
||||
var group = groups[index];
|
||||
|
||||
@@ -127,8 +46,9 @@ class NotificationScreenState extends State<NotificationScreen> {
|
||||
),
|
||||
),
|
||||
Column(
|
||||
children:
|
||||
group.items.map((item) => _buildItem(context, item)).toList())
|
||||
children: group.items
|
||||
.map((item) => NotificationItem(item: item))
|
||||
.toList())
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -184,21 +104,10 @@ class NotificationScreenState extends State<NotificationScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
// CupertinoSliverRefreshControl(
|
||||
// onRefresh: () async {
|
||||
// return Future.delayed(Duration(seconds: 3));
|
||||
// },
|
||||
// ),
|
||||
Container(
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: groups.length,
|
||||
itemBuilder: _buildGroupItem,
|
||||
),
|
||||
),
|
||||
],
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: groups.length,
|
||||
itemBuilder: _buildGroupItem,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,18 +1,18 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
// import 'package:device_info/device_info.dart';
|
||||
import 'package:git_flux/providers/providers.dart';
|
||||
import 'package:git_flux/providers/settings.dart';
|
||||
import 'package:git_flux/ios/ios.dart';
|
||||
import 'package:git_flux/android/android.dart';
|
||||
|
||||
class App extends StatelessWidget {
|
||||
final isIos = Platform.isIOS;
|
||||
final EventBloc eventBloc;
|
||||
final SettingsBloc settingsBloc;
|
||||
final NotificationBloc notificationBloc;
|
||||
final SearchBloc searchBloc;
|
||||
|
||||
App(this.eventBloc, this.notificationBloc, this.searchBloc);
|
||||
App(this.settingsBloc, this.notificationBloc, this.searchBloc);
|
||||
|
||||
_buildScreen() {
|
||||
// return IssueScreen(11609, 'flutter', 'flutter');
|
||||
@@ -33,7 +33,7 @@ class App extends StatelessWidget {
|
||||
child: NotificationProvider(
|
||||
bloc: notificationBloc,
|
||||
child: EventProvider(
|
||||
bloc: eventBloc,
|
||||
bloc: settingsBloc,
|
||||
child: MaterialApp(
|
||||
home: DefaultTextStyle(
|
||||
style: TextStyle(color: Color(0xff24292e)),
|
||||
@@ -52,7 +52,7 @@ class App extends StatelessWidget {
|
||||
}
|
||||
|
||||
void main() async {
|
||||
EventBloc eventBloc = EventBloc();
|
||||
SettingsBloc eventBloc = SettingsBloc();
|
||||
NotificationBloc notificationBloc = NotificationBloc();
|
||||
SearchBloc searchBloc = SearchBloc();
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:git_flux/utils/utils.dart';
|
||||
|
||||
class EventBloc {
|
||||
final _items = BehaviorSubject<List<Event>>(seedValue: []);
|
||||
final _page = BehaviorSubject(seedValue: 0);
|
||||
final _update = StreamController<bool>();
|
||||
|
||||
// Stream<int> get eventPage => _page.stream;
|
||||
Stream<List<Event>> get events => _items.stream;
|
||||
Sink<bool> get update => _update.sink;
|
||||
|
||||
EventBloc() {
|
||||
// _update.stream.listen((bool isRefresh) async {
|
||||
// if (isRefresh) {
|
||||
// _items.add(await fetchEvents(1));
|
||||
// _page.add(1);
|
||||
// } else {
|
||||
// _items.add(await fetchEvents(1));
|
||||
// _page.add(_page.value + 1);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_items.close();
|
||||
_page.close();
|
||||
}
|
||||
}
|
||||
|
||||
class EventProvider extends InheritedWidget {
|
||||
final EventBloc bloc;
|
||||
|
||||
EventProvider({
|
||||
Key key,
|
||||
Widget child,
|
||||
@required EventBloc bloc,
|
||||
}) : bloc = bloc,
|
||||
super(key: key, child: child);
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(InheritedWidget oldWidget) => true;
|
||||
|
||||
static EventBloc of(BuildContext context) =>
|
||||
(context.inheritFromWidgetOfExactType(EventProvider) as EventProvider)
|
||||
.bloc;
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
export 'event.dart';
|
||||
export 'notification.dart';
|
||||
export 'search.dart';
|
||||
export 'user.dart';
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:git_flux/utils/utils.dart';
|
||||
|
||||
class LayoutMap {
|
||||
static const material = 0;
|
||||
static const cupertino = 1;
|
||||
}
|
||||
|
||||
class SettingsBloc {
|
||||
final _layout = BehaviorSubject(seedValue: LayoutMap.material);
|
||||
// final _update = StreamController<bool>();
|
||||
|
||||
Stream<int> get layout {
|
||||
// _layout.value
|
||||
}
|
||||
Sink<int> get layoutUpdate => _layout.sink;
|
||||
|
||||
SettingsBloc() {}
|
||||
}
|
||||
|
||||
class EventProvider extends InheritedWidget {
|
||||
final SettingsBloc bloc;
|
||||
|
||||
EventProvider({
|
||||
Key key,
|
||||
Widget child,
|
||||
@required SettingsBloc bloc,
|
||||
}) : bloc = bloc,
|
||||
super(key: key, child: child);
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(InheritedWidget oldWidget) => true;
|
||||
|
||||
static SettingsBloc of(BuildContext context) =>
|
||||
(context.inheritFromWidgetOfExactType(EventProvider) as EventProvider)
|
||||
.bloc;
|
||||
}
|
||||
@@ -61,6 +61,9 @@ class NewsProviderState extends State<NewsProvider> {
|
||||
@override
|
||||
Widget build(context) {
|
||||
return widget.build(
|
||||
events: _events, controller: _controller, refresh: _refresh);
|
||||
events: _events,
|
||||
controller: _controller,
|
||||
refresh: _refresh,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import 'dart:core';
|
||||
import 'package:flutter/material.dart' hide Notification;
|
||||
import 'package:flutter/cupertino.dart' hide Notification;
|
||||
import 'package:git_flux/utils/utils.dart';
|
||||
|
||||
class NotificationItem extends StatelessWidget {
|
||||
const NotificationItem({
|
||||
Key key,
|
||||
@required this.item,
|
||||
}) : super(key: key);
|
||||
|
||||
final Notification item;
|
||||
|
||||
Widget _buildRoute(Notification item) {
|
||||
String type = item.subject.type;
|
||||
switch (type) {
|
||||
case 'Issue':
|
||||
case 'PullRequest':
|
||||
// return IssueScreen(item.repository.);
|
||||
default:
|
||||
throw new Exception('Unhandled notification type: $type');
|
||||
}
|
||||
}
|
||||
|
||||
IconData _buildIconData(String type) {
|
||||
switch (type) {
|
||||
case 'Issue':
|
||||
return Octicons.issue_opened;
|
||||
// color: Color.fromRGBO(0x28, 0xa7, 0x45, 1),
|
||||
case 'PullRequest':
|
||||
return Octicons.git_pull_request;
|
||||
// color: Color.fromRGBO(0x6f, 0x42, 0xc1, 1),
|
||||
default:
|
||||
throw new Exception('Unhandled icon type: $type');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
child: InkWell(
|
||||
// splashColor: Colors.transparent,
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
CupertinoPageRoute(builder: (context) => _buildRoute(item)),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Icon(_buildIconData(item.subject.type),
|
||||
color: CupertinoColors.inactiveGray),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.grey))),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(item.subject.title,
|
||||
style: TextStyle(height: 1)),
|
||||
Padding(padding: EdgeInsets.only(top: 4)),
|
||||
Text(TimeAgo.format(item.updatedAt),
|
||||
style: TextStyle(fontSize: 12))
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Icon(
|
||||
Octicons.check,
|
||||
color: CupertinoColors.inactiveGray,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -15,10 +15,6 @@ environment:
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^0.1.2
|
||||
http: ^0.11.3
|
||||
rxdart: ^0.20.0
|
||||
uri: ^0.11.3
|
||||
@@ -30,7 +26,6 @@ dependencies:
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
build_runner: ^1.1.3
|
||||
json_serializable: ^2.0.1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user