Refactor an fix

This commit is contained in:
Moustapha Kodjo Amadou 2025-11-09 01:15:27 +01:00
parent 251d7266f5
commit b8fffca2b3
5 changed files with 914 additions and 336 deletions

View file

@ -2,10 +2,13 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:mangayomi/main.dart'; import 'package:mangayomi/main.dart';
import 'package:mangayomi/models/chapter.dart'; import 'package:mangayomi/models/chapter.dart';
import 'package:mangayomi/models/manga.dart';
import 'package:mangayomi/modules/manga/reader/providers/push_router.dart'; import 'package:mangayomi/modules/manga/reader/providers/push_router.dart';
import 'package:mangayomi/modules/manga/reader/providers/reader_controller_provider.dart'; import 'package:mangayomi/modules/manga/reader/providers/reader_controller_provider.dart';
import 'package:mangayomi/providers/l10n_providers.dart';
import 'package:mangayomi/utils/date.dart'; import 'package:mangayomi/utils/date.dart';
import 'package:mangayomi/utils/extensions/build_context_extensions.dart'; import 'package:mangayomi/utils/extensions/build_context_extensions.dart';
import 'package:mangayomi/utils/extensions/string_extensions.dart';
import 'package:super_sliver_list/super_sliver_list.dart'; import 'package:super_sliver_list/super_sliver_list.dart';
Widget btnToShowChapterListDialog( Widget btnToShowChapterListDialog(
@ -21,11 +24,70 @@ Widget btnToShowChapterListDialog(
await showDialog( await showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return AlertDialog( return Dialog(
title: Text(title), shape: RoundedRectangleBorder(
content: SizedBox( borderRadius: BorderRadius.circular(20),
width: context.width(0.8), ),
child: ChapterListWidget(chapter: chapter), elevation: 8,
child: Container(
width: context.width(0.85),
constraints: BoxConstraints(maxHeight: context.height(0.8)),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
context.primaryColor.withValues(alpha: 0.05),
Colors.transparent,
],
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: context.primaryColor.withValues(alpha: 0.2),
width: 1,
),
),
),
child: Row(
children: [
Icon(
Icons.menu_book_rounded,
color: context.primaryColor,
size: 24,
),
const SizedBox(width: 12),
Expanded(
child: Text(
title,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: context.primaryColor,
),
),
),
IconButton(
onPressed: () => Navigator.pop(context),
icon: Icon(
Icons.close_rounded,
color: context.primaryColor.withValues(alpha: 0.7),
),
tooltip: 'Fermer',
),
],
),
),
Flexible(child: ChapterListWidget(chapter: chapter)),
],
),
), ),
); );
}, },
@ -79,22 +141,25 @@ class _ChapterListWidgetState extends State<ChapterListWidget> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scrollbar( return Scrollbar(
interactive: true, interactive: true,
thickness: 12, thickness: 8,
radius: const Radius.circular(10), radius: const Radius.circular(10),
controller: controller, controller: controller,
child: CustomScrollView( child: CustomScrollView(
controller: controller, controller: controller,
slivers: [ slivers: [
SliverPadding( SliverPadding(
padding: const EdgeInsets.symmetric(vertical: 2), padding: const EdgeInsets.all(12),
sliver: SuperSliverList.builder( sliver: SuperSliverList.builder(
itemCount: chapterList.length, itemCount: chapterList.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final chapter = chapterList[index]; final chapter = chapterList[index];
final currentChap = chapter == chapterList[currentChapIndex]; final currentChap = chapter == chapterList[currentChapIndex];
return ChapterListTile( return Padding(
chapter: chapter, padding: const EdgeInsets.only(bottom: 6),
currentChap: currentChap, child: ChapterListTile(
chapter: chapter,
currentChap: currentChap,
),
); );
}, },
), ),
@ -123,86 +188,224 @@ class _ChapterListTileState extends State<ChapterListTile> {
late bool isBookmarked = chapter.isBookmarked!; late bool isBookmarked = chapter.isBookmarked!;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return AnimatedContainer(
color: widget.currentChap duration: const Duration(milliseconds: 200),
? context.primaryColor.withValues(alpha: 0.3) decoration: BoxDecoration(
: null, color: widget.currentChap
child: ListTile( ? context.primaryColor.withValues(alpha: 0.15)
textColor: chapter.isRead! : Colors.transparent,
? context.isLight borderRadius: BorderRadius.circular(12),
? Colors.black.withValues(alpha: 0.4) border: widget.currentChap
: Colors.white.withValues(alpha: 0.3) ? Border.all(
color: context.primaryColor.withValues(alpha: 0.4),
width: 1.5,
)
: null, : null,
selectedColor: chapter.isRead! ),
? Colors.white.withValues(alpha: 0.3) child: Material(
: Colors.white, color: Colors.transparent,
onTap: () async { child: InkWell(
if (!widget.currentChap) { borderRadius: BorderRadius.circular(12),
Navigator.pop(context); onTap: () async {
pushReplacementMangaReaderView(context: context, chapter: chapter); if (!widget.currentChap) {
} Navigator.pop(context);
}, pushReplacementMangaReaderView(
title: Text( context: context,
chapter.name!, chapter: chapter,
style: const TextStyle(fontSize: 13), );
overflow: TextOverflow.ellipsis, }
), },
subtitle: Row( child: Padding(
children: [ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
if (!(chapter.manga.value!.isLocalArchive ?? false)) child: Row(
Consumer( children: [
builder: (context, ref, child) => Text( // Chapter indicator
chapter.dateUpload == null || chapter.dateUpload!.isEmpty Container(
? "" width: 4,
: dateFormat( height: 48,
chapter.dateUpload!, decoration: BoxDecoration(
ref: ref, color: chapter.isRead!
context: context, ? Colors.grey.withValues(alpha: 0.3)
), : context.primaryColor,
style: const TextStyle(fontSize: 11), borderRadius: BorderRadius.circular(2),
),
), ),
), const SizedBox(width: 12),
if (!chapter.isRead!) // Chapter content
if (chapter.lastPageRead!.isNotEmpty && Expanded(
chapter.lastPageRead != "1") child: Column(
if (chapter.scanlator != null && chapter.scanlator!.isNotEmpty) crossAxisAlignment: CrossAxisAlignment.start,
Row(
children: [ children: [
const Text(''),
Text( Text(
chapter.scanlator!, chapter.name!,
style: TextStyle( style: TextStyle(
fontSize: 11, fontSize: 14,
fontWeight: widget.currentChap
? FontWeight.bold
: FontWeight.w500,
color: chapter.isRead! color: chapter.isRead!
? context.isLight ? context.isLight
? Colors.black.withValues(alpha: 0.4) ? Colors.black.withValues(alpha: 0.4)
: Colors.white.withValues(alpha: 0.3) : Colors.white.withValues(alpha: 0.4)
: null, : null,
), ),
overflow: TextOverflow.ellipsis,
maxLines: 2,
), ),
const SizedBox(height: 4),
Row(
children: [
if (!(chapter.manga.value!.isLocalArchive ?? false))
Consumer(
builder: (context, ref, child) {
final dateText =
chapter.dateUpload == null ||
chapter.dateUpload!.isEmpty
? ""
: dateFormat(
chapter.dateUpload!,
ref: ref,
context: context,
);
return dateText.isNotEmpty
? Row(
children: [
Icon(
Icons.access_time_rounded,
size: 12,
color: Colors.grey,
),
const SizedBox(width: 4),
Text(
dateText,
style: const TextStyle(
fontSize: 11,
color: Colors.grey,
),
),
],
)
: const SizedBox.shrink();
},
),
if (chapter.scanlator != null &&
chapter.scanlator!.isNotEmpty)
Row(
children: [
if (!(chapter.manga.value!.isLocalArchive ??
false) &&
(chapter.dateUpload != null &&
chapter.dateUpload!.isNotEmpty))
const Padding(
padding: EdgeInsets.symmetric(
horizontal: 6,
),
child: Text(
'',
style: TextStyle(
fontSize: 11,
color: Colors.grey,
),
),
),
Icon(
Icons.group_rounded,
size: 12,
color: Colors.grey,
),
const SizedBox(width: 4),
Flexible(
child: Text(
chapter.scanlator!,
style: TextStyle(
fontSize: 11,
color: Colors.grey,
),
overflow: TextOverflow.ellipsis,
),
),
],
),
],
),
if (!chapter.isRead! &&
chapter.lastPageRead!.isNotEmpty &&
chapter.lastPageRead != "1")
Padding(
padding: const EdgeInsets.only(top: 4),
child: Row(
children: [
Icon(
Icons.bookmark_rounded,
size: 12,
color: context.primaryColor,
),
const SizedBox(width: 4),
Text(
chapter.manga.value!.itemType == ItemType.anime
? context.l10n.episode_progress(
Duration(
milliseconds: int.parse(
chapter.lastPageRead!,
),
).toString().substringBefore("."),
)
: context.l10n.page(
chapter.manga.value!.itemType ==
ItemType.manga
? chapter.lastPageRead!
: "${((double.tryParse(chapter.lastPageRead!) ?? 0) * 100).toStringAsFixed(0)} %",
),
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w500,
color: context.primaryColor,
),
),
],
),
),
], ],
), ),
], ),
), const SizedBox(width: 12),
trailing: Consumer( // Bookmark button
builder: (context, ref, child) => IconButton( Consumer(
onPressed: () { builder: (context, ref, child) => Material(
setState(() { color: Colors.transparent,
isBookmarked = !isBookmarked; child: InkWell(
}); borderRadius: BorderRadius.circular(20),
isar.writeTxnSync( onTap: () {
() => { setState(() {
isar.chapters.putSync( isBookmarked = !isBookmarked;
chapter });
..isBookmarked = isBookmarked isar.writeTxnSync(
..updatedAt = DateTime.now().millisecondsSinceEpoch, () => {
isar.chapters.putSync(
chapter
..isBookmarked = isBookmarked
..updatedAt =
DateTime.now().millisecondsSinceEpoch,
),
},
);
},
child: Padding(
padding: const EdgeInsets.all(8),
child: Icon(
isBookmarked
? Icons.bookmark_rounded
: Icons.bookmark_outline_rounded,
color: isBookmarked
? context.primaryColor
: Colors.grey,
size: 22,
),
),
),
), ),
}, ),
); ],
},
icon: Icon(
isBookmarked ? Icons.bookmark : Icons.bookmark_outline,
color: context.primaryColor,
), ),
), ),
), ),

View file

@ -79,6 +79,7 @@ class AutoBackupLocationState extends _$AutoBackupLocationState {
@riverpod @riverpod
Future<void> checkAndBackup(Ref ref) async { Future<void> checkAndBackup(Ref ref) async {
ref.keepAlive();
final settings = isar.settings.getSync(227); final settings = isar.settings.getSync(227);
final backupFrequency = _duration(settings!.backupFrequency); final backupFrequency = _duration(settings!.backupFrequency);
if (backupFrequency == null || settings.startDatebackup == null) return; if (backupFrequency == null || settings.startDatebackup == null) return;

View file

@ -117,6 +117,7 @@ class _NovelWebViewState extends ConsumerState<NovelWebView>
fontSize = initFontSize; fontSize = initFontSize;
}); });
}); });
if (!isDesktop) SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
discordRpc?.showChapterDetails(ref, chapter); discordRpc?.showChapterDetails(ref, chapter);
} }

View file

@ -172,22 +172,74 @@ class ReaderSettingsTab extends ConsumerWidget {
children: [ children: [
Row( Row(
children: [ children: [
const Icon(Icons.space_bar, size: 20), Container(
Expanded( padding: const EdgeInsets.all(10),
child: Slider( decoration: BoxDecoration(
value: padding.toDouble(), color: Theme.of(
min: 0, context,
max: 50, ).primaryColor.withValues(alpha: 0.1),
divisions: 50, borderRadius: BorderRadius.circular(10),
label: '$padding px', ),
onChanged: (value) { child: Icon(
ref Icons.space_bar_rounded,
.read(novelReaderPaddingStateProvider.notifier) size: 22,
.set(value.toInt()); color: Theme.of(context).primaryColor,
}, ),
),
const SizedBox(width: 12),
Expanded(
child: SliderTheme(
data: SliderTheme.of(context).copyWith(
trackHeight: 4,
thumbShape: const RoundSliderThumbShape(
enabledThumbRadius: 8,
),
overlayShape: const RoundSliderOverlayShape(
overlayRadius: 16,
),
activeTrackColor: Theme.of(context).primaryColor,
inactiveTrackColor: Theme.of(
context,
).primaryColor.withValues(alpha: 0.2),
thumbColor: Theme.of(context).primaryColor,
overlayColor: Theme.of(
context,
).primaryColor.withValues(alpha: 0.2),
),
child: Slider(
value: padding.toDouble(),
min: 0,
max: 50,
divisions: 50,
label: '$padding px',
onChanged: (value) {
ref
.read(novelReaderPaddingStateProvider.notifier)
.set(value.toInt());
},
),
),
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 6,
),
decoration: BoxDecoration(
color: Theme.of(
context,
).primaryColor.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
),
child: Text(
'${padding}px',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: Theme.of(context).primaryColor,
),
), ),
), ),
Text('${padding}px'),
], ],
), ),
], ],
@ -202,22 +254,76 @@ class ReaderSettingsTab extends ConsumerWidget {
children: [ children: [
Row( Row(
children: [ children: [
const Icon(Icons.height, size: 20), Container(
Expanded( padding: const EdgeInsets.all(10),
child: Slider( decoration: BoxDecoration(
value: lineHeight, color: Theme.of(
min: 1.0, context,
max: 3.0, ).primaryColor.withValues(alpha: 0.1),
divisions: 20, borderRadius: BorderRadius.circular(10),
label: lineHeight.toStringAsFixed(1), ),
onChanged: (value) { child: Icon(
ref Icons.height_rounded,
.read(novelReaderLineHeightStateProvider.notifier) size: 22,
.set(value); color: Theme.of(context).primaryColor,
}, ),
),
const SizedBox(width: 12),
Expanded(
child: SliderTheme(
data: SliderTheme.of(context).copyWith(
trackHeight: 4,
thumbShape: const RoundSliderThumbShape(
enabledThumbRadius: 8,
),
overlayShape: const RoundSliderOverlayShape(
overlayRadius: 16,
),
activeTrackColor: Theme.of(context).primaryColor,
inactiveTrackColor: Theme.of(
context,
).primaryColor.withValues(alpha: 0.2),
thumbColor: Theme.of(context).primaryColor,
overlayColor: Theme.of(
context,
).primaryColor.withValues(alpha: 0.2),
),
child: Slider(
value: lineHeight,
min: 1.0,
max: 3.0,
divisions: 20,
label: lineHeight.toStringAsFixed(1),
onChanged: (value) {
ref
.read(
novelReaderLineHeightStateProvider.notifier,
)
.set(value);
},
),
),
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 6,
),
decoration: BoxDecoration(
color: Theme.of(
context,
).primaryColor.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
),
child: Text(
lineHeight.toStringAsFixed(1),
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: Theme.of(context).primaryColor,
),
), ),
), ),
Text(lineHeight.toStringAsFixed(1)),
], ],
), ),
], ],
@ -328,19 +434,48 @@ class _SettingSection extends StatelessWidget {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Padding(
title, padding: const EdgeInsets.only(left: 4, bottom: 10),
style: TextStyle( child: Row(
fontSize: 16, children: [
fontWeight: FontWeight.bold, Container(
color: Theme.of(context).textTheme.titleLarge?.color, width: 4,
height: 20,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(width: 10),
Text(
title,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Theme.of(context).textTheme.titleLarge?.color,
letterSpacing: 0.3,
),
),
],
), ),
), ),
Card( Container(
child: Padding( decoration: BoxDecoration(
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 12), borderRadius: BorderRadius.circular(16),
child: child, gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Theme.of(context).primaryColor.withValues(alpha: 0.04),
Colors.transparent,
],
),
border: Border.all(
color: Theme.of(context).primaryColor.withValues(alpha: 0.1),
width: 1,
),
), ),
child: Padding(padding: const EdgeInsets.all(16), child: child),
), ),
], ],
); );
@ -402,38 +537,58 @@ class _ThemeButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return Material(
onTap: onTap, color: Colors.transparent,
child: Container( child: InkWell(
width: 70, onTap: onTap,
height: 60, borderRadius: BorderRadius.circular(12),
decoration: BoxDecoration( child: AnimatedContainer(
color: _parseColor(backgroundColor), duration: const Duration(milliseconds: 200),
borderRadius: BorderRadius.circular(8), width: 75,
border: Border.all( height: 70,
color: isSelected decoration: BoxDecoration(
? Theme.of(context).primaryColor color: _parseColor(backgroundColor),
: Colors.grey.withValues(alpha: 0.3), borderRadius: BorderRadius.circular(12),
width: isSelected ? 3 : 1, border: Border.all(
color: isSelected
? Theme.of(context).primaryColor
: Colors.grey.withValues(alpha: 0.3),
width: isSelected ? 3 : 1.5,
),
boxShadow: isSelected
? [
BoxShadow(
color: Theme.of(
context,
).primaryColor.withValues(alpha: 0.3),
blurRadius: 8,
offset: const Offset(0, 2),
),
]
: null,
), ),
), child: Column(
child: Column( mainAxisAlignment: MainAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center, children: [
children: [ Text(
Text( 'Aa',
'Aa', style: TextStyle(
style: TextStyle( color: _parseColor(textColor),
color: _parseColor(textColor), fontSize: 20,
fontSize: 18, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
), ),
), const SizedBox(height: 6),
const SizedBox(height: 4), Text(
Text( label,
label, style: TextStyle(
style: TextStyle(color: _parseColor(textColor), fontSize: 10), color: _parseColor(textColor),
), fontSize: 11,
], fontWeight: FontWeight.w500,
),
),
],
),
), ),
), ),
); );
@ -526,70 +681,127 @@ class _ColorPicker extends StatelessWidget {
Color selectedColor, Color selectedColor,
) { ) {
final isSelected = optionColor.toARGB32() == selectedColor.toARGB32(); final isSelected = optionColor.toARGB32() == selectedColor.toARGB32();
return GestureDetector( return Material(
onTap: () { color: Colors.transparent,
onColorChanged(_colorToHex(optionColor)); child: InkWell(
Navigator.of(context).pop(); onTap: () {
}, onColorChanged(_colorToHex(optionColor));
child: Container( Navigator.of(context).pop();
width: 50, },
height: 50, borderRadius: BorderRadius.circular(10),
decoration: BoxDecoration( child: AnimatedContainer(
color: optionColor, duration: const Duration(milliseconds: 200),
borderRadius: BorderRadius.circular(8), width: 56,
border: Border.all( height: 56,
color: isSelected ? Theme.of(context).primaryColor : Colors.grey, decoration: BoxDecoration(
width: isSelected ? 3 : 1, color: optionColor,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: isSelected ? Theme.of(context).primaryColor : Colors.grey,
width: isSelected ? 3 : 1.5,
),
boxShadow: isSelected
? [
BoxShadow(
color: Theme.of(
context,
).primaryColor.withValues(alpha: 0.4),
blurRadius: 8,
offset: const Offset(0, 2),
),
]
: null,
), ),
child: isSelected
? Icon(
Icons.check_circle_rounded,
size: 26,
color: optionColor.computeLuminance() > 0.5
? Colors.black
: Colors.white,
)
: null,
), ),
child: isSelected
? Icon(
Icons.check,
color: optionColor.computeLuminance() > 0.5
? Colors.black
: Colors.white,
)
: null,
), ),
); );
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return Material(
onTap: () => _showColorPickerDialog(context), color: Colors.transparent,
child: Container( child: InkWell(
padding: const EdgeInsets.all(12), onTap: () => _showColorPickerDialog(context),
decoration: BoxDecoration( borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.grey.withValues(alpha: 0.3)), child: Container(
borderRadius: BorderRadius.circular(8), padding: const EdgeInsets.all(14),
), decoration: BoxDecoration(
child: Row( border: Border.all(
children: [ color: Colors.grey.withValues(alpha: 0.3),
Container( width: 1.5,
width: 30,
height: 30,
decoration: BoxDecoration(
color: _parseColor(color),
borderRadius: BorderRadius.circular(6),
border: Border.all(color: Colors.grey),
),
), ),
const SizedBox(width: 12), borderRadius: BorderRadius.circular(12),
Expanded( gradient: LinearGradient(
child: Column( begin: Alignment.topLeft,
crossAxisAlignment: CrossAxisAlignment.start, end: Alignment.bottomRight,
children: [ colors: [
Text(label, style: const TextStyle(fontSize: 12)), Theme.of(context).primaryColor.withValues(alpha: 0.03),
Text( Colors.transparent,
color, ],
style: TextStyle(fontSize: 10, color: Colors.grey[600]), ),
),
child: Row(
children: [
Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: _parseColor(color),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: Colors.grey.withValues(alpha: 0.5),
width: 2,
), ),
], boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.1),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
), ),
), const SizedBox(width: 14),
const Icon(Icons.arrow_drop_down), Expanded(
], child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 2),
Text(
color,
style: TextStyle(
fontSize: 11,
color: Colors.grey[600],
fontFamily: 'monospace',
),
),
],
),
),
Icon(
Icons.palette_outlined,
color: Theme.of(context).primaryColor.withValues(alpha: 0.7),
size: 20,
),
],
),
), ),
), ),
); );
@ -609,29 +821,35 @@ class _AlignButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return Material(
onTap: onTap, color: Colors.transparent,
child: Container( child: InkWell(
width: 40, onTap: onTap,
height: 40, borderRadius: BorderRadius.circular(10),
decoration: BoxDecoration( child: AnimatedContainer(
color: isSelected duration: const Duration(milliseconds: 200),
? Theme.of(context).primaryColor.withValues(alpha: 0.2) width: 48,
: Colors.transparent, height: 48,
borderRadius: BorderRadius.circular(8), decoration: BoxDecoration(
border: Border.all( color: isSelected
? Theme.of(context).primaryColor.withValues(alpha: 0.15)
: Colors.transparent,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: isSelected
? Theme.of(context).primaryColor
: Colors.grey.withValues(alpha: 0.3),
width: isSelected ? 2 : 1.5,
),
),
child: Icon(
icon,
size: 22,
color: isSelected color: isSelected
? Theme.of(context).primaryColor ? Theme.of(context).primaryColor
: Colors.grey.withValues(alpha: 0.3), : Theme.of(context).iconTheme.color,
width: isSelected ? 2 : 1,
), ),
), ),
child: Icon(
icon,
color: isSelected
? Theme.of(context).primaryColor
: Theme.of(context).iconTheme.color,
),
), ),
); );
} }

