Skip to content

Conversation

NBA2K1
Copy link
Contributor

@NBA2K1 NBA2K1 commented Apr 24, 2025

This PR refactors code for better maintainability, fixes bugs in AniList and MyAnimeList integrations, adds a local folder scanning feature (#148), and enhances the library search (#349).

Changes

Refactoring & Code Quality

  • manga_reader_provider.dart, reader_view.dart:
    • Simplified widget code by reducing logic in build method.
    • Centralized async data-fetching logic for consistency.
    • Introduced ChapterWithPages to group chapters and pages.
    • Added scaffoldWith helper to reduce code duplication.
  • AniList, MyAnimeList, Kitsu:
    • Eliminated code duplication across tracking services.
  • m_bridge.dart:
    • Removed redundant code for cleaner implementation.
  • appearance_screen.dart:
    • Introduced SettingsSection class to reduce code duplication.
    • Extracted ListTile+Dialog blocks into private methods:
      • _buildLanguageTile
      • _buildFontTile
      • _buildRelativeTimestampTile
      • _buildDateFormatTile
  • custom_navigation_settings.dart:
    • Removed unnecessary SingleChildScrollView as ReorderableListView is scrollable.

Bug Fixes

  • AniList:
    • Fixed bug where newly added anime were marked as "Rewatching" instead of "Plan to Watch".
  • MyAnimeList (myanimelist/model.dart):
    • Removed incorrect expiresIn calculation in OAuth.fromJson. The login function already sets expiresIn as a millisecond timestamp. Previous logic inflated expiresIn, causing _getAccessToken to skip token refresh, leading to invalid token errors.
  • appearance_screen.dart:
    • Ensured FollowSystemThemeButton always appears in the first position, regardless of ON/OFF state (previously swapped with DarkModeButton when OFF).

New Features

  • file_scanner.dart:
    • Added provider to scan a user-created Mangayomi/local folder for manga/anime on app start.
    • Supported file types:
    Videotypes:   mp4, mov, avi, flv, wmv, mpeg, mkv
    Imagetypes:   jpg, jpeg, png, webp
    Archivetypes: cbz, zip, cbt, tar
  • library_screen.dart:
  • Added ignoreFiltersOnSearch checkbox to search the entire library, not just filtered categories (Downloaded, Unwatched/Unread, Started, Bookmarked).

Performance Improvements

  • m_client.dart:
  • Optimized getCookiesPref and deleteAllCookies by caching Uri.parse(url).host.
  • Cached RhttpCompatibleClients in httpClient with IOClient fallback.
  • Added delay in shouldAttemptRetryOnResponse to prevent busy looping.

Related Issues

NBA2K1 added 7 commits April 23, 2025 00:11
- Add `ChapterWithPages` model and `MangaReaderController` (FamilyAsyncNotifier)
  to load chapter + pages in a single provider (`mangaReaderProvider`)
- Replace synchronous Isar fetch in `MangaReaderView` with `ref.watch(mangaReaderProvider)`
- Unify loading, error, and data states using a shared `scaffoldWith` helper
- Remove duplicated `Scaffold`/`AppBar` boilerplate and inline SystemChrome restore logic
- Simplify error handling
Fixed a bug, where newly added animes to AniList would register as "Rewatching" instead of "Plan to watch".
- getCookiesPref() and deleteAllCookies():
Avoid repeated parsing of `Uri.parse(url).host` by creating a variable.

- httpClient():
cache RhttpCompatibleClients and add default IOClient fallback.

- shouldAttemptRetryOnResponse():
Added a delay to avoid busy looping.
Remove code duplication.
Added a checkbox "ignoreFiltersOnSearch" to the library search, so when checked, the whole library will be searched, not just the filtered library (Downloaded, Unwatched/Unread, Started, Bookmarked)

+ added some comments
@NBA2K1 NBA2K1 changed the title DRYing the code + AniList "Rewatching" bug fix DRYing the code + AniList "Rewatching" bug fix + #349 fix Apr 26, 2025
NBA2K1 added 7 commits April 27, 2025 03:15
Better text rendering of "ignore filters" checkbox on mobile.
Adds a line break to mobile devices, where horizontal space is limited.
remove code duplication by introducing a helper method _genericRoute().
Show the FollowSystemThemeButton always on first positon, whether ON or OFF.

Before, the FollowSystemThemeButton was on first position if it was ON and in second position if it was OFF (DarkModeButton took the first position)
- New SettingsSection class to remove code duplication

- Moved the big ListTile+Dialog blocks in their own private methods:
_buildLanguageTile(),
_buildFontTile(),
_buildRelativeTimestampTile(),
_buildDateFormatTile()
No need for SingleChildScrollView, because ReorderableListView already is scrollable
NBA2K1 added 5 commits April 29, 2025 18:18
Move the getDirectory() call out of the for loop to enhance performance.
getMangaChapterDirectory() now accepts an optional mangaMainDirectory
to avoid calling getMangaMainDirectory() and thus getDirectory() twice in places where both methods are called successively.
trim whitespace to prevent Exception
Users can now add Mangas/Animes to a **manually** created Mangayomi/local folder.
Feature as described:
```
App Home Location/
  local/
    Manga Title/
      cover.jpg (optional)
      Chapter 1/
        1.jpg
        ...
      Chapter 2.cbz
      ...
    Anime Title/
      cover.png (optional)
      Episode 1.mp4
      Episode 2.mkv
```

The folder (if exist) will be scanned once per app start.

**Supported filetypes:** (taken from lib/modules/library/providers/local_archive.dart, line 98)
```
Videotypes:   mp4, mov, avi, flv, wmv, mpeg, mkv
Imagetypes:   jpg, jpeg, png, webp
Archivetypes: cbz, zip, cbt, tar
```
@NBA2K1 NBA2K1 changed the title DRYing the code + AniList "Rewatching" bug fix + #349 fix DRYing the code + AniList "Rewatching" bug fix + #349 fix + Feature #148 May 2, 2025
Remove incorrect expiresIn calculation in `OAuth.fromJson`. The `login()`
function of the MyAnimeList class already sets expiresIn as an absolute timestamp in milliseconds.
Multiplying by 1000 and adding the current timestamp in fromJson caused
expiresIn to be inflated, making the expiration check in `_getAccessToken()`
always false, skipping token refresh and returning an invalid token.
@NBA2K1 NBA2K1 changed the title DRYing the code + AniList "Rewatching" bug fix + #349 fix + Feature #148 Refactor code, fix AniList/MAL bugs, add local scan (#148, #349) May 4, 2025
@NBA2K1
Copy link
Contributor Author

NBA2K1 commented May 4, 2025

Before the MyAnimeList expiresIn fix:

MAL expiresIn value

The token expiry is in the year 57,349 LOL

- Resolved the same timestamp conversion issue that affected MyAnimeList.
- Previously, seconds-to-milliseconds conversion and `DateTime.now()` were applied twice — once on `login()` and once in `_getAccessToken()` — resulting in incorrect expiry dates (e.g., year 57349).
- Updated Kitsu’s URL from `.io` to `.app`.
@kodjodevf kodjodevf merged commit e46975e into kodjodevf:main May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search of library only searches on the filtered elements Local manga entries as folders
2 participants