mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-27 05:49:25 -04:00
Basic setup for UserHabit
This commit is contained in:
parent
0f7d7f7bd1
commit
ff739d2e17
@ -32,30 +32,35 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
func applicationDidBecomeActive(_ application: UIApplication) {
|
||||
ZimMultiReader.shared.startScan()
|
||||
UserHabit.shared.appDidBecomeActive()
|
||||
}
|
||||
|
||||
func applicationWillResignActive(_ application: UIApplication) {
|
||||
let type = "org.kiwix.recent"
|
||||
let previousIndex: Int? = {
|
||||
guard let recent = UIApplication.shared.shortcutItems?.filter({$0.type == type}).first else {return nil}
|
||||
return UIApplication.shared.shortcutItems?.index(of: recent)
|
||||
}()
|
||||
|
||||
if let index = previousIndex { UIApplication.shared.shortcutItems?.remove(at: index) }
|
||||
|
||||
if let article = AppDelegate.mainController.article,
|
||||
let title = article.title, let url = article.url?.absoluteString {
|
||||
let item = UIMutableApplicationShortcutItem(type: type,
|
||||
localizedTitle: title,
|
||||
localizedSubtitle: nil,
|
||||
icon: UIApplicationShortcutIcon(templateImageName: "Recent"),
|
||||
userInfo: ["URL": url])
|
||||
if let index = previousIndex {
|
||||
UIApplication.shared.shortcutItems?.insert(item, at: index)
|
||||
} else {
|
||||
UIApplication.shared.shortcutItems?.append(item)
|
||||
func updateQuickActions() {
|
||||
let type = "org.kiwix.recent"
|
||||
let previousIndex: Int? = {
|
||||
guard let recent = UIApplication.shared.shortcutItems?.filter({$0.type == type}).first else {return nil}
|
||||
return UIApplication.shared.shortcutItems?.index(of: recent)
|
||||
}()
|
||||
|
||||
if let index = previousIndex { UIApplication.shared.shortcutItems?.remove(at: index) }
|
||||
|
||||
if let article = AppDelegate.mainController.article,
|
||||
let title = article.title, let url = article.url?.absoluteString {
|
||||
let item = UIMutableApplicationShortcutItem(type: type,
|
||||
localizedTitle: title,
|
||||
localizedSubtitle: nil,
|
||||
icon: UIApplicationShortcutIcon(templateImageName: "Recent"),
|
||||
userInfo: ["URL": url])
|
||||
if let index = previousIndex {
|
||||
UIApplication.shared.shortcutItems?.insert(item, at: index)
|
||||
} else {
|
||||
UIApplication.shared.shortcutItems?.append(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
updateQuickActions()
|
||||
UserHabit.shared.appDidBecomeActive()
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
|
@ -24,6 +24,7 @@
|
||||
971A107F1D022F74007FC62C /* ImportBookLearnMore.html in Resources */ = {isa = PBXBuildFile; fileRef = 971A107B1D022F74007FC62C /* ImportBookLearnMore.html */; };
|
||||
971A10801D022F74007FC62C /* Pic_I.png in Resources */ = {isa = PBXBuildFile; fileRef = 971A107C1D022F74007FC62C /* Pic_I.png */; };
|
||||
971A10811D022F74007FC62C /* Pic_P.png in Resources */ = {isa = PBXBuildFile; fileRef = 971A107D1D022F74007FC62C /* Pic_P.png */; };
|
||||
9725345F1E43E2250005D169 /* UserHabit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9725345E1E43E2250005D169 /* UserHabit.swift */; };
|
||||
9726591D1D90A64600D1DFFB /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9726591C1D90A64500D1DFFB /* Notification.swift */; };
|
||||
972F81571DDBFC79008D7289 /* Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = 972F81561DDBFC79008D7289 /* Search.swift */; };
|
||||
972F81591DDC1B71008D7289 /* Controllers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 972F81581DDC1B71008D7289 /* Controllers.swift */; };
|
||||
@ -168,6 +169,7 @@
|
||||
971A107D1D022F74007FC62C /* Pic_P.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Pic_P.png; path = Kiwix/HelpDocuments/Pic_P.png; sourceTree = SOURCE_ROOT; };
|
||||
971C4F0B1D3FFFA60027B7D2 /* Kiwix.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = Kiwix.entitlements; path = "Kiwix-iOS/Kiwix.entitlements"; sourceTree = SOURCE_ROOT; };
|
||||
97219DBC1D383A00009FDFF1 /* BookmarkHUD.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BookmarkHUD.swift; path = "Kiwix-iOS/Controller/Bookmark/BookmarkHUD.swift"; sourceTree = SOURCE_ROOT; };
|
||||
9725345E1E43E2250005D169 /* UserHabit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserHabit.swift; sourceTree = "<group>"; };
|
||||
9726591A1D8DB91200D1DFFB /* DownloadProgress.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DownloadProgress.swift; sourceTree = "<group>"; };
|
||||
9726591C1D90A64500D1DFFB /* Notification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
|
||||
972F81561DDBFC79008D7289 /* Search.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Search.swift; sourceTree = "<group>"; };
|
||||
@ -604,6 +606,7 @@
|
||||
97A9F6F41E2E990500F423AA /* JSInject.js */,
|
||||
97A1FD401D6F728200A80EE2 /* Preference.swift */,
|
||||
97A1FD411D6F728200A80EE2 /* StringTools.swift */,
|
||||
9725345E1E43E2250005D169 /* UserHabit.swift */,
|
||||
);
|
||||
path = Tools;
|
||||
sourceTree = "<group>";
|
||||
@ -989,6 +992,7 @@
|
||||
977AE7F91DD8F22400F1E581 /* SearchBar.swift in Sources */,
|
||||
97ED50111DD257D00089E9B6 /* Kiwix.xcdatamodeld in Sources */,
|
||||
9705D5981E368933005292AC /* CoreDataCollectionBaseController.swift in Sources */,
|
||||
9725345F1E43E2250005D169 /* UserHabit.swift in Sources */,
|
||||
97A127C91D777CF100FB204D /* RecentSearchController.swift in Sources */,
|
||||
97599AE21E28193D00BA15EF /* BookmarkCollectionController.swift in Sources */,
|
||||
);
|
||||
|
27
Kiwix/Tools/UserHabit.swift
Normal file
27
Kiwix/Tools/UserHabit.swift
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// UserHabit.swift
|
||||
// Kiwix
|
||||
//
|
||||
// Created by Chris Li on 2/2/17.
|
||||
// Copyright © 2017 Chris Li. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class UserHabit {
|
||||
static let shared = UserHabit()
|
||||
private init() {}
|
||||
|
||||
// MARK: - App Become Active
|
||||
|
||||
private var timeAppDidBecomeActive: Date?
|
||||
|
||||
func appDidBecomeActive() {
|
||||
timeAppDidBecomeActive = Date()
|
||||
}
|
||||
|
||||
func appWillResignActive() {
|
||||
let interval = timeAppDidBecomeActive?.timeIntervalSinceNow
|
||||
print(interval)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user