Compare commits

...

2 Commits

Author SHA1 Message Date
92a743f2f0 update date_display_format.dart (#379) 2024-02-20 22:21:25 -08:00
4148240daf update display_date_format.dart (#378) 2024-02-20 21:50:35 -08:00
6 changed files with 16 additions and 16 deletions

View File

@ -119,7 +119,7 @@ class PreferenceState extends Equatable {
Font get font => Font get font =>
Font.values.elementAt(preferences.singleWhereType<FontPreference>().val); Font.values.elementAt(preferences.singleWhereType<FontPreference>().val);
DisplayDateFormat get displayDateFormat => DisplayDateFormat.values DateDisplayFormat get displayDateFormat => DateDisplayFormat.values
.elementAt(preferences.singleWhereType<DateFormatPreference>().val); .elementAt(preferences.singleWhereType<DateFormatPreference>().val);
@override @override

View File

@ -3,7 +3,7 @@ import 'dart:io';
import 'package:hacki/extensions/date_time_extension.dart'; import 'package:hacki/extensions/date_time_extension.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
enum DisplayDateFormat { enum DateDisplayFormat {
timeAgo, timeAgo,
yMd, yMd,
yMEd, yMEd,
@ -24,7 +24,9 @@ enum DisplayDateFormat {
} }
String convertToString(int timestamp) { String convertToString(int timestamp) {
if (_cache.containsKey(timestamp)) { final bool isTimeAgo = this == timeAgo;
if (!isTimeAgo && _cache.containsKey(timestamp)) {
return _cache[timestamp] ?? 'This is wrong'; return _cache[timestamp] ?? 'This is wrong';
} }
@ -35,10 +37,8 @@ enum DisplayDateFormat {
final DateTime date = DateTime.fromMillisecondsSinceEpoch(updatedTimeStamp); final DateTime date = DateTime.fromMillisecondsSinceEpoch(updatedTimeStamp);
if (this == timeAgo) { if (isTimeAgo) {
final String dateString = date.toTimeAgoString(); return date.toTimeAgoString();
_cache[timestamp] = dateString;
return dateString;
} else { } else {
final String defaultLocale = Platform.localeName; final String defaultLocale = Platform.localeName;
final DateFormat formatter = DateFormat(name, defaultLocale).add_Hm(); final DateFormat formatter = DateFormat(name, defaultLocale).add_Hm();

View File

@ -1,7 +1,7 @@
export 'app_exception.dart'; export 'app_exception.dart';
export 'comments_order.dart'; export 'comments_order.dart';
export 'date_display_format.dart';
export 'discoverable_feature.dart'; export 'discoverable_feature.dart';
export 'display_date_format.dart';
export 'export_destination.dart'; export 'export_destination.dart';
export 'fetch_mode.dart'; export 'fetch_mode.dart';
export 'font.dart'; export 'font.dart';

View File

@ -548,7 +548,7 @@ final class TextScaleFactorPreference extends DoublePreference {
final class DateFormatPreference extends IntPreference { final class DateFormatPreference extends IntPreference {
DateFormatPreference({int? val}) : super(val: val ?? _dateFormatDefaultValue); DateFormatPreference({int? val}) : super(val: val ?? _dateFormatDefaultValue);
static final int _dateFormatDefaultValue = DisplayDateFormat.timeAgo.index; static final int _dateFormatDefaultValue = DateDisplayFormat.timeAgo.index;
@override @override
DateFormatPreference copyWith({required int? val}) { DateFormatPreference copyWith({required int? val}) {

View File

@ -171,18 +171,18 @@ class _SettingsState extends State<Settings> with ItemActionMixin {
const Text( const Text(
'Date time display of comments', 'Date time display of comments',
), ),
DropdownMenu<DisplayDateFormat>( DropdownMenu<DateDisplayFormat>(
initialSelection: preferenceState.displayDateFormat, initialSelection: preferenceState.displayDateFormat,
dropdownMenuEntries: DisplayDateFormat.values dropdownMenuEntries: DateDisplayFormat.values
.map( .map(
(DisplayDateFormat val) => (DateDisplayFormat val) =>
DropdownMenuEntry<DisplayDateFormat>( DropdownMenuEntry<DateDisplayFormat>(
value: val, value: val,
label: val.description, label: val.description,
), ),
) )
.toList(), .toList(),
onSelected: (DisplayDateFormat? order) { onSelected: (DateDisplayFormat? order) {
if (order != null) { if (order != null) {
HapticFeedbackUtil.selection(); HapticFeedbackUtil.selection();
context.read<PreferenceCubit>().update( context.read<PreferenceCubit>().update(
@ -190,7 +190,7 @@ class _SettingsState extends State<Settings> with ItemActionMixin {
val: order.index, val: order.index,
), ),
); );
DisplayDateFormat.clearCache(); DateDisplayFormat.clearCache();
} }
}, },
), ),

View File

@ -1,6 +1,6 @@
name: hacki name: hacki
description: A Hacker News reader. description: A Hacker News reader.
version: 2.7.0+138 version: 2.7.1+139
publish_to: none publish_to: none
environment: environment: