Commit c369d583 authored by Jose Blaya's avatar Jose Blaya

InApp messages

parent c9484de2
......@@ -31,6 +31,11 @@ public enum AvailableTiles: Int, EnumsBuilder {
case quickSettings
case favoriteServers
case connectionTile
case messages
public static func fixedTiles() -> [AvailableTiles] {
return [.messages]
}
public static func allTiles() -> [AvailableTiles] {
return [.region, .quickConnect, .ip, .subscription, .usage, .quickSettings, .favoriteServers, .connectionTile]
......
......@@ -28,6 +28,9 @@ public protocol TileProvider: class {
/// the visible tiles in the dashboard.
var visibleTiles: [AvailableTiles] { get set }
/// the fixed tiles in the dashboard.
var fixedTiles: [AvailableTiles] { get }
/// the order of the tiles to appear in the dashboard.
var orderedTiles: [AvailableTiles] { get set }
......
......@@ -45,7 +45,7 @@ public struct InAppMessage {
public let settingView: String?
public let settingLink: String?
init(withMessage message: [String: String], id: String, link: [String: String], type: InAppMessageType, level: InAppMessageLevel, actions: [String:Bool]?, view: String?, uri: String?) {
public init(withMessage message: [String: String], id: String, link: [String: String], type: InAppMessageType, level: InAppMessageLevel, actions: [String:Bool]?, view: String?, uri: String?) {
self.id = id
self.message = message
self.linkMessage = link
......@@ -60,9 +60,9 @@ public struct InAppMessage {
extension InAppMessage {
init(withMessage messageInformation: MessagesInformation.Message, andLevel level: InAppMessageLevel) {
init(withMessage messageInformation: MessageInformation, andLevel level: InAppMessageLevel) {
self.id = "messageInformation.id"
self.id = messageInformation.id
self.message = messageInformation.message
self.linkMessage = messageInformation.link.text
......
......@@ -43,6 +43,13 @@ class DefaultTileProvider: TileProvider, DatabaseAccess {
}
}
// MARK: TileProvider
var fixedTiles: [AvailableTiles] {
get {
return AvailableTiles.fixedTiles()
}
}
// MARK: TileProvider
var orderedTiles: [AvailableTiles] {
get {
......
......@@ -425,14 +425,14 @@ class PIAWebServices: WebServices, ConfigurationAccess {
if let token = Client.providers.accountProvider.token {
self.accountAPI.messages(token: token, callback: { (messages, error) in
self.accountAPI.message(token: token, callback: { (message, error) in
if let error = error {
callback?(nil, ClientError.malformedResponseData)
return
}
if let message = messages.first {
if let message = message {
let inAppMessage = InAppMessage(withMessage: message, andLevel: .api)
callback?(inAppMessage, nil)
} else {
......
......@@ -311,6 +311,8 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
}
public func inAppMessages(_ callback: LibraryCallback<InAppMessage>?) {
callback?(nil, nil)
delegate.inAppMessages { (message, error) in
callback?(message, error)
}
}
}
......@@ -26,6 +26,8 @@ public class MockTileProvider: TileProvider {
public var visibleTiles: [AvailableTiles] = AvailableTiles.defaultTiles()
public var fixedTiles: [AvailableTiles] = AvailableTiles.fixedTiles()
public var orderedTiles: [AvailableTiles] = AvailableTiles.defaultOrderedTiles()
/// :nodoc:
......
......@@ -24,6 +24,8 @@ import Foundation
class MockWebServices: WebServices {
var messageType: InAppMessageType = .view
var credentials: (() -> Credentials)?
var accountInfo: (() -> AccountInfo)?
......@@ -136,7 +138,10 @@ class MockWebServices: WebServices {
}
func messages(_ callback: LibraryCallback<InAppMessage>?) {
callback?(InAppMessage(withMessage: ["en" : "Message"], id: "123", link: ["en" : "Message"], type: .link, level: .api, actions: nil, view: nil, uri: "https://www.privateinternetaccess.com"), nil)
let testLink = InAppMessage(withMessage: ["en" : "This is a message"], id: "1", link: ["en" : "message"], type: .link, level: .api, actions: nil, view: nil, uri: "https://www.privateinternetaccess.com")
callback?(testLink, nil)
}
}
......@@ -35,6 +35,9 @@ public extension Notification.Name {
/// Reload the tiles.
static let PIATilesDidChange = Notification.Name("PIATilesDidChange")
/// Reload the tiles with animation.
static let PIAUpdateFixedTiles = Notification.Name("PIAUpdateFixedTiles")
/// Present Recover Signup page
static let PIARecoverAccount = Notification.Name("PIARecoverAccount")
......
......@@ -502,6 +502,29 @@ public class Theme {
return attributed
}
public func messageWithLinkText(withMessage message: String, link: String) -> NSAttributedString {
let plain = message.replacingOccurrences(
of: "$1",
with: link
) as NSString
let attributed = NSMutableAttributedString(string: plain as String)
let paragraph = NSMutableParagraphStyle()
paragraph.alignment = .center
paragraph.minimumLineHeight = 16
let fullRange = NSMakeRange(0, plain.length)
attributed.addAttribute(.font, value: UIFont.regularFontWith(size: 14), range: fullRange)
if Theme.current.palette.appearance == .dark {
attributed.addAttribute(.foregroundColor, value: UIColor.white, range: fullRange)
} else {
attributed.addAttribute(.foregroundColor, value: UIColor.piaGrey6, range: fullRange)
}
attributed.addAttribute(.paragraphStyle, value: paragraph, range: fullRange)
let range1 = plain.range(of: link)
attributed.addAttribute(.link, value: link, range: range1)
return attributed
}
// MARK: Composite
......
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