212 lines
8.7 KiB
Objective-C
212 lines
8.7 KiB
Objective-C
//
|
|
// WRReaderViewController.h
|
|
// WeRead (读书)
|
|
//
|
|
// Reverse-engineered header reconstruction.
|
|
// Main reader controller. Manages reading state, progress saving,
|
|
// chapter jumping, page rendering lifecycle, and the typesetter.
|
|
// 431 methods total — this header exposes the key public interface.
|
|
//
|
|
|
|
#import <UIKit/UIKit.h>
|
|
#import "WRPageViewController.h"
|
|
|
|
@class WRBook;
|
|
@class WRChapterData;
|
|
@class WRChapterPageCount;
|
|
@class WRPageView;
|
|
@class WRReadingProgress;
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
// ============================================================================
|
|
#pragma mark - Reading Progress Data
|
|
// ============================================================================
|
|
|
|
/// Encapsulates the current reading position.
|
|
@interface WRReadingProgress : NSObject
|
|
|
|
@property (nonatomic, copy, nullable) NSString *bookId;
|
|
@property (nonatomic, assign) NSUInteger chapterIndex; // Current chapter (0-based).
|
|
@property (nonatomic, assign) NSUInteger pageIndex; // Page within chapter (0-based).
|
|
@property (nonatomic, assign) NSUInteger charIndex; // Character offset within chapter.
|
|
@property (nonatomic, assign) CGFloat scrollOffset; // For scroll-based reading.
|
|
@property (nonatomic, copy, nullable) NSString *chapterId;
|
|
@property (nonatomic, assign) double readPercentage; // 0.0 .. 1.0.
|
|
|
|
@end
|
|
|
|
// ============================================================================
|
|
#pragma mark - WRReaderViewControllerDelegate
|
|
// ============================================================================
|
|
|
|
@protocol WRReaderViewControllerDelegate <NSObject>
|
|
@optional
|
|
|
|
/// Called when the reading progress changes (page flip, chapter jump).
|
|
- (void)readerViewController:(WRReaderViewController *)readerVC
|
|
didUpdateProgress:(WRReadingProgress *)progress;
|
|
|
|
/// Called when the reader needs to present a modal (e.g., settings, TOC).
|
|
- (void)readerViewController:(WRReaderViewController *)readerVC
|
|
presentViewController:(UIViewController *)viewController
|
|
animated:(BOOL)animated
|
|
completion:(void (^ __nullable)(void))completion;
|
|
|
|
/// Called when the reader exits.
|
|
- (void)readerViewControllerDidClose:(WRReaderViewController *)readerVC;
|
|
|
|
@end
|
|
|
|
// ============================================================================
|
|
#pragma mark - WRReaderViewController
|
|
// ============================================================================
|
|
|
|
@interface WRReaderViewController : UIViewController <WRPageViewControllerDelegate>
|
|
|
|
// ---- Delegate ----
|
|
@property (nonatomic, weak, nullable) id<WRReaderViewControllerDelegate> readerDelegate;
|
|
|
|
// ---- Book & Progress ----
|
|
/// The book being read.
|
|
@property (nonatomic, strong, readonly, nullable) WRBook *book;
|
|
|
|
/// The book identifier (convenience accessor).
|
|
@property (nonatomic, copy, readonly, nullable) NSString *bookId;
|
|
|
|
/// Current reading progress.
|
|
@property (nonatomic, strong, nullable) WRReadingProgress *readingProgress;
|
|
|
|
// ---- Chapter State ----
|
|
/// The chapter data for the currently loaded chapter.
|
|
@property (nonatomic, strong, nullable) WRChapterData *currentChapterData;
|
|
|
|
/// The page count calculator for the current chapter.
|
|
@property (nonatomic, strong, nullable) WRChapterPageCount *currentChapterPageCount;
|
|
|
|
/// The total number of chapters in the book.
|
|
@property (nonatomic, assign, readonly) NSUInteger totalChapters;
|
|
|
|
// ---- Reader Mode ----
|
|
/// Whether the reader is in doodle/drawing mode (for handwritten notes).
|
|
@property (nonatomic, assign, readonly) BOOL doodleMode;
|
|
|
|
/// Whether auto-read is active.
|
|
@property (nonatomic, assign, readonly) BOOL autoReadEnabled;
|
|
|
|
// ---- Typesetter ----
|
|
/// Whether the typesetter is currently recomposing (re-layout).
|
|
@property (nonatomic, assign, readonly) BOOL isRecomposing;
|
|
|
|
// ============================================================================
|
|
#pragma mark - Initialization
|
|
// ============================================================================
|
|
|
|
/// Full initialization with all options.
|
|
/// @param book The book model object.
|
|
/// @param progress Initial reading progress.
|
|
/// @param forceUseInitialProgress If YES, ignore any saved progress and use the given one.
|
|
/// @param doodleMode Start in doodle mode.
|
|
/// @param autoRead Start with auto-read enabled.
|
|
- (instancetype)initWithBook:(WRBook *)book
|
|
progress:(WRReadingProgress * __nullable)progress
|
|
forceUseInitialProgress:(BOOL)forceUseInitialProgress
|
|
doodleMode:(BOOL)doodleMode
|
|
autoRead:(BOOL)autoRead;
|
|
|
|
/// Convenience init with just a book ID (loads book data from cache/server).
|
|
- (instancetype)initWithBookId:(NSString *)bookId;
|
|
|
|
// ============================================================================
|
|
#pragma mark - Lifecycle
|
|
// ============================================================================
|
|
|
|
- (void)viewDidLoad;
|
|
|
|
// ============================================================================
|
|
#pragma mark - Page Rendering
|
|
// ============================================================================
|
|
|
|
/// Renders the page view for the given progress data. This is the main
|
|
/// entry point for displaying a page:
|
|
/// 1. Retrieves or computes the chapter data.
|
|
/// 2. Computes pagination for the current page size and typesetter settings.
|
|
/// 3. Creates/updates the WRPageView with the layout frame for the page range.
|
|
/// 4. Updates the page view controller's child.
|
|
///
|
|
/// @param pageView The page view to render into.
|
|
/// @param progressData The reading progress (chapter + page index).
|
|
/// @param source A string identifying the caller (for logging).
|
|
- (void)renderPageView:(WRPageView *)pageView
|
|
progressData:(WRReadingProgress *)progressData
|
|
source:(NSString *)source;
|
|
|
|
/// Recomposes (re-typesets) the current page view.
|
|
/// Called after font size, line spacing, or theme changes.
|
|
/// @param source A string identifying the caller.
|
|
- (void)recomposeCurrentPageViewWithSource:(NSString *)source;
|
|
|
|
/// Reloads all page views with new progress data.
|
|
/// Called after a full chapter change or settings change.
|
|
/// @param progressData The new reading progress.
|
|
/// @param source A string identifying the caller.
|
|
- (void)reloadPageViewsWithProgressData:(WRReadingProgress *)progressData
|
|
source:(NSString *)source;
|
|
|
|
// ============================================================================
|
|
#pragma mark - Chapter Navigation
|
|
// ============================================================================
|
|
|
|
/// Jumps to a specific chapter and position.
|
|
/// @param chapterIdx The chapter index (0-based).
|
|
/// @param position The page index within the chapter.
|
|
/// @param positionOfFile The character offset within the chapter (for precise positioning).
|
|
- (void)gotoChapterIdx:(NSUInteger)chapterIdx
|
|
position:(NSUInteger)position
|
|
positionOfFile:(NSUInteger)positionOfFile;
|
|
|
|
/// Advances to the next chapter. Resets page index to 0.
|
|
- (void)jumpReadingToNextChapter;
|
|
|
|
/// Goes back to the previous chapter. Sets page index to the last page.
|
|
- (void)jumpReadingToPreChapter;
|
|
|
|
// ============================================================================
|
|
#pragma mark - Page Flip Callback
|
|
// ============================================================================
|
|
|
|
/// Called by WRPageViewController when a page flip completes.
|
|
/// Updates progress, saves state, and triggers prefetching of adjacent chapters.
|
|
- (void)didFlipPage;
|
|
|
|
// ============================================================================
|
|
#pragma mark - Progress Persistence
|
|
// ============================================================================
|
|
|
|
/// Saves the current reading progress.
|
|
/// @param isAsync If YES, save asynchronously (non-blocking). If NO, save synchronously.
|
|
- (void)_saveReadingProgressAndIsAsync:(BOOL)isAsync;
|
|
|
|
// ============================================================================
|
|
#pragma mark - Typesetter
|
|
// ============================================================================
|
|
|
|
/// Modifies the typesetter attributes (font, size, spacing, etc.) and
|
|
/// triggers a full re-typeset.
|
|
/// @param block A block that receives a mutable dictionary of typesetter
|
|
/// attributes and modifies them in place.
|
|
- (void)changeTypesetterAttributesWithBlock:(void (^ __nonnull)(NSMutableDictionary *attrs))block;
|
|
|
|
// ============================================================================
|
|
#pragma mark - Pagination
|
|
// ============================================================================
|
|
|
|
/// Initializes or re-initializes the chapter page count calculator.
|
|
/// Called when the chapter changes, the view size changes, or typesetter
|
|
/// settings change.
|
|
- (void)initChapterPageCount;
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|