Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemor committed Sep 14, 2021
2 parents 163ccc6 + c00a035 commit b01f9d2
Show file tree
Hide file tree
Showing 10 changed files with 553 additions and 67 deletions.
16 changes: 16 additions & 0 deletions Sources/Paywall/Assets.xcassets/debugger.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "debugger.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Binary file not shown.
142 changes: 142 additions & 0 deletions Sources/Paywall/Debug/SWConsoleViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//
// File.swift
//
//
// Created by Jake Mor on 9/13/21.
//

import UIKit
import Foundation
import StoreKit

internal class SWConsoleViewController: UIViewController {

var products: [SKProduct] = []
var tableViewCellData = [(String, String)]()

lazy var productPicker: UIPickerView = {
let picker: UIPickerView = UIPickerView()
picker.delegate = self
picker.dataSource = self
picker.translatesAutoresizingMaskIntoConstraints = false
picker.tintColor = PrimaryColor
picker.backgroundColor = LightBackgroundColor
return picker
}()

lazy var tableView: UITableView = {
let tv = UITableView()
tv.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
tv.translatesAutoresizingMaskIntoConstraints = false
tv.backgroundView = nil
tv.backgroundColor = .clear
tv.delegate = self
tv.dataSource = self
tv.allowsSelection = false
tv.allowsMultipleSelection = false
return tv

}()

init(products: [SKProduct]) {
super.init(nibName: nil, bundle: nil)
self.products = products
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = DarkBackgroundColor
title = "Paywall Debugger"
view.addSubview(tableView)
view.addSubview(productPicker)

NSLayoutConstraint.activate([
productPicker.widthAnchor.constraint(equalTo: view.widthAnchor),
productPicker.heightAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.618),
productPicker.bottomAnchor.constraint(equalTo: view.bottomAnchor),
productPicker.centerXAnchor.constraint(equalTo: view.centerXAnchor),

tableView.widthAnchor.constraint(equalTo: view.widthAnchor),
tableView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
tableView.bottomAnchor.constraint(equalTo: productPicker.topAnchor),
tableView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
])

productPicker.reloadAllComponents()
reloadTableView()
}

func reloadTableView() {
let index = productPicker.selectedRow(inComponent: 0)

tableViewCellData = []
let p = products[index]
for i in p.eventData {
tableViewCellData.append(i)
}

tableViewCellData.sort { first, second in
let (a0, _) = first
let (a1, _) = second
return a0 < a1
}

tableView.reloadData()
}

}

extension SWConsoleViewController: UIPickerViewDelegate, UIPickerViewDataSource {
internal func numberOfComponents(in pickerView: UIPickerView) -> Int {
1
}

internal func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
products.count
}

internal func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let attributedString = NSAttributedString(string: products[row].productIdentifier, attributes: [NSAttributedString.Key.foregroundColor : PrimaryColor])
return attributedString
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
reloadTableView()
}
}

extension SWConsoleViewController: UITableViewDelegate, UITableViewDataSource {

func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableViewCellData.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell")

let (key, value) = tableViewCellData[indexPath.row]
cell.textLabel?.text = value
cell.textLabel?.textColor = .white
cell.detailTextLabel?.text = "{{ \(key) }}"
cell.detailTextLabel?.textColor = UIColor.white.withAlphaComponent(0.618)
cell.backgroundView = nil
cell.backgroundColor = .clear
cell.contentView.backgroundColor = .clear



return cell
}




}
58 changes: 55 additions & 3 deletions Sources/Paywall/Debug/SWDebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
import UIKit
import Foundation
import StoreKit

internal var PrimaryColor = UIColor(hexString: "#75FFF1")
internal var PrimaryButtonBackgroundColor = UIColor(hexString: "#203133")
Expand Down Expand Up @@ -42,6 +43,16 @@ internal class SWDebugViewController: UIViewController {
return b
}()

lazy var consoleButton: SWBounceButton = {
let b = SWBounceButton()
let image = UIImage(named: "debugger", in: Bundle.module, compatibleWith: nil)!
b.setImage(image, for: .normal)
b.translatesAutoresizingMaskIntoConstraints = false
b.imageView?.tintColor = UIColor.white.withAlphaComponent(0.5)
b.addTarget(self, action: #selector(pressedConsoleButton), for: .primaryActionTriggered)
return b
}()

lazy var bottomButton: SWBounceButton = {
let b = SWBounceButton()
b.setTitle("Preview", for: .normal)
Expand Down Expand Up @@ -119,6 +130,7 @@ internal class SWDebugViewController: UIViewController {
view.addSubview(previewContainerView)
view.addSubview(activityIndicator)
view.addSubview(logoImageView)
view.addSubview(consoleButton)
view.addSubview(exitButton)
view.addSubview(bottomButton)
previewContainerView.addSubview(previewPickerButton)
Expand All @@ -134,10 +146,13 @@ internal class SWDebugViewController: UIViewController {
previewContainerView.bottomAnchor.constraint(equalTo: bottomButton.topAnchor, constant: -30),

logoImageView.widthAnchor.constraint(equalTo: view.layoutMarginsGuide.widthAnchor, constant: -10),
logoImageView.heightAnchor.constraint(equalToConstant: 23),
logoImageView.heightAnchor.constraint(equalToConstant: 20),
logoImageView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor, constant: 20),
logoImageView.centerXAnchor.constraint(equalTo: view.centerXAnchor),

consoleButton.centerXAnchor.constraint(equalTo: bottomButton.leadingAnchor),
consoleButton.centerYAnchor.constraint(equalTo: logoImageView.centerYAnchor),

exitButton.centerXAnchor.constraint(equalTo: bottomButton.trailingAnchor),
exitButton.centerYAnchor.constraint(equalTo: logoImageView.centerYAnchor),

Expand Down Expand Up @@ -281,10 +296,47 @@ internal class SWDebugViewController: UIViewController {
}

@objc func pressedExitButton() {

presentingViewController?.dismiss(animated: true, completion: nil)

}

@objc func pressedConsoleButton() {


self.activityIndicator.startAnimating()
self.previewContainerView.isHidden = true

Network.shared.paywalls { [weak self] result in

switch(result){
case .success(let response):
let paywalls = response.paywalls

let paywallResponse = paywalls.first { p in
p.id == self?.paywallId
}

if let paywallResponse = paywallResponse {
StoreKitManager.shared.get(productsWithIds: paywallResponse.productIds) { productsById in
OnMain {
let products = Array(productsById.values)
let vc = SWConsoleViewController(products: products)
let nc = UINavigationController(rootViewController: vc)
self?.present(nc, animated: true)
}
}
}

case .failure(let error):
Logger.superwallDebug(string: "Debug Mode Error", error: error)
self?.activityIndicator.stopAnimating()
}

OnMain {
self?.activityIndicator.stopAnimating()
self?.previewContainerView.isHidden = false
}

}
}

@objc func pressedBottomButton() {
Expand Down
Loading

0 comments on commit b01f9d2

Please sign in to comment.