fix & refactor reader view

This commit is contained in:
kodjomoustapha 2023-07-19 14:40:15 +01:00
parent d04457c60b
commit 00c1cb216b
11 changed files with 332 additions and 458 deletions

View file

@ -180,5 +180,6 @@
"add_tracker": "Add tracking",
"one_tracker":"1 tracker",
"n_tracker":"{n} trackers",
"tracking": "Tracking"
"tracking": "Tracking",
"description": "Description"
}

View file

@ -136,8 +136,8 @@
"share":"Partager",
"n_chapters":"{number} chapitres",
"no_description":"Aucune description",
"resume":"Peprendre",
"read":"Coomencer",
"resume":"Reprendre",
"read":"Commencer",
"popular":"Populaire",
"refresh":"Actualiser",
"open_in_browser":"Ouvrir dans le navigateur",
@ -180,5 +180,6 @@
"add_tracker": "Ajouter le suivi",
"one_tracker":"Suivi par 1 service",
"n_tracker":"Suivi par {n} services",
"tracking": "Suivi"
"tracking": "Suivi",
"description": "Description"
}

View file

@ -340,13 +340,13 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
? Colors.transparent
: Theme.of(context).scaffoldBackgroundColor,
actions: [
if (!isLocalArchive)
IconButton(
splashRadius: 20,
onPressed: () {},
icon: const Icon(
Icons.download_outlined,
)),
// if (!isLocalArchive)
// IconButton(
// splashRadius: 20,
// onPressed: () {},
// icon: const Icon(
// Icons.download_outlined,
// )),
IconButton(
splashRadius: 20,
onPressed: () {
@ -1334,7 +1334,7 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
isNotEmpty
? Icons.done
: Icons.screen_rotation_alt_rounded,
size: 22,
size: 20,
color: color,
),
const SizedBox(
@ -1346,7 +1346,8 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
? l10n.one_tracker
: l10n.n_tracker(trackRes.length)
: l10n.tracking,
style: TextStyle(fontSize: 13, color: color),textAlign: TextAlign.center,
style: TextStyle(fontSize: 11, color: color),
textAlign: TextAlign.center,
),
],
);
@ -1380,7 +1381,7 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
children: [
Icon(
Icons.public,
size: 22,
size: 20,
color: secondaryColor(context),
),
const SizedBox(
@ -1389,7 +1390,7 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
Text(
'WebView',
style: TextStyle(
fontSize: 13, color: secondaryColor(context)),
fontSize: 11, color: secondaryColor(context)),
)
],
),
@ -1536,6 +1537,7 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
}
_editLocaleArchiveInfos() {
final l10n = l10nLocalizations(context)!;
TextEditingController? name =
TextEditingController(text: widget.manga!.name!);
TextEditingController? description =
@ -1544,8 +1546,8 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
context: context,
builder: (context) {
return AlertDialog(
title: const Text(
"Edit",
title: Text(
l10n.edit,
),
content: SizedBox(
height: 200,
@ -1557,9 +1559,9 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.only(left: 15),
child: Text("Name"),
Padding(
padding: const EdgeInsets.only(left: 15),
child: Text(l10n.name),
),
TextFormField(
controller: name,
@ -1572,9 +1574,9 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.only(left: 15),
child: Text("Description"),
Padding(
padding: const EdgeInsets.only(left: 15),
child: Text(l10n.description),
),
TextFormField(
controller: description,
@ -1593,7 +1595,7 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
onPressed: () {
Navigator.pop(context);
},
child: const Text("Cancel")),
child: Text(l10n.cancel)),
const SizedBox(
width: 15,
),
@ -1607,7 +1609,7 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
});
Navigator.pop(context);
},
child: const Text("Edit")),
child: Text(l10n.edit)),
],
)
],
@ -1635,6 +1637,7 @@ class _MangaDetailViewState extends ConsumerState<MangaDetailView>
child: ListView.separated(
padding: const EdgeInsets.all(0),
itemCount: entries!.length,
primary: false,
shrinkWrap: true,
itemBuilder: (context, index) {
return StreamBuilder(

View file

@ -56,6 +56,9 @@ class _MangaDetailsViewState extends ConsumerState<MangaDetailsView> {
.where(
(element) => element.mangaId == widget.manga.id)
.toList();
final isFr =
ref.watch(l10nLocaleStateProvider).languageCode ==
"fr";
if (entries.isNotEmpty && !incognitoMode) {
return CustomFloatingActionBtn(
isExtended: !isExtended,
@ -78,8 +81,8 @@ class _MangaDetailsViewState extends ConsumerState<MangaDetailsView> {
context: context,
chapter: widget.manga.chapters.last);
},
textWidth: 40,
width: 90,
textWidth: isFr ? 80 : 40,
width: isFr ? 130 : 90,
);
},
error: (Object error, StackTrace stackTrace) {
@ -154,42 +157,42 @@ class _MangaDetailsViewState extends ConsumerState<MangaDetailsView> {
),
)
: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor:
Theme.of(context).scaffoldBackgroundColor,
elevation: 0),
onPressed: () {
final checkCategoryList =
isar.categorys.filter().idIsNotNull().isNotEmptySync();
if (checkCategoryList) {
_openCategory(widget.manga);
} else {
final model = widget.manga;
isar.writeTxnSync(() {
model.favorite = true;
model.dateAdded = DateTime.now().millisecondsSinceEpoch;
isar.mangas.putSync(model);
});
}
},
child: Column(
children: [
Icon(
Icons.favorite_border_rounded,
size: 22,
color: secondaryColor(context),
),
const SizedBox(
height: 4,
),
Text(
l10n.add_to_library,
style: TextStyle(
color: secondaryColor(context), fontSize: 13),
)
],
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
elevation: 0),
onPressed: () {
final checkCategoryList =
isar.categorys.filter().idIsNotNull().isNotEmptySync();
if (checkCategoryList) {
_openCategory(widget.manga);
} else {
final model = widget.manga;
isar.writeTxnSync(() {
model.favorite = true;
model.dateAdded = DateTime.now().millisecondsSinceEpoch;
isar.mangas.putSync(model);
});
}
},
child: Column(
children: [
Icon(
Icons.favorite_border_rounded,
size: 20,
color: secondaryColor(context),
),
const SizedBox(
height: 4,
),
Text(
l10n.add_to_library,
style: TextStyle(
color: secondaryColor(context), fontSize: 11),
textAlign: TextAlign.center,
)
],
),
),
),
manga: widget.manga,
isExtended: (value) {
ref.read(isExtendedStateProvider.notifier).update(value);

View file

@ -15,7 +15,7 @@ class ReadMoreWidget extends StatefulWidget {
class ReadMoreWidgetState extends State<ReadMoreWidget>
with TickerProviderStateMixin {
late bool expanded = widget.text.trim().length < 232;
late bool expanded = true;
@override
Widget build(BuildContext context) {
final l10n = l10nLocalizations(context)!;

View file

@ -103,8 +103,10 @@ class _TrackerWidgetState extends ConsumerState<TrackerWidget> {
.textTheme
.bodyMedium!
.color,
overflow: TextOverflow.ellipsis,
fontSize: 16,
fontWeight: FontWeight.bold),
maxLines: 2,
),
),
),

View file

@ -1,153 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:mangayomi/modules/manga/reader/manga_reader_view.dart';
import 'package:mangayomi/modules/manga/reader/providers/reader_controller_provider.dart';
import 'package:mangayomi/providers/l10n_providers.dart';
import 'package:mangayomi/utils/media_query.dart';
class ChapterIntervalPageView extends ConsumerWidget {
final bool hasPrevChapter;
final bool hasNextChapter;
final UChapDataPreload uChapDataPreload;
final VoidCallback onTap;
const ChapterIntervalPageView(
{super.key,
required this.uChapDataPreload,
required this.hasPrevChapter,
required this.hasNextChapter,
required this.onTap});
@override
Widget build(BuildContext context, WidgetRef ref) {
final l10n = l10nLocalizations(context)!;
final readerController =
ReaderController(chapter: uChapDataPreload.chapter!);
String text = uChapDataPreload.hasPrevPrePage && hasPrevChapter
? l10n.current(":")
: l10n.finished(":");
final noMoreChapter = uChapDataPreload.hasNextPrePage && !hasNextChapter ||
uChapDataPreload.hasPrevPrePage && !hasPrevChapter;
// String noMore = uChapDataPreload.hasNextPrePage && !hasNextChapter
// ? l10n.next("")
// : l10n.previous("");
return SizedBox(
height: mediaHeight(context, 0.27),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (uChapDataPreload.hasPrevPrePage && hasPrevChapter)
Column(
children: [
Text(
l10n.previous(":"),
style: const TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 12),
),
Text(readerController.getPrevChapter().name!,
style: const TextStyle(color: Colors.white, fontSize: 12),
textAlign: TextAlign.center),
const SizedBox(
height: 10,
),
Column(
children: [
Text(
text,
style: const TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 12),
),
Wrap(
children: [
Text(
uChapDataPreload.chapter!.name!,
style: const TextStyle(
color: Colors.white, fontSize: 12),
textAlign: TextAlign.center,
),
const SizedBox(
width: 3,
),
const Icon(
FontAwesomeIcons.circleCheck,
color: Colors.white,
size: 17,
),
],
),
// ElevatedButton(onPressed: onTap, child: const Text("Retry")),
],
),
],
),
if (noMoreChapter)
Text(
l10n.no_more_chapter,
style: const TextStyle(color: Colors.white, fontSize: 14),
textAlign: TextAlign.center,
),
if (uChapDataPreload.hasNextPrePage && hasNextChapter)
Column(
children: [
Column(
children: [
Text(
text,
style: const TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 12),
),
Wrap(
alignment: WrapAlignment.center,
children: [
Text(
uChapDataPreload.chapter!.name!,
style: const TextStyle(
color: Colors.white, fontSize: 12),
textAlign: TextAlign.center,
),
const SizedBox(
width: 3,
),
const Icon(
FontAwesomeIcons.circleCheck,
color: Colors.white,
size: 16,
),
],
),
const SizedBox(
height: 10,
),
Text(
l10n.next(":"),
style: const TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
Text(
readerController.getNextChapter().name!,
style: const TextStyle(color: Colors.white, fontSize: 12),
textAlign: TextAlign.center,
),
const SizedBox(
height: 30,
),
// ElevatedButton(
// onPressed: onTap,
// child: const Text("Load Next chapter")),
],
),
],
),
],
),
);
}
}

