159 lines
6.4 KiB
Objective-C
159 lines
6.4 KiB
Objective-C
//
|
|
// WRReaderPencilNoteManager.h
|
|
// WeRead (读书)
|
|
// Reverse-engineered header
|
|
//
|
|
// Apple Pencil note manager. 11 class methods identified from binary.
|
|
// Stores drawings locally, uploads to Tencent Cloud COS.
|
|
// Supports draft and published states for pencil annotations.
|
|
//
|
|
|
|
#import <Foundation/Foundation.h>
|
|
#import <UIKit/UIKit.h>
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Pencil drawing color styles
|
|
// ---------------------------------------------------------------------------
|
|
typedef NS_ENUM(NSInteger, WRPencilColorStyle) {
|
|
WRPencilColorStyleBlack = 0,
|
|
WRPencilColorStyleGray = 1,
|
|
WRPencilColorStyleRed = 2,
|
|
WRPencilColorStyleBlue = 3,
|
|
WRPencilColorStyleYellow = 4,
|
|
WRPencilColorStyleGreen = 5,
|
|
WRPencilColorStylePencil = 6, // Natural pencil
|
|
WRPencilColorStylePen = 7, // Pen/fountain
|
|
WRPencilColorStyleMarker = 8, // Highlighter marker
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Upload callback
|
|
// ---------------------------------------------------------------------------
|
|
typedef void (^WRPencilUploadCallback)(BOOL success,
|
|
NSString * _Nullable imageUrl,
|
|
NSString * _Nullable drawingUrl,
|
|
NSError * _Nullable error);
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Download callback
|
|
// ---------------------------------------------------------------------------
|
|
typedef void (^WRPencilDownloadCallback)(BOOL success,
|
|
NSData * _Nullable drawingData,
|
|
NSError * _Nullable error);
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// WRReaderPencilNoteManager
|
|
// ---------------------------------------------------------------------------
|
|
@interface WRReaderPencilNoteManager : NSObject
|
|
|
|
#pragma mark - Drawing Existence Check
|
|
|
|
/// Check whether a pencil drawing exists locally for the given review item.
|
|
/// @param reviewItemId The review item identifier.
|
|
/// @param reviewId The review identifier.
|
|
/// @param isDraft YES to check for draft drawings, NO for published.
|
|
/// @return YES if the drawing file exists on disk.
|
|
+ (BOOL)checkDrawingExistsWithReviewItemId:(NSString *)reviewItemId
|
|
reviewId:(NSString *)reviewId
|
|
isDraft:(BOOL)isDraft;
|
|
|
|
#pragma mark - Delete Operations
|
|
|
|
/// Delete all locally stored review drawings.
|
|
+ (void)deleteAllReviewDrawings;
|
|
|
|
/// Delete a specific drawing.
|
|
/// @param reviewItemId The review item identifier.
|
|
/// @param reviewId The review identifier.
|
|
/// @param isDraft YES to delete the draft, NO for published.
|
|
+ (void)deleteDrawingWithReviewItemId:(NSString *)reviewItemId
|
|
reviewId:(NSString *)reviewId
|
|
isDraft:(BOOL)isDraft;
|
|
|
|
#pragma mark - Download
|
|
|
|
/// Download drawing data from Tencent Cloud COS.
|
|
/// @param cosUrl The COS URL for the drawing data.
|
|
/// @param destPath Local destination path.
|
|
/// @param callback Called with the downloaded data or error.
|
|
+ (void)downloadDrawingDataFromCosWithUrl:(NSString *)cosUrl
|
|
desPath:(NSString *)destPath
|
|
callback:(WRPencilDownloadCallback)callback;
|
|
|
|
#pragma mark - File Paths
|
|
|
|
/// Return the base directory for pencil drawing files.
|
|
+ (NSString *)drawingFileDirectory;
|
|
|
|
/// Return the file path for a specific drawing.
|
|
/// @param reviewItemId The review item identifier.
|
|
/// @param reviewId The review identifier.
|
|
/// @param isDraft YES for draft path, NO for published path.
|
|
+ (NSString *)drawingFilePathWithReviewItemId:(NSString *)reviewItemId
|
|
reviewId:(NSString *)reviewId
|
|
isDraft:(BOOL)isDraft;
|
|
|
|
/// Return the file path for a drawing's rendered image.
|
|
/// @param reviewItemId The review item identifier.
|
|
/// @param reviewId The review identifier.
|
|
+ (NSString *)imageFilePathWithReviewItemId:(NSString *)reviewItemId
|
|
reviewId:(NSString *)reviewId;
|
|
|
|
#pragma mark - Upload
|
|
|
|
/// Upload a pencil drawing image and data to Tencent Cloud COS.
|
|
/// @param drawing The rendered UIImage of the drawing.
|
|
/// @param colorStyle The color/style used for the drawing.
|
|
/// @param uploadImage YES to upload the image, NO for data only.
|
|
/// @param canRetry YES if the upload can be retried on failure.
|
|
+ (void)uploadPencilDrawing:(UIImage *)drawing
|
|
colorStyle:(WRPencilColorStyle)colorStyle
|
|
onlyUploadImage:(BOOL)uploadImage
|
|
canRetry:(BOOL)canRetry;
|
|
|
|
/// Upload pencil note raw data (PKDrawing serialized data).
|
|
/// @param noteData The serialized drawing data.
|
|
/// @param suffix File suffix/extension (e.g., "drawing", "png").
|
|
+ (void)uploadPencilNoteData:(NSData *)noteData
|
|
suffix:(NSString *)suffix;
|
|
|
|
#pragma mark - Local Storage
|
|
|
|
/// Write raw drawing data to local storage.
|
|
/// @param data The drawing data to write.
|
|
/// @param reviewItemId The review item identifier.
|
|
/// @param reviewId The review identifier.
|
|
/// @param isDraft YES for draft, NO for published.
|
|
+ (void)writeDrawingDataToLocal:(NSData *)data
|
|
reviewItemId:(NSString *)reviewItemId
|
|
reviewId:(NSString *)reviewId
|
|
isDraft:(BOOL)isDraft;
|
|
|
|
/// Write a rendered drawing image to local storage.
|
|
/// @param drawing The UIImage to write.
|
|
/// @param reviewItemId The review item identifier.
|
|
/// @param reviewId The review identifier.
|
|
/// @param isDraft YES for draft, NO for published.
|
|
+ (void)writeDrawingToLocal:(UIImage *)drawing
|
|
reviewItemId:(NSString *)reviewItemId
|
|
reviewId:(NSString *)reviewId
|
|
isDraft:(BOOL)isDraft;
|
|
|
|
#pragma mark - Additional Methods (Reconstructed)
|
|
|
|
/// Return the total size of all stored pencil drawings in bytes.
|
|
+ (NSUInteger)totalDrawingStorageSize;
|
|
|
|
/// Return a list of all locally stored drawing review item IDs.
|
|
+ (NSArray<NSString *> *)allStoredDrawingReviewItemIds;
|
|
|
|
/// Render a PKDrawing data to UIImage.
|
|
+ (nullable UIImage *)renderDrawingDataToImage:(NSData *)drawingData
|
|
scale:(CGFloat)scale;
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|