Skip to content

Commit

Permalink
Events Time Filter (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa authored Jun 19, 2024
2 parents 7e2ff5e + ada083f commit 90693a6
Show file tree
Hide file tree
Showing 30 changed files with 558 additions and 165 deletions.
5 changes: 5 additions & 0 deletions bluecherry_appcast.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
<channel>
<title>Bluecherry - Appcast</title>
<item>
<title>Version 3.0.0-beta17</title>
<description>Fixed Secondary Windows; Improved logging; and Addressed memory leaks and stream continuity.</description>
<pubDate>Fri, 07 Jun 2024</pubDate>
</item>
<item>
<title>Version 3.0.0-beta16</title>
<description>Improved iOS support, improved events fetching logic and performance and implemented software zoom.</description>
Expand Down
2 changes: 1 addition & 1 deletion installer/windows-installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Bluecherry DVR"
#define MyAppVersion "3.0.0-beta16"
#define MyAppVersion "3.0.0-beta17"
#define MyAppPublisher "Bluecherry DVR"
#define MyAppURL "https://www.bluecherrydvr.com/"
#define MyAppExeName "bluecherry_client.exe"
Expand Down
9 changes: 5 additions & 4 deletions lib/api/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:bluecherry_client/api/api_helpers.dart';
import 'package:bluecherry_client/models/device.dart';
import 'package:bluecherry_client/models/event.dart';
import 'package:bluecherry_client/models/server.dart';
import 'package:bluecherry_client/utils/date.dart';
import 'package:bluecherry_client/utils/methods.dart';
import 'package:flutter/foundation.dart';
import 'package:xml2json/xml2json.dart';
Expand Down Expand Up @@ -45,8 +46,8 @@ extension EventsExtension on API {
return [];
}

var startTime = data['startTime'] as DateTime?;
final endTime = data['endTime'] as DateTime?;
var startTime = (data['startTime'] as DateTime?)?.toLocal();
final endTime = (data['endTime'] as DateTime?)?.toLocal();
final deviceId = data['device_id'] as int?;
final limit = (data['limit'] as int?) ?? -1;

Expand Down Expand Up @@ -151,11 +152,11 @@ extension EventsExtension on API {
title: e['title']['\$t'],
publishedRaw: e['published']['\$t'],
published: e['published'] == null || e['published']['\$t'] == null
? DateTime.now()
? DateTimeExtension.now()
: DateTime.parse(e['published']['\$t']),
updatedRaw: e['updated']['\$t'] ?? e['published']['\$t'],
updated: e['updated'] == null || e['updated']['\$t'] == null
? DateTime.now()
? DateTimeExtension.now()
: DateTime.parse(e['updated']['\$t']),
category: e['category']['term'],
mediaID: !e.containsKey('content')
Expand Down
19 changes: 17 additions & 2 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"lastImageUpdate": "Last Image Update",
"fps": "FPS",
"date": "Date",
"time": "Time",
"lastUpdate": "Last Update",
"screens": "Screens",
"directCamera": "Direct Camera",
Expand Down Expand Up @@ -332,13 +333,16 @@
}
}
},
"timeFilter": "Time filter",
"period": "Period",
"dateTimeFilter": "Date and Time Filter",
"dateFilter": "Date Filter",
"timeFilter": "Time Filter",
"fromDate": "From",
"toDate": "To",
"today": "Today",
"yesterday": "Yesterday",
"never": "never",
"fromToDate": "{from} to {to}",
"fromToDate": "From {from} to {to}",
"@fromToDate": {
"placeholders": {
"from": {
Expand All @@ -349,6 +353,17 @@
}
}
},
"@fromToTime": {
"placeholders": {
"from": {
"type": "String"
},
"to": {
"type": "String"
}
}
},
"mostRecent": "Most recent",
"allowAlarms": "Allow alarms",
"nextEvents": "Next events",
"nEvents": "{n, plural, =0{No events} =1{1 event} other{{n} events}}",
Expand Down
15 changes: 15 additions & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"lastImageUpdate": "Dernier rafraîchissemente",
"fps": "FPS",
"date": "Date",
"time": "Time",
"lastUpdate": "Dernière mise à jour",
"screens": "Écrans",
"directCamera": "Caméra direct",
Expand Down Expand Up @@ -310,6 +311,9 @@
}
}
},
"period": "Period",
"dateTimeFilter": "Date Time Filter",
"dateFilter": "Date Filter",
"timeFilter": "Filtre par période",
"fromDate": "De",
"toDate": "À",
Expand All @@ -327,6 +331,17 @@
}
}
},
"@fromToTime": {
"placeholders": {
"from": {
"type": "String"
},
"to": {
"type": "String"
}
}
},
"mostRecent": "Most recent",
"allowAlarms": "Permettre les alarmes",
"nextEvents": "Prochains évènements",
"nEvents": "{n, plural, =0{Aucun évènement} =1{1 évènement} other{{n} évènements}}",
Expand Down
15 changes: 15 additions & 0 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"lastImageUpdate": "Ostatnia aktualizacja obrazu",
"fps": "FPS",
"date": "Data",
"time": "Time",
"lastUpdate": "Ostatnia aktualizacja",
"screens": "Ekrany",
"directCamera": "Kamera bezpośrednia",
Expand Down Expand Up @@ -332,6 +333,9 @@
}
}
},
"period": "Period",
"dateTimeFilter": "Date Time Filter",
"dateFilter": "Date Filter",
"timeFilter": "Filtr czasu",
"fromDate": "Od",
"toDate": "Do",
Expand All @@ -349,6 +353,17 @@
}
}
},
"@fromToTime": {
"placeholders": {
"from": {
"type": "String"
},
"to": {
"type": "String"
}
}
},
"mostRecent": "Most recent",
"allowAlarms": "Zezwól na alarmy",
"nextEvents": "Następne zdarzenia",
"nEvents": "{n, plural, =0{Brak zdarzeń} =1{1 zdarzenie} other{{n} zdarzeń}}",
Expand Down
19 changes: 17 additions & 2 deletions lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"lastImageUpdate": "Última atualização da imagem",
"fps": "FPS",
"date": "Data",
"time": "Hora",
"lastUpdate": "Última atualização",
"screens": "Câmeras",
"directCamera": "Câmera específica",
Expand Down Expand Up @@ -332,13 +333,16 @@
}
}
},
"timeFilter": "Filtro de tempo",
"period": "Período",
"dateTimeFilter": "Filtro de Data e Hora",
"dateFilter": "Periodo",
"timeFilter": "Filtro de Tempo",
"fromDate": "De",
"toDate": "à",
"today": "Hoje",
"yesterday": "Ontem",
"never": "Nunca",
"fromToDate": "{from} à {to}",
"fromToDate": "De {from} à {to}",
"@fromToDate": {
"placeholders": {
"from": {
Expand All @@ -349,6 +353,17 @@
}
}
},
"@fromToTime": {
"placeholders": {
"from": {
"type": "String"
},
"to": {
"type": "String"
}
}
},
"mostRecent": "Mais recentes",
"allowAlarms": "Permitir alarmes",
"nextEvents": "Próximos eventos",
"nEvents": "{n, plural, =0{Nenhum evento} =1{1 evento} other{{n} eventos}}",
Expand Down
10 changes: 6 additions & 4 deletions lib/models/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import 'package:bluecherry_client/models/server.dart';
import 'package:bluecherry_client/providers/server_provider.dart';
import 'package:bluecherry_client/utils/date.dart';
import 'package:bluecherry_client/utils/extensions.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down Expand Up @@ -64,10 +65,11 @@ class Event {
this.mediaID,
this.mediaURL,
}) : server = server ?? ServersProvider.instance.servers.first,
publishedRaw = publishedRaw ?? DateTime.now().toIso8601String(),
published = published ?? DateTime.now(),
updatedRaw = updatedRaw ?? DateTime.now().toIso8601String(),
updated = updated ?? DateTime.now();
publishedRaw =
publishedRaw ?? DateTimeExtension.now().toIso8601String(),
published = published ?? DateTimeExtension.now(),
updatedRaw = updatedRaw ?? DateTimeExtension.now().toIso8601String(),
updated = updated ?? DateTimeExtension.now();

