ReadViewSDK/Doc/WXRead/decompiled/WRPageHighlight.m

106 lines
3.5 KiB
Objective-C

//
// WRPageHighlight.m
// WeRead (读书)
// Reverse-engineered implementation reconstruction
//
// 3 methods identified from binary. WRPageHighlight is a lightweight
// model for text highlights on a page.
//
#import "WRPageHighlight.h"
#import "WRBookmark.h"
// ---------------------------------------------------------------------------
// Color utility
// ---------------------------------------------------------------------------
static UIColor *UIColorForHighlightColor(WRHighlightColor color)
{
switch (color) {
case WRHighlightColorYellow:
return [UIColor colorWithRed:1.0 green:0.92 blue:0.23 alpha:0.35];
case WRHighlightColorBlue:
return [UIColor colorWithRed:0.26 green:0.65 blue:0.96 alpha:0.35];
case WRHighlightColorRed:
return [UIColor colorWithRed:0.96 green:0.26 blue:0.26 alpha:0.35];
case WRHighlightColorGreen:
return [UIColor colorWithRed:0.30 green:0.85 blue:0.39 alpha:0.35];
case WRHighlightColorPurple:
return [UIColor colorWithRed:0.67 green:0.33 blue:0.97 alpha:0.35];
default:
return [UIColor colorWithRed:1.0 green:0.92 blue:0.23 alpha:0.35];
}
}
static NSString *NSStringFromHighlightColor(WRHighlightColor color)
{
switch (color) {
case WRHighlightColorYellow: return @"yellow";
case WRHighlightColorBlue: return @"blue";
case WRHighlightColorRed: return @"red";
case WRHighlightColorGreen: return @"green";
case WRHighlightColorPurple: return @"purple";
default: return @"yellow";
}
}
#pragma mark - Implementation
@implementation WRPageHighlight
- (instancetype)initWithBookId:(NSString *)bookId
chapterUid:(NSString *)chapterUid
startPos:(NSInteger)startPos
endPos:(NSInteger)endPos
text:(NSString *)text
color:(WRHighlightColor)color
{
self = [super init];
if (self) {
_highlightId = [[NSUUID UUID] UUIDString];
_bookId = [bookId copy];
_chapterUid = [chapterUid copy];
_startPos = startPos;
_endPos = endPos;
_chapterOffset = startPos; // Simplified; real impl maps global->local
_markedText = [text copy];
_color = color;
_colorStyle = NSStringFromHighlightColor(color);
_createTime = [[NSDate date] timeIntervalSince1970];
_isSynced = NO;
}
return self;
}
- (WRBookmark *)toBookmark
{
WRBookmark *bookmark = [WRBookmark highlightWithBookId:_bookId
chapterUid:_chapterUid
startPos:_startPos
endPos:_endPos
text:_markedText
colorStyle:_colorStyle];
bookmark.bookmarkId = _highlightId;
bookmark.chapterOffset = _chapterOffset;
bookmark.pageIndex = _pageIndex;
bookmark.createTime = _createTime;
bookmark.isSynced = _isSynced;
return bookmark;
}
- (UIColor *)uiColor
{
return UIColorForHighlightColor(_color);
}
#pragma mark - NSObject
- (NSString *)description
{
return [NSString stringWithFormat:@"<WRPageHighlight: %@ [%@] '%@'>",
_highlightId, _colorStyle,
[_markedText substringToIndex:MIN(40, _markedText.length)]];
}
@end