Lang Select Localization + Refactor

This commit is contained in:
Chris Li 2016-06-12 16:27:22 -04:00
parent e32e0664b1
commit 653b3bbdab
8 changed files with 25 additions and 168 deletions

View File

@ -87,7 +87,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, OperationQueueDelegate {
// The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
// Create the coordinator and store
let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
let url = NSFileManager.libDirURL.URLByAppendingPathComponent("kiwix.sqlite")
let libDirPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomainMask.UserDomainMask, true).first!
let libDirURL = NSURL(fileURLWithPath: libDirPath, isDirectory: true)
let url = libDirURL.URLByAppendingPathComponent("kiwix.sqlite")
var failureReason = "There was an error creating or loading the application's saved data."
do {
let options = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]

View File

@ -11,7 +11,7 @@ import CoreData
class LanguageTBVC: UITableViewController, NSFetchedResultsControllerDelegate {
let managedObjectContext = UIApplication.appDelegate.managedObjectContext
let managedObjectContext = NSManagedObjectContext.mainQueueContext
var showLanguageSet = Set<Language>()
var showLanguages = [Language]()
var hideLanguages = [Language]()
@ -19,7 +19,7 @@ class LanguageTBVC: UITableViewController, NSFetchedResultsControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
title = "Languages"
title = NSLocalizedString("Languages", comment: "Language selection: Title")
showLanguages = Language.fetch(displayed: true, context: managedObjectContext)
hideLanguages = Language.fetch(displayed: false, context: managedObjectContext)
@ -97,9 +97,9 @@ class LanguageTBVC: UITableViewController, NSFetchedResultsControllerDelegate {
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if showLanguages.count == 0 {
return section == 0 ? "" : "ALL "
return section == 0 ? "" : NSLocalizedString("ALL", comment: "Language selection: table section title") + " "
} else {
return section == 0 ? "SHOWING" : "HIDING"
return section == 0 ? NSLocalizedString("SHOWING", comment: "Language selection: table section title") : NSLocalizedString("HIDING", comment: "Language selection: table section title")
}
}

View File

@ -14,7 +14,7 @@ import DateTools
class LibraryOnlineTBVC: UITableViewController, NSFetchedResultsControllerDelegate, BookTableCellDelegate, LTBarButtonItemDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
var booksShowingDetail = Set<Book>()
var messsageLabelConfigTimer: NSTimer?
var messsageLabelRefreshTimer: NSTimer?
var refreshing = false
// MARK: - Override
@ -35,12 +35,12 @@ class LibraryOnlineTBVC: UITableViewController, NSFetchedResultsControllerDelega
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
segmentedControl.selectedSegmentIndex = 0
messsageLabelConfigTimer = NSTimer.scheduledTimerWithTimeInterval(60.0, target: self, selector: #selector(configureMessage), userInfo: nil, repeats: true)
messsageLabelRefreshTimer = NSTimer.scheduledTimerWithTimeInterval(60.0, target: self, selector: #selector(configureMessage), userInfo: nil, repeats: true)
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
messsageLabelConfigTimer?.invalidate()
messsageLabelRefreshTimer?.invalidate()
}

View File

@ -36,7 +36,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>14</string>
<string>19</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>

View File

@ -1,127 +0,0 @@
//
// NSFileManager+.swift
// Grid
//
// Created by Chris on 12/10/15.
// Copyright © 2015 Chris. All rights reserved.
//
import UIKit
extension NSFileManager {
// MARK: - Path Utilities
class var docDirPath: String {
let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
return paths.first!
}
class var docDirURL: NSURL {
return NSURL(fileURLWithPath: docDirPath, isDirectory: true)
}
class var libDirPath: String {
let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomainMask.UserDomainMask, true)
return paths.first!
}
class var libDirURL: NSURL {
return NSURL(fileURLWithPath: libDirPath, isDirectory: true)
}
// MARK: - Move Book
class func move(book: Book, fromURL: NSURL, suggestedFileName: String?) {
let fileName: String = {
if let suggestedFileName = suggestedFileName {return suggestedFileName}
if let id = book.id {return "\(id).zim"}
return NSDate().description + ".zim"
}()
let directory = docDirURL
createDirectory(directory, includeInICloudBackup: false)
let destination = directory.URLByAppendingPathComponent(fileName)
moveOrReplaceFile(from: fromURL, to: destination)
}
// MARK: - Book Resume Data
class func resumeDataURL(book: Book) -> NSURL {
let tempDownloadLocation = NSURL(fileURLWithPath: libDirPath).URLByAppendingPathComponent("DownloadTemp", isDirectory: true)
return tempDownloadLocation.URLByAppendingPathComponent(book.id ?? NSDate().description, isDirectory: false)
}
class func saveResumeData(data: NSData, book: Book) {
let tempDownloadLocation = NSURL(fileURLWithPath: libDirPath).URLByAppendingPathComponent("DownloadTemp", isDirectory: true)
if !NSFileManager.defaultManager().fileExistsAtPath(tempDownloadLocation.path!) {
do {
try NSFileManager.defaultManager().createDirectoryAtURL(tempDownloadLocation, withIntermediateDirectories: true, attributes: [NSURLIsExcludedFromBackupKey: true])
} catch let error as NSError {
print("Create temp download folder failed: \(error.localizedDescription)")
}
}
data.writeToURL(resumeDataURL(book), atomically: true)
}
class func readResumeData(book: Book) -> NSData? {
guard let path = resumeDataURL(book).path else {return nil}
return NSFileManager.defaultManager().contentsAtPath(path)
}
class func removeResumeData(book: Book) {
if NSFileManager.defaultManager().fileExistsAtPath(resumeDataURL(book).path!) {
removeFile(atURL: resumeDataURL(book))
}
}
// MARK: General Move File
class func removeFile(atURL location: NSURL) -> Bool {
var succeed = true
do {
try NSFileManager.defaultManager().removeItemAtURL(location)
} catch let error as NSError {
succeed = false
print("Remove File failed: \(error.localizedDescription)")
}
return succeed
}
class func moveOrReplaceFile(from fromURL: NSURL, to toURL: NSURL) -> Bool {
var succeed = true
guard let path = toURL.path else {return false}
if NSFileManager.defaultManager().fileExistsAtPath(path) {
succeed = removeFile(atURL: toURL)
}
do {
try NSFileManager.defaultManager().moveItemAtURL(fromURL, toURL: toURL)
} catch let error as NSError {
succeed = false
print("Move File failed: \(error.localizedDescription)")
}
return succeed
}
class func createDirectory(url: NSURL, includeInICloudBackup: Bool) {
guard let path = url.path else {return}
do {
try NSFileManager.defaultManager().createDirectoryAtPath(path, withIntermediateDirectories: true, attributes: [NSURLIsExcludedFromBackupKey: true])
} catch let error as NSError {
print("Create Directory failed: \(error.localizedDescription)")
}
}
// MARK: - Directory Contents
class func contentsOfDirectoryAtURL(url: NSURL) -> [NSURL]? {
do {
return try NSFileManager.defaultManager().contentsOfDirectoryAtURL(url, includingPropertiesForKeys: [NSURLFileResourceTypeKey], options: NSDirectoryEnumerationOptions.SkipsHiddenFiles)
} catch let error as NSError {
print(error.localizedDescription)
return nil
}
}
}

View File

@ -11,7 +11,8 @@ import UIKit
class Utilities: NSObject {
class func availableDiskspaceInBytes() -> Int64? {
do {
let systemAttributes = try NSFileManager.defaultManager().attributesOfFileSystemForPath(NSFileManager.docDirPath)
let docDirPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).first!
let systemAttributes = try NSFileManager.defaultManager().attributesOfFileSystemForPath(docDirPath)
guard let freeSize = systemAttributes[NSFileSystemFreeSize] as? NSNumber else {return nil}
return freeSize.longLongValue
} catch let error as NSError {

View File

@ -10,10 +10,9 @@ import Foundation
import CoreData
import UIKit
// MARK: -
// MARK: - CoreData
extension NSFetchedResultsController {
func performFetch(deleteCache deleteCache: Bool) {
do {
if deleteCache {
@ -28,6 +27,12 @@ extension NSFetchedResultsController {
}
}
extension NSManagedObjectContext {
class var mainQueueContext: NSManagedObjectContext {
return (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
}
}
// MARK: - UI
extension UIStoryboard {
@ -79,10 +84,4 @@ extension UIAlertController {
self.init(title: title, message: message , preferredStyle: style)
for action in actions {addAction(action)}
}
}
extension NSManagedObjectContext {
class var mainQueueContext: NSManagedObjectContext {
return (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
}
}

View File

@ -105,7 +105,6 @@
971A106F1D022E62007FC62C /* DownloadProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A106D1D022E62007FC62C /* DownloadProgress.swift */; };
971A10701D022E62007FC62C /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A106E1D022E62007FC62C /* Network.swift */; };
971A10721D022E74007FC62C /* KiwixURLProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A10711D022E74007FC62C /* KiwixURLProtocol.swift */; };
971A10741D022E80007FC62C /* NSFileManager+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A10731D022E80007FC62C /* NSFileManager+.swift */; };
971A10771D022F05007FC62C /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 971A10791D022F05007FC62C /* Localizable.stringsdict */; };
971A107E1D022F74007FC62C /* DownloaderLearnMore.html in Resources */ = {isa = PBXBuildFile; fileRef = 971A107A1D022F74007FC62C /* DownloaderLearnMore.html */; };
971A107F1D022F74007FC62C /* ImportBookLearnMore.html in Resources */ = {isa = PBXBuildFile; fileRef = 971A107B1D022F74007FC62C /* ImportBookLearnMore.html */; };
@ -160,6 +159,7 @@
9763A62C1CEBA4F9008A2718 /* DirectoryMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97A714091C274FCB00951244 /* DirectoryMonitor.swift */; };
9763A62D1CEBA524008A2718 /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97E891681CA976E90001CA32 /* FileManager.swift */; };
976AB2671CBD8B3D00B06EB0 /* 1.5.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 976AB2661CBD8B3D00B06EB0 /* 1.5.xcmappingmodel */; };
977305361D0DFD110081B8F0 /* KiwixURLProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A10711D022E74007FC62C /* KiwixURLProtocol.swift */; };
977998741C1E0B7900B1DD5E /* Book+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9779986E1C1E0B7900B1DD5E /* Book+CoreDataProperties.swift */; };
977998751C1E0B7900B1DD5E /* DownloadTask+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9779986F1C1E0B7900B1DD5E /* DownloadTask+CoreDataProperties.swift */; };
977998761C1E0B7900B1DD5E /* DownloadTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 977998701C1E0B7900B1DD5E /* DownloadTask.swift */; };
@ -407,7 +407,6 @@
971A106D1D022E62007FC62C /* DownloadProgress.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DownloadProgress.swift; path = "Kiwix-iOS/Model/DownloadProgress.swift"; sourceTree = SOURCE_ROOT; };
971A106E1D022E62007FC62C /* Network.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Network.swift; path = "Kiwix-iOS/Model/Network.swift"; sourceTree = SOURCE_ROOT; };
971A10711D022E74007FC62C /* KiwixURLProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = KiwixURLProtocol.swift; path = "Kiwix-iOS/Model/KiwixURLProtocol.swift"; sourceTree = SOURCE_ROOT; };
971A10731D022E80007FC62C /* NSFileManager+.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSFileManager+.swift"; path = "Kiwix-iOS/Model/NSFileManager+.swift"; sourceTree = SOURCE_ROOT; };
971A10781D022F05007FC62C /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = en; path = en.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
971A107A1D022F74007FC62C /* DownloaderLearnMore.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = DownloaderLearnMore.html; path = Kiwix/HelpDocuments/DownloaderLearnMore.html; sourceTree = SOURCE_ROOT; };
971A107B1D022F74007FC62C /* ImportBookLearnMore.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = ImportBookLearnMore.html; path = Kiwix/HelpDocuments/ImportBookLearnMore.html; sourceTree = SOURCE_ROOT; };
@ -867,6 +866,7 @@
9779987A1C1E1C9600B1DD5E /* Extensions.swift */,
97E891681CA976E90001CA32 /* FileManager.swift */,
979C51511CECA9AF001707F2 /* StringTools.swift */,
971A10711D022E74007FC62C /* KiwixURLProtocol.swift */,
97254FDD1C26442F0056950B /* ZIMMultiReader */,
);
name = Shared;
@ -966,14 +966,6 @@
name = Setting;
sourceTree = "<group>";
};
977998851C1E2C2600B1DD5E /* Utilities */ = {
isa = PBXGroup;
children = (
971A106B1D022E50007FC62C /* Utilities.swift */,
);
name = Utilities;
sourceTree = "<group>";
};
978C58791C1CCC920077AE47 /* Supporting */ = {
isa = PBXGroup;
children = (
@ -1015,10 +1007,9 @@
978C588B1C1CD1E30077AE47 /* Model */ = {
isa = PBXGroup;
children = (
97EE24EF1C2078A400DFC672 /* Extension */,
971A10711D022E74007FC62C /* KiwixURLProtocol.swift */,
975B90FD1CEB909100D13906 /* iOSExtensions.swift */,
971904A41CA3204B002E9CFF /* Network */,
977998851C1E2C2600B1DD5E /* Utilities */,
971A106B1D022E50007FC62C /* Utilities.swift */,
);
name = Model;
path = Kiwix;
@ -1249,15 +1240,6 @@
path = Kiwix;
sourceTree = "<group>";
};
97EE24EF1C2078A400DFC672 /* Extension */ = {
isa = PBXGroup;
children = (
975B90FD1CEB909100D13906 /* iOSExtensions.swift */,
971A10731D022E80007FC62C /* NSFileManager+.swift */,
);
name = Extension;
sourceTree = "<group>";
};
CFDF64EC6F9DB861DEEB91A0 /* Frameworks */ = {
isa = PBXGroup;
children = (
@ -1679,6 +1661,7 @@
979CB6741D05C44F005E1BA1 /* UserNotificationCondition.swift in Sources */,
975227A31D020C00001D1DDE /* stringTools.cpp in Sources */,
979CB6601D05C44F005E1BA1 /* HealthCondition.swift in Sources */,
977305361D0DFD110081B8F0 /* KiwixURLProtocol.swift in Sources */,
979CB6721D05C44F005E1BA1 /* SilentCondition.swift in Sources */,
979CB65A1D05C44F005E1BA1 /* UserNotificationCapability.swift in Sources */,
979CB6B21D05C520005E1BA1 /* DelayOperation.swift in Sources */,
@ -1853,7 +1836,6 @@
979CB6B31D05C520005E1BA1 /* Dictionary+Operations.swift in Sources */,
979CB64B1D05C44F005E1BA1 /* LocationCapability-iOS.swift in Sources */,
979CB6611D05C44F005E1BA1 /* LocationCondition.swift in Sources */,
971A10741D022E80007FC62C /* NSFileManager+.swift in Sources */,
971A102D1D022AD5007FC62C /* BookCollectionCell.swift in Sources */,
971A10601D022DF2007FC62C /* LanguageTBVC.swift in Sources */,
971A106A1D022E15007FC62C /* BookmarkHUDVC.swift in Sources */,