Work on implementing search filter in app [WIP]
This commit is contained in:
@@ -27,6 +27,26 @@ enum ChannelSelector {
|
||||
final String apiKey;
|
||||
}
|
||||
|
||||
class MessageFilter {
|
||||
List<String>? channelIDs;
|
||||
String? searchFilter;
|
||||
List<String>? senderNames;
|
||||
List<String>? usedKeys;
|
||||
List<int>? priority;
|
||||
DateTime? timeBefore;
|
||||
DateTime? timeAfter;
|
||||
|
||||
MessageFilter({
|
||||
this.channelIDs,
|
||||
this.searchFilter,
|
||||
this.senderNames,
|
||||
this.usedKeys,
|
||||
this.priority,
|
||||
this.timeBefore,
|
||||
this.timeAfter,
|
||||
});
|
||||
}
|
||||
|
||||
class APIClient {
|
||||
static const String _base = 'https://simplecloudnotifier.de/api/v2';
|
||||
|
||||
@@ -226,7 +246,7 @@ class APIClient {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<(String, List<SCNMessage>)> getMessageList(TokenSource auth, String pageToken, {int? pageSize, List<String>? channelIDs}) async {
|
||||
static Future<(String, List<SCNMessage>)> getMessageList(TokenSource auth, String pageToken, {int? pageSize, MessageFilter? filter}) async {
|
||||
return await _request(
|
||||
name: 'getMessageList',
|
||||
method: 'GET',
|
||||
@@ -234,7 +254,12 @@ class APIClient {
|
||||
query: {
|
||||
'next_page_token': pageToken,
|
||||
if (pageSize != null) 'page_size': pageSize.toString(),
|
||||
if (channelIDs != null) 'channel_id': channelIDs.join(","),
|
||||
if (filter?.channelIDs != null) 'channel_id': filter!.channelIDs!.join(","),
|
||||
if (filter?.senderNames != null) 'sender': filter!.senderNames!.join(","),
|
||||
if (filter?.timeBefore != null) 'before': filter!.timeBefore!.toIso8601String(),
|
||||
if (filter?.timeAfter != null) 'after': filter!.timeAfter!.toIso8601String(),
|
||||
if (filter?.priority != null) 'priority': filter!.priority!.map((p) => p.toString()).join(","),
|
||||
if (filter?.usedKeys != null) 'used_key': filter!.usedKeys!.join(","),
|
||||
},
|
||||
fn: (json) => SCNMessage.fromPaginatedJsonArray(json, 'messages', 'next_page_token'),
|
||||
authToken: auth.getToken(),
|
||||
@@ -339,4 +364,8 @@ class APIClient {
|
||||
authToken: token,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<List<String>> getSenderNameList(AppAuth userAcc) {
|
||||
return Future.value(['TODO']); //TODO
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import 'package:provider/provider.dart';
|
||||
import 'package:simplecloudnotifier/components/layout/app_bar_filter_dialog.dart';
|
||||
import 'package:simplecloudnotifier/components/layout/app_bar_progress_indicator.dart';
|
||||
import 'package:simplecloudnotifier/pages/debug/debug_main.dart';
|
||||
import 'package:simplecloudnotifier/pages/message_list/message_filter_chiplet.dart';
|
||||
import 'package:simplecloudnotifier/settings/app_settings.dart';
|
||||
import 'package:simplecloudnotifier/state/app_bar_state.dart';
|
||||
import 'package:simplecloudnotifier/state/app_events.dart';
|
||||
@@ -108,7 +109,8 @@ class _SCNAppBarState extends State<SCNAppBar> {
|
||||
icon: const Icon(FontAwesomeIcons.solidMagnifyingGlass),
|
||||
onPressed: () {
|
||||
value.setShowSearchField(false);
|
||||
AppEvents().notifySearchListeners(_ctrlSearchField.text);
|
||||
final chiplet = MessageFilterChiplet(label: _ctrlSearchField.text, value: _ctrlSearchField.text, type: MessageFilterChipletType.search);
|
||||
AppEvents().notifyFilterListeners([MessageFilterChipletType.search], [chiplet]);
|
||||
_ctrlSearchField.clear();
|
||||
},
|
||||
),
|
||||
@@ -157,7 +159,8 @@ class _SCNAppBarState extends State<SCNAppBar> {
|
||||
),
|
||||
onSubmitted: (value) {
|
||||
AppBarState().setShowSearchField(false);
|
||||
AppEvents().notifySearchListeners(_ctrlSearchField.text);
|
||||
final chiplet = MessageFilterChiplet(label: _ctrlSearchField.text, value: _ctrlSearchField.text, type: MessageFilterChipletType.search);
|
||||
AppEvents().notifyFilterListeners([MessageFilterChipletType.search], [chiplet]);
|
||||
_ctrlSearchField.clear();
|
||||
},
|
||||
);
|
||||
|
@@ -1,5 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:simplecloudnotifier/components/modals/filter_modal_channel.dart';
|
||||
import 'package:simplecloudnotifier/components/modals/filter_modal_keytoken.dart';
|
||||
import 'package:simplecloudnotifier/components/modals/filter_modal_priority.dart';
|
||||
import 'package:simplecloudnotifier/components/modals/filter_modal_sendername.dart';
|
||||
import 'package:simplecloudnotifier/components/modals/filter_modal_time.dart';
|
||||
import 'package:simplecloudnotifier/state/app_bar_state.dart';
|
||||
import 'package:simplecloudnotifier/utils/navi.dart';
|
||||
|
||||
class AppBarFilterDialog extends StatefulWidget {
|
||||
@@ -48,17 +54,17 @@ class _AppBarFilterDialogState extends State<AppBarFilterDialog> {
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(height: 4),
|
||||
_buildFilterItem(context, FontAwesomeIcons.magnifyingGlass, 'Search'),
|
||||
_buildFilterItem(context, FontAwesomeIcons.magnifyingGlass, 'Search', _showSearch),
|
||||
Divider(),
|
||||
_buildFilterItem(context, FontAwesomeIcons.snake, 'Channel'),
|
||||
_buildFilterItem(context, FontAwesomeIcons.snake, 'Channel', _showChannelModal),
|
||||
Divider(),
|
||||
_buildFilterItem(context, FontAwesomeIcons.signature, 'Sender'),
|
||||
_buildFilterItem(context, FontAwesomeIcons.signature, 'Sender', _showSenderModal),
|
||||
Divider(),
|
||||
_buildFilterItem(context, FontAwesomeIcons.timer, 'Time'),
|
||||
_buildFilterItem(context, FontAwesomeIcons.timer, 'Time', _showTimeModal),
|
||||
Divider(),
|
||||
_buildFilterItem(context, FontAwesomeIcons.bolt, 'Priority'),
|
||||
_buildFilterItem(context, FontAwesomeIcons.bolt, 'Priority', _showPriorityModal),
|
||||
Divider(),
|
||||
_buildFilterItem(context, FontAwesomeIcons.gearCode, 'Key'),
|
||||
_buildFilterItem(context, FontAwesomeIcons.gearCode, 'Key', _showKeytokenModal),
|
||||
SizedBox(height: 4),
|
||||
],
|
||||
),
|
||||
@@ -72,15 +78,39 @@ class _AppBarFilterDialogState extends State<AppBarFilterDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterItem(BuildContext context, IconData icon, String label) {
|
||||
Widget _buildFilterItem(BuildContext context, IconData icon, String label, void Function(BuildContext context) action) {
|
||||
return ListTile(
|
||||
visualDensity: VisualDensity.compact,
|
||||
title: Text(label),
|
||||
leading: Icon(icon),
|
||||
onTap: () {
|
||||
Navi.popDialog(context);
|
||||
//TOOD show more...
|
||||
action(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showSearch(BuildContext context) {
|
||||
AppBarState().setShowSearchField(true);
|
||||
}
|
||||
|
||||
void _showPriorityModal(BuildContext context) {
|
||||
showDialog<void>(context: context, builder: (BuildContext context) => FilterModalPriority());
|
||||
}
|
||||
|
||||
void _showChannelModal(BuildContext context) {
|
||||
showDialog<void>(context: context, builder: (BuildContext context) => FilterModalChannel());
|
||||
}
|
||||
|
||||
void _showSenderModal(BuildContext context) {
|
||||
showDialog<void>(context: context, builder: (BuildContext context) => FilterModalSendername());
|
||||
}
|
||||
|
||||
void _showKeytokenModal(BuildContext context) {
|
||||
showDialog<void>(context: context, builder: (BuildContext context) => FilterModalKeytoken());
|
||||
}
|
||||
|
||||
void _showTimeModal(BuildContext context) {
|
||||
showDialog<void>(context: context, builder: (BuildContext context) => FilterModalTime());
|
||||
}
|
||||
}
|
||||
|
114
flutter/lib/components/modals/filter_modal_channel.dart
Normal file
114
flutter/lib/components/modals/filter_modal_channel.dart
Normal file
@@ -0,0 +1,114 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:simplecloudnotifier/api/api_client.dart';
|
||||
import 'package:simplecloudnotifier/models/channel.dart';
|
||||
import 'package:simplecloudnotifier/pages/message_list/message_filter_chiplet.dart';
|
||||
import 'package:simplecloudnotifier/state/app_auth.dart';
|
||||
import 'package:simplecloudnotifier/state/app_events.dart';
|
||||
import 'package:simplecloudnotifier/types/immediate_future.dart';
|
||||
|
||||
class FilterModalChannel extends StatefulWidget {
|
||||
@override
|
||||
_FilterModalChannelState createState() => _FilterModalChannelState();
|
||||
}
|
||||
|
||||
class _FilterModalChannelState extends State<FilterModalChannel> {
|
||||
Set<String> _selectedEntries = {};
|
||||
|
||||
late ImmediateFuture<List<Channel>>? _futureChannels;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_futureChannels = null;
|
||||
_futureChannels = ImmediateFuture.ofFuture(() async {
|
||||
final userAcc = Provider.of<AppAuth>(context, listen: false);
|
||||
if (!userAcc.isAuth()) throw new Exception('not logged in');
|
||||
|
||||
final channels = await APIClient.getChannelList(userAcc, ChannelSelector.all);
|
||||
|
||||
return channels.where((p) => p.subscription?.confirmed ?? false).map((e) => e.channel).toList(); // return only subscribed channels
|
||||
}());
|
||||
}
|
||||
|
||||
void toggleEntry(String channelID) {
|
||||
setState(() {
|
||||
if (_selectedEntries.contains(channelID)) {
|
||||
_selectedEntries.remove(channelID);
|
||||
} else {
|
||||
_selectedEntries.add(channelID);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Channels'),
|
||||
content: Container(
|
||||
width: 9000,
|
||||
height: 9000,
|
||||
child: () {
|
||||
if (_futureChannels == null) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return FutureBuilder(
|
||||
future: _futureChannels!.future,
|
||||
builder: ((context, snapshot) {
|
||||
if (_futureChannels?.value != null) {
|
||||
return _buildList(context, _futureChannels!.value!);
|
||||
} else if (snapshot.connectionState == ConnectionState.done && snapshot.hasError) {
|
||||
return Text('Error: ${snapshot.error}'); //TODO better error display
|
||||
} else if (snapshot.connectionState == ConnectionState.done) {
|
||||
return _buildList(context, snapshot.data!);
|
||||
} else {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
}),
|
||||
);
|
||||
}(),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
|
||||
child: const Text('Apply'),
|
||||
onPressed: () {
|
||||
onOkay();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void onOkay() {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
final chiplets = _selectedEntries
|
||||
.map((e) => MessageFilterChiplet(
|
||||
label: _futureChannels?.get()?.map((e) => e as Channel?).firstWhere((p) => p?.channelID == e, orElse: () => null)?.displayName ?? '???',
|
||||
value: e,
|
||||
type: MessageFilterChipletType.channel,
|
||||
))
|
||||
.toList();
|
||||
|
||||
AppEvents().notifyFilterListeners([MessageFilterChipletType.channel], chiplets);
|
||||
}
|
||||
|
||||
Widget _buildList(BuildContext context, List<Channel> list) {
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (builder, index) {
|
||||
final channel = list[index];
|
||||
return ListTile(
|
||||
title: Text(channel.displayName),
|
||||
leading: Icon(_selectedEntries.contains(channel.channelID) ? Icons.check_box : Icons.check_box_outline_blank, color: Theme.of(context).primaryColor),
|
||||
onTap: () => toggleEntry(channel.channelID),
|
||||
visualDensity: VisualDensity(vertical: -4),
|
||||
);
|
||||
},
|
||||
itemCount: list.length,
|
||||
);
|
||||
}
|
||||
}
|
114
flutter/lib/components/modals/filter_modal_keytoken.dart
Normal file
114
flutter/lib/components/modals/filter_modal_keytoken.dart
Normal file
@@ -0,0 +1,114 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:simplecloudnotifier/api/api_client.dart';
|
||||
import 'package:simplecloudnotifier/models/keytoken.dart';
|
||||
import 'package:simplecloudnotifier/pages/message_list/message_filter_chiplet.dart';
|
||||
import 'package:simplecloudnotifier/state/app_auth.dart';
|
||||
import 'package:simplecloudnotifier/state/app_events.dart';
|
||||
import 'package:simplecloudnotifier/types/immediate_future.dart';
|
||||
|
||||
class FilterModalKeytoken extends StatefulWidget {
|
||||
@override
|
||||
_FilterModalKeytokenState createState() => _FilterModalKeytokenState();
|
||||
}
|
||||
|
||||
class _FilterModalKeytokenState extends State<FilterModalKeytoken> {
|
||||
Set<String> _selectedEntries = {};
|
||||
|
||||
late ImmediateFuture<List<KeyToken>>? _futureKeyTokens;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_futureKeyTokens = null;
|
||||
_futureKeyTokens = ImmediateFuture.ofFuture(() async {
|
||||
final userAcc = Provider.of<AppAuth>(context, listen: false);
|
||||
if (!userAcc.isAuth()) throw new Exception('not logged in');
|
||||
|
||||
final toks = await APIClient.getKeyTokenList(userAcc);
|
||||
|
||||
return toks;
|
||||
}());
|
||||
}
|
||||
|
||||
void toggleEntry(String senderID) {
|
||||
setState(() {
|
||||
if (_selectedEntries.contains(senderID)) {
|
||||
_selectedEntries.remove(senderID);
|
||||
} else {
|
||||
_selectedEntries.add(senderID);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Senders'),
|
||||
content: Container(
|
||||
width: 9000,
|
||||
height: 9000,
|
||||
child: () {
|
||||
if (_futureKeyTokens == null) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return FutureBuilder(
|
||||
future: _futureKeyTokens!.future,
|
||||
builder: ((context, snapshot) {
|
||||
if (_futureKeyTokens?.value != null) {
|
||||
return _buildList(context, _futureKeyTokens!.value!);
|
||||
} else if (snapshot.connectionState == ConnectionState.done && snapshot.hasError) {
|
||||
return Text('Error: ${snapshot.error}'); //TODO better error display
|
||||
} else if (snapshot.connectionState == ConnectionState.done) {
|
||||
return _buildList(context, snapshot.data!);
|
||||
} else {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
}),
|
||||
);
|
||||
}(),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
|
||||
child: const Text('Apply'),
|
||||
onPressed: () {
|
||||
onOkay();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void onOkay() {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
final chiplets = _selectedEntries
|
||||
.map((e) => MessageFilterChiplet(
|
||||
label: _futureKeyTokens?.get()?.map((e) => e as KeyToken?).firstWhere((p) => p?.keytokenID == e, orElse: () => null)?.name ?? '???',
|
||||
value: e,
|
||||
type: MessageFilterChipletType.sender,
|
||||
))
|
||||
.toList();
|
||||
|
||||
AppEvents().notifyFilterListeners([MessageFilterChipletType.sender], chiplets);
|
||||
}
|
||||
|
||||
Widget _buildList(BuildContext context, List<KeyToken> list) {
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (builder, index) {
|
||||
final sender = list[index];
|
||||
return ListTile(
|
||||
title: Text(sender.name),
|
||||
leading: Icon(_selectedEntries.contains(sender.keytokenID) ? Icons.check_box : Icons.check_box_outline_blank, color: Theme.of(context).primaryColor),
|
||||
onTap: () => toggleEntry(sender.keytokenID),
|
||||
visualDensity: VisualDensity(vertical: -4),
|
||||
);
|
||||
},
|
||||
itemCount: list.length,
|
||||
);
|
||||
}
|
||||
}
|
67
flutter/lib/components/modals/filter_modal_priority.dart
Normal file
67
flutter/lib/components/modals/filter_modal_priority.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:simplecloudnotifier/pages/message_list/message_filter_chiplet.dart';
|
||||
import 'package:simplecloudnotifier/state/app_events.dart';
|
||||
|
||||
class FilterModalPriority extends StatefulWidget {
|
||||
@override
|
||||
_FilterModalPriorityState createState() => _FilterModalPriorityState();
|
||||
}
|
||||
|
||||
class _FilterModalPriorityState extends State<FilterModalPriority> {
|
||||
Set<int> _selectedEntries = {};
|
||||
|
||||
Map<int, (String, String)> _texts = {
|
||||
0: ('Low (0)', 'Low'),
|
||||
1: ('Normal (1)', 'Normal'),
|
||||
2: ('High (2)', 'High'),
|
||||
};
|
||||
|
||||
void toggleEntry(int entry) {
|
||||
setState(() {
|
||||
if (_selectedEntries.contains(entry)) {
|
||||
_selectedEntries.remove(entry);
|
||||
} else {
|
||||
_selectedEntries.add(entry);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Priority'),
|
||||
content: Container(
|
||||
width: 0,
|
||||
height: 200,
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (builder, index) {
|
||||
return ListTile(
|
||||
title: Text(_texts[index]?.$1 ?? '???'),
|
||||
leading: Icon(_selectedEntries.contains(index) ? Icons.check_box : Icons.check_box_outline_blank, color: Theme.of(context).primaryColor),
|
||||
onTap: () => toggleEntry(index),
|
||||
);
|
||||
},
|
||||
itemCount: 3,
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
|
||||
child: const Text('Apply'),
|
||||
onPressed: () {
|
||||
onOkay();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void onOkay() {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
final chiplets = _selectedEntries.map((e) => MessageFilterChiplet(label: _texts[e]?.$2 ?? '???', value: e, type: MessageFilterChipletType.priority)).toList();
|
||||
|
||||
AppEvents().notifyFilterListeners([MessageFilterChipletType.priority], chiplets);
|
||||
}
|
||||
}
|
113
flutter/lib/components/modals/filter_modal_sendername.dart
Normal file
113
flutter/lib/components/modals/filter_modal_sendername.dart
Normal file
@@ -0,0 +1,113 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:simplecloudnotifier/api/api_client.dart';
|
||||
import 'package:simplecloudnotifier/pages/message_list/message_filter_chiplet.dart';
|
||||
import 'package:simplecloudnotifier/state/app_auth.dart';
|
||||
import 'package:simplecloudnotifier/state/app_events.dart';
|
||||
import 'package:simplecloudnotifier/types/immediate_future.dart';
|
||||
|
||||
class FilterModalSendername extends StatefulWidget {
|
||||
@override
|
||||
_FilterModalSendernameState createState() => _FilterModalSendernameState();
|
||||
}
|
||||
|
||||
class _FilterModalSendernameState extends State<FilterModalSendername> {
|
||||
Set<String> _selectedEntries = {};
|
||||
|
||||
late ImmediateFuture<List<String>>? _futureSenders;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_futureSenders = null;
|
||||
_futureSenders = ImmediateFuture.ofFuture(() async {
|
||||
final userAcc = Provider.of<AppAuth>(context, listen: false);
|
||||
if (!userAcc.isAuth()) throw new Exception('not logged in');
|
||||
|
||||
final senders = await APIClient.getSenderNameList(userAcc);
|
||||
|
||||
return senders;
|
||||
}());
|
||||
}
|
||||
|
||||
void toggleEntry(String senderID) {
|
||||
setState(() {
|
||||
if (_selectedEntries.contains(senderID)) {
|
||||
_selectedEntries.remove(senderID);
|
||||
} else {
|
||||
_selectedEntries.add(senderID);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Senders'),
|
||||
content: Container(
|
||||
width: 9000,
|
||||
height: 9000,
|
||||
child: () {
|
||||
if (_futureSenders == null) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return FutureBuilder(
|
||||
future: _futureSenders!.future,
|
||||
builder: ((context, snapshot) {
|
||||
if (_futureSenders?.value != null) {
|
||||
return _buildList(context, _futureSenders!.value!);
|
||||
} else if (snapshot.connectionState == ConnectionState.done && snapshot.hasError) {
|
||||
return Text('Error: ${snapshot.error}'); //TODO better error display
|
||||
} else if (snapshot.connectionState == ConnectionState.done) {
|
||||
return _buildList(context, snapshot.data!);
|
||||
} else {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
}),
|
||||
);
|
||||
}(),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
|
||||
child: const Text('Apply'),
|
||||
onPressed: () {
|
||||
onOkay();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void onOkay() {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
final chiplets = _selectedEntries
|
||||
.map((e) => MessageFilterChiplet(
|
||||
label: e,
|
||||
value: e,
|
||||
type: MessageFilterChipletType.sender,
|
||||
))
|
||||
.toList();
|
||||
|
||||
AppEvents().notifyFilterListeners([MessageFilterChipletType.sender], chiplets);
|
||||
}
|
||||
|
||||
Widget _buildList(BuildContext context, List<String> list) {
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (builder, index) {
|
||||
final sender = list[index];
|
||||
return ListTile(
|
||||
title: Text(sender),
|
||||
leading: Icon(_selectedEntries.contains(sender) ? Icons.check_box : Icons.check_box_outline_blank, color: Theme.of(context).primaryColor),
|
||||
onTap: () => toggleEntry(sender),
|
||||
visualDensity: VisualDensity(vertical: -4),
|
||||
);
|
||||
},
|
||||
itemCount: list.length,
|
||||
);
|
||||
}
|
||||
}
|
49
flutter/lib/components/modals/filter_modal_time.dart
Normal file
49
flutter/lib/components/modals/filter_modal_time.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:simplecloudnotifier/api/api_client.dart';
|
||||
import 'package:simplecloudnotifier/pages/message_list/message_filter_chiplet.dart';
|
||||
import 'package:simplecloudnotifier/state/app_auth.dart';
|
||||
import 'package:simplecloudnotifier/state/app_events.dart';
|
||||
import 'package:simplecloudnotifier/types/immediate_future.dart';
|
||||
|
||||
class FilterModalTime extends StatefulWidget {
|
||||
@override
|
||||
_FilterModalTimeState createState() => _FilterModalTimeState();
|
||||
}
|
||||
|
||||
class _FilterModalTimeState extends State<FilterModalTime> {
|
||||
DateTime? _tsBefore = null;
|
||||
DateTime? _tsAfter = null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Timerange'),
|
||||
content: Container(
|
||||
width: 9000,
|
||||
height: 9000,
|
||||
child: Placeholder(),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(textStyle: Theme.of(context).textTheme.labelLarge),
|
||||
child: const Text('Apply'),
|
||||
onPressed: () {
|
||||
onOkay();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void onOkay() {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
//TODO
|
||||
}
|
||||
}
|
@@ -359,7 +359,7 @@ Future<void> _receiveMessage(RemoteMessage message, bool foreground) async {
|
||||
SCNDataCache().addToMessageCache([msg]);
|
||||
if (foreground) AppEvents().notifyMessageReceivedListeners(msg);
|
||||
} catch (exc, trace) {
|
||||
ApplicationLog.error('Failed to query+persist message' + exc.toString(), trace: trace);
|
||||
ApplicationLog.error('Failed to query+persist message: ' + exc.toString(), trace: trace);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -12,11 +12,11 @@ class Channel extends HiveObject implements FieldDebuggable {
|
||||
@HiveField(10)
|
||||
final String ownerUserID;
|
||||
@HiveField(11)
|
||||
final String internalName;
|
||||
final String internalName; // = InternalName, used for sending, normalized, cannot be changed
|
||||
@HiveField(12)
|
||||
final String displayName;
|
||||
final String displayName; // = DisplayName, used for display purposes, can be changed, initially equals InternalName
|
||||
@HiveField(13)
|
||||
final String? descriptionName;
|
||||
final String? descriptionName; // = DescriptionName, (optional), longer description text, initally nil
|
||||
@HiveField(14)
|
||||
final String? subscribeKey;
|
||||
@HiveField(15)
|
||||
|
@@ -75,7 +75,7 @@ class _ChannelRootPageState extends State<ChannelRootPage> with RouteAware {
|
||||
() async {
|
||||
_reloadEnqueued = false;
|
||||
AppBarState().setLoadingIndeterminate(true);
|
||||
await Future.delayed(const Duration(milliseconds: 500)); // prevents flutter bug where the whole process crashes ?!?
|
||||
await Future.delayed(const Duration(milliseconds: 500), () {}); // prevents flutter bug where the whole process crashes ?!?
|
||||
await _backgroundRefresh();
|
||||
}();
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ class _ChannelListItemState extends State<ChannelListItem> {
|
||||
lastMessage = SCNDataCache().getMessagesSorted().where((p) => p.channelID == widget.channel.channelID).firstOrNull;
|
||||
|
||||
() async {
|
||||
final (_, channelMessages) = await APIClient.getMessageList(acc, '@start', pageSize: 1, channelIDs: [widget.channel.channelID]);
|
||||
final (_, channelMessages) = await APIClient.getMessageList(acc, '@start', pageSize: 1, filter: MessageFilter(channelIDs: [widget.channel.channelID]));
|
||||
setState(() {
|
||||
lastMessage = channelMessages.firstOrNull;
|
||||
});
|
||||
|
@@ -55,7 +55,7 @@ class _ChannelMessageViewPageState extends State<ChannelMessageViewPage> {
|
||||
}
|
||||
|
||||
try {
|
||||
final (npt, newItems) = await APIClient.getMessageList(acc, thisPageToken, pageSize: cfg.messagePageSize, channelIDs: [this.widget.channel.channelID]);
|
||||
final (npt, newItems) = await APIClient.getMessageList(acc, thisPageToken, pageSize: cfg.messagePageSize, filter: MessageFilter(channelIDs: [this.widget.channel.channelID]));
|
||||
|
||||
SCNDataCache().addToMessageCache(newItems); // no await
|
||||
|
||||
|
@@ -11,8 +11,8 @@ enum MessageFilterChipletType {
|
||||
}
|
||||
|
||||
class MessageFilterChiplet {
|
||||
final String label;
|
||||
final String value;
|
||||
final String label; // display value
|
||||
final dynamic value; // search/api value
|
||||
final MessageFilterChipletType type;
|
||||
|
||||
MessageFilterChiplet({required this.label, required this.value, required this.type});
|
||||
|
@@ -39,7 +39,7 @@ class _MessageListPageState extends State<MessageListPage> with RouteAware {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
AppEvents().subscribeSearchListener(_onAppBarSearch);
|
||||
AppEvents().subscribeFilterListener(_onAddFilter);
|
||||
AppEvents().subscribeMessageReceivedListener(_onMessageReceivedViaNotification);
|
||||
|
||||
_pagingController.addPageRequestListener(_fetchPage);
|
||||
@@ -92,7 +92,7 @@ class _MessageListPageState extends State<MessageListPage> with RouteAware {
|
||||
@override
|
||||
void dispose() {
|
||||
ApplicationLog.debug('MessageListPage::dispose');
|
||||
AppEvents().unsubscribeSearchListener(_onAppBarSearch);
|
||||
AppEvents().unsubscribeFilterListener(_onAddFilter);
|
||||
AppEvents().unsubscribeMessageReceivedListener(_onMessageReceivedViaNotification);
|
||||
Navi.modalRouteObserver.unsubscribe(this);
|
||||
_pagingController.dispose();
|
||||
@@ -139,7 +139,7 @@ class _MessageListPageState extends State<MessageListPage> with RouteAware {
|
||||
SCNDataCache().setChannelCache(channels); // no await
|
||||
}
|
||||
|
||||
final (npt, newItems) = await APIClient.getMessageList(acc, thisPageToken, pageSize: cfg.messagePageSize);
|
||||
final (npt, newItems) = await APIClient.getMessageList(acc, thisPageToken, pageSize: cfg.messagePageSize, filter: _getFilter());
|
||||
|
||||
SCNDataCache().addToMessageCache(newItems); // no await
|
||||
|
||||
@@ -267,16 +267,28 @@ class _MessageListPageState extends State<MessageListPage> with RouteAware {
|
||||
child: InputChip(
|
||||
avatar: Icon(chiplet.icon()),
|
||||
label: Text(chiplet.label),
|
||||
onDeleted: () => setState(() => _filterChiplets.remove(chiplet)),
|
||||
onDeleted: () => _onRemFilter(chiplet),
|
||||
onPressed: () {/* TODO idk what to do here ? */},
|
||||
visualDensity: VisualDensity(horizontal: -4, vertical: -4),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onAppBarSearch(String str) {
|
||||
void _onAddFilter(List<MessageFilterChipletType> remTypeList, List<MessageFilterChiplet> chiplets) {
|
||||
setState(() {
|
||||
_filterChiplets = _filterChiplets.where((element) => false).toList() + [MessageFilterChiplet(label: str, value: str, type: MessageFilterChipletType.search)];
|
||||
final remTypes = remTypeList.toSet();
|
||||
|
||||
_filterChiplets = _filterChiplets.where((element) => !remTypes.contains(element.type)).toList() + chiplets;
|
||||
|
||||
_pagingController.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
void _onRemFilter(MessageFilterChiplet chiplet) {
|
||||
setState(() {
|
||||
_filterChiplets.remove(chiplet);
|
||||
|
||||
_pagingController.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -285,4 +297,35 @@ class _MessageListPageState extends State<MessageListPage> with RouteAware {
|
||||
_pagingController.itemList = [msg] + (_pagingController.itemList ?? []);
|
||||
});
|
||||
}
|
||||
|
||||
MessageFilter _getFilter() {
|
||||
var filter = MessageFilter();
|
||||
|
||||
var chipletsChannel = _filterChiplets.where((p) => p.type == MessageFilterChipletType.channel).toList();
|
||||
if (chipletsChannel.isNotEmpty) {
|
||||
filter.channelIDs = chipletsChannel.map((p) => p.value as String).toList();
|
||||
}
|
||||
|
||||
var chipletsSearch = _filterChiplets.where((p) => p.type == MessageFilterChipletType.search).toList();
|
||||
if (chipletsSearch.isNotEmpty) {
|
||||
filter.searchFilter = chipletsSearch.map((p) => p.value as String).first;
|
||||
}
|
||||
|
||||
var chipletsKeyTokens = _filterChiplets.where((p) => p.type == MessageFilterChipletType.sendkey).toList();
|
||||
if (chipletsKeyTokens.isNotEmpty) {
|
||||
filter.usedKeys = chipletsKeyTokens.map((p) => p.value as String).toList();
|
||||
}
|
||||
|
||||
var chipletPriority = _filterChiplets.where((p) => p.type == MessageFilterChipletType.priority).toList();
|
||||
if (chipletPriority.isNotEmpty) {
|
||||
filter.priority = chipletPriority.map((p) => p.value as int).toList();
|
||||
}
|
||||
|
||||
var chipletSender = _filterChiplets.where((p) => p.type == MessageFilterChipletType.sender).toList();
|
||||
if (chipletSender.isNotEmpty) {
|
||||
filter.senderNames = chipletSender.map((p) => p.value as String).toList();
|
||||
}
|
||||
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import 'package:simplecloudnotifier/models/scn_message.dart';
|
||||
import 'package:simplecloudnotifier/pages/message_list/message_filter_chiplet.dart';
|
||||
import 'package:simplecloudnotifier/state/application_log.dart';
|
||||
|
||||
class AppEvents {
|
||||
@@ -10,25 +11,30 @@ class AppEvents {
|
||||
|
||||
AppEvents._internal() {}
|
||||
|
||||
List<void Function(String)> _searchListeners = [];
|
||||
List<void Function(SCNMessage)> _messageReceivedListeners = [];
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
void subscribeSearchListener(void Function(String) listener) {
|
||||
_searchListeners.add(listener);
|
||||
List<void Function(List<MessageFilterChipletType> types, List<MessageFilterChiplet>)> _filterListeners = [];
|
||||
|
||||
void subscribeFilterListener(void Function(List<MessageFilterChipletType> types, List<MessageFilterChiplet>) listener) {
|
||||
_filterListeners.add(listener);
|
||||
}
|
||||
|
||||
void unsubscribeSearchListener(void Function(String) listener) {
|
||||
_searchListeners.remove(listener);
|
||||
void unsubscribeFilterListener(void Function(List<MessageFilterChipletType> types, List<MessageFilterChiplet>) listener) {
|
||||
_filterListeners.remove(listener);
|
||||
}
|
||||
|
||||
void notifySearchListeners(String query) {
|
||||
ApplicationLog.debug('[AppEvents] onSearch: $query');
|
||||
void notifyFilterListeners(List<MessageFilterChipletType> types, List<MessageFilterChiplet> query) {
|
||||
ApplicationLog.debug('[AppEvents] onFilter: [${types.join(" ; ")}], [${query.map((e) => e.label).join('|')}]');
|
||||
|
||||
for (var listener in _searchListeners) {
|
||||
listener(query);
|
||||
for (var listener in _filterListeners) {
|
||||
listener(types, query);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
List<void Function(SCNMessage)> _messageReceivedListeners = [];
|
||||
|
||||
void subscribeMessageReceivedListener(void Function(SCNMessage) listener) {
|
||||
_messageReceivedListeners.add(listener);
|
||||
}
|
||||
|
@@ -1,18 +1,26 @@
|
||||
// This class is useful togther with FutureBuilder
|
||||
// Unfortunately Future.value(x) in FutureBuilder always results in one frame were snapshot.connectionState is waiting
|
||||
// Whit way we can set the ImmediateFuture.value directly and circumvent that.
|
||||
// This way we can set the ImmediateFuture.value directly and circumvent that.
|
||||
|
||||
class ImmediateFuture<T> {
|
||||
final Future<T> future;
|
||||
final T? value;
|
||||
|
||||
T? _futureValue = null;
|
||||
|
||||
ImmediateFuture(this.future, this.value);
|
||||
|
||||
ImmediateFuture.ofFuture(Future<T> v)
|
||||
: future = v,
|
||||
value = null;
|
||||
value = null {
|
||||
future.then((v) => _futureValue = v);
|
||||
}
|
||||
|
||||
ImmediateFuture.ofValue(T v)
|
||||
: future = Future.value(v),
|
||||
value = v;
|
||||
|
||||
T? get() {
|
||||
return value ?? _futureValue;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user