Skip to content

Commit

Permalink
Remove timeago
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Dec 19, 2024
1 parent 70d284c commit 2081125
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 100 deletions.
68 changes: 0 additions & 68 deletions lib/src/intl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:intl/intl.dart';
import 'package:lichess_mobile/src/binding.dart';
import 'package:lichess_mobile/src/model/settings/general_preferences.dart';
import 'package:lichess_mobile/src/model/settings/preferences_storage.dart';
import 'package:timeago/timeago.dart' as timeago;

/// Setup [Intl.defaultLocale] and timeago locale and messages.
Future<Locale> setupIntl(WidgetsBinding widgetsBinding) async {
Expand All @@ -22,72 +21,5 @@ Future<Locale> setupIntl(WidgetsBinding widgetsBinding) async {

Intl.defaultLocale = locale.toLanguageTag();

// we need to setup timeago locale manually
final currentLocale = Intl.getCurrentLocale();
final longLocale = Intl.canonicalizedLocale(currentLocale);
final messages = _timeagoLocales[longLocale];
if (messages != null) {
timeago.setLocaleMessages(longLocale, messages);
timeago.setDefaultLocale(longLocale);
} else {
final shortLocale = Intl.shortLocale(currentLocale);
final messages = _timeagoLocales[shortLocale];
if (messages != null) {
timeago.setLocaleMessages(shortLocale, messages);
timeago.setDefaultLocale(shortLocale);
}
}

return locale;
}

final Map<String, timeago.LookupMessages> _timeagoLocales = {
'am': timeago.AmMessages(),
'ar': timeago.ArMessages(),
'az': timeago.AzMessages(),
'be': timeago.BeMessages(),
'bs': timeago.BsMessages(),
'ca': timeago.CaMessages(),
'cs': timeago.CsMessages(),
'da': timeago.DaMessages(),
'de': timeago.DeMessages(),
'dv': timeago.DvMessages(),
'en': timeago.EnMessages(),
'es': timeago.EsMessages(),
'et': timeago.EtMessages(),
'fa': timeago.FaMessages(),
'fi': timeago.FiMessages(),
'fr': timeago.FrMessages(),
'gr': timeago.GrMessages(),
'he': timeago.HeMessages(),
'hi': timeago.HiMessages(),
'hr': timeago.HrMessages(),
'hu': timeago.HuMessages(),
'id': timeago.IdMessages(),
'it': timeago.ItMessages(),
'ja': timeago.JaMessages(),
'km': timeago.KmMessages(),
'ko': timeago.KoMessages(),
'ku': timeago.KuMessages(),
'lv': timeago.LvMessages(),
'mn': timeago.MnMessages(),
'ms_MY': timeago.MsMyMessages(),
'nb_NO': timeago.NbNoMessages(),
'nl': timeago.NlMessages(),
'nn_NO': timeago.NnNoMessages(),
'pl': timeago.PlMessages(),
'pt_BR': timeago.PtBrMessages(),
'ro': timeago.RoMessages(),
'ru': timeago.RuMessages(),
'sr': timeago.SrMessages(),
'sv': timeago.SvMessages(),
'ta': timeago.TaMessages(),
'th': timeago.ThMessages(),
'tk': timeago.TkMessages(),
'tr': timeago.TrMessages(),
'uk': timeago.UkMessages(),
'ur': timeago.UrMessages(),
'vi': timeago.ViMessages(),
'zh_CN': timeago.ZhCnMessages(),
'zh': timeago.ZhMessages(),
};
4 changes: 2 additions & 2 deletions lib/src/view/game/game_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:lichess_mobile/src/model/game/game_status.dart';
import 'package:lichess_mobile/src/network/http.dart';
import 'package:lichess_mobile/src/styles/lichess_colors.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/l10n.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/utils/share.dart';
Expand All @@ -23,7 +24,6 @@ import 'package:lichess_mobile/src/widgets/board_thumbnail.dart';
import 'package:lichess_mobile/src/widgets/feedback.dart';
import 'package:lichess_mobile/src/widgets/list.dart';
import 'package:lichess_mobile/src/widgets/user_full_name.dart';
import 'package:timeago/timeago.dart' as timeago;

final _dateFormatter = DateFormat.yMMMd().add_Hm();

Expand Down Expand Up @@ -420,7 +420,7 @@ class ExtendedGameListTile extends StatelessWidget {
aiLevel: opponent.aiLevel,
rating: opponent.rating,
),
subtitle: Text(timeago.format(game.lastMoveAt)),
subtitle: Text(relativeDate(context.l10n, game.lastMoveAt, shortDate: false)),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expand Down
9 changes: 2 additions & 7 deletions lib/src/view/game/offline_correspondence_games_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/model/correspondence/correspondence_game_storage.dart';
import 'package:lichess_mobile/src/model/correspondence/offline_correspondence_game.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/l10n.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/view/correspondence/offline_correspondence_game_screen.dart';
import 'package:lichess_mobile/src/widgets/board_preview.dart';
import 'package:lichess_mobile/src/widgets/platform_scaffold.dart';
import 'package:lichess_mobile/src/widgets/user_full_name.dart';
import 'package:timeago/timeago.dart' as timeago;

class OfflineCorrespondenceGamesScreen extends ConsumerWidget {
const OfflineCorrespondenceGamesScreen({super.key});
Expand Down Expand Up @@ -69,12 +69,7 @@ class OfflineCorrespondenceGamePreview extends ConsumerWidget {
children: [
UserFullNameWidget(user: game.opponent.user, style: Styles.boardPreviewTitle),
if (game.myTimeLeft(lastModified) != null)
Text(
timeago.format(
DateTime.now().add(game.myTimeLeft(lastModified)!),
allowFromNow: true,
),
),
Text(relativeDate(context.l10n, DateTime.now().add(game.myTimeLeft(lastModified)!))),
Icon(game.perf.icon, size: 40, color: DefaultTextStyle.of(context).style.color),
],
),
Expand Down
5 changes: 2 additions & 3 deletions lib/src/view/home/home_tab_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import 'package:lichess_mobile/src/widgets/buttons.dart';
import 'package:lichess_mobile/src/widgets/feedback.dart';
import 'package:lichess_mobile/src/widgets/misc.dart';
import 'package:lichess_mobile/src/widgets/user_full_name.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:url_launcher/url_launcher.dart';

final editModeProvider = StateProvider<bool>((ref) => false);
Expand Down Expand Up @@ -663,9 +662,9 @@ class _GamePreviewCarouselItem extends StatelessWidget {
],
Text(
game.secondsLeft != null && game.isMyTurn
? timeago.format(
? relativeDate(
context.l10n,
DateTime.now().add(Duration(seconds: game.secondsLeft!)),
allowFromNow: true,
)
: game.isMyTurn
? context.l10n.yourTurn
Expand Down
7 changes: 2 additions & 5 deletions lib/src/view/play/ongoing_games_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/model/account/account_repository.dart';
import 'package:lichess_mobile/src/model/account/ongoing_game.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/l10n.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/view/game/game_screen.dart';
import 'package:lichess_mobile/src/widgets/board_preview.dart';
import 'package:lichess_mobile/src/widgets/platform.dart';
import 'package:lichess_mobile/src/widgets/user_full_name.dart';
import 'package:timeago/timeago.dart' as timeago;

class OngoingGamesScreen extends ConsumerWidget {
const OngoingGamesScreen({super.key});
Expand Down Expand Up @@ -83,10 +83,7 @@ class OngoingGamePreview extends ConsumerWidget {
Text(game.isMyTurn ? context.l10n.yourTurn : context.l10n.waitingForOpponent),
if (game.isMyTurn && game.secondsLeft != null)
Text(
timeago.format(
DateTime.now().add(Duration(seconds: game.secondsLeft!)),
allowFromNow: true,
),
relativeDate(context.l10n, DateTime.now().add(Duration(seconds: game.secondsLeft!))),
),
],
),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/view/puzzle/puzzle_history_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import 'package:lichess_mobile/src/model/puzzle/puzzle_activity.dart';
import 'package:lichess_mobile/src/model/puzzle/puzzle_angle.dart';
import 'package:lichess_mobile/src/model/puzzle/puzzle_theme.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/l10n.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/utils/screen.dart';
import 'package:lichess_mobile/src/view/puzzle/puzzle_screen.dart';
import 'package:lichess_mobile/src/widgets/board_thumbnail.dart';
import 'package:lichess_mobile/src/widgets/feedback.dart';
import 'package:lichess_mobile/src/widgets/platform_scaffold.dart';
import 'package:timeago/timeago.dart' as timeago;

final _dateFormatter = DateFormat.yMMMd();

Expand Down Expand Up @@ -155,7 +155,7 @@ class _BodyState extends ConsumerState<_Body> {
final title =
DateTime.now().difference(element).inDays >= 15
? _dateFormatter.format(element)
: timeago.format(element);
: relativeDate(context.l10n, element);
return Padding(
padding: const EdgeInsets.only(left: _kPuzzlePadding).add(Styles.sectionTopPadding),
child: Text(
Expand Down
4 changes: 2 additions & 2 deletions lib/src/view/study/study_list_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:lichess_mobile/src/model/study/study_filter.dart';
import 'package:lichess_mobile/src/model/study/study_list_paginator.dart';
import 'package:lichess_mobile/src/styles/lichess_icons.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/l10n.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/lichess_assets.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
Expand All @@ -19,7 +20,6 @@ import 'package:lichess_mobile/src/widgets/platform_scaffold.dart';
import 'package:lichess_mobile/src/widgets/platform_search_bar.dart';
import 'package:lichess_mobile/src/widgets/user_full_name.dart';
import 'package:logging/logging.dart';
import 'package:timeago/timeago.dart' as timeago;

final _logger = Logger('StudyListScreen');

Expand Down Expand Up @@ -385,7 +385,7 @@ class _StudySubtitle extends StatelessWidget {
),
const TextSpan(text: ' • '),
],
TextSpan(text: timeago.format(study.updatedAt)),
TextSpan(text: relativeDate(context.l10n, study.updatedAt)),
],
),
);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/view/user/user_profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import 'package:lichess_mobile/src/model/user/profile.dart';
import 'package:lichess_mobile/src/model/user/user.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/duration.dart';
import 'package:lichess_mobile/src/utils/l10n.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/lichess_assets.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/view/user/user_screen.dart';
import 'package:lichess_mobile/src/widgets/buttons.dart';
import 'package:linkify/linkify.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:url_launcher/url_launcher.dart';

import 'countries.dart';
Expand Down Expand Up @@ -112,7 +112,7 @@ class UserProfileWidget extends ConsumerWidget {
Text('${context.l10n.memberSince} ${DateFormat.yMMMMd().format(user.createdAt!)}'),
if (user.seenAt != null) ...[
const SizedBox(height: 5),
Text(context.l10n.lastSeenActive(timeago.format(user.seenAt!))),
Text(context.l10n.lastSeenActive(relativeDate(context.l10n, user.seenAt!))),
],
if (user.playTime != null) ...[
const SizedBox(height: 5),
Expand Down
8 changes: 0 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1473,14 +1473,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.3"
timeago:
dependency: "direct main"
description:
name: timeago
sha256: "054cedf68706bb142839ba0ae6b135f6b68039f0b8301cbe8784ae653d5ff8de"
url: "https://pub.dev"
source: hosted
version: "3.7.0"
timezone:
dependency: transitive
description:
Expand Down
1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ dependencies:
url: https://github.com/lichess-org/dart-stockfish.git
ref: 0b4d8f20f72beb43c853230dd18063bee242487d
stream_transform: ^2.1.0
timeago: ^3.6.0
url_launcher: ^6.1.9
visibility_detector: ^0.4.0
wakelock_plus: ^1.1.1
Expand Down

0 comments on commit 2081125

Please sign in to comment.