fix manga local cover & history grouped list date
This commit is contained in:
parent
eb6fa6d26f
commit
d105b4bd10
3 changed files with 62 additions and 37 deletions
|
|
@ -122,12 +122,19 @@ class _HistoryScreenState extends ConsumerState<HistoryScreen> {
|
|||
if (entries.isNotEmpty) {
|
||||
return GroupedListView<History, String>(
|
||||
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,
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue