changes for novel support

This commit is contained in:
playerterra1 2024-11-05 14:55:54 +00:00
parent 04ddbb6ac7
commit 752387ccde
11 changed files with 44 additions and 36 deletions

View file

@ -1,5 +1,6 @@
import 'package:isar/isar.dart';
import 'package:mangayomi/models/chapter.dart';
import 'package:mangayomi/models/manga.dart';
part 'history.g.dart';
@collection
@ -11,7 +12,7 @@ class History {
int? chapterId;
bool? isManga;
ItemType? itemType;
final chapter = IsarLink<Chapter>();
@ -19,7 +20,7 @@ class History {
History({
this.id = Isar.autoIncrement,
required this.isManga,
required this.itemType,
required this.chapterId,
required this.mangaId,
required this.date,
@ -29,7 +30,7 @@ class History {
chapterId = json['chapterId'];
date = json['date'];
id = json['id'];
isManga = json['isManga'];
itemType = json['itemType'];
mangaId = json['mangaId'];
}
@ -37,7 +38,7 @@ class History {
'chapterId': chapterId,
'date': date,
'id': id,
'isManga': isManga,
'itemType': itemType,
'mangaId': mangaId
};
}

View file

@ -22,8 +22,6 @@ class Manga {
@enumerated
late Status status;
bool? isManga;
@enumerated
late ItemType itemType;
@ -65,7 +63,6 @@ class Manga {
required this.name,
required this.status,
required this.description,
this.isManga = true,
this.itemType = ItemType.manga,
this.dateAdded,
this.lastUpdate,
@ -87,7 +84,6 @@ class Manga {
id = json['id'];
imageUrl = json['imageUrl'];
isLocalArchive = json['isLocalArchive'];
isManga = json['isManga'];
itemType = ItemType.values[json['itemType']];
lang = json['lang'];
lastRead = json['lastRead'];
@ -111,7 +107,6 @@ class Manga {
'id': id,
'imageUrl': imageUrl,
'isLocalArchive': isLocalArchive,
'isManga': isManga,
'itemType': itemType.index,
'lang': lang,
'lastRead': lastRead,

View file

@ -133,7 +133,7 @@ class AnimeStreamController extends _$AnimeStreamController {
history = History(
mangaId: getAnime().id,
date: DateTime.now().millisecondsSinceEpoch.toString(),
isManga: getAnime().isManga,
itemType: getAnime().itemType,
chapterId: episode.id)
..chapter.value = episode;
} else {

View file

@ -236,7 +236,7 @@ class _MangaGlobalImageCardState extends ConsumerState<MangaGlobalImageCard>
context: context,
getManga: getMangaDetail,
lang: widget.source.lang!,
isManga: widget.source.isManga ?? true,
itemType: widget.source.itemType,
useMaterialRoute: true,
source: widget.source.name!);
},

View file

@ -32,7 +32,7 @@ Future addTorrentFromUrlOrFromFile(
favorite: true,
source: 'torrent',
author: '',
isManga: false,
itemType: ItemType.anime,
genre: [],
imageUrl: '',
lang: '',

View file

@ -24,7 +24,6 @@ Future importArchivesFromFile(ImportArchivesFromFileRef ref, Manga? mManga,
favorite: true,
source: 'archive',
author: '',
isManga: itemType == ItemType.manga,
itemType: itemType,
genre: [],
imageUrl: '',

View file

@ -279,7 +279,7 @@ class _LibraryGridViewWidgetState extends State<LibraryGridViewWidget> {
.idIsNotNull()
.and()
.chapter((q) => q.manga((q) =>
q.isMangaEqualTo(entry.isManga!)))
q.itemTypeEqualTo(entry.itemType!)))
.watch(fireImmediately: true),
builder: (context, snapshot) {
if (snapshot.hasData &&

View file

@ -264,7 +264,7 @@ class LibraryListViewWidget extends StatelessWidget {
.idIsNotNull()
.and()
.chapter((q) => q.manga((q) =>
q.isMangaEqualTo(entry.isManga!)))
q.itemTypeEqualTo(entry.itemType)))
.watch(fireImmediately: true),
builder: (context, snapshot) {
if (snapshot.hasData &&

View file

@ -42,11 +42,12 @@ class MainScreen extends ConsumerWidget {
location == '/mangaReaderView' || location == '/animePlayerView' || location == '/novelReaderView';
int currentIndex = switch (location) {
null || '/MangaLibrary' => 0,
'/AnimeLibrary' => 1, // TODO add /NovelLibrary
'/AnimeLibrary' => 1,
'/updates' => 2,
'/history' => 3,
'/browse' => 4,
_ => 5,
'/NovelLibrary' => 5,
_ => 6,
};
final incognitoMode = ref.watch(incognitoModeStateProvider);
@ -95,6 +96,7 @@ class MainScreen extends ConsumerWidget {
null => 100,
!= '/MangaLibrary' &&
!= '/AnimeLibrary' &&
!= '/NovelLibrary' &&
!= '/history' &&
!= '/updates' &&
!= '/browse' &&
@ -134,6 +136,15 @@ class MainScreen extends ConsumerWidget {
padding: const EdgeInsets.only(
top: 5),
child: Text(l10n.anime))),
NavigationRailDestination(
selectedIcon: const Icon(
Icons.local_library),
icon: const Icon(Icons
.local_library_outlined),
label: Padding(
padding: const EdgeInsets.only(
top: 5),
child: Text(l10n.novel))),
NavigationRailDestination(
selectedIcon:
const Icon(Icons.new_releases),
@ -180,9 +191,10 @@ class MainScreen extends ConsumerWidget {
final fn = switch (newIndex) {
0 => route.go('/MangaLibrary'),
1 => route.go('/AnimeLibrary'),
2 => route.go('/updates'),
3 => route.go('/history'),
4 => route.go('/browse'),
2 => route.go('/NovelLibrary'),
3 => route.go('/updates'),
4 => route.go('/history'),
5 => route.go('/browse'),
_ => route.go('/more'),
};
fn;
@ -216,6 +228,7 @@ class MainScreen extends ConsumerWidget {
null => null,
!= '/MangaLibrary' &&
!= '/AnimeLibrary' &&
!= '/NovelLibrary' &&
!= '/history' &&
!= '/updates' &&
!= '/browse' &&

View file

@ -39,15 +39,15 @@ Future<void> migration(MigrationRef ref) async {
//chapterId and isManga in History
for (var history in histories) {
final chapterId = history.chapter.value?.id;
final isManga = history.chapter.value?.manga.value?.isManga;
final itemType = history.chapter.value?.manga.value?.itemType;
isar.historys.putSync(history
..chapterId = chapterId
..isManga = isManga);
..itemType = itemType);
}
// isManga in Track
for (var track in tracks) {
final isManga = isar.mangas.getSync(track.mangaId!)?.isManga;
isar.tracks.putSync(track..isManga = isManga);
final itemType = isar.mangas.getSync(track.mangaId!)?.itemType;
isar.tracks.putSync(track..itemType = itemType);
}
});
}

View file

@ -19,7 +19,7 @@ import 'package:mangayomi/modules/widgets/cover_view_widget.dart';
class MangaImageCardWidget extends ConsumerWidget {
final Source source;
final bool isManga;
final ItemType itemType;
final bool isComfortableGrid;
final MManga? getMangaDetail;
@ -28,7 +28,7 @@ class MangaImageCardWidget extends ConsumerWidget {
super.key,
required this.getMangaDetail,
required this.isComfortableGrid,
required this.isManga});
required this.itemType});
@override
Widget build(BuildContext context, WidgetRef ref) {
@ -68,7 +68,7 @@ class MangaImageCardWidget extends ConsumerWidget {
getManga: getMangaDetail!,
lang: source.lang!,
source: source.name!,
isManga: isManga);
itemType: itemType);
},
onLongPress: () {
pushToMangaReaderDetail(
@ -76,7 +76,7 @@ class MangaImageCardWidget extends ConsumerWidget {
getManga: getMangaDetail!,
lang: source.lang!,
source: source.name!,
isManga: isManga,
itemType: itemType,
addToFavourite: true);
},
onSecondaryTap: () {
@ -85,7 +85,7 @@ class MangaImageCardWidget extends ConsumerWidget {
getManga: getMangaDetail!,
lang: source.lang!,
source: source.name!,
isManga: isManga,
itemType: itemType,
addToFavourite: true);
},
children: [
@ -121,13 +121,13 @@ class MangaImageCardWidget extends ConsumerWidget {
class MangaImageCardListTileWidget extends ConsumerWidget {
final Source source;
final bool isManga;
final ItemType itemType;
final MManga? getMangaDetail;
const MangaImageCardListTileWidget(
{required this.source,
super.key,
required this.isManga,
required this.itemType,
required this.getMangaDetail});
@override
@ -166,7 +166,7 @@ class MangaImageCardListTileWidget extends ConsumerWidget {
getManga: getMangaDetail!,
lang: source.lang!,
source: source.name!,
isManga: isManga);
itemType: itemType);
},
onLongPress: () {
pushToMangaReaderDetail(
@ -174,7 +174,7 @@ class MangaImageCardListTileWidget extends ConsumerWidget {
getManga: getMangaDetail!,
lang: source.lang!,
source: source.name!,
isManga: isManga,
itemType: itemType,
addToFavourite: true);
},
onSecondaryTap: () {
@ -183,7 +183,7 @@ class MangaImageCardListTileWidget extends ConsumerWidget {
getManga: getMangaDetail!,
lang: source.lang!,
source: source.name!,
isManga: isManga,
itemType: itemType,
addToFavourite: true);
},
child: Row(
@ -252,7 +252,7 @@ Future<void> pushToMangaReaderDetail(
required String source,
int? archiveId,
Manga? mangaM,
bool? isManga,
ItemType? itemType,
bool useMaterialRoute = false,
bool addToFavourite = false}) async {
int? mangaId;
@ -269,7 +269,7 @@ Future<void> pushToMangaReaderDetail(
source: source,
lang: lang,
lastUpdate: 0,
isManga: isManga ?? true,
itemType: itemType ?? ItemType.manga,
artist: getManga.artist ?? '');
final empty = isar.mangas
.filter()