Skip to content

Commit

Permalink
v0.3.3 (#95)
Browse files Browse the repository at this point in the history
* updated MacOs workflow

* fixed multiple bugs in reader and resume button
  • Loading branch information
DattatreyaReddy authored Dec 15, 2022
1 parent 18ff790 commit 76e1e9b
Show file tree
Hide file tree
Showing 17 changed files with 307 additions and 197 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- os: ubuntu-20.04
target: linux
build_path: build/linux/x64/release/bundle
- os: macos-10.15 # Catalina
- os: macos-latest # Catalina
target: macos
build_path: build/macos/Build/Products/Release
- os: windows-2019
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import '../../../domain/source/source_model.dart';
part 'source_manga_controller.g.dart';

@riverpod
Future<Source?> source(SourceRef ref, String sourceId) {
FutureOr<Source?> source(SourceRef ref, String sourceId) async {
final token = CancelToken();
ref.onDispose(token.cancel);
final result = ref
final result = await ref
.watch(sourceRepositoryProvider)
.getSource(sourceId: sourceId, cancelToken: token);
ref.keepAlive();
Expand All @@ -33,11 +33,12 @@ Future<Source?> source(SourceRef ref, String sourceId) {
Future<List<Filter>?> baseSourceMangaFilterList(
BaseSourceMangaFilterListRef ref,
String sourceId,
) {
) async {
final token = CancelToken();
ref.onDispose(token.cancel);
final result =
ref.watch(sourceRepositoryProvider).getFilterList(sourceId: sourceId);
final result = await ref
.watch(sourceRepositoryProvider)
.getFilterList(sourceId: sourceId);
ref.keepAlive();
return result;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MangaChapterList extends _$MangaChapterList {
}

@riverpod
List<Chapter>? mangaChapterListWithFilter(
AsyncValue<List<Chapter>?> mangaChapterListWithFilter(
MangaChapterListWithFilterRef ref, {
required String mangaId,
}) {
Expand Down Expand Up @@ -130,8 +130,32 @@ List<Chapter>? mangaChapterListWithFilter(
}
}

return chapterList.valueOrNull?.where(applyChapterFilter).toList()
?..sort(applyChapterSort);
return chapterList.copyWithData(
(data) => [...?data?.where(applyChapterFilter)]..sort(applyChapterSort),
);
}

@riverpod
Chapter? firstUnreadInFilteredChapterList(
FirstUnreadInFilteredChapterListRef ref, {
required String mangaId,
}) {
final isAscSorted = ref.watch(mangaChapterSortDirectionProvider) ??
DBKeys.chapterSortDirection.initial;
final filteredList = ref
.watch(mangaChapterListWithFilterProvider(mangaId: mangaId))
.valueOrNull;
if (filteredList == null) {
return null;
} else {
if (isAscSorted) {
return filteredList
.firstWhereOrNull((element) => !element.read.ifNull(true));
} else {
return filteredList
.lastWhereOrNull((element) => !element.read.ifNull(true));
}
}
}

@riverpod
Expand All @@ -140,18 +164,26 @@ Pair<Chapter?, Chapter?>? getPreviousAndNextChapters(
required String mangaId,
required String chapterIndex,
}) {
final filteredList =
ref.watch(mangaChapterListWithFilterProvider(mangaId: mangaId));
if (filteredList == null) return null;
final currentChapterIndex =
filteredList.indexWhere((element) => "${element.index}" == chapterIndex);
return Pair(
first:
currentChapterIndex > 0 ? filteredList[currentChapterIndex - 1] : null,
second: currentChapterIndex < (filteredList.length - 1)
final isAscSorted = ref.watch(mangaChapterSortDirectionProvider) ??
DBKeys.chapterSortDirection.initial;
final filteredList = ref
.watch(mangaChapterListWithFilterProvider(mangaId: mangaId))
.valueOrNull;
if (filteredList == null) {
return null;
} else {
final currentChapterIndex = filteredList
.indexWhere((element) => "${element.index}" == chapterIndex);
final prevChapter =
currentChapterIndex > 0 ? filteredList[currentChapterIndex - 1] : null;
final nextChapter = currentChapterIndex < (filteredList.length - 1)
? filteredList[currentChapterIndex + 1]
: null,
);
: null;
return Pair(
first: isAscSorted ? nextChapter : prevChapter,
second: isAscSorted ? prevChapter : nextChapter,
);
}
}

@riverpod
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ class MangaDetailsScreen extends HookConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final provider = mangaWithIdProvider(mangaId: mangaId);
final chapterListProvider = mangaChapterListProvider(mangaId: mangaId);
final provider = useMemoized(() => mangaWithIdProvider(mangaId: mangaId));
final chapterListProvider = useMemoized(
() => mangaChapterListProvider(mangaId: mangaId),
);
final manga = ref.watch(provider);
final chapterList = ref.watch(chapterListProvider);
final filteredChapterList =
ref.watch(mangaChapterListWithFilterProvider(mangaId: mangaId));

final firstUnreadChapter = ref.watch(
firstUnreadInFilteredChapterListProvider(mangaId: mangaId),
);

final selectedChapters = useState<Map<int, Chapter>>({});
refresh([onlineFetch = false]) async {
final refresh = useCallback(([onlineFetch = false]) async {
if (context.mounted && onlineFetch) {
ref.read(toastProvider(context)).show(
LocaleKeys.updating.tr(),
Expand All @@ -50,10 +58,10 @@ class MangaDetailsScreen extends HookConsumerWidget {
withMicrotask: true,
);
}
}
}, []);

useEffect(() {
if (!chapterList.isLoading && !manga.isLoading) refresh();
if (!filteredChapterList.isLoading && !manga.isLoading) refresh();
return;
}, []);

Expand All @@ -75,10 +83,14 @@ class MangaDetailsScreen extends HookConsumerWidget {
onPressed: () {
selectedChapters.value = {
for (Chapter i in [
...?ref.read(mangaChapterListWithFilterProvider(
mangaId: mangaId))
...?ref
.read(
mangaChapterListWithFilterProvider(
mangaId: mangaId),
)
.valueOrNull
])
i.id ?? -1: i
if (i.id != null) i.id!: i
};
},
icon: const Icon(Icons.select_all_rounded),
Expand All @@ -87,12 +99,15 @@ class MangaDetailsScreen extends HookConsumerWidget {
onPressed: () {
final newMap = {
for (Chapter i in [
...?ref.read(mangaChapterListWithFilterProvider(
mangaId: mangaId))
...?ref
.read(mangaChapterListWithFilterProvider(
mangaId: mangaId))
.valueOrNull
])
i.id ?? -1: i
}..removeWhere((key, value) =>
selectedChapters.value.containsKey(key));
if (i.id != null &&
!selectedChapters.value.containsKey(key))
i.id!: i
};
selectedChapters.value = newMap;
},
icon: const Icon(Icons.flip_to_back_rounded),
Expand Down Expand Up @@ -162,32 +177,36 @@ class MangaDetailsScreen extends HookConsumerWidget {
selectedChapters: selectedChapters,
)
: null,
floatingActionButton: FloatingActionButton.extended(
isExtended: context.isTablet,
label: Text(
data?.lastChapterRead?.index != null
? LocaleKeys.resume.tr()
: LocaleKeys.start.tr(),
),
icon: const Icon(Icons.play_arrow_rounded),
onPressed: () {
context.push(
Routes.getReader(
"${data?.id}", "${data?.lastChapterRead?.index ?? 1}"),
);
},
),
floatingActionButton: firstUnreadChapter != null
? FloatingActionButton.extended(
isExtended: context.isTablet,
label: Text(
data?.lastChapterRead?.index != null
? LocaleKeys.resume.tr()
: LocaleKeys.start.tr(),
),
icon: const Icon(Icons.play_arrow_rounded),
onPressed: () {
context.push(
Routes.getReader(
"${firstUnreadChapter.mangaId ?? mangaId}",
"${firstUnreadChapter.index ?? 0}",
),
);
},
)
: null,
body: data != null
? context.isTablet
? BigScreenMangaDetails(
chapterList: chapterList,
chapterList: filteredChapterList,
manga: data,
mangaId: mangaId,
onRefresh: refresh,
selectedChapters: selectedChapters,
)
: SmallScreenMangaDetails(
chapterList: chapterList,
chapterList: filteredChapterList,
manga: data,
mangaId: mangaId,
onRefresh: refresh,
Expand Down
Loading

0 comments on commit 76e1e9b

Please sign in to comment.