Desktop right-click for long press on chapter

just like with the LibraryGridView
This commit is contained in:
NBA2K1 2025-07-12 20:24:34 +02:00
parent 775e51e617
commit aef659000d

View file

@ -24,113 +24,116 @@ class ChapterListTileWidget extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final isLongPressed = ref.watch(isLongPressedStateProvider);
final l10n = l10nLocalizations(context)!;
return Container(
color: chapterList.contains(chapter)
? context.primaryColor.withValues(alpha: 0.4)
: null,
child: ListTile(
textColor: chapter.isRead!
? context.isLight
? Colors.black.withValues(alpha: 0.4)
: Colors.white.withValues(alpha: 0.3)
: null,
selectedColor: chapter.isRead!
? Colors.white.withValues(alpha: 0.3)
: Colors.white,
onLongPress: () {
if (!isLongPressed) {
ref.read(chaptersListStateProvider.notifier).update(chapter);
ref
.read(isLongPressedStateProvider.notifier)
.update(!isLongPressed);
} else {
ref.read(chaptersListStateProvider.notifier).update(chapter);
}
},
onTap: () async {
if (isLongPressed) {
ref.read(chaptersListStateProvider.notifier).update(chapter);
} else {
chapter.pushToReaderView(context, ignoreIsRead: true);
}
},
title: Row(
children: [
chapter.isBookmarked!
? Icon(Icons.bookmark, size: 16, color: context.primaryColor)
: Container(),
Flexible(child: _buildTitle(chapter.name!, context)),
],
),
subtitle: Row(
children: [
if ((chapter.manga.value!.isLocalArchive ?? false) == false)
Text(
chapter.dateUpload == null || chapter.dateUpload!.isEmpty
? ""
: dateFormat(
chapter.dateUpload!,
ref: ref,
context: context,
child: GestureDetector(
onLongPress: () => _handleInteraction(ref),
onSecondaryTap: () => _handleInteraction(ref),
child: ListTile(
textColor: chapter.isRead!
? context.isLight
? Colors.black.withValues(alpha: 0.4)
: Colors.white.withValues(alpha: 0.3)
: null,
selectedColor: chapter.isRead!
? Colors.white.withValues(alpha: 0.3)
: Colors.white,
onTap: () async => _handleInteraction(ref, context),
title: Row(
children: [
chapter.isBookmarked!
? Icon(Icons.bookmark, size: 16, color: context.primaryColor)
: Container(),
Flexible(child: _buildTitle(chapter.name!, context)),
],
),
subtitle: Row(
children: [
if ((chapter.manga.value!.isLocalArchive ?? false) == false)
Text(
chapter.dateUpload == null || chapter.dateUpload!.isEmpty
? ""
: dateFormat(
chapter.dateUpload!,
ref: ref,
context: context,
),
style: const TextStyle(fontSize: 11),
),
if (!chapter.isRead!)
if (chapter.lastPageRead!.isNotEmpty &&
chapter.lastPageRead != "1")
Row(
children: [
const Text(''),
Text(
chapter.manga.value!.itemType == ItemType.anime
? l10n.episode_progress(
Duration(
milliseconds: int.parse(
chapter.lastPageRead!,
),
).toString().substringBefore("."),
)
: l10n.page(
chapter.manga.value!.itemType == ItemType.manga
? chapter.lastPageRead!
: "${((double.tryParse(chapter.lastPageRead!) ?? 0) * 100).toStringAsFixed(0)} %",
),
style: TextStyle(
fontSize: 11,
color: context.isLight
? Colors.black.withValues(alpha: 0.4)
: Colors.white.withValues(alpha: 0.3),
),
),
style: const TextStyle(fontSize: 11),
),
if (!chapter.isRead!)
if (chapter.lastPageRead!.isNotEmpty &&
chapter.lastPageRead != "1")
],
),
if (chapter.scanlator?.isNotEmpty ?? false)
Row(
children: [
const Text(''),
Text(
chapter.manga.value!.itemType == ItemType.anime
? l10n.episode_progress(
Duration(
milliseconds: int.parse(chapter.lastPageRead!),
).toString().substringBefore("."),
)
: l10n.page(
chapter.manga.value!.itemType == ItemType.manga
? chapter.lastPageRead!
: "${((double.tryParse(chapter.lastPageRead!) ?? 0) * 100).toStringAsFixed(0)} %",
),
chapter.scanlator!,
style: TextStyle(
fontSize: 11,
color: context.isLight
? Colors.black.withValues(alpha: 0.4)
: Colors.white.withValues(alpha: 0.3),
color: chapter.isRead!
? context.isLight
? Colors.black.withValues(alpha: 0.4)
: Colors.white.withValues(alpha: 0.3)
: null,
),
),
],
),
if (chapter.scanlator?.isNotEmpty ?? false)
Row(
children: [
const Text(''),
Text(
chapter.scanlator!,
style: TextStyle(
fontSize: 11,
color: chapter.isRead!
? context.isLight
? Colors.black.withValues(alpha: 0.4)
: Colors.white.withValues(alpha: 0.3)
: null,
),
),
],
),
],
],
),
trailing:
!sourceExist || (chapter.manga.value!.isLocalArchive ?? false)
? null
: ChapterPageDownload(chapter: chapter),
),
trailing: !sourceExist || (chapter.manga.value!.isLocalArchive ?? false)
? null
: ChapterPageDownload(chapter: chapter),
),
);
}
void _handleInteraction(WidgetRef ref, [BuildContext? context]) {
final isLongPressed = ref.read(isLongPressedStateProvider);
if (isLongPressed) {
ref.read(chaptersListStateProvider.notifier).update(chapter);
} else {
if (context != null) {
chapter.pushToReaderView(context, ignoreIsRead: true);
} else {
ref.read(chaptersListStateProvider.notifier).update(chapter);
ref.read(isLongPressedStateProvider.notifier).update(!isLongPressed);
}
}
}
Widget _buildTitle(String text, BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {