|
@@ -733,7 +733,7 @@ extension KMLeftSideViewController {
|
|
|
if self.noteSearchMode {
|
|
|
self.reloadNoteForSearchMode()
|
|
|
} else {
|
|
|
- self.reloadAnnotation()
|
|
|
+ self.reloadNoteForSortMode()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1203,7 +1203,7 @@ extension KMLeftSideViewController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // 数据模型\化
|
|
|
+ // 数据模型化
|
|
|
let model = KMAnnotationListModel()
|
|
|
var datas: [KMBotaAnnotationModel] = []
|
|
|
var prePageIdx: Int = NSNotFound
|
|
@@ -1310,6 +1310,104 @@ extension KMLeftSideViewController {
|
|
|
self.note_refrshUIIfNeed()
|
|
|
}
|
|
|
|
|
|
+ func reloadNoteForSortMode() {
|
|
|
+ // 处理排序
|
|
|
+ var models: [KMBotaAnnotationModel] = []
|
|
|
+ for selM in self.annoListModel?.datas ?? [] {
|
|
|
+ for model in selM.items {
|
|
|
+ guard let annoModel = model as? KMBotaAnnotationModel else {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ models.append(annoModel)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.noteSortType == .page {
|
|
|
+ if self.isAscendSort { /// 排序(升序)
|
|
|
+ models.sort {
|
|
|
+ let idx0 = $0.anno?.page?.pageIndex() ?? 0
|
|
|
+ let idx1 = $1.anno?.page?.pageIndex() ?? 0
|
|
|
+ return idx0 <= idx1
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ models.sort {
|
|
|
+ let idx0 = $0.anno?.page?.pageIndex() ?? 0
|
|
|
+ let idx1 = $1.anno?.page?.pageIndex() ?? 0
|
|
|
+ return idx0 > idx1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if self.noteSortType == .time {
|
|
|
+ if self.isAscendSort { /// 排序(升序)
|
|
|
+ models.sort {
|
|
|
+ if $0.anno?.modificationDate() == nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if $1.anno?.modificationDate() == nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return $0.anno!.modificationDate() <= $1.anno!.modificationDate()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ models.sort {
|
|
|
+ if $0.anno?.modificationDate() == nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if $1.anno?.modificationDate() == nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return $0.anno!.modificationDate() > $1.anno!.modificationDate()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 数据模型\化
|
|
|
+ let listModel = KMAnnotationListModel()
|
|
|
+ var prePageIdx: Int = NSNotFound
|
|
|
+ var preDate: Date?
|
|
|
+ var secM: KMBotaAnnotationSectionModel?
|
|
|
+ for itemM in models {
|
|
|
+ guard let anno = itemM.anno else {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.noteSortType == .page {
|
|
|
+ let pageIdx = Int(anno.pageIndex())
|
|
|
+ if pageIdx != prePageIdx { // 不是同一个页面
|
|
|
+ secM = KMBotaAnnotationSectionModel()
|
|
|
+ listModel.datas.append(secM!)
|
|
|
+ secM?.isExpand = itemM.sectionModel?.isExpand ?? true
|
|
|
+ }
|
|
|
+
|
|
|
+ secM?.items.append(itemM)
|
|
|
+ prePageIdx = Int(anno.pageIndex())
|
|
|
+ } else { // time
|
|
|
+ let date = anno.modificationDate()
|
|
|
+ if let same = date?.isSameDay(other: preDate), same == false { // 不是同一天
|
|
|
+ secM = KMBotaAnnotationSectionModel()
|
|
|
+ listModel.datas.append(secM!)
|
|
|
+ secM?.isExpand = itemM.sectionModel?.isExpand ?? true
|
|
|
+ }
|
|
|
+
|
|
|
+ secM?.items.append(itemM)
|
|
|
+ preDate = date
|
|
|
+ }
|
|
|
+
|
|
|
+ var tmpSelM = itemM.sectionModel
|
|
|
+ itemM.sectionModel = secM
|
|
|
+
|
|
|
+ let footerI = KMBotaAnnotationFooterModel()
|
|
|
+ footerI.anno = anno
|
|
|
+ secM?.items.append(footerI)
|
|
|
+ footerI.isExpand = itemM.footerModel?.isExpand ?? false
|
|
|
+ itemM.footerModel = footerI
|
|
|
+ footerI.annoModel = itemM
|
|
|
+ }
|
|
|
+
|
|
|
+ self.annoListModel = listModel
|
|
|
+
|
|
|
+ self.note_refrshUIIfNeed()
|
|
|
+ }
|
|
|
+
|
|
|
// 搜索 Action
|
|
|
func updateNoteFilterPredicate() {
|
|
|
var stringValue = self.noteSearchField.stringValue
|