Skip to content

Commit

Permalink
Events Dates Reestructuring (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa authored Apr 2, 2024
2 parents 3366447 + a245a1e commit d2de71b
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 67 deletions.
16 changes: 10 additions & 6 deletions lib/api/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extension EventsExtension on API {
events = ((jsonDecode(response.body) as Map)['entry'] as Iterable)
.cast<Map>()
.map((eventObject) {
final published = DateTime.parse(eventObject['published']).toLocal();
final published = DateTime.parse(eventObject['published']);
final event = Event(
server: server,
id: () {
Expand All @@ -115,10 +115,12 @@ extension EventsExtension on API {
'-1',
),
title: eventObject['title'],
publishedRaw: eventObject['published'],
published: published,
updatedRaw: eventObject['updated'] ?? eventObject['published'],
updated: eventObject['updated'] == null
? published
: DateTime.parse(eventObject['updated']).toLocal(),
: DateTime.parse(eventObject['updated']),
category: eventObject['category']['term'],
mediaID: eventObject.containsKey('content')
? int.parse(eventObject['content']['media_id'])
Expand Down Expand Up @@ -147,12 +149,14 @@ extension EventsExtension on API {
deviceID:
int.parse((e['category']['term'] as String).split('/').first),
title: e['title']['\$t'],
publishedRaw: e['published']['\$t'],
published: e['published'] == null || e['published']['\$t'] == null
? DateTime.now().toLocal()
: DateTime.parse(e['published']['\$t']).toLocal(),
? DateTime.now()
: DateTime.parse(e['published']['\$t']),
updatedRaw: e['updated']['\$t'] ?? e['published']['\$t'],
updated: e['updated'] == null || e['updated']['\$t'] == null
? DateTime.now().toLocal()
: DateTime.parse(e['updated']['\$t']).toLocal(),
? DateTime.now()
: DateTime.parse(e['updated']['\$t']),
category: e['category']['term'],
mediaID: !e.containsKey('content')
? null
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,19 @@
"firstEventInitialPoint": "First event",
"hourAgoInitialPoint": "1 hour ago",
"@@APPLICATION": {},
"appearance": "Appearance",
"theme": "Theme",
"themeDescription": "Change the appearance of the app",
"system": "System",
"light": "Light",
"dark": "Dark",
"dateAndTime": "Date and Time",
"dateFormat": "Date Format",
"dateFormatDescription": "What format to use for displaying dates",
"timeFormat": "Time Format",
"timeFormatDescription": "What format to use for displaying time",
"convertToLocalTime": "Convert dates to the local timezone",
"convertToLocalTimeDescription": "This will affect the date and time displayed in the app. This is useful when you are in a different timezone than the server. When disabled, the server timezone will be used.",
"@@PRIVACY_AND_SECURITY": {},
"privacyAndSecurity": "Privacy and Security",
"allowDataCollection": "Allow Bluecherry to collect usage data",
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,19 @@
"firstEventInitialPoint": "First event",
"hourAgoInitialPoint": "1 hour ago",
"@@APPLICATION": {},
"appearance": "Appearance",
"theme": "Thème",
"themeDescription": "Modifier l'apparence de l'application",
"system": "Système",
"light": "Clair",
"dark": "Sombre",
"dateAndTime": "Date and Time",
"dateFormat": "Format de la date",
"dateFormatDescription": "What format to use for displaying dates",
"timeFormat": "Format de l'heure",
"timeFormatDescription": "What format to use for displaying time",
"convertToLocalTime": "Convert dates to the local timezone",
"convertToLocalTimeDescription": "Convert all dates to the local timezone. This will affect the date and time displayed in the app. This is useful when you are in a different timezone than the server.",
"@@PRIVACY_AND_SECURITY": {},
"privacyAndSecurity": "Privacy and Security",
"allowDataCollection": "Allow Bluecherry to collect usage data",
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,19 @@
"firstEventInitialPoint": "First event",
"hourAgoInitialPoint": "1 hour ago",
"@@APPLICATION": {},
"appearance": "Appearance",
"theme": "Motyw",
"themeDescription": "Zmień wygląd aplikacji",
"system": "Systemowy",
"light": "Jasny",
"dark": "Ciemny",
"dateAndTime": "Date and Time",
"dateFormat": "Format daty",
"dateFormatDescription": "What format to use for displaying dates",
"timeFormat": "Format czasu",
"timeFormatDescription": "What format to use for displaying time",
"convertToLocalTime": "Convert dates to the local timezone",
"convertToLocalTimeDescription": "This will affect the date and time displayed in the app. This is useful when you are in a different timezone than the server. When disabled, the server timezone will be used.",
"@@PRIVACY_AND_SECURITY": {},
"privacyAndSecurity": "Privacy and Security",
"allowDataCollection": "Allow Bluecherry to collect usage data",
Expand Down
4 changes: 4 additions & 0 deletions lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,19 @@
"firstEventInitialPoint": "Primeiro evento",
"hourAgoInitialPoint": "1 hora atrás",
"@@APPLICATION": {},
"appearance": "Appearance",
"theme": "Aparência",
"themeDescription": "Mude a aparência do aplicativo",
"system": "Padrão do Sistema",
"light": "Claro",
"dark": "Escuro",
"dateAndTime": "Date and Time",
"dateFormat": "Formato da Data",
"dateFormatDescription": "Qual formato usar para exibir datas",
"timeFormat": "Formato de Hora",
"timeFormatDescription": "Qual formato usar para exibir horas",
"convertToLocalTime": "Convert dates to the local timezone",
"convertToLocalTimeDescription": "This will affect the date and time displayed in the app. This is useful when you are in a different timezone than the server. When disabled, the server timezone will be used.",
"@@PRIVACY_AND_SECURITY": {},
"privacyAndSecurity": "Privacidade e Segurança",
"allowDataCollection": "Permitir que Bluecherry colete dados de uso",
Expand Down
69 changes: 44 additions & 25 deletions lib/models/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class Event {
final int id;
final int deviceID;
final String title;
final String publishedRaw;
final DateTime published;
final String updatedRaw;
final DateTime updated;
final String? category;
final int? mediaID;
Expand All @@ -40,7 +42,9 @@ class Event {
required this.id,
required this.deviceID,
required this.title,
required this.publishedRaw,
required this.published,
required this.updatedRaw,
required this.updated,
required this.category,
required this.mediaID,
Expand All @@ -52,13 +56,17 @@ class Event {
this.id = 1,
this.deviceID = 1,
this.title = '',
String? publishedRaw,
DateTime? published,
String? updatedRaw,
DateTime? updated,
this.category,
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();

String get deviceName {
Expand Down Expand Up @@ -86,7 +94,9 @@ class Event {
other.id == id &&
other.deviceID == deviceID &&
other.title == title &&
other.publishedRaw == publishedRaw &&
other.published == published &&
other.updatedRaw == updatedRaw &&
other.updated == updated &&
other.category == category &&
other.mediaID == mediaID &&
Expand All @@ -99,39 +109,18 @@ class Event {
id.hashCode ^
deviceID.hashCode ^
title.hashCode ^
publishedRaw.hashCode ^
published.hashCode ^
updatedRaw.hashCode ^
updated.hashCode ^
category.hashCode ^
mediaID.hashCode ^
mediaURL.hashCode;
}

@override
String toString() =>
'Event($id, $deviceID, $title, $published, $updated, $category, $mediaID, $mediaURL)';

Event copyWith(
Server? server,
int? id,
int? deviceID,
String? title,
DateTime? published,
DateTime? updated,
String? category,
int? mediaID,
Uri? mediaURL,
) {
return Event(
server: server ?? this.server,
deviceID: deviceID ?? this.deviceID,
id: id ?? this.id,
title: title ?? this.title,
published: published ?? this.published,
updated: updated ?? this.updated,
category: category ?? this.category,
mediaID: mediaID ?? this.mediaID,
mediaURL: mediaURL ?? this.mediaURL,
);
String toString() {
return 'Event(server: $server, id: $id, deviceID: $deviceID, title: $title, publishedRaw: $publishedRaw, published: $published, updatedRaw: $updatedRaw, updated: $updated, category: $category, mediaID: $mediaID, mediaURL: $mediaURL)';
}

Map<String, dynamic> toJson() => {
Expand All @@ -152,7 +141,9 @@ class Event {
deviceID: json['deviceID'],
id: json['id'],
title: json['title'],
publishedRaw: json['published'],
published: DateTime.parse(json['published']),
updatedRaw: json['updated'],
updated: DateTime.parse(json['updated']),
category: json['category'],
mediaID: json['mediaID'],
Expand Down Expand Up @@ -210,6 +201,34 @@ class Event {
return EventType.unknown;
}
}

Event copyWith({
Server? server,
int? id,
int? deviceID,
String? title,
String? publishedRaw,
DateTime? published,
String? updatedRaw,
DateTime? updated,
String? category,
int? mediaID,
Uri? mediaURL,
}) {
return Event(
server: server ?? this.server,
id: id ?? this.id,
deviceID: deviceID ?? this.deviceID,
title: title ?? this.title,
publishedRaw: publishedRaw ?? this.publishedRaw,
published: published ?? this.published,
updatedRaw: updatedRaw ?? this.updatedRaw,
updated: updated ?? this.updated,
category: category ?? this.category,
mediaID: mediaID ?? this.mediaID,
mediaURL: mediaURL ?? this.mediaURL,
);
}
}

enum EventPriority {
Expand Down
34 changes: 16 additions & 18 deletions lib/providers/settings_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class _SettingsOption<T> {
});
}

T call() {
return value;
}

final T? min;
final T? max;

Expand Down Expand Up @@ -127,6 +131,11 @@ class _SettingsOption<T> {
_value = (await getDefault?.call()) ?? def;
}
}

@override
String toString() {
return 'SettingsOption<$T>($key: $_value)';
}
}

class SettingsProvider extends UnityProvider {
Expand Down Expand Up @@ -292,6 +301,10 @@ class SettingsProvider extends UnityProvider {
def: DateFormat('hh:mm a'),
key: 'application.time_format',
);
final kConvertTimeToLocalTimezone = _SettingsOption<bool>(
def: false,
key: 'application.convert_time_to_local_timezone',
);

// Window
final kLaunchAppOnStartup = _SettingsOption(
Expand Down Expand Up @@ -417,6 +430,7 @@ class SettingsProvider extends UnityProvider {
kLanguageCode.loadData(data),
kDateFormat.loadData(data),
kTimeFormat.loadData(data),
kConvertTimeToLocalTimezone.loadData(data),
kLaunchAppOnStartup.loadData(data),
kMinimizeToTray.loadData(data),
kAnimationsEnabled.loadData(data),
Expand Down Expand Up @@ -486,6 +500,8 @@ class SettingsProvider extends UnityProvider {
kLanguageCode.key: kLanguageCode.saveAs(kLanguageCode.value),
kDateFormat.key: kDateFormat.saveAs(kDateFormat.value),
kTimeFormat.key: kTimeFormat.saveAs(kTimeFormat.value),
kConvertTimeToLocalTimezone.key: kConvertTimeToLocalTimezone
.saveAs(kConvertTimeToLocalTimezone.value),
kLaunchAppOnStartup.key:
kLaunchAppOnStartup.saveAs(kLaunchAppOnStartup.value),
kMinimizeToTray.key: kMinimizeToTray.saveAs(kMinimizeToTray.value),
Expand Down Expand Up @@ -519,24 +535,6 @@ class SettingsProvider extends UnityProvider {
save();
}

/// Formats the date according to the current [dateFormat].
///
/// [toLocal] defines if the date will be converted to local time. Defaults to `true`
String formatDate(DateTime date, {bool toLocal = false}) {
if (toLocal) date = date.toLocal();

return kDateFormat.value.format(date);
}

/// Formats the date according to the current [dateFormat].
///
/// [toLocal] defines if the date will be converted to local time. Defaults to `true`
String formatTime(DateTime time, {bool toLocal = false}) {
if (toLocal) time = time.toLocal();

return kTimeFormat.value.format(time);
}

void toggleCycling() {
kLayoutCycleEnabled.value = !kLayoutCycleEnabled.value;
save();
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/downloads/downloads_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'package:bluecherry_client/providers/downloads_provider.dart';
import 'package:bluecherry_client/providers/home_provider.dart';
import 'package:bluecherry_client/providers/settings_provider.dart';
import 'package:bluecherry_client/screens/downloads/indicators.dart';
import 'package:bluecherry_client/utils/date.dart';
import 'package:bluecherry_client/utils/extensions.dart';
import 'package:bluecherry_client/utils/methods.dart';
import 'package:bluecherry_client/utils/theme.dart';
Expand Down Expand Up @@ -155,7 +156,7 @@ class _DownloadTileState extends State<DownloadTile> {
final settings = context.watch<SettingsProvider>();

final eventType = widget.event.type.locale(context).uppercaseFirst;
final at = settings.formatDate(widget.event.published);
final at = settings.formatRawDateAndTime(widget.event.publishedRaw);

final shape = RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
Expand Down
1 change: 1 addition & 0 deletions lib/screens/events_browser/events_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import 'package:bluecherry_client/screens/events_browser/filter.dart';
import 'package:bluecherry_client/screens/events_browser/sidebar.dart';
import 'package:bluecherry_client/screens/players/event_player_desktop.dart';
import 'package:bluecherry_client/utils/constants.dart';
import 'package:bluecherry_client/utils/date.dart';
import 'package:bluecherry_client/utils/extensions.dart';
import 'package:bluecherry_client/utils/methods.dart';
import 'package:bluecherry_client/widgets/desktop_buttons.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/events_browser/events_screen_desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class EventsScreenDesktop extends StatelessWidget {
),
_buildTilePart(
child: Text(
'${settings.formatDate(event.updated)} ${settings.formatTime(event.updated).toUpperCase()}',
settings.formatRawDateAndTime(event.publishedRaw),
),
flex: 2,
),
Expand Down
1 change: 1 addition & 0 deletions lib/screens/layouts/video_status_label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import 'package:bluecherry_client/models/device.dart';
import 'package:bluecherry_client/models/event.dart';
import 'package:bluecherry_client/providers/settings_provider.dart';
import 'package:bluecherry_client/utils/date.dart';
import 'package:bluecherry_client/utils/extensions.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down
Loading

0 comments on commit d2de71b

Please sign in to comment.