This commit is contained in:
kodjomoustapha 2024-09-12 12:58:24 +01:00
parent b8635a36a8
commit 938e42aa15
6 changed files with 177 additions and 135 deletions

View file

@ -360,5 +360,12 @@
"or": "OR",
"advanced": "Advanced",
"use_native_http_client": "Use native http client",
"use_native_http_client_info": "it automatically supports platform features such VPNs, support more HTTP features such as HTTP/3 and custom redirect handling"
"use_native_http_client_info": "it automatically supports platform features such VPNs, support more HTTP features such as HTTP/3 and custom redirect handling",
"n_hour_ago": "{hour} hour ago",
"n_hours_ago": "{hours} hours ago",
"n_minute_ago": "{minute} minute ago",
"n_minutes_ago": "{minutes} minutes ago",
"n_day_ago": "{day} day ago",
"now": "now",
"library_last_updated": "Library last updated: {lastUpdated}"
}

View file

@ -1,7 +1,5 @@
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:grouped_list/sliver_grouped_list.dart';
import 'package:isar/isar.dart';
@ -10,16 +8,14 @@ import 'package:mangayomi/models/chapter.dart';
import 'package:mangayomi/models/feed.dart';
import 'package:mangayomi/models/history.dart';
import 'package:mangayomi/models/manga.dart';
import 'package:mangayomi/modules/feed/widgets/feed_chapter_list_tile_widget.dart';
import 'package:mangayomi/modules/history/providers/isar_providers.dart';
import 'package:mangayomi/providers/l10n_providers.dart';
import 'package:mangayomi/utils/cached_network.dart';
import 'package:mangayomi/utils/constant.dart';
import 'package:mangayomi/utils/date.dart';
import 'package:mangayomi/utils/extensions/chapter.dart';
import 'package:mangayomi/utils/headers.dart';
import 'package:mangayomi/modules/library/widgets/search_text_form_field.dart';
import 'package:mangayomi/modules/widgets/error_text.dart';
import 'package:mangayomi/modules/widgets/progress_center.dart';
import 'package:mangayomi/utils/extensions/build_context_extensions.dart';
class FeedScreen extends ConsumerStatefulWidget {
const FeedScreen({super.key});
@ -184,8 +180,7 @@ class _FeedTabState extends ConsumerState<FeedTab> {
@override
Widget build(BuildContext context) {
final l10n = l10nLocalizations(context)!;
final feed =
ref.watch(getAllFeedStreamProvider(isManga: widget.isManga));
final feed = ref.watch(getAllFeedStreamProvider(isManga: widget.isManga));
return Scaffold(
body: feed.when(
data: (data) {
@ -196,10 +191,30 @@ class _FeedTabState extends ConsumerState<FeedTab> {
.contains(widget.query.toLowerCase())
: true)
.toList();
final lastUpdatedList =
data.map((e) => e.chapter.value!.manga.value!.lastUpdate!).toList();
lastUpdatedList.sort((a, b) => a.compareTo(b));
final lastUpdated = lastUpdatedList.firstOrNull;
if (entries.isNotEmpty) {
return CustomScrollView(
slivers: [
if (lastUpdated != null)
SliverPadding(
padding: const EdgeInsets.only(
left: 10, right: 10, top: 10, bottom: 20),
sliver: SliverList(
delegate: SliverChildListDelegate.fixed([
Text(
l10n.library_last_updated(dateFormat(
lastUpdated.toString(),
ref: ref,
context: context,
showHOURorMINUTE: true)),
style: TextStyle(
fontStyle: FontStyle.italic,
color: context.secondaryColor))
])),
),
SliverGroupedListView<Feed, String>(
elements: entries,
groupBy: (element) => dateFormat(element.date!,
@ -221,123 +236,9 @@ class _FeedTabState extends ConsumerState<FeedTab> {
),
),
itemBuilder: (context, Feed element) {
final manga = element.chapter.value!.manga.value!;
final chapter = element.chapter.value!;
return ElevatedButton(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(0),
backgroundColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0)),
elevation: 0,
shadowColor: Colors.transparent),
onPressed: () {
chapter.pushToReaderView(context);
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: SizedBox(
height: 105,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 60,
height: 90,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(7)),
),
onPressed: () {
context.push('/manga-reader/detail',
extra: manga.id);
},
child: ClipRRect(
borderRadius: BorderRadius.circular(7),
child: manga.customCoverImage != null
? Image.memory(
manga.customCoverImage as Uint8List)
: cachedNetworkImage(
headers: ref.watch(headersProvider(
source: manga.source!,
lang: manga.lang!)),
imageUrl: toImgUrl(
manga.customCoverFromTracker ??
manga.imageUrl ??
""),
width: 60,
height: 90,
fit: BoxFit.cover),
),
),
),
Flexible(
child: Row(
children: [
Expanded(
child: Container(
color: Colors.transparent,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
manga.name!,
style: TextStyle(
fontSize: 14,
color: Theme.of(context)
.textTheme
.bodyLarge!
.color,
fontWeight: FontWeight.bold),
textAlign: TextAlign.start,
),
Wrap(
crossAxisAlignment:
WrapCrossAlignment.end,
children: [
Text(
chapter.name!,
style: TextStyle(
fontSize: 11,
color: Theme.of(context)
.textTheme
.bodyLarge!
.color,
),
),
Text(
" - ${dateFormatHour(element.date!, context)}",
style: TextStyle(
fontSize: 11,
color: Theme.of(context)
.textTheme
.bodyLarge!
.color,
fontWeight:
FontWeight.w400),
),
],
),
],
),
),
),
),
],
),
)
],
),
),
),
);
return FeedChapterListTileWidget(
chapter: chapter, sourceExist: true);
},
itemComparator: (item1, item2) =>
item1.date!.compareTo(item2.date!),
@ -347,7 +248,7 @@ class _FeedTabState extends ConsumerState<FeedTab> {
);
}
return Center(
child: Text(l10n.nothing_read_recently),
child: Text(l10n.no_recent_updates),
);
},
error: (Object error, StackTrace stackTrace) {

View file

@ -0,0 +1,112 @@
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:mangayomi/models/chapter.dart';
import 'package:mangayomi/modules/widgets/custom_extended_image_provider.dart';
import 'package:mangayomi/utils/constant.dart';
import 'package:mangayomi/modules/manga/download/download_page_widget.dart';
import 'package:mangayomi/utils/extensions/chapter.dart';
import 'package:mangayomi/utils/headers.dart';
class FeedChapterListTileWidget extends ConsumerWidget {
final Chapter chapter;
final bool sourceExist;
const FeedChapterListTileWidget({
required this.chapter,
required this.sourceExist,
super.key,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final manga = chapter.manga.value!;
return Material(
borderRadius: BorderRadius.circular(5),
color: Colors.transparent,
clipBehavior: Clip.antiAliasWithSaveLayer,
child: InkWell(
onTap: () async {
chapter.pushToReaderView(context, ignoreIsRead: true);
},
onLongPress: () {},
onSecondaryTap: () {},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 13, vertical: 5),
child: Container(
height: 45,
decoration: BoxDecoration(borderRadius: BorderRadius.circular(5)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Row(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(5),
child: Material(
child: GestureDetector(
onTap: () {
context.push('/manga-reader/detail',
extra: manga.id);
},
child: Ink.image(
fit: BoxFit.cover,
width: 40,
height: 45,
image: manga.customCoverImage != null
? MemoryImage(
manga.customCoverImage as Uint8List)
as ImageProvider
: CustomExtendedNetworkImageProvider(
toImgUrl(manga.customCoverFromTracker ??
manga.imageUrl!),
headers: ref.watch(headersProvider(
source: manga.source!,
lang: manga.lang!)),
),
child: InkWell(child: Container()),
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(manga.name!,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 14,
color: Theme.of(context)
.textTheme
.bodyLarge!
.color)),
Text(chapter.name!,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 11,
color: Theme.of(context)
.textTheme
.bodyLarge!
.color)),
],
),
),
)
],
),
),
if (sourceExist) ChapterPageDownload(chapter: chapter)
],
),
),
),
),
);
}
}

