-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.swift
173 lines (134 loc) · 6.5 KB
/
App.swift
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//
// App.swift
// Kapıştır
//
// Created by Evren Yortuçboylu on 13/03/16.
// Copyright © 2016 Evren Yortuçboylu. All rights reserved.
//
import Foundation
import AVFoundation
import Kingfisher
import Crashlytics
struct App {
struct UI {
static let batchSize = 10
static var onboarded = false
static var createOnboarded = false
static let DEBUG = 0
static let questionScrollDelay = UInt32(1300000)
static let colorButtonFollow = UIColor(red: 176/255, green: 193/255, blue: 206/255, alpha: 1.0)
static func showServerError(completion completionCallback: (()->Void)?) {
let alert = UIAlertController(
title: "Sunucu Hatası",
message: "İnternete bağlanılamıyor. Lütfen internet bağlantınızı kontrol ederek tekrar deneyiniz.",
preferredStyle: .Alert
)
alert.addAction(UIAlertAction(title: "Tamam", style: .Default, handler: { (action) -> Void in
alert.dismissViewControllerAnimated(true, completion: nil)
}))
App.UI.getTopMostViewController().presentViewController(alert, animated: true, completion: completionCallback)
}
static func noQuestionsLeftMessage() {
let alert = UIAlertController(
title: "Bu Kadar",
message: "Bugünlük bu kadar. Elimizde şu anda başka kapıştır kalmadı. Sen ekleyebilirsin!",
preferredStyle: .Alert
)
alert.addAction(UIAlertAction(title: "Peki", style: .Default, handler: { (action) -> Void in
alert.dismissViewControllerAnimated(true, completion: nil)
}))
App.UI.getTopMostViewController().presentViewController(alert, animated: true, completion: nil)
}
static func getTopMostViewController() -> UIViewController {
var topController = UIApplication.sharedApplication().keyWindow?.rootViewController
while let presentedViewController = topController!.presentedViewController {
topController = presentedViewController
}
return topController!
}
}
struct Play {
static var audioPlayer: AVAudioPlayer?
static func Applause(){
let soundFileUrl = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("applause", ofType: "mp3")!)
do{
audioPlayer = try AVAudioPlayer(contentsOfURL: soundFileUrl)
audioPlayer!.prepareToPlay()
audioPlayer!.play()
} catch {
}
}
static func Stop() {
audioPlayer?.stop()
}
}
struct URLs {
static var backendEndpoint: String!
static var getQuestionsUrl = "question/fetch/1"
static var uploadImage = "question/image"
static var saveUser = "user"
static var saveQuestion = "question"
static var saveAnswer = "answer"
static var getUserQuestions = "user/questions"
static var followQuestion = "favorite"
static var reportQuestion = "reportabuse"
static var deleteQuestion = "question/delete"
static var banUser = "user/block"
}
struct Keys {
static var clientId: String!
static var version: String!
static var installation: String!
static var requestHeaders: [String:String]!
}
struct Store {
static func loadAppSettings() {
let path = NSBundle.mainBundle().pathForResource("Info", ofType: "plist")
let dict = NSDictionary(contentsOfFile: path!)
let clientId = dict!.valueForKey("clientId") as? String
let version = dict!.valueForKey("version") as? String
let installation = dict!.valueForKey("installation") as? String
let backendEndpoint = dict!.valueForKey("backendEndpoint") as? String
App.Keys.clientId = clientId!
App.Keys.installation = installation!
App.Keys.version = version!
App.URLs.getQuestionsUrl = backendEndpoint! + App.URLs.getQuestionsUrl
App.URLs.uploadImage = backendEndpoint! + App.URLs.uploadImage
App.URLs.saveUser = backendEndpoint! + App.URLs.saveUser
App.URLs.saveQuestion = backendEndpoint! + App.URLs.saveQuestion
App.URLs.saveAnswer = backendEndpoint! + App.URLs.saveAnswer
App.URLs.getUserQuestions = backendEndpoint! + App.URLs.getUserQuestions
App.URLs.followQuestion = backendEndpoint! + App.URLs.followQuestion
App.URLs.reportQuestion = backendEndpoint! + App.URLs.reportQuestion
App.URLs.deleteQuestion = backendEndpoint! + App.URLs.deleteQuestion
App.URLs.banUser = backendEndpoint! + App.URLs.banUser
App.Keys.requestHeaders = [
"x-voter-client-id": App.Keys.clientId,
"x-voter-version": App.Keys.version,
"x-voter-installation": UIDevice.currentDevice().identifierForVendor!.UUIDString
]
App.Keys.installation = UIDevice.currentDevice().identifierForVendor!.UUIDString
App.UI.onboarded = true // NSUserDefaults.standardUserDefaults().valueForKey("onboarded") != nil
App.UI.createOnboarded = NSUserDefaults.standardUserDefaults().valueForKey("createOnboarded") != nil
print("createOnboarded \(UI.createOnboarded)")
print("app setting loaded \(App.Keys.requestHeaders)")
//let cache = KingfisherManager.sharedManager.cache
//cache.maxMemoryCost = 600*400*10
}
static func saveUserOnboarded() {
NSUserDefaults.standardUserDefaults().setValue("yes", forKey: "onboarded")
App.UI.onboarded = true
print("onboarded saved")
}
static func saveCreateOnboarded() {
NSUserDefaults.standardUserDefaults().setValue("yes", forKey: "createOnboarded")
App.UI.createOnboarded = true
print("createOnboarded saved")
}
}
struct Logging {
static func Log(text: String) {
CLSLogv(text + " %@", getVaList([UserStore.user?.facebookId ?? ""]))
}
}
}