View file

@ -34,136 +34,291 @@ void showCategorySelectionDialog({
showDialog( showDialog(
context: context, context: context,
builder: (context) => StatefulBuilder( builder: (context) => StatefulBuilder(
builder: (context, setState) => AlertDialog( builder: (context, setState) => Dialog(
title: Text(l10n.set_categories), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
content: SizedBox( elevation: 8,
width: context.width(0.8), child: Container(
child: StreamBuilder( width: context.width(0.85),
stream: isar.categorys constraints: BoxConstraints(maxHeight: context.height(0.75)),
.filter() decoration: BoxDecoration(
.idIsNotNull() borderRadius: BorderRadius.circular(20),
.and() gradient: LinearGradient(
.forItemTypeEqualTo(itemType) begin: Alignment.topLeft,
.watch(fireImmediately: true), end: Alignment.bottomRight,
builder: (context, snapshot) { colors: [
if (!snapshot.hasData || snapshot.data!.isEmpty) { context.primaryColor.withValues(alpha: 0.05),
return Text(l10n.library_no_category_exist); Colors.transparent,
} ],
var entries = (snapshot.data! ),
..sort((a, b) => (a.pos ?? 0).compareTo(b.pos ?? 0)));
if (isFavorite || isBulk) {
// When item is in library, hide hidden categories in list
entries = entries.where((e) => !(e.hide ?? false)).toList();
}
if (entries.isEmpty) return Text(l10n.library_no_category_exist);
return SuperListView.builder(
shrinkWrap: true,
itemCount: entries.length,
itemBuilder: (context, index) {
final category = entries[index];
final isSelected = categoryIds.contains(category.id);
if (!isBulk) {
return ListTileChapterFilter(
label: category.name!,
onTap: () {
setState(() {
isSelected
? categoryIds.remove(category.id)
: categoryIds.add(category.id!);
});
},
type: isSelected ? 1 : 0,
);
}
return ListTileMangaCategory(
category: category,
categoryIds: categoryIds,
mangasList: bulkMangas,
onTap: () {
setState(() {
if (isSelected) {
categoryIds.remove(category.id);
} else {
categoryIds.add(category.id!);
}
});
},
res: (res) {
if (res.isNotEmpty && !isSelected) {
categoryIds.add(category.id!);
}
},
);
},
);
},
), ),
), child: Column(
actions: [ mainAxisSize: MainAxisSize.min,
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
TextButton( // Header
child: Text(l10n.edit), Container(
onPressed: () { padding: const EdgeInsets.all(20),
context.push( decoration: BoxDecoration(
"/categories", border: Border(
extra: ( bottom: BorderSide(
true, color: context.primaryColor.withValues(alpha: 0.2),
itemType == ItemType.manga width: 1,
? 0
: itemType == ItemType.anime
? 1
: 2,
), ),
);
Navigator.pop(context);
},
),
Row(
children: [
TextButton(
child: Text(l10n.cancel),
onPressed: () => Navigator.pop(context),
), ),
const SizedBox(width: 15), ),
TextButton( child: Row(
child: Text(l10n.ok), children: [
onPressed: () { Container(
isar.writeTxnSync(() { padding: const EdgeInsets.all(10),
if (isBulk) { decoration: BoxDecoration(
for (var manga in bulkMangas) { color: context.primaryColor.withValues(alpha: 0.15),
manga.categories = categoryIds; borderRadius: BorderRadius.circular(12),
manga.updatedAt = ),
DateTime.now().millisecondsSinceEpoch; child: Icon(
isar.mangas.putSync(manga); Icons.category_rounded,
color: context.primaryColor,
size: 24,
),
),
const SizedBox(width: 12),
Expanded(
child: Text(
l10n.set_categories,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: context.primaryColor,
),
),
),
IconButton(
onPressed: () => Navigator.pop(context),
icon: Icon(
Icons.close_rounded,
color: context.primaryColor.withValues(alpha: 0.7),
),
),
],
),
),
// Content
Flexible(
child: Padding(
padding: const EdgeInsets.all(16),
child: StreamBuilder(
stream: isar.categorys
.filter()
.idIsNotNull()
.and()
.forItemTypeEqualTo(itemType)
.watch(fireImmediately: true),
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data!.isEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.category_outlined,
size: 64,
color: Colors.grey.withValues(alpha: 0.5),
),
const SizedBox(height: 16),
Text(
l10n.library_no_category_exist,
style: TextStyle(
color: Colors.grey.withValues(alpha: 0.7),
fontSize: 15,
),
),
],
),
);
}
var entries = (snapshot.data!
..sort((a, b) => (a.pos ?? 0).compareTo(b.pos ?? 0)));
if (isFavorite || isBulk) {
// When item is in library, hide hidden categories in list
entries = entries
.where((e) => !(e.hide ?? false))
.toList();
}
if (entries.isEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.category_outlined,
size: 64,
color: Colors.grey.withValues(alpha: 0.5),
),
const SizedBox(height: 16),
Text(
l10n.library_no_category_exist,
style: TextStyle(
color: Colors.grey.withValues(alpha: 0.7),
fontSize: 15,
),
),
],
),
);
}
return SuperListView.builder(
shrinkWrap: true,
itemCount: entries.length,
itemBuilder: (context, index) {
final category = entries[index];
final isSelected = categoryIds.contains(category.id);
if (!isBulk) {
return Padding(
padding: const EdgeInsets.only(bottom: 6),
child: ListTileChapterFilter(
label: category.name!,
onTap: () {
setState(() {
isSelected
? categoryIds.remove(category.id)
: categoryIds.add(category.id!);
});
},
type: isSelected ? 1 : 0,
),
);
} }
} else { return Padding(
if (!isFavorite) { padding: const EdgeInsets.only(bottom: 6),
singleManga!.favorite = true; child: ListTileMangaCategory(
singleManga.dateAdded = category: category,
DateTime.now().millisecondsSinceEpoch; categoryIds: categoryIds,
} mangasList: bulkMangas,
singleManga.categories = categoryIds; onTap: () {
singleManga.updatedAt = setState(() {
DateTime.now().millisecondsSinceEpoch; if (isSelected) {
isar.mangas.putSync(singleManga); categoryIds.remove(category.id);
} } else {
if (isBulk) { categoryIds.add(category.id!);
ref.read(mangasListStateProvider.notifier).clear(); }
ref });
.read(isLongPressedStateProvider.notifier) },
.update(false); res: (res) {
} if (res.isNotEmpty && !isSelected) {
}); categoryIds.add(category.id!);
if (context.mounted) Navigator.pop(context); }
},
),
);
},
);
}, },
), ),
], ),
),
// Actions
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
border: Border(
top: BorderSide(
color: context.primaryColor.withValues(alpha: 0.1),
width: 1,
),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton.icon(
icon: const Icon(Icons.edit_rounded, size: 18),
label: Text(l10n.edit),
style: TextButton.styleFrom(
foregroundColor: context.primaryColor,
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
),
onPressed: () {
context.push(
"/categories",
extra: (
true,
itemType == ItemType.manga
? 0
: itemType == ItemType.anime
? 1
: 2,
),
);
Navigator.pop(context);
},
),
Row(
children: [
TextButton(
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
),
onPressed: () => Navigator.pop(context),
child: Text(l10n.cancel),
),
const SizedBox(width: 12),
FilledButton(
style: FilledButton.styleFrom(
backgroundColor: context.primaryColor,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 12,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
onPressed: () {
isar.writeTxnSync(() {
if (isBulk) {
for (var manga in bulkMangas) {
manga.categories = categoryIds;
manga.updatedAt =
DateTime.now().millisecondsSinceEpoch;
isar.mangas.putSync(manga);
}
} else {
if (!isFavorite) {
singleManga!.favorite = true;
singleManga.dateAdded =
DateTime.now().millisecondsSinceEpoch;
}
singleManga.categories = categoryIds;
singleManga.updatedAt =
DateTime.now().millisecondsSinceEpoch;
isar.mangas.putSync(singleManga);
}
if (isBulk) {
ref
.read(mangasListStateProvider.notifier)
.clear();
ref
.read(isLongPressedStateProvider.notifier)
.update(false);
}
});
if (context.mounted) Navigator.pop(context);
},
child: Text(l10n.ok),
),
],
),
],
),
), ),
], ],
), ),
], ),
), ),
), ),
); );