Skip to content

Commit

Permalink
Add notification tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
bstillitano committed Aug 24, 2021
1 parent f0f8d83 commit 42b3f75
Show file tree
Hide file tree
Showing 29 changed files with 69 additions and 22 deletions.
1 change: 1 addition & 0 deletions Sources/Scyther/Components/Cells/Models/ButtonRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ internal struct ButtonRow: Row {
var image: UIImage?
var imageURL: URL?
var accessoryType: UITableViewCell.AccessoryType?
var shouldShowMenuForRow: Bool? = false
}
#endif
1 change: 1 addition & 0 deletions Sources/Scyther/Components/Cells/Models/CheckmarkRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ internal struct CheckmarkRow: Row {
var image: UIImage?
var imageURL: URL?
var accessoryType: UITableViewCell.AccessoryType?
var shouldShowMenuForRow: Bool? = false
}
#endif
1 change: 1 addition & 0 deletions Sources/Scyther/Components/Cells/Models/DefaultRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ class DefaultRow: Row {
var image: UIImage?
var imageURL: URL?
var accessoryType: UITableViewCell.AccessoryType?
var shouldShowMenuForRow: Bool? = false
}
#endif
1 change: 1 addition & 0 deletions Sources/Scyther/Components/Cells/Models/DeviceRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ class DeviceRow: Row {
var image: UIImage?
var imageURL: URL?
var accessoryType: UITableViewCell.AccessoryType?
var shouldShowMenuForRow: Bool? = false
}
#endif
1 change: 1 addition & 0 deletions Sources/Scyther/Components/Cells/Models/EmptyRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ internal struct EmptyRow: Row {
var image: UIImage?
var imageURL: URL?
var accessoryType: UITableViewCell.AccessoryType?
var shouldShowMenuForRow: Bool? = false
}
#endif
1 change: 1 addition & 0 deletions Sources/Scyther/Components/Cells/Models/FontRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ class FontRow: Row {
var imageURL: URL?
var accessoryType: UITableViewCell.AccessoryType?
var font: UIFont?
var shouldShowMenuForRow: Bool? = false
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class NetworkLogRow: Row {
var image: UIImage?
var imageURL: URL?
var accessoryType: UITableViewCell.AccessoryType? = .disclosureIndicator
var shouldShowMenuForRow: Bool? = false

/// Color representing the response code of the network request
var httpStatusColor: UIColor = .systemGray
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ internal struct PreviewableRow: Row {
var imageURL: URL?
var accessoryType: UITableViewCell.AccessoryType?
var previewView: UIView = UIView()
var shouldShowMenuForRow: Bool? = false
}
#endif
1 change: 1 addition & 0 deletions Sources/Scyther/Components/Cells/Models/SliderRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ class SliderRow: Row {
var slider: UISlider = UISlider()
var sliderValueLabel: UILabel = UILabel()
weak var sliderCellDelegate: SliderCellDelegate?
var shouldShowMenuForRow: Bool? = false
}
#endif
1 change: 1 addition & 0 deletions Sources/Scyther/Components/Cells/Models/SubtitleRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ class SubtitleRow: Row {
var image: UIImage?
var imageURL: URL?
var accessoryType: UITableViewCell.AccessoryType?
var shouldShowMenuForRow: Bool? = false
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ internal struct SwitchAccessoryRow: Row {
var image: UIImage?
var imageURL: URL?
var accessoryType: UITableViewCell.AccessoryType?
var shouldShowMenuForRow: Bool? = false
}
#endif
2 changes: 1 addition & 1 deletion Sources/Scyther/Components/Cells/SliderCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if os(iOS)
import UIKit

protocol SliderCellDelegate: class {
protocol SliderCellDelegate: AnyObject {
func sliderValueChanged(slider: UISlider?, label: UILabel)
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Scyther/Models/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal protocol Row {
var image: UIImage? { get set }
var imageURL: URL? { get set }
var accessoryType: UITableViewCell.AccessoryType? { get set }
var shouldShowMenuForRow: Bool? { get set }
}

extension Row {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Scyther/Models/ScytherPreviewable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

@objc
public protocol ScytherPreviewable: class {
public protocol ScytherPreviewable: AnyObject {
static var previewView: UIView { get }
static var name: String { get}
static var details: String { get }
Expand Down
10 changes: 8 additions & 2 deletions Sources/Scyther/Scyther.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

/// Optional delegate that can be implemented to allow an app/caller to know that certain actions have been performed. This `protocol`is not required to be implemented in order for Scyther to work properly, it should be used primarily as a UI convenience; i.e. When switching environments, show a `UIAlertController`
public protocol ScytherDelegate: class {
public protocol ScytherDelegate: AnyObject {
func scyther(didSwitchToEnvironment environment: String)
}

Expand Down Expand Up @@ -50,9 +50,15 @@ public class Scyther {
/// `InterfaceToolkit` utility class. Used for overlaying UI Elements onto the running application.
public static let interfaceToolkit: InterfaceToolkit = InterfaceToolkit.instance

/// Developer options that will be displayed on the main manue
/// Developer options that will be displayed on the main menu
public var developerOptions: [DeveloperOption] = []

/// 64 Character device token registered with APNS. Example: 30eee4d53612de08c61477d4503b23220d76d74efed258230ef3536afd4504f2
public var apnsToken: String?

/// Variable length device token registerd with FCM. Example: dEoOEdh9yEy5sK-BeTxzJR:APA91bH0bNeYvYadpl98frTc6FYY1DbicXc40QrTDj5aOFxPNZF-JLEGvawxWl6g9GXgZod04_UV95zBlzdYFnxByHSCcySmzyrqfPk1IQC7aIfefBTL7a3FX9dQVNnG4x1igi317YUf
public var fcmToken: String?

/// Initialises the Scyther library and sets the required data to properly intercept network calls and console logs.
public func start() {
/// Set data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if !os(macOS)
import UIKit

internal protocol CookieBrowserViewModelProtocol: class {
internal protocol CookieBrowserViewModelProtocol: AnyObject {
func viewModelShouldReloadData()
func viewModel(viewModel: CookieBrowserViewModel?, shouldShowViewController viewController: UIViewController?)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if !os(macOS)
import UIKit

internal protocol CookieDetailsViewModelProtocol: class {
internal protocol CookieDetailsViewModelProtocol: AnyObject {
func viewModelShouldReloadData()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if !os(macOS)
import UIKit

internal protocol FeatureFlagsViewModelProtocol: class {
internal protocol FeatureFlagsViewModelProtocol: AnyObject {
func viewModelShouldReloadData()
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Scyther/User Interface/Fonts/FontsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if !os(macOS)
import UIKit

internal protocol FontsViewModelProtocol: class {
internal protocol FontsViewModelProtocol: AnyObject {
func viewModelShouldReloadData()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if !os(macOS)
import UIKit

internal protocol GridOverlayViewModelProtocol: class {
internal protocol GridOverlayViewModelProtocol: AnyObject {
func viewModelShouldReloadData()
}

Expand Down
16 changes: 16 additions & 0 deletions Sources/Scyther/User Interface/Menu/MenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ extension MenuViewController: UITableViewDelegate {
}
viewModel?.performAction(for: row, indexPath: indexPath)
}

func tableView(_ tableView: UITableView, shouldShowMenuForRowAt indexPath: IndexPath) -> Bool {
guard let row = viewModel?.row(at: indexPath) else { return false }
return row.shouldShowMenuForRow ?? false
}

func tableView(_ tableView: UITableView, canPerformAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) -> Bool {
return (action == #selector(copy(_:)))
}

func tableView(_ tableView: UITableView, performAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) {
if action == #selector(copy(_:)) {
guard let cell = tableView.cellForRow(at: indexPath), let key = cell.textLabel?.text else { return }
UIPasteboard.general.string = "\(key): \(cell.detailTextLabel?.text ?? "")"
}
}
}

extension MenuViewController: MenuViewModelProtocol {
Expand Down
25 changes: 19 additions & 6 deletions Sources/Scyther/User Interface/Menu/MenuViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if !os(macOS)
import UIKit

internal protocol MenuViewModelProtocol: class {
internal protocol MenuViewModelProtocol: AnyObject {
func viewModelShouldReloadData()
func viewModel(viewModel: MenuViewModel?, shouldShowViewController viewController: UIViewController?)
}
Expand Down Expand Up @@ -42,12 +42,13 @@ internal class MenuViewModel {
return row
}

func valueRow(name: String, value: String?, icon: UIImage?) -> DefaultRow {
func valueRow(name: String, value: String?, icon: UIImage?, showMenu: Bool = false) -> DefaultRow {
let row: DefaultRow = DefaultRow()
row.text = name
row.detailText = value
row.image = icon
row.style = .default
row.shouldShowMenuForRow = showMenu
row.accessoryType = UITableViewCell.AccessoryType.none
return row
}
Expand Down Expand Up @@ -176,14 +177,25 @@ internal class MenuViewModel {
icon: UIImage(systemImage: "terminal"),
actionController: ConsoleLoggerViewController()))
supportSection.rows.append(emptyRow(text: "More coming soon"))


/// Setup Notifications Section
var notificationsSection: Section = Section()
notificationsSection.title = "Notifications"
notificationsSection.rows.append(actionRow(name: "Notification Tester",
icon: UIImage(systemImage: "bell"),
actionController: NotificationTesterViewController()))
notificationsSection.rows.append(valueRow(name: "APNS Token",
value: Scyther.instance.apnsToken ?? "Not set",
icon: UIImage(systemImage: "applelogo"),
showMenu: true))
notificationsSection.rows.append(valueRow(name: "FCM Token",
value: Scyther.instance.fcmToken ?? "Not set",
icon: UIImage(systemImage: "flame"),
showMenu: true))

/// Setup UI/UX Section
var uiUxSection: Section = Section()
uiUxSection.title = "UI/UX"
uiUxSection.rows.append(actionRow(name: "Push Notifications",
icon: UIImage(systemImage: "bell"),
actionController: NotificationTesterViewController()))
uiUxSection.rows.append(actionRow(name: "Fonts",
icon: UIImage(systemImage: "textformat"),
actionController: FontsViewController()))
Expand Down Expand Up @@ -216,6 +228,7 @@ internal class MenuViewModel {
sections.append(environmentSection)
sections.append(securitySection)
sections.append(supportSection)
sections.append(notificationsSection)
sections.append(uiUxSection)
sections.append(developmentSection)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if !os(macOS)
import UIKit

internal protocol LogDetailsViewModelProtocol: class {
internal protocol LogDetailsViewModelProtocol: AnyObject {
func viewModelShouldReloadData()
func viewModel(viewModel: LogDetailsViewModel?, shouldShowViewController viewController: UIViewController?)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if !os(macOS)
import UIKit

internal protocol NetworkLoggerViewModelProtocol: class {
internal protocol NetworkLoggerViewModelProtocol: AnyObject {
func viewModelShouldReloadData()
func viewModel(viewModel: NetworkLoggerViewModel?, shouldShowViewController viewController: UIViewController?)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum NotificationTextField: String {
case payload
}

internal protocol NotitificationTesterProtocol: class {
internal protocol NotitificationTesterProtocol: AnyObject {
func viewModelShouldReloadData()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if !os(macOS)
import UIKit

internal protocol ServerConfigurationViewModelProtocol: class {
internal protocol ServerConfigurationViewModelProtocol: AnyObject {
func viewModelShouldReloadData()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if !os(macOS)
import UIKit

internal protocol InterfacePreviewsViewModelProtocol: class {
internal protocol InterfacePreviewsViewModelProtocol: AnyObject {
func viewModelShouldReloadData()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if !os(macOS)
import UIKit

internal protocol UserDefaultsViewModelProtocol: class {
internal protocol UserDefaultsViewModelProtocol: AnyObject {
func viewModelShouldReloadData()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#if !os(macOS)
import UIKit

protocol TopLevelViewDelegate: class {
protocol TopLevelViewDelegate: AnyObject {
func topLevelView(topLevelView: TopLevelView, didUpdateVisibility isHidden: Bool)
}

Expand Down

0 comments on commit 42b3f75

Please sign in to comment.