Browse Source

Merge pull request #87 from jld3103/feature/updating-relative-times

neon: Implement self updating relative times
pull/88/head
jld3103 2 years ago committed by GitHub
parent
commit
b8ee427c46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      packages/neon/lib/src/apps/files/widgets/browser_view.dart
  2. 6
      packages/neon/lib/src/apps/news/widgets/articles_view.dart
  3. 6
      packages/neon/lib/src/apps/notes/widgets/notes_view.dart
  4. 4
      packages/neon/lib/src/apps/notifications/pages/main.dart
  5. 2
      packages/neon/lib/src/neon.dart
  6. 22
      packages/neon/lib/src/widgets/relative_time.dart

4
packages/neon/lib/src/apps/files/widgets/browser_view.dart

@ -244,7 +244,9 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
),
subtitle: Row(
children: [
Text(CustomTimeAgo.format(details.lastModified)),
RelativeTime(
date: details.lastModified,
),
if (details.size > 0) ...[
const SizedBox(
width: 10,

6
packages/neon/lib/src/apps/news/widgets/articles_view.dart

@ -169,10 +169,8 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
borderRadius: const BorderRadius.all(Radius.circular(2)),
),
),
Text(
CustomTimeAgo.format(
DateTime.fromMillisecondsSinceEpoch(article.pubDate! * 1000),
),
RelativeTime(
date: DateTime.fromMillisecondsSinceEpoch(article.pubDate! * 1000),
style: const TextStyle(
fontWeight: FontWeight.w300,
fontSize: 12,

6
packages/neon/lib/src/apps/notes/widgets/notes_view.dart

@ -89,10 +89,8 @@ class NotesView extends StatelessWidget {
title: Text(note.title!),
subtitle: Row(
children: [
Text(
CustomTimeAgo.format(
DateTime.fromMillisecondsSinceEpoch(note.modified! * 1000),
),
RelativeTime(
date: DateTime.fromMillisecondsSinceEpoch(note.modified! * 1000),
),
if (note.category! != '') ...[
const SizedBox(

4
packages/neon/lib/src/apps/notifications/pages/main.dart

@ -81,7 +81,9 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
height: 5,
),
],
Text(CustomTimeAgo.format(DateTime.parse(notification.datetime!))),
RelativeTime(
date: DateTime.parse(notification.datetime!),
),
],
),
leading: matchingAppImplementations.isNotEmpty

2
packages/neon/lib/src/neon.dart

@ -69,7 +69,6 @@ part 'platform/platform.dart';
part 'utils/account_options.dart';
part 'utils/app_implementation.dart';
part 'utils/confirmation_dialog.dart';
part 'utils/custom_timeago.dart';
part 'utils/env.dart';
part 'utils/global.dart';
part 'utils/global_options.dart';
@ -99,5 +98,6 @@ part 'widgets/image_wrapper.dart';
part 'widgets/neon_logo.dart';
part 'widgets/nextcloud_logo.dart';
part 'widgets/no_animation_page_route.dart';
part 'widgets/relative_time.dart';
part 'widgets/result_stream_builder.dart';
part 'widgets/standard_rx_result_builder.dart';

22
packages/neon/lib/src/utils/custom_timeago.dart → packages/neon/lib/src/widgets/relative_time.dart

@ -1,9 +1,18 @@
part of '../neon.dart';
class CustomTimeAgo {
class RelativeTime extends StatelessWidget {
const RelativeTime({
required this.date,
this.style,
super.key,
});
final DateTime date;
final TextStyle? style;
static String format(final DateTime date) {
final now = DateTime.now();
var diff = now.difference(date);
var diff = now.difference(date.toLocal());
final text = StringBuffer();
// Sometimes something can be messed up...
@ -28,4 +37,13 @@ class CustomTimeAgo {
return text.toString();
}
@override
Widget build(final BuildContext context) => StreamBuilder(
stream: Stream.periodic(const Duration(minutes: 1)),
builder: (final context, final _) => Text(
format(date),
style: style,
),
);
}
Loading…
Cancel
Save