mirror of
https://github.com/pd4d10/git-touch.git
synced 2026-06-04 23:30:15 -05: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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user