mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-27 13:59:04 -04:00
Refactors and fixes
This commit is contained in:
parent
0136e66d94
commit
d6718d2d67
@ -340,10 +340,10 @@
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="bDK-ON-vzl">
|
||||
<rect key="frame" x="60" y="31" width="307" height="2"/>
|
||||
<rect key="frame" x="60" y="33" width="307" height="2"/>
|
||||
</progressView>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kV6-Lt-E6s">
|
||||
<rect key="frame" x="60" y="35" width="307" height="15"/>
|
||||
<rect key="frame" x="60" y="39" width="307" height="15"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="12"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
@ -351,7 +351,7 @@
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="GhC-S8-4Ak" firstAttribute="centerY" secondItem="nVN-8L-w1D" secondAttribute="centerY" id="1HQ-Ka-V5B"/>
|
||||
<constraint firstItem="kV6-Lt-E6s" firstAttribute="top" secondItem="bDK-ON-vzl" secondAttribute="bottom" constant="2" id="BCZ-fO-oVq"/>
|
||||
<constraint firstItem="kV6-Lt-E6s" firstAttribute="top" secondItem="bDK-ON-vzl" secondAttribute="bottom" constant="4" id="BCZ-fO-oVq"/>
|
||||
<constraint firstAttribute="leadingMargin" secondItem="GhC-S8-4Ak" secondAttribute="leading" id="KJW-gj-p94"/>
|
||||
<constraint firstItem="kV6-Lt-E6s" firstAttribute="leading" secondItem="GhC-S8-4Ak" secondAttribute="trailing" constant="8" id="MH1-8I-9h5"/>
|
||||
<constraint firstItem="bDK-ON-vzl" firstAttribute="leading" secondItem="GhC-S8-4Ak" secondAttribute="trailing" constant="8" id="Nq4-pU-ACR"/>
|
||||
@ -360,7 +360,7 @@
|
||||
<constraint firstAttribute="trailingMargin" secondItem="bDK-ON-vzl" secondAttribute="trailing" id="giD-gR-Qou"/>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="kV6-Lt-E6s" secondAttribute="trailing" id="lFV-oP-iqa"/>
|
||||
<constraint firstItem="Zkf-Od-qYs" firstAttribute="leading" secondItem="GhC-S8-4Ak" secondAttribute="trailing" constant="8" id="pm3-kg-EYD"/>
|
||||
<constraint firstItem="bDK-ON-vzl" firstAttribute="top" secondItem="Zkf-Od-qYs" secondAttribute="bottom" constant="2" id="rV9-Mq-ksX"/>
|
||||
<constraint firstItem="bDK-ON-vzl" firstAttribute="top" secondItem="Zkf-Od-qYs" secondAttribute="bottom" constant="4" id="rV9-Mq-ksX"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
<connections>
|
||||
|
@ -11,7 +11,6 @@
|
||||
9705D5941E368189005292AC /* Library.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9705D5931E368189005292AC /* Library.storyboard */; };
|
||||
9705D5961E368712005292AC /* LibraryBooksController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9705D5951E368712005292AC /* LibraryBooksController.swift */; };
|
||||
9705D5981E368933005292AC /* CoreDataCollectionBaseController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9705D5971E368933005292AC /* CoreDataCollectionBaseController.swift */; };
|
||||
970A2A221DD562CB0078BB7C /* BookOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 970A2A211DD562CB0078BB7C /* BookOperations.swift */; };
|
||||
970E7F741D9DB0FC00741290 /* 1.8.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 970E7F731D9DB0FC00741290 /* 1.8.xcmappingmodel */; };
|
||||
970E7F831DA0305000741290 /* WelcomeController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 970E7F7F1DA0305000741290 /* WelcomeController.swift */; };
|
||||
9711871E1CEB449A00B9909D /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 9711871D1CEB449A00B9909D /* libz.tbd */; };
|
||||
@ -150,7 +149,6 @@
|
||||
9705D5951E368712005292AC /* LibraryBooksController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LibraryBooksController.swift; sourceTree = "<group>"; };
|
||||
9705D5971E368933005292AC /* CoreDataCollectionBaseController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataCollectionBaseController.swift; sourceTree = "<group>"; };
|
||||
970912551D7F452C00BBD5A1 /* 1.8.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = 1.8.xcdatamodel; sourceTree = "<group>"; };
|
||||
970A2A211DD562CB0078BB7C /* BookOperations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BookOperations.swift; sourceTree = "<group>"; };
|
||||
970E7F731D9DB0FC00741290 /* 1.8.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; name = 1.8.xcmappingmodel; path = Kiwix/CoreData/Migration/1.8.xcmappingmodel; sourceTree = SOURCE_ROOT; };
|
||||
970E7F7C1DA0305000741290 /* Alerts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Alerts.swift; sourceTree = "<group>"; };
|
||||
970E7F7F1DA0305000741290 /* WelcomeController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WelcomeController.swift; sourceTree = "<group>"; };
|
||||
@ -251,7 +249,6 @@
|
||||
97C601DB1D7F15C400362D4F /* Bookmark.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Bookmark.storyboard; sourceTree = "<group>"; };
|
||||
97C601DD1D7F342100362D4F /* HTMLHeading.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTMLHeading.swift; sourceTree = "<group>"; };
|
||||
97D0E9921DDA487E0029530E /* SearchBaseController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchBaseController.swift; sourceTree = "<group>"; };
|
||||
97D4D64E1D874E6E00C1B065 /* SearchOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchOperation.swift; sourceTree = "<group>"; };
|
||||
97D6811C1D6F70AC00E5FA99 /* Queue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Queue.swift; sourceTree = "<group>"; };
|
||||
97D6811E1D6F70AC00E5FA99 /* ScanLocalBook.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScanLocalBook.swift; sourceTree = "<group>"; };
|
||||
97D681211D6F70AC00E5FA99 /* UpdateWidgetDataSourceOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateWidgetDataSourceOperation.swift; sourceTree = "<group>"; };
|
||||
@ -678,12 +675,10 @@
|
||||
children = (
|
||||
97D6811C1D6F70AC00E5FA99 /* Queue.swift */,
|
||||
9764CBD21D8083AA00072D6A /* ArticleOperation.swift */,
|
||||
970A2A211DD562CB0078BB7C /* BookOperations.swift */,
|
||||
973A5C981DEBC54800C7804C /* CloudKit.swift */,
|
||||
973208281DD223DB00EDD3DC /* RefreshLibrary.swift */,
|
||||
97D6811E1D6F70AC00E5FA99 /* ScanLocalBook.swift */,
|
||||
972F81561DDBFC79008D7289 /* Search.swift */,
|
||||
97D4D64E1D874E6E00C1B065 /* SearchOperation.swift */,
|
||||
97D681211D6F70AC00E5FA99 /* UpdateWidgetDataSourceOperation.swift */,
|
||||
976C1DD31E300695005EDEC4 /* UIProcedure.swift */,
|
||||
);
|
||||
@ -916,7 +911,6 @@
|
||||
97A1FD161D6F71CE00A80EE2 /* DirectoryMonitor.swift in Sources */,
|
||||
9726591D1D90A64600D1DFFB /* Notification.swift in Sources */,
|
||||
971A102C1D022AD5007FC62C /* BarButtonItems.swift in Sources */,
|
||||
970A2A221DD562CB0078BB7C /* BookOperations.swift in Sources */,
|
||||
97A1FD391D6F724E00A80EE2 /* pathTools.cpp in Sources */,
|
||||
972F81591DDC1B71008D7289 /* Controllers.swift in Sources */,
|
||||
976B86D81DDA0C7E00FA7FD1 /* SearchContainer.swift in Sources */,
|
||||
|
@ -96,15 +96,3 @@ class ArticleLoadOperation: Procedure {
|
||||
}
|
||||
}
|
||||
|
||||
class SpotlightIndexOperation: Procedure {
|
||||
init(url: URL) {
|
||||
assert(Thread.isMainThread, "This Operation can only be initialized in the main thread")
|
||||
super.init()
|
||||
}
|
||||
|
||||
override func execute() {
|
||||
AppDelegate.persistentContainer.viewContext.performAndWait {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
//
|
||||
// Book.swift
|
||||
// Kiwix
|
||||
//
|
||||
// Created by Chris Li on 11/10/16.
|
||||
// Copyright © 2016 Chris Li. All rights reserved.
|
||||
//
|
||||
|
||||
import ProcedureKit
|
||||
|
||||
/*
|
||||
Removes all zim file (single & chuncked) and the idx folder that belong to a book
|
||||
*/
|
||||
|
||||
class DeleteBookFileOperation: Procedure {
|
||||
let zimID: ZimID
|
||||
|
||||
init(zimID: ZimID) {
|
||||
self.zimID = zimID
|
||||
super.init()
|
||||
}
|
||||
|
||||
override func execute() {
|
||||
guard let mainZimURL = ZimMultiReader.shared.readers[zimID]?.fileURL,
|
||||
let fileName = mainZimURL.pathComponents.last else {
|
||||
print("Cannot find reader")
|
||||
finish()
|
||||
return
|
||||
}
|
||||
|
||||
let urls = URLSnapShot.zimFileURLsInDocDir().union(URLSnapShot.indexFolderURLsInDocDir())
|
||||
urls.forEach { (url) in
|
||||
guard url.pathComponents.last == fileName else {return}
|
||||
try? FileManager.default.removeItem(at: url)
|
||||
}
|
||||
|
||||
finish()
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
//
|
||||
// SearchOperation.swift
|
||||
// Kiwix
|
||||
//
|
||||
// Created by Chris Li on 9/12/16.
|
||||
// Copyright © 2016 Chris Li. All rights reserved.
|
||||
//
|
||||
|
||||
import CoreData
|
||||
import ProcedureKit
|
||||
|
||||
class SearchOperation: GroupProcedure {
|
||||
fileprivate(set) var results = [SearchResult]()
|
||||
let searchTerm: String
|
||||
|
||||
init(searchTerm: String) {
|
||||
self.searchTerm = searchTerm
|
||||
super.init(operations: [])
|
||||
}
|
||||
|
||||
override func execute() {
|
||||
let searches = Book.fetchLocal(NSManagedObjectContext.mainQueueContext)
|
||||
.filter({ $1.includeInSearch })
|
||||
.map({ BookSearch(zimID: $1.id, searchTerm: searchTerm) })
|
||||
let sort = Sort()
|
||||
searches.forEach { (search) in
|
||||
sort.injectResultFromDependency(search, block: { (operation, dependency, errors) in
|
||||
operation.requirement += dependency.results
|
||||
})
|
||||
}
|
||||
|
||||
sort.addObserver(DidFinishObserver { [unowned self] (operation, errors) in
|
||||
guard let operation = operation as? Sort else {return}
|
||||
self.results = operation.requirement
|
||||
})
|
||||
|
||||
addOperations(searches)
|
||||
addOperation(sort)
|
||||
|
||||
super.execute()
|
||||
}
|
||||
}
|
||||
|
||||
private class BookSearch: Procedure {
|
||||
let zimID: String
|
||||
let searchTerm: String
|
||||
fileprivate var results = [SearchResult]()
|
||||
|
||||
init(zimID: String, searchTerm: String) {
|
||||
self.zimID = zimID
|
||||
self.searchTerm = searchTerm
|
||||
super.init()
|
||||
}
|
||||
|
||||
override fileprivate func execute() {
|
||||
defer { finish() }
|
||||
guard let reader = ZimMultiReader.shared.readers[zimID] else {return}
|
||||
|
||||
guard !isCancelled else {return}
|
||||
let indexedDics = reader.search(usingIndex: searchTerm) as? [[String: AnyObject]] ?? [[String: AnyObject]]()
|
||||
|
||||
guard !isCancelled else {return}
|
||||
let titleDics = reader.searchSuggestionsSmart(searchTerm) as? [[String: AnyObject]] ?? [[String: AnyObject]]()
|
||||
|
||||
guard !isCancelled else {return}
|
||||
let mixedDics = titleDics + indexedDics // It is important we process the title search result first, so that we always keep the indexed search result
|
||||
for dic in mixedDics {
|
||||
guard let result = SearchResult (rawResult: dic, lowerCaseSearchTerm: searchTerm) else {continue}
|
||||
self.results.append(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class Sort: Procedure, AutomaticInjectionOperationType {
|
||||
var requirement = [SearchResult]()
|
||||
|
||||
fileprivate override func execute() {
|
||||
defer { finish() }
|
||||
guard !isCancelled else {return}
|
||||
sort()
|
||||
}
|
||||
|
||||
fileprivate func sort() {
|
||||
requirement.sort { (result0, result1) -> Bool in
|
||||
if result0.score != result1.score {
|
||||
return result0.score < result1.score
|
||||
} else {
|
||||
if result0.snippet != nil {return true}
|
||||
if result1.snippet != nil {return false}
|
||||
return titleCaseInsensitiveCompare(result0, result1: result1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func titleCaseInsensitiveCompare(_ result0: SearchResult, result1: SearchResult) -> Bool {
|
||||
return result0.title.caseInsensitiveCompare(result1.title) == ComparisonResult.orderedAscending
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user