-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStickerPageViewControllerDataSource.swift
More file actions
49 lines (41 loc) · 1.54 KB
/
StickerPageViewControllerDataSource.swift
File metadata and controls
49 lines (41 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import UIKit
/**
* Creates StickerPickerViewController instances from StickerPack objects.
*/
public class StickerPageViewControllerDataSource
: NSObject
, ArrayPageViewControllerDataSource
{
private let stickerPacks: [StickerPack]
private weak var stickerPickerDelegate: StickerPickerViewDelegate?
public init(stickerPacks: [StickerPack], stickerPickerDelegate: StickerPickerViewDelegate) {
self.stickerPacks = stickerPacks
self.stickerPickerDelegate = stickerPickerDelegate
}
public func create(index: Int) -> UIViewController {
let pack = self.stickerPacks[index]
let controller = StickerPickerViewController()
controller.stickerPack = pack
controller.delegate = self.stickerPickerDelegate
return controller
}
public func indexOf(viewController: UIViewController) -> Int {
let pack = (viewController as! StickerPickerViewController).stickerPack!
return self.stickerPacks.firstIndex { $0.url == pack.url }!
}
public func count() -> Int {
return self.stickerPacks.count
}
public func initialPage() -> Int? {
if !PreferenceManager.shared.rememberSelectedPack() {
return nil
}
guard let pageUrl = PreferenceManager.standard.lastStickerPageUrl() else { return nil }
return self.stickerPacks.firstIndex {
$0.url.path == pageUrl
}
}
public func didShowPage(index: Int) {
PreferenceManager.standard.setLastStickerPageUrl(self.stickerPacks[index].url.path)
}
}