mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-22 11:03:21 -04:00
Multiple changes
- iPhone js, adjust thumbs layout, now they take up the whole width - NetworkObserver, correct task count - refactor and very minor improvements
This commit is contained in:
parent
cd134e785e
commit
553a464157
@ -45,7 +45,7 @@ class LibraryDownloadTBVC: UITableViewController, NSFetchedResultsControllerDele
|
||||
let downloadTask = fetchedResultController.objectAtIndexPath(indexPath) as? DownloadTask,
|
||||
let book = downloadTask.book else {return}
|
||||
switch downloadTask.state {
|
||||
case .Downloading:
|
||||
case .Downloading, .Queued:
|
||||
Network.sharedInstance.pause(book)
|
||||
case .Paused, .Error:
|
||||
Network.sharedInstance.resume(book)
|
||||
|
@ -123,8 +123,6 @@ class SearchResultTBVC: UIViewController, UITableViewDataSource, UITableViewDele
|
||||
if results.count > 0 {
|
||||
self.tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0), atScrollPosition: .Top, animated: true)
|
||||
}
|
||||
// This line below works prefectly if tableview doesn't hide keyboard on drag
|
||||
//self.tableView.setContentOffset(CGPointMake(0, 0 - self.tableView.contentInset.top), animated: true)
|
||||
}
|
||||
ZIMMultiReader.sharedInstance.searchQueue.addOperation(operation)
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>291</string>
|
||||
<string>366</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -1,13 +1,41 @@
|
||||
/**
|
||||
* Created by chrisli on 10/5/15.
|
||||
*/
|
||||
var tables = document.getElementsByTagName("table");
|
||||
var i;
|
||||
for (i = 0; i < tables.length; i++) {
|
||||
org_html = tables[i].outerHTML;
|
||||
new_html = "<div id='slidesInner' style ='width:100%;'>" + org_html + "</div>";
|
||||
tables[i].outerHTML = new_html;
|
||||
tables[i].parentNode.style.overflow = "auto";
|
||||
tables[i].style.margin = "auto";
|
||||
tables[i].style.width = "100%";
|
||||
}
|
||||
function adjustTables() {
|
||||
var tables = document.getElementsByTagName("table");
|
||||
var i;
|
||||
for (i = 0; i < tables.length; i++) {
|
||||
org_html = tables[i].outerHTML;
|
||||
new_html = "<div id='slidesInner' style ='width:100%;'>" + org_html + "</div>";
|
||||
tables[i].outerHTML = new_html;
|
||||
tables[i].parentNode.style.overflow = "auto";
|
||||
tables[i].style.margin = "auto";
|
||||
tables[i].style.width = "100%";
|
||||
}
|
||||
}
|
||||
|
||||
function adjustThumbLayout(thumbs) {
|
||||
var i;
|
||||
for (i = 0; i < thumbs.length; i++) {
|
||||
thumbs[i].style.width = "100%";
|
||||
thumbs[i].style.paddingLeft = "4px";
|
||||
thumbs[i].style.paddingRight = "4px";
|
||||
var inner = thumbs[i].getElementsByClassName("thumbinner")[0];
|
||||
if (inner) {
|
||||
inner.style.width = "100%";
|
||||
var captions = inner.getElementsByClassName("thumbcaption");
|
||||
var j;
|
||||
for (j= 0; j < captions.length; j++) {
|
||||
captions[j].style.textAlign = "center";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
adjustTables();
|
||||
adjustThumbLayout(document.getElementsByClassName("thumb tright"));
|
||||
adjustThumbLayout(document.getElementsByClassName("thumb tleft"));
|
||||
adjustThumbLayout(document.getElementsByClassName("thumb tmulti tright"));
|
||||
adjustThumbLayout(document.getElementsByClassName("thumb tmulti tleft"));
|
||||
|
||||
|
||||
|
@ -18,6 +18,7 @@ struct NetworkObserver: OperationObserver {
|
||||
init() { }
|
||||
|
||||
func operationDidStart(operation: Operation) {
|
||||
print("NetworkObserver: \(operation.name ?? "Unknown") operation did start")
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
// Increment the network indicator's "reference count"
|
||||
NetworkIndicatorController.sharedIndicatorController.networkActivityDidStart()
|
||||
@ -27,13 +28,19 @@ struct NetworkObserver: OperationObserver {
|
||||
func operation(operation: Operation, didProduceOperation newOperation: NSOperation) { }
|
||||
|
||||
func operationDidFinish(operation: Operation, errors: [NSError]) {
|
||||
// If an op is cancelled, operationDidStart will not be called
|
||||
print("NetworkObserver: \(operation.name ?? "Unknown") operation did finish")
|
||||
guard !operation.cancelled else {return}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue()) {
|
||||
// Decrement the network indicator's "reference count".
|
||||
NetworkIndicatorController.sharedIndicatorController.networkActivityDidEnd()
|
||||
}
|
||||
}
|
||||
|
||||
func operationDidCancel(operation: Operation) { }
|
||||
func operationDidCancel(operation: Operation) {
|
||||
print("NetworkObserver: \(operation.name ?? "Unknown") operation did cancel")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ class RefreshLibraryOperation: GroupOperation {
|
||||
parseOperation.xmlData = data
|
||||
}
|
||||
let fetchOperation = URLSessionTaskOperation(task: task)
|
||||
fetchOperation.name = "Library XML download operation"
|
||||
|
||||
#if os(iOS) || os(watchOS) || os(tvOS)
|
||||
fetchOperation.addObserver(NetworkObserver())
|
||||
|
@ -24,7 +24,7 @@ class SearchOperation: GroupOperation {
|
||||
let managedObjectContext = UIApplication.appDelegate.managedObjectContext
|
||||
guard let book = Book.fetch(id, context: managedObjectContext) else {continue}
|
||||
guard book.includeInSearch else {continue}
|
||||
let operation = SingleBookSearchOperation(zimReader: zimReader, searchTerm: searchTerm, completionHandler: { [unowned sortOperation] (results) in
|
||||
let operation = SingleBookSearchOperation(zimReader: zimReader, searchTerm: searchTerm.lowercaseString, completionHandler: { [unowned sortOperation] (results) in
|
||||
sortOperation.results += results
|
||||
})
|
||||
|
||||
@ -61,6 +61,7 @@ private class SingleBookSearchOperation: Operation {
|
||||
var results = [SearchResult]()
|
||||
for dic in resultDics {
|
||||
guard let result = SearchResult(rawResult: dic) else {continue}
|
||||
print(result)
|
||||
results.append(result)
|
||||
}
|
||||
completionHandler(results)
|
||||
@ -77,7 +78,7 @@ private class SortSearchResultsOperation: Operation {
|
||||
}
|
||||
|
||||
override private func execute() {
|
||||
sortBySearchMethod()
|
||||
sort()
|
||||
completionHandler(results)
|
||||
finish()
|
||||
}
|
||||
@ -87,7 +88,7 @@ private class SortSearchResultsOperation: Operation {
|
||||
2. Among Xapian results: sort by percent, then title case insensitive compare
|
||||
3. Among searchSuggestionSmart results: sort by title case insensitive compare
|
||||
*/
|
||||
private func sortBySearchMethod() {
|
||||
private func sort() {
|
||||
results.sortInPlace { (result0, result1) -> Bool in
|
||||
let result0Percent = result0.percent ?? -1
|
||||
let result1Percent = result1.percent ?? -1
|
||||
|
@ -160,10 +160,11 @@ extension ZimReader {
|
||||
}
|
||||
}
|
||||
|
||||
class SearchResult {
|
||||
class SearchResult: CustomStringConvertible {
|
||||
let bookID: String
|
||||
let title: String
|
||||
let percent: Double? // range: 0-100
|
||||
let distance: Int64 // Levenshtein distance, non negative integer
|
||||
let path: String?
|
||||
let snippet: String?
|
||||
|
||||
@ -172,10 +173,18 @@ class SearchResult {
|
||||
self.title = (rawResult["title"] as? String) ?? ""
|
||||
|
||||
self.percent = (rawResult["percent"] as? NSNumber)?.doubleValue
|
||||
self.distance = (rawResult["distance"]as? NSNumber)?.longLongValue ?? 0
|
||||
self.path = rawResult["path"] as? String
|
||||
self.snippet = rawResult["snippet"] as? String
|
||||
|
||||
if bookID == "" {return nil}
|
||||
if title == "" {return nil}
|
||||
}
|
||||
|
||||
var description: String {
|
||||
var parts = [bookID, title]
|
||||
if let percent = percent {parts.append("\(percent)%")}
|
||||
parts.append("dist: \(distance)")
|
||||
return parts.joinWithSeparator(", ")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user