Skip to content
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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

mooninbeom
Copy link
Collaborator

변경 사항

  • 모아보기 기능 구현
  • Comment, Highlight Annotation 추가 방식 수정(Annotation의 Contents 활용)
  • AnnotationCollection 엔티티 추가

스크린샷 or 영상 링크

스크린샷 2025-02-01 오후 6 53 53 스크린샷 2025-02-01 오후 6 54 01

팀원에게 전달할 사항(Optional)

  • 기존 Annotation의 프로퍼티를 활용해 CoreData을 사용하지 않고 구현을 해보았습니다.
  • 다만 기존에 되어 있는 Annotation(Highlight, Comment)의 경우에는 프로퍼티 수정이 어려워 해당 업데이트를 통해 새롭게 적용되는 Annotation에서 부터 지원이 됩니다!

close #459

@mooninbeom mooninbeom added Feature 기능의 추가가 필요할 때 PR-NeedReview 작업이 완료되고 리뷰가 필요한 PR labels Feb 1, 2025
@mooninbeom mooninbeom self-assigned this Feb 1, 2025
Comment on lines +11 to +23
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
}
}
Copy link
Collaborator Author

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")
Copy link
Collaborator Author

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)"
Copy link
Collaborator Author

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])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NotificationCenter를 통해 PDFView에게 액션을 전달합니다.
해당 페이지로 이동

Comment on lines +24 to +68
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 = ""
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 PDFDocument의 모든 PDFPage를 순회하여 필요한 PDFAnnotation들의 정보를 갖고와 필터링 한 후 Entity로 변환하여 저장합니다.

Comment on lines +519 to +525
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
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment에 사용되는 Underline annotation에 정보를 저장합니다.

Copy link
Collaborator

@Dorii0513 Dorii0513 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 해보는데 코멘트 주석이 두번씩 저장되는 것 같아요!
보니까 주석 자체도 두번씩 덧 그려지고 있어요
스크린샷 2025-02-02 오후 3 24 01

그리고 코멘트 삭제 / 수정 창의 위치도 이상한 곳에 뜨네요
스크린샷 2025-02-02 오후 3 24 33

setValue 값이 바뀌어서 적용이 안된 부분이 있나봅니다 !
이따 알바 갔다와서 저도 함 확인해 볼게용
(아직 시간 있으깐 일단 여행을 잘 즐기시죠 !!!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature 기능의 추가가 필요할 때 PR-NeedReview 작업이 완료되고 리뷰가 필요한 PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feat] 모아보기 기능 구현
2 participants