View file

@ -115,17 +115,6 @@ class ReaderController {
}
}
void setChapterPageLastRead(int pageIndex) {
if (!incognitoMode) {
final chap = chapter;
isar.writeTxnSync(() {
chap.isRead = (pageIndex + 1) == getPageLength([]);
chap.lastPageRead = (pageIndex + 1).toString();
isar.chapters.putSync(chap);
});
}
}
void setChapterBookmarked() {
if (!incognitoMode) {
final isBookmarked = getChapterBookmarked();
@ -224,8 +213,14 @@ class ReaderController {
chapterPageIndexs.add(ChapterPageIndex()
..chapterId = chapter.id
..index = newIndex);
isar.writeTxnSync(() => isar.settings
.putSync(getIsarSetting()..chapterPageIndexList = chapterPageIndexs));
final chap = chapter;
isar.writeTxnSync(() {
isar.settings.putSync(
getIsarSetting()..chapterPageIndexList = chapterPageIndexs);
chap.isRead = (newIndex + 1) == getPageLength([]);
chap.lastPageRead = (newIndex + 1).toString();
isar.chapters.putSync(chap);
});
}
}

View file

@ -10,7 +10,6 @@ import 'package:go_router/go_router.dart';
import 'package:mangayomi/main.dart';
import 'package:mangayomi/models/chapter.dart';
import 'package:mangayomi/models/settings.dart';
import 'package:mangayomi/modules/manga/reader/chapter_interval_page_view.dart';
import 'package:mangayomi/modules/more/settings/reader/providers/reader_state_provider.dart';
import 'package:mangayomi/sources/utils/utils.dart';
import 'package:mangayomi/modules/manga/reader/providers/push_router.dart';
@ -165,7 +164,7 @@ class _MangaChapterPageGalleryState
late Chapter chapter = widget.chapter;
final List<UChapDataPreload> _uChapDataPreload = [];
List<UChapDataPreload> _uChapDataPreload = [];
bool animatePageTransitions =
isar.settings.getSync(227)!.animatePageTransitions!;
Duration? _doubleTapAnimationDuration() {
@ -209,110 +208,182 @@ class _MangaChapterPageGalleryState
super.initState();
}
_preloadNextChapter(
GetChapterUrlModel chapterData,
Chapter chapter,
) {
bool isExist = false;
List<UChapDataPreload> preChap = [];
for (var ee in _uChapDataPreload) {
if (chapterData.uChapDataPreload.first.chapter!.name ==
ee.chapter!.name) {
isExist = true;
_preloadNextChapter(GetChapterUrlModel chapterData, Chapter chap) {
try {
int length = 0;
bool isExist = false;
List<UChapDataPreload> uChapDataPreloadP = [];
List<UChapDataPreload> uChapDataPreloadL = _uChapDataPreload;
List<UChapDataPreload> preChap = [];
for (var ee in _uChapDataPreload) {
if (chapterData.uChapDataPreload.first.chapter!.url ==
ee.chapter!.url) {
isExist = true;
}
}
}
if (!isExist) {
for (var aa in chapterData.uChapDataPreload) {
preChap.add(aa);
if (!isExist) {
for (var aa in chapterData.uChapDataPreload) {
preChap.add(aa);
}
}
}
if (preChap.isNotEmpty) {
preChap.add(UChapDataPreload(
chapter, null, null, null, null, null, true, false, null));
_uChapDataPreload.addAll(preChap);
}
setState(() {});
if (preChap.isNotEmpty) {
length = _uChapDataPreload.length;
for (var i = 0; i < preChap.length; i++) {
int index = i + length;
final dataPreload = preChap[i];
uChapDataPreloadP.add(UChapDataPreload(
dataPreload.chapter,
dataPreload.path,
dataPreload.url,
dataPreload.isLocale,
dataPreload.archiveImage,
dataPreload.index,
dataPreload.chapterUrlModel,
index));
}
if (mounted) {
uChapDataPreloadL.addAll(uChapDataPreloadP);
setState(() {
_uChapDataPreload = uChapDataPreloadL;
_chapterUrlModel = chapterData;
_readerController = ReaderController(chapter: chap);
_readerController = ReaderController(
chapter: _uChapDataPreload[_currentIndex].chapter!);
chapter = chap;
});
}
}
} catch (_) {}
}
_preloadPrevChapter(GetChapterUrlModel chapterData, Chapter chapter) {
// bool isExist = false;
// List<UChapDataPreload> preChap = [];
// for (var ee in uChapDataPreload) {
// if (chapterData.uChapDataPreload.first.chapter!.name == ee.chapter!.name) {
// isExist = true;
_preloadPrevChapter(GetChapterUrlModel chapterData, Chapter chap) async {
// try {
// int length = 0;
// bool isExist = false;
// List<UChapDataPreload> preChap = [];
// for (var ee in _uChapDataPreload) {
// if (chapterData.uChapDataPreload.first.chapter!.url ==
// ee.chapter!.url) {
// isExist = true;
// }
// }
// }
// if (!isExist) {
// for (var aa in chapterData.uChapDataPreload) {
// preChap.add(aa);
// if (!isExist) {
// for (var aa in chapterData.uChapDataPreload) {
// preChap.add(aa);
// }
// }
// }
// if (preChap.isNotEmpty) {
// preChap.add(UChapDataPreload(chapter, null, null, null, null, null, false, true));
// uChapDataPreload.insertAll(0, preChap);
// _currentIndex = _currentIndex + preChap.length - 1;
// }
// print({"leng${preChap.length}"});
// _currentIndex = chapterData.pageUrls.length - 1 + _currentIndex;
// print(_currentIndex);
// _chapterUrlModel = chapterData;
// _readerController = ReaderController(chapter: chapter);
// setState(() {});
// if (preChap.isNotEmpty) {
// if (_uChapDataPreload.isNotEmpty) {
// length = preChap.length;
// for (var i = 0; i < _uChapDataPreload.length; i++) {
// int index = i + length;
// final dataPreload = _uChapDataPreload[i];
// preChap.add(UChapDataPreload(
// dataPreload.chapter,
// dataPreload.path,
// dataPreload.url,
// dataPreload.isLocale,
// dataPreload.archiveImage,
// dataPreload.index,
// dataPreload.hasNextPrePage,
// dataPreload.hasPrevPrePage,
// dataPreload.chapterUrlModel,
// index));
// }
// }
// if (mounted) {
// _uChapDataPreload.clear();
// _uChapDataPreload.addAll(preChap);
// setState(() {
// _readerController = ReaderController(chapter: chap);
// _currentIndex =
// _uChapDataPreload[_currentIndex + 1].pageIndex! + length;
// _chapterUrlModel = chapterData;
// chapter = chap;
// });
// try {
// if (_isVerticalContinous()) {
// _observerController.jumpTo(index: _currentIndex);
// } else {
// _extendedController.jumpToPage(_currentIndex);
// }
// } catch (_) {}
// }
// }
// } catch (_) {}
}
late bool _isBookmarked = _readerController.getChapterBookmarked();
_initCurrentIndex() async {
_uChapDataPreload.addAll(_chapterUrlModel.uChapDataPreload);
_uChapDataPreload.add(UChapDataPreload(
chapter, null, null, null, null, null, true, false, null));
_readerController.setMangaHistoryUpdate();
await Future.delayed(const Duration(milliseconds: 1));
_selectedValue = _readerController.getReaderMode();
_setReaderMode(_selectedValue!, true);
ref.read(currentIndexProvider(chapter).notifier).setCurrentIndex(
_uChapDataPreload[_currentIndex].index!,
);
}
void _onPageChanged(int index) {
if (!(_uChapDataPreload[index].hasNextPrePage ||
_uChapDataPreload[index].hasPrevPrePage)) {
_readerController =
ReaderController(chapter: _uChapDataPreload[index].chapter!);
_chapterUrlModel = _uChapDataPreload[_posIndex ?? 0].chapterUrlModel!;
_readerController.setMangaHistoryUpdate();
_readerController.setPageIndex(_currentIndex + 1);
_readerController.setChapterPageLastRead(_currentIndex + 1);
_isBookmarked = _readerController.getChapterBookmarked();
_posIndex = index;
_currentIndex = _uChapDataPreload[index].index!;
_readerController =
ReaderController(chapter: _uChapDataPreload[index].chapter!);
ref.read(currentIndexProvider(chapter).notifier).setCurrentIndex(
_currentIndex,
);
_chapterUrlModel = _uChapDataPreload[index].chapterUrlModel!;
setState(() {});
_currentIndex = index;
_isBookmarked = _readerController.getChapterBookmarked();
_readerController.setMangaHistoryUpdate();
_readerController.setPageIndex(_uChapDataPreload[_currentIndex].index!);
ref.read(currentIndexProvider(chapter).notifier).setCurrentIndex(
_uChapDataPreload[index].index!,
);
if (_uChapDataPreload[index].index! == 0) {
try {
bool hasPrevChapter = _readerController.getChapterIndex() + 1 !=
_readerController.getChaptersLength();
final chapter =
hasPrevChapter ? _readerController.getPrevChapter() : null;
if (chapter != null) {
ref
.watch(getChapterUrlProvider(
chapter: chapter,
).future)
.then((value) async {
await _preloadPrevChapter(value, chapter);
});
}
} catch (_) {}
}
if (_uChapDataPreload[index].index! ==
_readerController.getPageLength([]) - 1) {
try {
bool hasNextChapter = _readerController.getChapterIndex() != 0;
final chapter =
hasNextChapter ? _readerController.getNextChapter() : null;
if (chapter != null) {
ref
.watch(getChapterUrlProvider(
chapter: chapter,
).future)
.then((value) {
_preloadNextChapter(value, chapter);
});
}
} catch (_) {}
}
setState(() {});
}
final double _imageDetailY = 0;
void _onBtnTapped(int index, bool isPrev,
{bool isSlide = false, int? slideAddValueIndex}) {
if (_uChapDataPreload[_posIndex ?? 0].chapter!.name !=
_uChapDataPreload.first.chapter!.name) {
if (_uChapDataPreload[_posIndex ?? 0].index != null) {
int plu = 0;
if (isPrev && isSlide && slideAddValueIndex != null) {
plu = slideAddValueIndex;
} else if (isPrev) {
plu = -1;
} else {
plu = 1;
}
index = _uChapDataPreload.indexWhere(
(element) => element == _uChapDataPreload[_posIndex ?? 0]) +
plu;
}
}
void _onBtnTapped(int index, bool isPrev, {bool isSlide = false}) {
if (isPrev) {
if (_selectedValue == ReaderMode.verticalContinuous ||
_selectedValue == ReaderMode.webtoon) {
@ -662,47 +733,58 @@ class _MangaChapterPageGalleryState
),
),
),
Flexible(
child:
Consumer(builder: (context, ref, child) {
final currentIndex = ref
.watch(currentIndexProvider(chapter));
return Slider(
onChanged: (newValue) {
if (_readerController.getPageLength(
_chapterUrlModel.pageUrls) !=
_currentIndex + 1) {
int slideAddValueIndex = 0;
if (newValue < _currentIndex) {
slideAddValueIndex = -1;
} else {
slideAddValueIndex = 1;
}
_onBtnTapped(newValue.toInt(), true,
if (_isView)
Flexible(
child: Consumer(
builder: (context, ref, child) {
final currentIndex = ref
.watch(currentIndexProvider(chapter));
return Slider(
onChanged: (value) {
ref
.read(
currentIndexProvider(chapter)
.notifier)
.setCurrentIndex(value.toInt());
},
onChangeEnd: (newValue) {
try {
final index = _uChapDataPreload
.where((element) =>
element.chapter ==
chapter &&
element.index ==
newValue.toInt())
.toList()
.first
.pageIndex;
_onBtnTapped(
index!,
true,
isSlide: true,
slideAddValueIndex:
slideAddValueIndex);
}
},
divisions: max(
_readerController.getPageLength(
_chapterUrlModel.pageUrls) -
1,
1),
value: min(
currentIndex.toDouble(),
_readerController
.getPageLength(
_chapterUrlModel.pageUrls)
.toDouble()),
min: 0,
max: (_readerController.getPageLength(
_chapterUrlModel.pageUrls) -
1)
.toDouble(),
);
}),
),
);
} catch (_) {}
},
divisions:
_readerController.getPageLength(
_chapterUrlModel.pageUrls) -
1,
value: min(
currentIndex.toDouble(),
_readerController
.getPageLength(
_chapterUrlModel.pageUrls)
.toDouble()),
label: '${currentIndex + 1}',
min: 0,
max: (_readerController.getPageLength(
_chapterUrlModel.pageUrls) -
1)
.toDouble(),
);
}),
),
Padding(
padding: const EdgeInsets.only(right: 12),
child: Transform.scale(
@ -871,9 +953,9 @@ class _MangaChapterPageGalleryState
'${currentIndex + 1} / ${_readerController.getPageLength(_chapterUrlModel.pageUrls)}',
style: const TextStyle(
color: Colors.white,
fontSize: 12.0,
fontSize: 13.0,
shadows: <Shadow>[
Shadow(offset: Offset(0.0, 0.0), blurRadius: 10.0)
Shadow(offset: Offset(0.0, 0.0), blurRadius: 7.0)
],
),
textAlign: TextAlign.center,
@ -1064,9 +1146,7 @@ class _MangaChapterPageGalleryState
final model = resultMap[_listViewContext];
if (model == null) return;
_posIndex = model.firstChild?.index ?? 0;
if (!(_uChapDataPreload[_posIndex ?? 0]
.hasNextPrePage ||
_uChapDataPreload[_posIndex ?? 0].hasPrevPrePage)) {
setState(() {
_readerController = ReaderController(
chapter:
_uChapDataPreload[_posIndex ?? 0].chapter!);
@ -1074,97 +1154,73 @@ class _MangaChapterPageGalleryState
_chapterUrlModel = _uChapDataPreload[_posIndex ?? 0]
.chapterUrlModel!;
_currentIndex =
_uChapDataPreload[_posIndex ?? 0].index!;
_currentIndex = _posIndex!;
});
_isBookmarked =
_readerController.getChapterBookmarked();
_readerController.setMangaHistoryUpdate();
_readerController.setPageIndex(
_uChapDataPreload[_posIndex ?? 0].index!);
ref
.read(currentIndexProvider(chapter).notifier)
.setCurrentIndex(
_currentIndex,
);
_isBookmarked =
_readerController.getChapterBookmarked();
_readerController.setMangaHistoryUpdate();
_readerController.setPageIndex(_currentIndex);
_readerController
.setChapterPageLastRead(_currentIndex);
setState(() {});
}
ref
.read(currentIndexProvider(chapter).notifier)
.setCurrentIndex(
_uChapDataPreload[_posIndex ?? 0].index!,
);
},
child: ListView.separated(
cacheExtent: 5 * mediaHeight(context, 1),
cacheExtent: 199 * mediaHeight(context, 1),
itemCount: _uChapDataPreload.length,
controller: _scrollController,
itemBuilder: (context, index) {
if (_listViewContext != context) {
_listViewContext = context;
}
_scrollController.addListener(() {
if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) {
if (_uChapDataPreload[index].hasNextPrePage ||
_uChapDataPreload[index].hasPrevPrePage) {
_scrollController.position.minScrollExtent) {
try {
bool hasPrevChapter =
_readerController.getChapterIndex() + 1 !=
_readerController.getChaptersLength();
final chapter = hasPrevChapter
? _readerController.getPrevChapter()
: null;
if (chapter != null) {
ref
.watch(getChapterUrlProvider(
chapter: chapter,
).future)
.then((value) async {
await _preloadPrevChapter(value, chapter);
});
}
} catch (_) {}
}
if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) {
try {
bool hasNextChapter =
_readerController.getChapterIndex() != 0;
final chapter = _uChapDataPreload[index]
.hasNextPrePage &&
hasNextChapter
final chapter = hasNextChapter
? _readerController.getNextChapter()
: _uChapDataPreload[index].hasPrevPrePage &&
hasPrevChapter
? _readerController.getPrevChapter()
: null;
: null;
if (chapter != null) {
ref
.watch(getChapterUrlProvider(
chapter: chapter,
).future)
.then((value) {
if (_uChapDataPreload[index]
.hasNextPrePage) {
_preloadNextChapter(value, chapter);
} else {
_preloadPrevChapter(value, chapter);
}
_preloadNextChapter(value, chapter);
});
}
}
} catch (_) {}
}
});
if (_uChapDataPreload[index].hasNextPrePage ||
_uChapDataPreload[index].hasPrevPrePage) {
bool hasPrevChapter =
_readerController.getChapterIndex() + 1 !=
_readerController.getChaptersLength();
bool hasNextChapter =
_readerController.getChapterIndex() != 0;
final chapter =
_uChapDataPreload[index].hasNextPrePage &&
hasNextChapter
? _readerController.getNextChapter()
: _uChapDataPreload[index].hasPrevPrePage &&
hasPrevChapter
? _readerController.getPrevChapter()
: null;
if (chapter == null) {
return ChapterIntervalPageView(
uChapDataPreload: _uChapDataPreload[index],
onTap: () async {},
hasNextChapter: hasNextChapter,
hasPrevChapter: hasPrevChapter,
);
}
return ChapterIntervalPageView(
uChapDataPreload: _uChapDataPreload[index],
onTap: () async {},
hasNextChapter: hasNextChapter,
hasPrevChapter: hasPrevChapter,
);
}
return GestureDetector(
behavior: HitTestBehavior.translucent,
onDoubleTapDown: (TapDownDetails details) {
@ -1219,37 +1275,6 @@ class _MangaChapterPageGalleryState
: true;
},
itemBuilder: (BuildContext context, int index) {
if (_uChapDataPreload[index].hasNextPrePage ||
_uChapDataPreload[index].hasPrevPrePage) {
bool hasPrevChapter =
_readerController.getChapterIndex() + 1 !=
_readerController.getChaptersLength();
bool hasNextChapter =
_readerController.getChapterIndex() != 0;
final chapter =
_uChapDataPreload[index].hasNextPrePage &&
hasNextChapter
? _readerController.getNextChapter()
: _uChapDataPreload[index].hasPrevPrePage &&
hasPrevChapter
? _readerController.getPrevChapter()
: null;
if (chapter == null) {
return ChapterIntervalPageView(
uChapDataPreload: _uChapDataPreload[index],
onTap: () async {},
hasNextChapter: hasNextChapter,
hasPrevChapter: hasPrevChapter,
);
}
return ChapterIntervalPageView(
uChapDataPreload: _uChapDataPreload[index],
onTap: () async {},
hasNextChapter: hasNextChapter,
hasPrevChapter: hasPrevChapter,
);
}
return ImageViewCenter(
archiveImage:
_cropImagesList.isNotEmpty && cropBorders == true
@ -1478,9 +1503,8 @@ class UChapDataPreload {
final bool? isLocale;
final Uint8List? archiveImage;
final int? index;
final bool hasNextPrePage;
final bool hasPrevPrePage;
final GetChapterUrlModel? chapterUrlModel;
final int? pageIndex;
UChapDataPreload(
this.chapter,
this.path,
@ -1488,8 +1512,7 @@ class UChapDataPreload {
this.isLocale,
this.archiveImage,
this.index,
this.hasNextPrePage,
this.hasPrevPrePage,
this.chapterUrlModel,
this.pageIndex,
);
}

View file

@ -17,7 +17,7 @@ import 'package:mangayomi/modules/library/library_screen.dart';
import 'package:mangayomi/modules/manga/detail/manga_detail_main.dart';
import 'package:mangayomi/modules/manga/home/manga_home_screen.dart';
import 'package:mangayomi/modules/manga/home/manga_search_screen.dart';
import 'package:mangayomi/modules/manga/reader/manga_reader_view.dart';
import 'package:mangayomi/modules/manga/reader/reader_view.dart';
import 'package:mangayomi/modules/more/about_screen.dart';
import 'package:mangayomi/modules/more/download_queue/download_queue_screen.dart';
import 'package:mangayomi/modules/more/more_screen.dart';

View file

@ -10,7 +10,7 @@ import 'package:mangayomi/main.dart';
import 'package:mangayomi/models/chapter.dart';
import 'package:mangayomi/models/settings.dart';
import 'package:mangayomi/modules/archive_reader/providers/archive_reader_providers.dart';
import 'package:mangayomi/modules/manga/reader/manga_reader_view.dart';
import 'package:mangayomi/modules/manga/reader/reader_view.dart';
import 'package:mangayomi/providers/storage_provider.dart';
import 'package:mangayomi/eval/runtime/runtime.dart';
import 'package:mangayomi/sources/utils/utils.dart';
@ -51,7 +51,7 @@ Future<GetChapterUrlModel> getChapterUrl(
final storageProvider = StorageProvider();
path = await storageProvider.getMangaChapterDirectory(chapter);
final mangaDirectory = await storageProvider.getMangaMainDirectory(chapter);
List<Uint8List?> archiveImages = [];
final isLocalArchive = (chapter.archivePath ?? '').isNotEmpty;
if (!chapter.manga.value!.isLocalArchive!) {
@ -145,14 +145,13 @@ Future<GetChapterUrlModel> getChapterUrl(
isLocaleList[i],
archiveImages[i],
i,
false,
false,
GetChapterUrlModel(
path: path,
pageUrls: pageUrls,
isLocaleList: isLocaleList,
archiveImages: archiveImages,
uChapDataPreload: uChapDataPreloadp)));
uChapDataPreload: uChapDataPreloadp),
i));
}
}