diff --git a/lib/modules/history/history_screen.dart b/lib/modules/history/history_screen.dart index 8e170ca..6334502 100644 --- a/lib/modules/history/history_screen.dart +++ b/lib/modules/history/history_screen.dart @@ -122,12 +122,19 @@ class _HistoryScreenState extends ConsumerState { if (entries.isNotEmpty) { return GroupedListView( elements: entries, - groupBy: (element) => element.date!, + groupBy: (element) => dateFormat(element.date!, + ref: ref, + forHistoryValue: true, + useRelativeTimesTamps: false), groupSeparatorBuilder: (String groupByValue) => Padding( padding: const EdgeInsets.only(bottom: 8, left: 12), child: Row( children: [ - Text(dateFormat(groupByValue, ref: ref)), + Text(dateFormat( + null, + stringDate: groupByValue, + ref: ref, + )), ], ), ), diff --git a/lib/modules/widgets/manga_image_card_widget.dart b/lib/modules/widgets/manga_image_card_widget.dart index 1b5ba31..aa68bf0 100644 --- a/lib/modules/widgets/manga_image_card_widget.dart +++ b/lib/modules/widgets/manga_image_card_widget.dart @@ -1,3 +1,5 @@ +import 'dart:typed_data'; + import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -36,11 +38,17 @@ class MangaImageCardWidget extends ConsumerWidget { .watch(fireImmediately: true), builder: (context, snapshot) { return CoverViewWidget( - image: CachedNetworkImageProvider( - getMangaDetail!.imageUrl!, - headers: - ref.watch(headersProvider(source: getMangaDetail!.source!)), - ), + image: snapshot.hasData && + snapshot.data!.isNotEmpty && + snapshot.data!.first.customCoverImage != null + ? MemoryImage( + snapshot.data!.first.customCoverImage as Uint8List) + as ImageProvider + : CachedNetworkImageProvider( + getMangaDetail!.imageUrl!, + headers: ref.watch( + headersProvider(source: getMangaDetail!.source!)), + ), onTap: () { pushToMangaReaderDetail( context: context, getManga: getMangaDetail!, lang: lang); diff --git a/lib/utils/date.dart b/lib/utils/date.dart index 8e0a68f..d5665b7 100644 --- a/lib/utils/date.dart +++ b/lib/utils/date.dart @@ -2,45 +2,55 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:intl/intl.dart'; import 'package:mangayomi/modules/more/settings/appearance/providers/date_format_state_provider.dart'; -String dateFormat(String timestamp, +String dateFormat(String? timestamp, {required WidgetRef ref, + String? stringDate, + bool forHistoryValue = false, bool useRelativeTimesTamps = true, String dateFormat = ""}) { final relativeTimestamps = ref.watch(relativeTimesTampsStateProvider); final dateFrmt = ref.watch(dateFormatStateProvider); - final dateTime = DateTime.fromMillisecondsSinceEpoch(int.parse(timestamp)); + final dateTime = stringDate != null + ? DateTime.parse(stringDate) + : DateTime.fromMillisecondsSinceEpoch(int.parse(timestamp!)); + stringDate = null; final date = DateTime(dateTime.year, dateTime.month, dateTime.day); - final now = DateTime.now(); - final today = DateTime(now.year, now.month, now.day); - final yesterday = DateTime(now.year, now.month, now.day - 1); - final twoDaysAgo = DateTime(now.year, now.month, now.day - 2); - final threeDaysAgo = DateTime(now.year, now.month, now.day - 3); - final fourDaysAgo = DateTime(now.year, now.month, now.day - 4); - final fiveDaysAgo = DateTime(now.year, now.month, now.day - 5); - final sixDaysAgo = DateTime(now.year, now.month, now.day - 6); - final aWeekAgo = DateTime(now.year, now.month, now.day - 7); - final formatter = - DateFormat(dateFormat.isEmpty ? dateFrmt : dateFormat, "en"); + if (stringDate == null) { + final now = DateTime.now(); + final today = DateTime(now.year, now.month, now.day); + final yesterday = DateTime(now.year, now.month, now.day - 1); + final twoDaysAgo = DateTime(now.year, now.month, now.day - 2); + final threeDaysAgo = DateTime(now.year, now.month, now.day - 3); + final fourDaysAgo = DateTime(now.year, now.month, now.day - 4); + final fiveDaysAgo = DateTime(now.year, now.month, now.day - 5); + final sixDaysAgo = DateTime(now.year, now.month, now.day - 6); + final aWeekAgo = DateTime(now.year, now.month, now.day - 7); + final formatter = + DateFormat(dateFormat.isEmpty ? dateFrmt : dateFormat, "en"); - if (date == today && useRelativeTimesTamps && relativeTimestamps != 0) { - return 'Today'; - } else if (date == yesterday && - useRelativeTimesTamps && - relativeTimestamps != 0) { - return 'Yesterday'; - } else if (useRelativeTimesTamps && relativeTimestamps == 2) { - if (date.isAfter(twoDaysAgo) || - date.isAfter(twoDaysAgo) || - date.isAfter(threeDaysAgo) || - date.isAfter(fourDaysAgo) || - date.isAfter(fiveDaysAgo) || - date.isAfter(sixDaysAgo) || - date.isAfter(aWeekAgo)) { - final difference = today.difference(date).inDays; - return difference != 7 ? '$difference days ago' : 'A week ago'; + if (date == today && useRelativeTimesTamps && relativeTimestamps != 0) { + return 'Today'; + } else if (date == yesterday && + useRelativeTimesTamps && + relativeTimestamps != 0) { + return 'Yesterday'; + } else if (useRelativeTimesTamps && relativeTimestamps == 2) { + if (date.isAfter(twoDaysAgo) || + date.isAfter(twoDaysAgo) || + date.isAfter(threeDaysAgo) || + date.isAfter(fourDaysAgo) || + date.isAfter(fiveDaysAgo) || + date.isAfter(sixDaysAgo) || + date.isAfter(aWeekAgo)) { + final difference = today.difference(date).inDays; + return difference != 7 ? '$difference days ago' : 'A week ago'; + } } + return forHistoryValue + ? DateTime(dateTime.year, dateTime.month, dateTime.day).toString() + : formatter.format(date); } - return formatter.format(date); + return date.toString(); } String dateFormatHour(String timestamp) {