Преглед изворни кода

【注释回复】补充时间分组

tangchao пре 5 месеци
родитељ
комит
af479ab317

+ 12 - 0
PDF Office/PDF Master/Class/Home/Category/Date+KMExtensions.swift

@@ -44,6 +44,18 @@ extension Date {
         return result
     }
     
+    func isSameDay(other: Date?) -> Bool {
+        guard let theOtherDate = other else {
+            return false
+        }
+        let calendar = Calendar.current
+        let unit: Set<Calendar.Component> = [.day,.month,.year]
+        let otherComps = calendar.dateComponents(unit, from: theOtherDate)
+        let theCmps = calendar.dateComponents(unit, from: self)
+        
+        return (theCmps.year == otherComps.year) && (theCmps.month == otherComps.month) && (theCmps.day == otherComps.day)
+    }
+    
     // MARK: 日期对应当周的周几. 周一为开始, 周天为结束
     private func dayForWeekAtIndex() -> Int {
         let components = Calendar.current.dateComponents([.weekday], from: self)

+ 11 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/View/KMNoteReplyCellView.swift

@@ -8,7 +8,7 @@
 import Cocoa
 
 class KMNoteReplyCellView: NSTableCellView, NibLoadable {
-    @IBOutlet weak var backgroundBox: NSBox!
+    @IBOutlet weak var backgroundBox: KMBox!
     @IBOutlet weak var titleLabel: NSTextField!
     @IBOutlet weak var timeLabel: NSTextField!
     
@@ -32,6 +32,15 @@ class KMNoteReplyCellView: NSTableCellView, NibLoadable {
     override func awakeFromNib() {
         super.awakeFromNib()
         self.backgroundBox.borderWidth = 0
+        self.backgroundBox.moveCallback = { [weak self] enter, theBox in
+            if enter {
+                theBox.fillColor = NSColor(hex: "#467DDE").withAlphaComponent(0.2)
+                self?.moreBox.isHidden = false
+            } else {
+                theBox.fillColor = .clear
+                self?.moreBox.isHidden = true
+            }
+        }
 
         self.titleLabel.textColor = KMAppearance.Layout.h1Color()
         self.timeLabel.font = .SFProTextSemiboldFont(14)
@@ -43,6 +52,7 @@ class KMNoteReplyCellView: NSTableCellView, NibLoadable {
         self.contentLabel.font = .SFProTextRegularFont(14)
         self.contentLabel.textColor = KMAppearance.KM_757780_Color()
         
+        self.moreBox.isHidden = true
         self.moreBox.borderWidth = 0
         self.moreButton.stringValue = ""
         self.moreButton.target = self

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/View/KMNoteReplyCellView.xib

@@ -13,7 +13,7 @@
             <rect key="frame" x="0.0" y="0.0" width="248" height="70"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>
-                <box boxType="custom" cornerRadius="4" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="Gun-Jd-J23">
+                <box boxType="custom" cornerRadius="4" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="Gun-Jd-J23" customClass="KMBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                     <rect key="frame" x="16" y="0.0" width="220" height="66"/>
                     <view key="contentView" id="v5i-Rx-mrG">
                         <rect key="frame" x="1" y="1" width="218" height="64"/>

+ 21 - 18
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Note.swift

@@ -975,24 +975,35 @@ extension KMLeftSideViewController {
             let model = KMAnnotationListModel()
             var datas: [KMBotaAnnotationModel] = []
             var prePageIdx: Int = NSNotFound
+            var preDate: Date?
+            var secM: KMBotaAnnotationSectionModel?
             for anno in allAnnotation {
-//                if self.noteSortType == .page {
+                let item = KMBotaAnnotationModel()
+                item.anno = anno
+                item.showPage = self.annoListIsShowPage()
+                item.showTime = self.annoListIsShowTime()
+                item.showAuthor = self.annoListIsShowAnther()
+                
+//                datas.append(item)
+                if self.noteSortType == .page {
                     let pageIdx = Int(anno.pageIndex())
-                    var secM: KMBotaAnnotationSectionModel?
                     if pageIdx != prePageIdx { // 不是同一个页面
                         secM = KMBotaAnnotationSectionModel()
                         model.datas.append(secM!)
                     }
                     
-                    let item = KMBotaAnnotationModel()
-                    item.anno = anno
-                    item.showPage = self.annoListIsShowPage()
-                    item.showTime = self.annoListIsShowTime()
-                    item.showAuthor = self.annoListIsShowAnther()
-//                    datas.append(item)
                     secM?.items.append(item)
-                    
                     prePageIdx = Int(anno.pageIndex())
+                } else { // time
+                    let date = anno.modificationDate()
+                    if let same = date?.isSameDay(other: preDate), same == false { // 不是同一天
+                        secM = KMBotaAnnotationSectionModel()
+                        model.datas.append(secM!)
+                    }
+                    
+                    secM?.items.append(item)
+                    preDate = date
+                }
                 
                 let replyAnnos = self.noteReplyHanddler.fetchReplyAnnotations(anno) ?? []
                 for replyAnno in replyAnnos {
@@ -1003,20 +1014,12 @@ extension KMLeftSideViewController {
                     replyM.annoModel = item
                     item.replyAnnos.append(replyM)
                 }
-                
+            
                 let footerI = KMBotaAnnotationFooterModel()
                 footerI.anno = anno
                 secM?.items.append(footerI)
                 item.footerModel = footerI
                 footerI.annoModel = item
-//                }
-                
-//                let item = KMBotaAnnotationModel()
-//                item.anno = anno
-//                item.showPage = self.annoListIsShowPage()
-//                item.showTime = self.annoListIsShowTime()
-//                item.showAuthor = self.annoListIsShowAnther()
-//                datas.append(item)
             }
 //            model.datas = datas
             self.annoListModel = model

+ 12 - 2
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -2060,8 +2060,18 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                     cell = KMSectionCellView.createFromNib()
                 }
                 cell?.isExpand = true
-                cell?.titleLabel.stringValue = "Page 2"
-                cell?.countLabel.stringValue = "\(data.itemCount)"
+                if self.noteSortType == .page {
+                    let pageIndex = data.items.first?.anno?.page.pageIndex() ?? 0
+                    cell?.titleLabel.stringValue = NSLocalizedString("Page", comment: "") + " \(pageIndex + 1)"
+                } else {
+                    if let date = data.items.first?.anno?.modificationDate() {
+                        let string = KMTools.timeString(timeDate: date)
+                        cell?.titleLabel.stringValue = string
+                    } else {
+                        cell?.titleLabel.stringValue = ""
+                    }
+                }
+                cell?.countLabel.stringValue = "\(data.itemCount / 2)"
                 
                 cell?.itemClick = { idx, _ in
                     if idx == 1 { // 收取 & 展开