Skip to content

Commit

Permalink
Add 'always force 24 hour' setting (#862)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertodoering committed Dec 20, 2022
1 parent db3c184 commit a1ab328
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
10 changes: 10 additions & 0 deletions lib/components/settings/general/general_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ class _GeneralSettingsList extends ConsumerWidget {
),
),
VerticalSpacer.normal,
Card(
child: RbySwitchTile(
leading: const Icon(Icons.access_time),
title: const Text('always use 24-hour time format'),
value: general.alwaysUse24HourFormat,
borderRadius: theme.shape.borderRadius,
onChanged: generalNotifier.setAlwaysUse24HourFormat,
),
),
VerticalSpacer.normal,
Card(
child: RbySwitchTile(
leading: const Icon(FeatherIcons.feather),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class GeneralPreferencesNotifier extends StateNotifier<GeneralPreferences> {
preferences.getBool('timelineRefreshBehavior', false),
hideHomeAppBar: preferences.getBool('hideHomeTabBar', true),
bottomAppBar: preferences.getBool('bottomAppBar', false),
alwaysUse24HourFormat: preferences.getBool(
'alwaysUse24HourFormat',
false,
),
),
);

Expand All @@ -56,6 +60,7 @@ class GeneralPreferencesNotifier extends StateNotifier<GeneralPreferences> {
setFloatingComposeButton(false);
setHideHomeAppbar(true);
setBottomAppBar(false);
setAlwaysUse24HourFormat(false);
}

void setShowChangelogDialog(bool value) {
Expand Down Expand Up @@ -98,6 +103,11 @@ class GeneralPreferencesNotifier extends StateNotifier<GeneralPreferences> {
_preferences.setBool('bottomAppBar', value);
}

void setAlwaysUse24HourFormat(bool value) {
state = state.copyWith(alwaysUse24HourFormat: value);
_preferences.setBool('alwaysUse24HourFormat', value);
}

void updateLastShownVersion() {
final version = _deviceInfo.packageInfo?.buildNumber;

Expand Down Expand Up @@ -155,6 +165,7 @@ class GeneralPreferences with _$GeneralPreferences {
/// Whether the app bar should be built at the bottom of the home screen
/// instead of the top.
required bool bottomAppBar,
required bool alwaysUse24HourFormat,
}) = _GeneralPreferences;

GeneralPreferences._();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:harpy/api/api.dart';
import 'package:harpy/components/components.dart';
import 'package:rby/rby.dart';

class TweetCardDetails extends StatelessWidget {
class TweetCardDetails extends ConsumerWidget {
const TweetCardDetails({
required this.tweet,
required this.style,
Expand All @@ -13,16 +14,18 @@ class TweetCardDetails extends StatelessWidget {
final TweetCardElementStyle style;

@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
final l10n = Localizations.of<MaterialLocalizations>(
context,
MaterialLocalizations,
)!;
final general = ref.watch(generalPreferencesProvider);

final date = l10n.formatFullDate(tweet.createdAt.toLocal());
final time = l10n.formatTimeOfDay(
TimeOfDay.fromDateTime(tweet.createdAt.toLocal()),
alwaysUse24HourFormat: general.alwaysUse24HourFormat,
);

final textStyle = theme.textTheme.bodyText2!.apply(
Expand Down
10 changes: 7 additions & 3 deletions lib/components/tweet/widgets/card_content/tweet_card_handle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class _CreatedAtRelativeTimeState extends State<_CreatedAtRelativeTime> {
}
}

class _CreatedAtAbsoluteTime extends StatelessWidget {
class _CreatedAtAbsoluteTime extends ConsumerWidget {
const _CreatedAtAbsoluteTime({
required this.localCreatedAt,
this.sizeDelta = 0,
Expand All @@ -136,15 +136,19 @@ class _CreatedAtAbsoluteTime extends StatelessWidget {
final double sizeDelta;

@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
final l10n = Localizations.of<MaterialLocalizations>(
context,
MaterialLocalizations,
)!;
final general = ref.watch(generalPreferencesProvider);

final date = l10n.formatCompactDate(localCreatedAt);
final time = l10n.formatTimeOfDay(TimeOfDay.fromDateTime(localCreatedAt));
final time = l10n.formatTimeOfDay(
TimeOfDay.fromDateTime(localCreatedAt),
alwaysUse24HourFormat: general.alwaysUse24HourFormat,
);

return FittedBox(
child: Text(
Expand Down
2 changes: 2 additions & 0 deletions lib/components/tweet/widgets/tweet_actions_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ void showTweetActionsBottomSheet(
ref.context,
MaterialLocalizations,
)!;
final general = ref.watch(generalPreferencesProvider);

final date = l10n.formatFullDate(tweet.createdAt.toLocal());
final time = l10n.formatTimeOfDay(
TimeOfDay.fromDateTime(tweet.createdAt.toLocal()),
alwaysUse24HourFormat: general.alwaysUse24HourFormat,
);

showRbyBottomSheet<void>(
Expand Down

0 comments on commit a1ab328

Please sign in to comment.