Commit 191be8ea authored by Jose Blaya's avatar Jose Blaya

Toggle to retrieve messages

parent 52e57934
......@@ -88,6 +88,9 @@ class AppPreferences {
// Dedicated IP relations
static let tokenIPRelation = "TokenIPRelation"
// In app messages
static let stopInAppMessages = "stopInAppMessages"
}
static let shared = AppPreferences()
......@@ -418,6 +421,14 @@ class AppPreferences {
}
}
var stopInAppMessages: Bool {
get {
return defaults.bool(forKey: Entries.stopInAppMessages) ?? false
}
set {
defaults.set(newValue, forKey: Entries.stopInAppMessages)
}
}
private init() {
guard let defaults = UserDefaults(suiteName: AppConstants.appGroup) else {
......@@ -449,7 +460,8 @@ class AppPreferences {
Entries.successConnections: 0,
Entries.failureConnections: 0,
Entries.showGeoServers: true,
Entries.dismissedMessages: []
Entries.dismissedMessages: [],
Entries.stopInAppMessages: false
])
}
......@@ -604,6 +616,7 @@ class AppPreferences {
Client.resetServers(completionBlock: {_ in })
failureConnections = 0
showGeoServers = true
stopInAppMessages = false
dedicatedTokenIPReleation = [:]
MessagesManager.shared.reset()
}
......@@ -634,6 +647,7 @@ class AppPreferences {
Client.resetServers(completionBlock: {_ in })
failureConnections = 0
showGeoServers = true
stopInAppMessages = false
dismissedMessages = []
dedicatedTokenIPReleation = [:]
MessagesManager.shared.reset()
......
......@@ -40,14 +40,14 @@ public class MessagesManager: NSObject {
func refreshMessages() {
/* Not available yet
Client.providers.accountProvider.inAppMessages(forAppVersion: Macros.localizedVersionNumber()) { (message, error) in
if let message = message, !message.wasDismissed() {
self.apiMessage = message
Macros.postNotification(.PIAUpdateFixedTiles)
if !AppPreferences.shared.stopInAppMessages {
Client.providers.accountProvider.inAppMessages(forAppVersion: Macros.localizedVersionNumber()) { (message, error) in
if let message = message, !message.wasDismissed() {
self.apiMessage = message
Macros.postNotification(.PIAUpdateFixedTiles)
}
}
}
*/
}
func postSystemMessage(message: InAppMessage) {
......
......@@ -85,7 +85,9 @@ enum Setting: Int {
case mace
case darkTheme
case stopInAppMessages
case sendDebugLog
case resetSettings
......@@ -148,6 +150,8 @@ class SettingsViewController: AutolayoutViewController {
case autoConnectSettings
case inAppSettings
case geoSettings
case contentBlocker
......@@ -168,6 +172,7 @@ class SettingsViewController: AutolayoutViewController {
.ikeV2encryption,
.applicationSettings,
.autoConnectSettings,
.inAppSettings,
.geoSettings,
.applicationInformation,
.reset,
......@@ -197,6 +202,9 @@ class SettingsViewController: AutolayoutViewController {
], // dynamic
.applicationSettings: [], // dynamic
.autoConnectSettings: [], // dynamic
.inAppSettings: [
.stopInAppMessages
],
.geoSettings: [
.geoServers
],
......@@ -252,6 +260,8 @@ class SettingsViewController: AutolayoutViewController {
private lazy var switchEnvironment = UISwitch()
private lazy var switchInAppMessages = UISwitch()
private lazy var imvSelectedOption = UIImageView(image: Asset.accessorySelected.image)
private var isContentBlockerEnabled = false
......@@ -315,6 +325,7 @@ class SettingsViewController: AutolayoutViewController {
switchGeoServers.addTarget(self, action: #selector(toggleGEOServers(_:)), for: .valueChanged)
switchEnableNMT.addTarget(self, action: #selector(toggleNMT(_:)), for: .valueChanged)
switchEnvironment.addTarget(self, action: #selector(toggleEnv(_:)), for: .valueChanged)
switchInAppMessages.addTarget(self, action: #selector(toggleStopInAppMessages(_:)), for: .valueChanged)
redisplaySettings()
NotificationCenter.default.addObserver(self,
......@@ -437,6 +448,11 @@ class SettingsViewController: AutolayoutViewController {
redisplaySettings()
}
@objc private func toggleStopInAppMessages(_ sender: UISwitch) {
AppPreferences.shared.stopInAppMessages = sender.isOn
redisplaySettings()
}
@objc private func showContentBlockerTutorial() {
perform(segue: StoryboardSegue.Main.contentBlockerSegueIdentifier)
}
......@@ -953,6 +969,9 @@ extension SettingsViewController: UITableViewDataSource, UITableViewDelegate {
case .autoConnectSettings:
return nil
case .inAppSettings:
return nil
case .geoSettings:
return nil
......@@ -1283,6 +1302,13 @@ extension SettingsViewController: UITableViewDataSource, UITableViewDelegate {
cell.detailTextLabel?.text = nil
cell.accessoryView = switchEnvironment
cell.selectionStyle = .none
switchEnvironment.isOn = Client.environment == .staging
case .stopInAppMessages:
cell.textLabel?.text = L10n.Inapp.Messages.Toggle.title
cell.detailTextLabel?.text = nil
cell.accessoryView = switchInAppMessages
cell.selectionStyle = .none
switchInAppMessages.isOn = AppPreferences.shared.stopInAppMessages
case .customServers:
cell.textLabel?.text = "Custom Servers"
cell.detailTextLabel?.text = nil
......
......@@ -456,6 +456,15 @@ internal enum L10n {
}
}
internal enum Inapp {
internal enum Messages {
internal enum Toggle {
/// Stop in-app communication messages
internal static let title = L10n.tr("Localizable", "inapp.messages.toggle.title")
}
}
}
internal enum Menu {
internal enum Accessibility {
/// Menu
......
......@@ -380,3 +380,6 @@
// RECONNECTIONS
"server.reconnection.please.wait" = "Please wait...";
"server.reconnection.still.connection" = "Still trying to connect...";
// INAPP MESSAGES
"inapp.messages.toggle.title" = "Stop in-app communication messages";
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment