Skip to content

Refactor#21

Merged
Aatricks merged 4 commits intomainfrom
Refactor
Jan 12, 2026
Merged

Refactor#21
Aatricks merged 4 commits intomainfrom
Refactor

Conversation

@Aatricks
Copy link
Owner

This pull request introduces significant improvements to error handling, code structure, and content parsing logic across the application. The most notable changes include a comprehensive refactor of the HTML parsing logic for better manga/novel detection, systematic replacement of try/catch blocks with Kotlin’s runCatching for more concise error handling, and modularization of utility functions for improved readability and maintainability.

Error Handling Improvements:

  • Replaced traditional try/catch blocks with runCatching in repository methods and throughout MainActivity, leading to more concise and idiomatic Kotlin error handling. (BaseRepository.kt, MainActivity.kt, ExploreRepository.kt, LibraryRepository.kt) [1] [2] [3] [4]

HTML Parsing and Content Extraction Enhancements:

  • Refactored HtmlParser to modularize and clarify the logic for cleaning documents, parsing images and paragraphs, filtering out ads and irrelevant content, and merging paragraphs. Improved manga/novel detection logic to better distinguish between image-heavy and text-heavy content. (HtmlParser.kt) [1] [2]
  • Added helper functions for merging paragraphs and determining when to merge or stop merging based on sentence structure. (HtmlParser.kt)

Code Structure and Readability:

  • Extracted repeated logic into private helper functions (e.g., filterSources, mapFileTypeToContentType, buildMemoryCache, buildDiskCache) for improved maintainability. (ExploreRepository.kt, MainActivity.kt, EasyReaderApplication.kt) [1] [2] [3]
  • Updated method signatures to explicitly declare Unit return types for clarity and consistency. (MainActivity.kt, LibraryRepository.kt) [1] [2]

Image Loader Configuration:

  • Modularized the image loader setup in EasyReaderApplication by moving cache configuration into dedicated helper methods, improving clarity and flexibility. (EasyReaderApplication.kt)

Permissions and File Handling:

  • Streamlined file permission checks and file type handling in MainActivity, using helper methods and more robust logic for determining permissions and supported file types. (MainActivity.kt)

These changes collectively improve the app’s robustness, readability, and maintainability, while also enhancing its ability to accurately parse and display both manga and novel content.

…ance

- Simplified getFileName method by extracting content query logic into a separate function.
- Enhanced error handling using runCatching for safer resource management.
- Streamlined getFileSize and getInputStream methods.
- Optimized text processing in TextUtils by consolidating regex patterns and improving whitespace handling.
- Refactored chapter title extraction and cleaning logic for better clarity and maintainability.
- Improved paragraph formatting and merging logic to handle edge cases more effectively.
@Aatricks Aatricks self-assigned this Jan 12, 2026
@Aatricks Aatricks merged commit b5b7154 into main Jan 12, 2026
1 check passed
@Aatricks Aatricks deleted the Refactor branch January 12, 2026 19:39
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.

1 participant