View file

@ -304,8 +304,10 @@ class MainScreen extends ConsumerWidget {
} else if (newIndex == 2) {
route.go('/history');
} else if (newIndex == 3) {
route.go('/browse');
route.go('/feed');
} else if (newIndex == 4) {
route.go('/browse');
} else if (newIndex == 5) {
route.go('/more');
}
},

View file

@ -84,13 +84,12 @@ Future<dynamic> updateMangaDetail(UpdateMangaDetailRef ref,
.addUpdatedChapter(chap, false, false);
isar.chapters.putSync(chap);
chap.manga.saveSync();
final savedChapter = isar.chapters.getSync(chap.id!);
if (savedChapter != null) {
if (manga.chapters.isNotEmpty) {
final feed = Feed(
mangaId: mangaId,
chapterName: savedChapter.name,
date: savedChapter.dateUpload)
..chapter.value = savedChapter;
chapterName: chap.name,
date: DateTime.now().millisecondsSinceEpoch.toString())
..chapter.value = chap;
isar.feeds.putSync(feed);
feed.chapter.saveSync();
}

View file

@ -10,7 +10,8 @@ String dateFormat(String? timestamp,
String? stringDate,
bool forHistoryValue = false,
bool useRelativeTimesTamps = true,
String dateFormat = ""}) {
String dateFormat = "",
bool showHOURorMINUTE = false}) {
final l10n = l10nLocalizations(context)!;
final locale = currentLocale(context);
final relativeTimestamps = ref.watch(relativeTimesTampsStateProvider);
@ -34,6 +35,22 @@ String dateFormat(String? timestamp,
dateFormat.isEmpty ? dateFrmt : dateFormat, locale.toLanguageTag());
if (date == today && useRelativeTimesTamps && relativeTimestamps != 0) {
if (showHOURorMINUTE) {
final difference = now.difference(dateTime);
if (difference.inMinutes < 60) {
return switch (difference.inMinutes) {
0 => l10n.now,
1 => l10n.n_minute_ago(difference.inMinutes),
_ => l10n.n_minutes_ago(difference.inMinutes),
};
} else if (difference.inHours < 24) {
return switch (difference.inHours) {
1 => l10n.n_hour_ago(difference.inHours),
_ => l10n.n_hours_ago(difference.inHours),
};
}
}
return l10n.today;
} else if (date == yesterday &&
useRelativeTimesTamps &&
@ -48,7 +65,11 @@ String dateFormat(String? timestamp,
date.isAfter(sixDaysAgo) ||
date.isAfter(aWeekAgo)) {
final difference = today.difference(date).inDays;
return difference != 7 ? l10n.n_days_ago(difference) : l10n.a_week_ago;
return switch (difference) {
1 => l10n.n_day_ago(difference),
!= 7 => l10n.n_days_ago(difference),
_ => l10n.a_week_ago,
};
}
}
return forHistoryValue