String get deviceName {
return title
Expand Down
36 changes: 31 additions & 5 deletions lib/providers/events_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,22 @@ class EventsProvider extends UnityProvider {
save();
}

DateTime? startTime, endTime;
DateTime? _startDate;
DateTime? get startDate => _startDate;
set startDate(DateTime? value) {
_startDate = value;
notifyListeners();
}

DateTime? _endDate;
DateTime? get endDate => _endDate;
set endDate(DateTime? value) {
_endDate = value;
notifyListeners();
}

bool get isDateSet => _startDate != null && _endDate != null;

EventsMinLevelFilter _levelFilter = EventsMinLevelFilter.any;
EventsMinLevelFilter get levelFilter => _levelFilter;
set levelFilter(EventsMinLevelFilter value) {
Expand Down Expand Up @@ -122,7 +137,10 @@ class EventsProvider extends UnityProvider {
}

extension EventsScreenProvider on EventsProvider {
Future<void> loadEvents() async {
Future<void> loadEvents({
DateTime? startDate,
DateTime? endDate,
}) async {
loadedEvents = LoadedEvents();
_notify();

Expand All @@ -140,8 +158,8 @@ extension EventsScreenProvider on EventsProvider {
await Future.wait(allowedDevices.map((device) async {
final iterable = (await API.instance.getEvents(
server,
startTime: startTime,
endTime: endTime,
startTime: startDate ?? this.startDate,
endTime: endDate ?? this.startDate,
device: device,
))
.toList()
Expand All @@ -157,7 +175,15 @@ extension EventsScreenProvider on EventsProvider {
break;
}
return false;
});
})
..removeWhere((event) {
if (!isDateSet) return false;

return event.published.toUtc().isBefore(startDate!.toUtc()) ||
event.updated.toUtc().isAfter(endDate!.toUtc());
})
..sort(
(a, b) => b.published.toUtc().compareTo(a.published.toUtc()));

loadedEvents!.events[server] ??= [];
loadedEvents!.events[server]!.addAll(iterable);
Expand Down
3 changes: 2 additions & 1 deletion lib/providers/update_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ class UpdateManager extends UnityProvider {
if (versions != this.versions) this.versions = versions;

loading = false;
lastCheck = DateTime.now(); // this updates the screen already
// this updates the screen already because "lastCheck" is a setter. No need to trigger the update again
lastCheck = DateTime.now();
} catch (error, stackTrace) {
debugPrint(error.toString());
debugPrint(stackTrace.toString());
Expand Down
17 changes: 15 additions & 2 deletions lib/screens/downloads/downloads_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,21 @@ class _DownloadTileState extends State<DownloadTile> {
Text(eventType),
Text(widget.event.deviceName),
Text(widget.event.server.name),
Text(widget.event.duration
.humanReadable(context)),
Text(
() {
var fileSize = '';
if (isDownloaded) {
final size =
File(widget.downloadPath!).mbSize;
fileSize =
' (${size.toStringAsFixed(2)} MB)';
}

return widget.event.duration
.humanReadable(context) +
fileSize;
}(),
),
Text(at),
],
),
Expand Down
Loading

0 comments on commit 90693a6

Please sign in to comment.