Skip to content

Commit

Permalink
Merge branch '1.7'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.gitignore
  • Loading branch information
Chris Li committed Aug 5, 2016
2 parents 9259c9f + b436327 commit 536a129
Show file tree
Hide file tree
Showing 137 changed files with 2,994 additions and 5,285 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ Kiwix/libkiwix/C&C++
Kiwix/libkiwix/include
Kiwix/libkiwix/shared
Kiwix/libkiwix/static
<<<<<<< HEAD
*.a
=======
Kiwix/libkiwix/iOS
Kiwix/libkiwix/macOS
>>>>>>> 1.7
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Designs/Icons/bookmark.psd
Binary file not shown.
92 changes: 78 additions & 14 deletions Kiwix-iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@

import UIKit
import CoreData
import PSOperations

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, OperationQueueDelegate {

var window: UIWindow?
var mainController: MainController? {
return (window?.rootViewController as? UINavigationController)?.topViewController as? MainController
}

private let recentShortcutTypeString = "org.kiwix.recent"

func recordActiveSession() {
Preference.activeUseHistory.append(NSDate())
}

// MARK: -

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
NSURLProtocol.registerClass(KiwixURLProtocol)
Expand All @@ -28,22 +36,89 @@ class AppDelegate: UIResponder, UIApplicationDelegate, OperationQueueDelegate {
return true
}

func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
switch shortcutItem.type {
case "org.kiwix.search":
mainController?.hidePresentedController(false, completion: {
self.mainController?.showSearch(animated: false)
completionHandler(true)
})
case "org.kiwix.bookmarks":
mainController?.hidePresentedController(false, completion: {
self.mainController?.hideSearch(animated: false)
self.mainController?.showBookmarkTBVC()
completionHandler(true)
})
case recentShortcutTypeString:
guard let urlString = shortcutItem.userInfo?["URL"] as? String else {completionHandler(false); return}
mainController?.load(NSURL(string: urlString))
completionHandler(true)
default:
completionHandler(false)
return
}
}

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
// Here we get what notification permission user currently allows
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
self.saveContext()
}

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
guard url.scheme.caseInsensitiveCompare("kiwix") == .OrderedSame else {return false}
mainController?.load(url)
return true
}

// MARK: - Active

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
NSTimer.scheduledTimerWithTimeInterval(60.0, target: self, selector: #selector(AppDelegate.recordActiveSession), userInfo: nil, repeats: false)
removeAllDynamicShortcutItems()
}

func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
// UIApplication.updateApplicationIconBadgeNumber()

//UIApplication.updateApplicationIconBadgeNumber()

if let article = mainController?.article {
addRecentArticleShortCutItem(article)
}
}

// class func updateApplicationIconBadgeNumber() {
// guard let settings = UIApplication.sharedApplication().currentUserNotificationSettings() else {return}
// guard settings.types.contains(UIUserNotificationType.Badge) else {return}
// //UIApplication.sharedApplication().applicationIconBadgeNumber = downloader.taskCount ?? 0
// }

// MARK: - Shotcut Items

func removeAllDynamicShortcutItems() {
guard let items = UIApplication.sharedApplication().shortcutItems?.filter({$0.type == recentShortcutTypeString}) else {return}
for item in items {
guard let index = UIApplication.sharedApplication().shortcutItems?.indexOf(item) else {continue}
UIApplication.sharedApplication().shortcutItems?.removeAtIndex(index)
}
}

func addRecentArticleShortCutItem(article: Article) {
guard let title = article.title, let url = article.urlString else {return}
let icon = UIApplicationShortcutIcon(templateImageName: "Recent")
let item = UIMutableApplicationShortcutItem(type: recentShortcutTypeString, localizedTitle: title, localizedSubtitle: "", icon: icon, userInfo: ["URL": url])
UIApplication.sharedApplication().shortcutItems?.append(item)
}

// MARK: - Background

func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
Expand All @@ -52,18 +127,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, OperationQueueDelegate {
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
NSTimer.scheduledTimerWithTimeInterval(60.0, target: self, selector: #selector(AppDelegate.recordActiveSession), userInfo: nil, repeats: false)
ZIMMultiReader.sharedInstance.rescan()
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
self.saveContext()
}

func application(application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: () -> Void) {
Network.sharedInstance.rejoinSessionWithIdentifier(identifier, completionHandler: completionHandler)
Expand Down Expand Up @@ -115,6 +178,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, OperationQueueDelegate {
let coordinator = self.persistentStoreCoordinator
var managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
managedObjectContext.persistentStoreCoordinator = coordinator
managedObjectContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
return managedObjectContext
}()

Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Kiwix-iOS/Assets.xcassets/BookmarkAdded.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "BookmarkAdded.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"idiom" : "universal",
"filename" : "BlankImage.png",
"filename" : "favorite.png",
"scale" : "3x"
}
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Kiwix-iOS/Assets.xcassets/BookmarkRemoved.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "BookmarkRemoved.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"idiom" : "universal",
"filename" : "magnifying-glass34.png",
"filename" : "magnifying-glass-2.png",
"scale" : "3x"
}
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
21 changes: 21 additions & 0 deletions Kiwix-iOS/Assets.xcassets/Recent.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "counterclockwise-rotation.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"idiom" : "universal",
"filename" : "multimedia.png",
"filename" : "star.png",
"scale" : "3x"
}
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions Kiwix-iOS/Assets.xcassets/StarShortcut.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "star-1.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions Kiwix-iOS/Controller/Bookmark/BookmarkController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// BookmarkController.swift
// Kiwix
//
// Created by Chris Li on 7/14/16.
// Copyright © 2016 Chris. All rights reserved.
//

import UIKit

class BookmarkController: UIViewController {

var bookmarkAdded = true
private var timer: NSTimer?

@IBOutlet weak var centerView: UIView!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var label: UILabel!
@IBOutlet weak var messageLabel: UILabel!
@IBOutlet weak var centerViewYOffset: NSLayoutConstraint!

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
setNeedsStatusBarAppearanceUpdate()
label.text = bookmarkAdded ? NSLocalizedString("Bookmarked", comment: "Bookmark Overlay") : NSLocalizedString("Removed", comment: "Bookmark Overlay")
messageLabel.text = NSLocalizedString("Tap anywhere to dismiss", comment: "Bookmark Overlay")
messageLabel.alpha = 1.0
imageView.highlighted = !bookmarkAdded
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(BookmarkController.dismissSelf), userInfo: nil, repeats: false)
}

@IBAction func tapRecognized(sender: UITapGestureRecognizer) {
dismissSelf()
}

func dismissSelf() {
dismissViewControllerAnimated(true, completion: nil)
}

var topHalfHeight: CGFloat {
return centerView.frame.height / 2 + imageView.frame.height
}

var bottomHalfHeight: CGFloat {
return centerView.frame.height / 2 + label.frame.height
}
}
Loading

0 comments on commit 536a129

Please sign in to comment.