-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] 모아보기 기능 구현 #460
base: develop
Are you sure you want to change the base?
[Feat] 모아보기 기능 구현 #460
Conversation
struct AnnotationCollection: Identifiable, Equatable { | ||
let id: String | ||
|
||
let annotation: AnnotationCase | ||
let commenText: String? | ||
let contents: AttributedString | ||
let pageIndex: Int | ||
|
||
enum AnnotationCase: Equatable { | ||
case highlight | ||
case comment | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모아보기 뷰에서 사용되는 Entity 입니다
@@ -18,4 +18,5 @@ extension Notification.Name { | |||
static let isFigureCaptured = Notification.Name("isFigureCaptured") | |||
static let isCollectionCaptured = Notification.Name("isCollectionCaptured") | |||
static let changeHomePaperInfo = Notification.Name("changeHomePaperInfo") | |||
static let didSelectAnnotationCollection = Notification.Name("didSelectAnnotationCollection") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PDFView로 Action을 전달하기 위한 Notification 입니다
@@ -236,7 +237,8 @@ extension MainPDFViewModel { | |||
let highlight = PDFAnnotation(bounds: bounds, forType: .highlight, withProperties: nil) | |||
highlight.endLineStyle = .none | |||
highlight.color = highlightColor | |||
|
|||
highlight.contents = "UH|\(selection.string ?? "nil")|\(color.rawValue)|\(id)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모아보기에 필요한 정보들(하이라이트 or 코멘트 인지, 선택된 영역의 String, 사용된 color, id값)을
PDFAnnotation 프로퍼티에 저장합니다.
.lineLimit(9) | ||
} | ||
.onTapGesture { | ||
NotificationCenter.default.post(name: .didSelectAnnotationCollection, object: nil, userInfo: ["index": annotation.pageIndex]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NotificationCenter를 통해 PDFView에게 액션을 전달합니다.
해당 페이지로 이동
for i in 0 ..< pageCount { | ||
guard let page = document.page(at: i) else { continue } | ||
|
||
page.annotations.forEach { annotation in | ||
switch annotation.markupType { | ||
case .highlight: | ||
if let contents = annotation.contents { | ||
if contents.split(separator: "|")[0] == "UH" || contents.split(separator: "|")[0] == "UC" { | ||
let id = contents.split(separator: "|").last! | ||
|
||
if id != currentId { | ||
if !resultText.isEmpty { | ||
extractAnnotation( | ||
contents: currentContents, | ||
body: resultText.replacingOccurrences(of: "\n", with: " "), | ||
index: i | ||
) | ||
resultText = "" | ||
} | ||
|
||
currentId = String(id) | ||
currentContents = contents | ||
} | ||
|
||
let text = annotation.contents!.split(separator: "|")[1] | ||
if text == " " { return } | ||
|
||
resultText += text | ||
} | ||
} | ||
|
||
default: | ||
break | ||
} | ||
} | ||
|
||
if !resultText.isEmpty { | ||
extractAnnotation( | ||
contents: currentContents, | ||
body: resultText.replacingOccurrences(of: "\n", with: " "), | ||
index: i | ||
) | ||
resultText = "" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 PDFDocument의 모든 PDFPage를 순회하여 필요한 PDFAnnotation들의 정보를 갖고와 필터링 한 후 Entity로 변환하여 저장합니다.
if textInputed { | ||
underline.setValue("UC| |" + newComment.id.uuidString, forAnnotationKey: .contents) | ||
} else { | ||
let text = "UC|\(newComment.selectedText)|\(newComment.text)|\(newComment.id.uuidString)" | ||
underline.contents = text | ||
textInputed = true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment에 사용되는 Underline annotation에 정보를 저장합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
변경 사항
AnnotationCollection
엔티티 추가스크린샷 or 영상 링크
팀원에게 전달할 사항(Optional)
close #459