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.values.elementAt(preferences.singleWhereType<FontPreference>().val);
DisplayDateFormat get displayDateFormat => DisplayDateFormat.values
DateDisplayFormat get displayDateFormat => DateDisplayFormat.values
.elementAt(preferences.singleWhereType<DateFormatPreference>().val);
@override

View File

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

View File

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

View File

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

View File

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

View File

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