diff --git a/Kiwix-iOS/Controller/Library/BookDetailController.swift b/Kiwix-iOS/Controller/Library/BookDetailController.swift
index 618c9712..f6383bae 100644
--- a/Kiwix-iOS/Controller/Library/BookDetailController.swift
+++ b/Kiwix-iOS/Controller/Library/BookDetailController.swift
@@ -94,14 +94,15 @@ class BookDetailController: UITableViewController, DZNEmptyDataSetSource, DZNEmp
cellTitles.append([])
}
- if let isLocal = book.isLocal?.boolValue {
- if isLocal {
- cellTitles[1] = [LocalizedStrings.remove]
- } else {
- cellTitles[1] = book.spaceState == .NotEnough ? [LocalizedStrings.spaceNotEnough] : [LocalizedStrings.download]
- }
- } else {
+ switch book.state {
+ case .Cloud:
+ cellTitles[1] = book.spaceState == .NotEnough ? [LocalizedStrings.spaceNotEnough] : [LocalizedStrings.download]
+ case .Downloading:
cellTitles[1] = [LocalizedStrings.downloading]
+ case .Local:
+ cellTitles[1] = [LocalizedStrings.remove]
+ default:
+ break
}
}
diff --git a/Kiwix-iOS/Controller/Library/CloudBooksController.swift b/Kiwix-iOS/Controller/Library/CloudBooksController.swift
index 95e9333f..77ab036c 100644
--- a/Kiwix-iOS/Controller/Library/CloudBooksController.swift
+++ b/Kiwix-iOS/Controller/Library/CloudBooksController.swift
@@ -336,7 +336,7 @@ class CloudBooksController: UITableViewController, NSFetchedResultsControllerDel
}
private var onlineCompoundPredicate: NSCompoundPredicate {
- let isCloudPredicate = NSPredicate(format: "isLocal == false")
+ let isCloudPredicate = NSPredicate(format: "stateRaw == 0")
return NSCompoundPredicate(andPredicateWithSubpredicates: [langPredicate, isCloudPredicate])
}
diff --git a/Kiwix-iOS/Controller/Library/DownloadTasksController.swift b/Kiwix-iOS/Controller/Library/DownloadTasksController.swift
index 40b390df..6f32ec08 100644
--- a/Kiwix-iOS/Controller/Library/DownloadTasksController.swift
+++ b/Kiwix-iOS/Controller/Library/DownloadTasksController.swift
@@ -221,7 +221,7 @@ class DownloadTasksController: UITableViewController, NSFetchedResultsController
// Remove resume data
// Delete downloadTask object and set book to not local
downloadTask.book?.removeResumeData()
- downloadTask.book?.isLocal = NSNumber(bool: false)
+ downloadTask.book?.state = .Cloud
self.managedObjectContext.deleteObject(downloadTask)
}
} else {
diff --git a/Kiwix-iOS/Controller/Library/LocalBooksController.swift b/Kiwix-iOS/Controller/Library/LocalBooksController.swift
index 264f946f..1a6df356 100644
--- a/Kiwix-iOS/Controller/Library/LocalBooksController.swift
+++ b/Kiwix-iOS/Controller/Library/LocalBooksController.swift
@@ -146,7 +146,7 @@ class LocalBooksController: UITableViewController, NSFetchedResultsControllerDel
let langDescriptor = NSSortDescriptor(key: "language.name", ascending: true)
let titleDescriptor = NSSortDescriptor(key: "title", ascending: true)
fetchRequest.sortDescriptors = [langDescriptor, titleDescriptor]
- fetchRequest.predicate = NSPredicate(format: "isLocal == true")
+ fetchRequest.predicate = NSPredicate(format: "stateRaw >= 2")
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: "language.name", cacheName: "LocalFRC" + NSBundle.buildVersion)
fetchedResultsController.delegate = self
fetchedResultsController.performFetch(deleteCache: false)
diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist
index ee893931..6886b31c 100644
--- a/Kiwix-iOS/Info.plist
+++ b/Kiwix-iOS/Info.plist
@@ -49,7 +49,7 @@
CFBundleVersion
- 1.8.1047
+ 1.8.1070
ITSAppUsesNonExemptEncryption
LSRequiresIPhoneOS
diff --git a/Kiwix-iOSWidgets/Bookmarks/Info.plist b/Kiwix-iOSWidgets/Bookmarks/Info.plist
index d1d7749a..6ad39a9c 100644
--- a/Kiwix-iOSWidgets/Bookmarks/Info.plist
+++ b/Kiwix-iOSWidgets/Bookmarks/Info.plist
@@ -21,7 +21,7 @@
CFBundleSignature
????
CFBundleVersion
- 1.8.1051
+ 1.8.1074
NSExtension
NSExtensionMainStoryboard
diff --git a/Kiwix.xcodeproj/project.pbxproj b/Kiwix.xcodeproj/project.pbxproj
index 07eac6f3..1d30e096 100644
--- a/Kiwix.xcodeproj/project.pbxproj
+++ b/Kiwix.xcodeproj/project.pbxproj
@@ -81,13 +81,13 @@
9764F5931D830EF200E0B1C4 /* liblzma.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 9764F5921D830EF200E0B1C4 /* liblzma.tbd */; };
9764F5971D8339D500E0B1C4 /* JSInjection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9764F5961D8339D500E0B1C4 /* JSInjection.swift */; };
9764F5991D833F2B00E0B1C4 /* KiwixURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9764F5981D833F2B00E0B1C4 /* KiwixURL.swift */; };
- 9764F59F1D83553F00E0B1C4 /* 1.8.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 9764F59E1D83553F00E0B1C4 /* 1.8.xcmappingmodel */; };
9779C3141D4575AD0064CC8E /* NotificationCenter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97E609F01D103DED00EBCB9D /* NotificationCenter.framework */; };
9779C3171D4575AE0064CC8E /* TodayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9779C3161D4575AE0064CC8E /* TodayViewController.swift */; };
9779C31A1D4575AE0064CC8E /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9779C3181D4575AE0064CC8E /* MainInterface.storyboard */; };
9779C31E1D4575AE0064CC8E /* Bookmarks.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 9779C3131D4575AD0064CC8E /* Bookmarks.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
9787BC211D9318300030D311 /* WelcomeController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9787BC201D9318300030D311 /* WelcomeController.swift */; };
9787BC231D9318570030D311 /* TableOfContentsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9787BC221D9318570030D311 /* TableOfContentsController.swift */; };
+ 9787BC271D944E890030D311 /* 1.8.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 9787BC261D944E890030D311 /* 1.8.xcmappingmodel */; };
979C518D1CECAE4C001707F2 /* PreferenceWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 979C518B1CECAE4C001707F2 /* PreferenceWindowController.swift */; };
979CB60F1D04AD04005E1BA1 /* PreferenceTabController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 979CB60E1D04AD04005E1BA1 /* PreferenceTabController.swift */; };
979CB6C81D05CF37005E1BA1 /* SearchResultController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 979CB6C71D05CF37005E1BA1 /* SearchResultController.swift */; };
@@ -302,7 +302,6 @@
9764F5921D830EF200E0B1C4 /* liblzma.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = liblzma.tbd; path = usr/lib/liblzma.tbd; sourceTree = SDKROOT; };
9764F5961D8339D500E0B1C4 /* JSInjection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = JSInjection.swift; path = Main/JSInjection.swift; sourceTree = ""; };
9764F5981D833F2B00E0B1C4 /* KiwixURL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KiwixURL.swift; sourceTree = ""; };
- 9764F59E1D83553F00E0B1C4 /* 1.8.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; name = 1.8.xcmappingmodel; path = Kiwix/CoreData/Migration/1.8.xcmappingmodel; sourceTree = SOURCE_ROOT; };
976A0C801D41619C0006A742 /* DZNEmptyDataSet.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DZNEmptyDataSet.framework; path = "../../../../Users/chrisli/Library/Developer/Xcode/DerivedData/Kiwix-ayxrfhaqnfxzendihdolvkklkmhk/Build/Products/Debug-iphoneos/DZNEmptyDataSet/DZNEmptyDataSet.framework"; sourceTree = ""; };
9779C3131D4575AD0064CC8E /* Bookmarks.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = Bookmarks.appex; sourceTree = BUILT_PRODUCTS_DIR; };
9779C3161D4575AE0064CC8E /* TodayViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayViewController.swift; sourceTree = ""; };
@@ -310,6 +309,7 @@
9779C31B1D4575AE0064CC8E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
9787BC201D9318300030D311 /* WelcomeController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WelcomeController.swift; path = Others/WelcomeController.swift; sourceTree = ""; };
9787BC221D9318570030D311 /* TableOfContentsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TableOfContentsController.swift; path = Others/TableOfContentsController.swift; sourceTree = ""; };
+ 9787BC261D944E890030D311 /* 1.8.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; name = 1.8.xcmappingmodel; path = Kiwix/CoreData/Migration/1.8.xcmappingmodel; sourceTree = SOURCE_ROOT; };
979C518B1CECAE4C001707F2 /* PreferenceWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PreferenceWindowController.swift; path = "Kiwix-OSX/Controllers/PreferenceWindowController.swift"; sourceTree = SOURCE_ROOT; };
979CB60E1D04AD04005E1BA1 /* PreferenceTabController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PreferenceTabController.swift; path = Controllers/PreferenceTabController.swift; sourceTree = ""; };
979CB6C71D05CF37005E1BA1 /* SearchResultController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SearchResultController.swift; path = Controllers/SearchResultController.swift; sourceTree = ""; };
@@ -545,7 +545,7 @@
children = (
97D6812F1D6F70EC00E5FA99 /* 1.5.xcmappingmodel */,
97D681301D6F70EC00E5FA99 /* MigrationPolicy.swift */,
- 9764F59E1D83553F00E0B1C4 /* 1.8.xcmappingmodel */,
+ 9787BC261D944E890030D311 /* 1.8.xcmappingmodel */,
);
name = Migration;
path = Kiwix;
@@ -1542,7 +1542,7 @@
97D681231D6F70AC00E5FA99 /* GlobalQueue.swift in Sources */,
97A1FD3B1D6F724E00A80EE2 /* stringTools.cpp in Sources */,
97A1FD321D6F723D00A80EE2 /* resourceTools.cpp in Sources */,
- 9764F59F1D83553F00E0B1C4 /* 1.8.xcmappingmodel in Sources */,
+ 9787BC271D944E890030D311 /* 1.8.xcmappingmodel in Sources */,
971A10321D022AD5007FC62C /* SearchBar.swift in Sources */,
97E60A061D10504000EBCB9D /* LibraryBackupTBVC.swift in Sources */,
97A1FD451D6F728200A80EE2 /* StringTools.swift in Sources */,
diff --git a/Kiwix.xcworkspace/xcuserdata/chrisli.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Kiwix.xcworkspace/xcuserdata/chrisli.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
index 71c1f447..4aa29e0d 100644
--- a/Kiwix.xcworkspace/xcuserdata/chrisli.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ b/Kiwix.xcworkspace/xcuserdata/chrisli.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -25,13 +25,13 @@
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
- filePath = "Kiwix/Operations/GlobalQueue.swift"
- timestampString = "496186011.525439"
+ filePath = "Kiwix/CoreData/Migration/MigrationPolicy.swift"
+ timestampString = "496258633.225782"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "44"
- endingLineNumber = "44"
- landmarkName = "add(load:)"
+ startingLineNumber = "20"
+ endingLineNumber = "20"
+ landmarkName = "bookState(bool:)"
landmarkType = "7">
diff --git a/Kiwix/CoreData/Classes/Book+CoreDataProperties.swift b/Kiwix/CoreData/Classes/Book+CoreDataProperties.swift
index e53127f2..a3b78b7d 100644
--- a/Kiwix/CoreData/Classes/Book+CoreDataProperties.swift
+++ b/Kiwix/CoreData/Classes/Book+CoreDataProperties.swift
@@ -25,11 +25,11 @@ extension Book {
@NSManaged var hasPic: Bool
@NSManaged var id: String
@NSManaged var includeInSearch: Bool
- @NSManaged var isLocal: NSNumber?
@NSManaged var mediaCount: Int64
@NSManaged var meta4URL: String?
@NSManaged var pid: String?
@NSManaged var publisher: String?
+ @NSManaged var stateRaw: Int16
@NSManaged var title: String?
@NSManaged var articles: Set
diff --git a/Kiwix/CoreData/Classes/Book.swift b/Kiwix/CoreData/Classes/Book.swift
index f60d9c00..115cacc7 100644
--- a/Kiwix/CoreData/Classes/Book.swift
+++ b/Kiwix/CoreData/Classes/Book.swift
@@ -112,7 +112,7 @@ class Book: NSManagedObject {
class func fetchLocal(context: NSManagedObjectContext) -> [ZimID: Book] {
let fetchRequest = NSFetchRequest(entityName: "Book")
- let predicate = NSPredicate(format: "isLocal = true")
+ let predicate = NSPredicate(format: "stateRaw == 2")
fetchRequest.predicate = predicate
let localBooks = fetch(fetchRequest, type: Book.self, context: context) ?? [Book]()
@@ -218,6 +218,22 @@ class Book: NSManagedObject {
// MARK: - States
+ var state: BookState {
+ get {
+ switch stateRaw {
+ case 0: return .Cloud
+ case 1: return .Downloading
+ case 2: return .Local
+ case 3: return .Retained
+ case 4: return .Purgeable
+ default: return .Cloud
+ }
+ }
+ set {
+ stateRaw = Int16(newValue.rawValue)
+ }
+ }
+
var spaceState: BookSpaceState {
guard let freeSpaceInBytes = UIDevice.availableDiskSpace?.freeSize else {return .Enough}
if (0.8 * Double(freeSpaceInBytes)) > Double(fileSize) {
@@ -230,6 +246,11 @@ class Book: NSManagedObject {
}
}
+enum BookState: Int {
+ case Cloud, Downloading, Local, Retained, Purgeable
+}
+
+
enum BookSpaceState: Int {
case Enough, Caution, NotEnough
}
diff --git a/Kiwix/CoreData/Kiwix.xcdatamodeld/1.8.xcdatamodel/contents b/Kiwix/CoreData/Kiwix.xcdatamodeld/1.8.xcdatamodel/contents
index 1b663afa..d22ce979 100644
--- a/Kiwix/CoreData/Kiwix.xcdatamodeld/1.8.xcdatamodel/contents
+++ b/Kiwix/CoreData/Kiwix.xcdatamodeld/1.8.xcdatamodel/contents
@@ -1,11 +1,12 @@
-
+
+
@@ -35,11 +36,11 @@
-
+
@@ -90,7 +91,7 @@
-
+
diff --git a/Kiwix/CoreData/Migration/1.8.xcmappingmodel/xcmapping.xml b/Kiwix/CoreData/Migration/1.8.xcmappingmodel/xcmapping.xml
deleted file mode 100644
index 4dfbd2ce..00000000
--- a/Kiwix/CoreData/Migration/1.8.xcmappingmodel/xcmapping.xml
+++ /dev/null
@@ -1,318 +0,0 @@
-
-
-
-
-
- 134481920
- AE8F995C-4A62-4E29-98FB-89EFF72A63B2
- 155
-
-
-
- NSPersistenceFrameworkVersion
- 752
- NSStoreModelVersionHashes
-
- XDDevAttributeMapping
-
- 0plcXXRN7XHKl5CcF+fwriFmUpON3ZtcI/AfK748aWc=
-
- XDDevEntityMapping
-
- qeN1Ym3TkWN1G6dU9RfX6Kd2ccEvcDVWHpd3LpLgboI=
-
- XDDevMappingModel
-
- EqtMzvRnVZWkXwBHu4VeVGy8UyoOe+bi67KC79kphlQ=
-
- XDDevPropertyMapping
-
- XN33V44TTGY4JETlMoOB5yyTKxB+u4slvDIinv0rtGA=
-
- XDDevRelationshipMapping
-
- akYY9LhehVA/mCb4ATLWuI9XGLcjpm14wWL1oEBtIcs=
-
-
- NSStoreModelVersionHashesVersion
- 3
- NSStoreModelVersionIdentifiers
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Kiwix/CoreData/Migration/MigrationPolicy.swift b/Kiwix/CoreData/Migration/MigrationPolicy.swift
index 8abe2c05..c2aa051e 100644
--- a/Kiwix/CoreData/Migration/MigrationPolicy.swift
+++ b/Kiwix/CoreData/Migration/MigrationPolicy.swift
@@ -14,3 +14,13 @@ class MigrationPolicy1_5: NSEntityMigrationPolicy {
return !bool
}
}
+
+class MigrationPolicy1_8: NSEntityMigrationPolicy {
+ func bookState(bool: NSNumber?) -> NSNumber {
+ if let bool = bool?.boolValue {
+ return bool ? NSNumber(integer: 2) : NSNumber(integer: 0)
+ } else {
+ return NSNumber(integer: 1)
+ }
+ }
+}
diff --git a/Kiwix/Operations/BookOperation.swift b/Kiwix/Operations/BookOperation.swift
index 452dd619..02bddc68 100644
--- a/Kiwix/Operations/BookOperation.swift
+++ b/Kiwix/Operations/BookOperation.swift
@@ -31,7 +31,7 @@ class DownloadBookOperation: URLSessionDownloadTaskOperation {
guard let bookID = self.bookID,
let book = Book.fetch(bookID, context: context),
let downloadTask = DownloadTask.addOrUpdate(book, context: context) else {return}
- book.isLocal = nil
+ book.state = .Downloading
downloadTask.state = .Queued
// Overwrite progress
@@ -75,14 +75,14 @@ class DownloadBookOperation: URLSessionDownloadTaskOperation {
context.performBlockAndWait({
guard let bookID = self.bookID,
let book = Book.fetch(bookID, context: context) else {return}
- book.isLocal = nil
+ book.state = .Downloading
})
} else {
let context = NSManagedObjectContext.mainQueueContext
context.performBlockAndWait({
guard let bookID = self.bookID,
let book = Book.fetch(bookID, context: context) else {return}
- book.isLocal = false
+ book.state = .Cloud
guard let downloadTask = book.downloadTask else {return}
context.deleteObject(downloadTask)
diff --git a/Kiwix/Operations/RefreshLibraryOperation.swift b/Kiwix/Operations/RefreshLibraryOperation.swift
index 9862c05c..8ba2a1d0 100644
--- a/Kiwix/Operations/RefreshLibraryOperation.swift
+++ b/Kiwix/Operations/RefreshLibraryOperation.swift
@@ -114,7 +114,7 @@ private class Process: Operation, NSXMLParserDelegate, AutomaticInjectionOperati
guard let book = Book.fetch(id, context: self.context) else {return}
// Delete Book object only if book is online, i.e., is not associated with a download task or is not local
- guard book.isLocal == false else {return}
+ guard book.state == .Cloud else {return}
self.context.deleteObject(book)
self.hasUpdate = true
})
diff --git a/Kiwix/Operations/ScanLocalBookOperation.swift b/Kiwix/Operations/ScanLocalBookOperation.swift
index eb0d2cae..84314b7a 100644
--- a/Kiwix/Operations/ScanLocalBookOperation.swift
+++ b/Kiwix/Operations/ScanLocalBookOperation.swift
@@ -74,7 +74,7 @@ class ScanLocalBookOperation: Operation {
for id in removedZimFileIDs {
guard let book = localBooks[id] else {continue}
if let _ = book.meta4URL {
- book.isLocal = false
+ book.state = .Cloud
} else {
context.deleteObject(book)
}
@@ -86,7 +86,7 @@ class ScanLocalBookOperation: Operation {
let book = Book.fetch(id, context: NSManagedObjectContext.mainQueueContext)
return book ?? Book.add(reader.metaData, context: NSManagedObjectContext.mainQueueContext)
}() else {return}
- book.isLocal = true
+ book.state = .Local
book.hasIndex = reader.hasIndex()
book.hasPic = !reader.fileURL.absoluteString!.containsString("nopic")
if let downloadTask = book.downloadTask {context.deleteObject(downloadTask)}
diff --git a/Kiwix/ZimMultiReader/ZimMultiReader.swift b/Kiwix/ZimMultiReader/ZimMultiReader.swift
index 81ae2834..1218a1df 100644
--- a/Kiwix/ZimMultiReader/ZimMultiReader.swift
+++ b/Kiwix/ZimMultiReader/ZimMultiReader.swift
@@ -88,7 +88,8 @@ class ZimMultiReader: NSObject, DirectoryMonitorDelegate {
// MARK: - Loading System
- func data(id: String, contentURLString: String) -> [String: AnyObject]? {
+ func data(host: String, contentURLString: String) -> [String: AnyObject]? {
+ let id = pidMap[host] ?? host
guard let reader = readers[id] else {return nil}
return reader.dataWithContentURLString(contentURLString) as? [String: AnyObject]
}