Skip to content

Commit

Permalink
Add dynamic usage of kits
Browse files Browse the repository at this point in the history
Improve code design
  • Loading branch information
jpbernius committed Nov 15, 2018
1 parent fb6c41b commit 3df60db
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 47 deletions.
2 changes: 1 addition & 1 deletion CUU.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'CUU'
s.version = '1.4.0'
s.version = '2.0.0'
s.summary = 'CUU is a framework to help analyzing th usage of your applications.'

# This description is used to generate tags and improve search results.
Expand Down
29 changes: 19 additions & 10 deletions CUU/Classes/CUU.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
public enum CUUStartOption: Int {
case Features = 0
case Interactions
case Behavior
case Notes
case ThinkingAloud
case Emotions
}

public class CUU {

// - MARK: Attributes
Expand All @@ -10,43 +19,43 @@ public class CUU {
/**
* The shared ThinkingAloudKit instance.
*/
public static let thinkingAloudKit = ThinkingAloudKit()
static let thinkingAloudKit = ThinkingAloudKit()

/**
* The shared EmotionKit instance.
*/
public static let emotionKit = EmotionKit()
static let emotionKit = EmotionKit()

/**
* The shared FeatureKit instance.
*/
public static let featureKit = FeatureKit()
static let featureKit = FeatureKit()

/**
* The shared InteractionKit instance.
*/
public static var iKit: InteractionKit {
static var iKit: InteractionKit {
return InteractionKit.shared
}

/**
* The shared BehaviorKit instance.
*/
public static var bKit: BehaviorKit {
static var bKit: BehaviorKit {
return BehaviorKit.shared
}

/**
* The shared CUUNetworkManager instance.
*/
public static var networkManager: CUUNetworkManager {
static var networkManager: CUUNetworkManager {
return CUUNetworkManager.shared
}

/**
* Starts CUU.
/*
* Starts CUU with the given input.
*/
public static func start() {
public static func start(with options:[CUUStartOption] = [.Behavior, .Notes]) {
CUU.configuration = configuration

// Check if we already asked before.
Expand All @@ -57,7 +66,7 @@ public class CUU {
// We did not ask before, so do it now.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
guard let currentVC = CUUUtils.getTopViewController() else { return }
let startVC = CUUStartViewController()
let startVC = CUUStartViewController(with: options)
currentVC.present(startVC, animated: true, completion: nil)
}
}
Expand Down
2 changes: 0 additions & 2 deletions CUU/Classes/CUUCore/CUUStartOptionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class CUUStartOptionView: UIView {
self.addSubview(titleLabel)
self.addSubview(contentLabel)
self.addSubview(disableButton)

self.disableButton.isSelected = true
}

required init?(coder aDecoder: NSCoder) {
Expand Down
81 changes: 62 additions & 19 deletions CUU/Classes/CUUCore/CUUStartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
import Foundation
import UIKit

enum CUUStartOption: Int {
case Features = 0
case Interactions
case Behavior
case Notes
case ThinkingAloud
case Emotions
}

protocol CUUStartViewDelegate : class {
func didPressContinueButton(with selection: [CUUStartOption]) -> Void
}
Expand All @@ -29,11 +20,15 @@ class CUUStartView: UIView, CUUStartViewOptionDelegate {

weak var delegate : CUUStartViewDelegate?

var selectedOptions: [CUUStartOption] = [.Features, .Interactions, .Behavior, .Notes]
// Options selected by the user.
var selectedOptions : [CUUStartOption] = [.Features, .Interactions]

// Options allowed by the developer.
var allowedOptions : [CUUStartOption] = [.Features, .Interactions]

// MARK: Initialization

override init(frame: CGRect) {
init(frame: CGRect, options: [CUUStartOption]) {
super.init(frame: frame)

self.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -53,8 +48,32 @@ class CUUStartView: UIView, CUUStartViewOptionDelegate {

self.featureKitView.delegate = self
self.interactionKitView.delegate = self
self.behaviorKitView.delegate = self
self.noteKitView.delegate = self

if options.contains(.Behavior) {
self.kitStackView.addArrangedSubview(self.behaviorKitView)
self.behaviorKitView.delegate = self
self.selectedOptions.append(.Behavior)
self.allowedOptions.append(.Behavior)
}

if options.contains(.Notes) {
self.kitStackView.addArrangedSubview(self.noteKitView)
self.noteKitView.delegate = self
self.selectedOptions.append(.Notes)
self.allowedOptions.append(.Behavior)
}

if options.contains(.ThinkingAloud) {
self.kitStackView.addArrangedSubview(self.thinkingAloudKitView)
self.thinkingAloudKitView.delegate = self
self.allowedOptions.append(.ThinkingAloud)
}

if options.contains(.Emotions) {
self.kitStackView.addArrangedSubview(self.emotionKitView)
self.emotionKitView.delegate = self
self.allowedOptions.append(.Emotions)
}
}

required init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -163,31 +182,55 @@ class CUUStartView: UIView, CUUStartViewOptionDelegate {
let view = CUUStartOptionView(frame: .zero, option: .Features)
view.translatesAutoresizingMaskIntoConstraints = false
view.titleLabel.text = "FeatureKit"
view.contentLabel.text = "Information on whether a feature has been used and how often."
view.contentLabel.text = "Tracks if the usage of a feature is started, cancelled, or finished. Cannot be disabled."
view.isUserInteractionEnabled = false
view.disableButton.isSelected = true
return view
}()

var interactionKitView : CUUStartOptionView = {
let view = CUUStartOptionView(frame: .zero, option: .Interactions)
view.translatesAutoresizingMaskIntoConstraints = false
view.titleLabel.text = "InteractionKit"
view.contentLabel.text = "Information on application usage and device specifications."
view.contentLabel.text = "Collects information on application usage and device specifications. Cannot be disabled."
view.isUserInteractionEnabled = false
view.disableButton.isSelected = true
return view
}()

var behaviorKitView : CUUStartOptionView = {
let view = CUUStartOptionView(frame: .zero, option: .Behavior)
view.translatesAutoresizingMaskIntoConstraints = false
view.titleLabel.text = "BehaviorKit"
view.contentLabel.text = "Information on analyzed user behavior. Allows to draw conclusions on user gender, age and application usage skill level."
view.contentLabel.text = "Analyzes user interactions and device data to draw conclusions about person- and application-related information as well as application-related usability issues.l."
view.disableButton.isSelected = true
return view
}()

var noteKitView : CUUStartOptionView = {
let view = CUUStartOptionView(frame: .zero, option: .Notes)
view.translatesAutoresizingMaskIntoConstraints = false
view.titleLabel.text = "NoteKit"
view.contentLabel.text = "Enables you to give us textual feedback whenever you shake your device."
view.contentLabel.text = "Enables textual feedback by shaking the device."
view.disableButton.isSelected = true
return view
}()

var thinkingAloudKitView : CUUStartOptionView = {
let view = CUUStartOptionView(frame: .zero, option: .ThinkingAloud)
view.translatesAutoresizingMaskIntoConstraints = false
view.titleLabel.text = "ThinkingAloudKit"
view.contentLabel.text = "Enables verbal feedback for specific features using the Thinking Aloud method."
view.disableButton.isSelected = false
return view
}()

var emotionKitView : CUUStartOptionView = {
let view = CUUStartOptionView(frame: .zero, option: .Emotions)
view.translatesAutoresizingMaskIntoConstraints = false
view.titleLabel.text = "EmotionKit"
view.contentLabel.text = "Derives emotions based on facial expressions to draw conclusions about the usage of a feature."
view.disableButton.isSelected = false
return view
}()

Expand All @@ -214,11 +257,11 @@ class CUUStartView: UIView, CUUStartViewOptionDelegate {

func didPressDisableButton(enabled: Bool, option: CUUStartOption) {
if (enabled) {
if !selectedOptions.contains(option) {
if !selectedOptions.contains(option) && allowedOptions.contains(option) {
selectedOptions.append(option)
}
} else {
if selectedOptions.contains(option) {
if selectedOptions.contains(option) && allowedOptions.contains(option) {
if let index = selectedOptions.index(of: option) {
selectedOptions.remove(at: index)
}
Expand Down
21 changes: 13 additions & 8 deletions CUU/Classes/CUUCore/CUUStartViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ import UIKit

class CUUStartViewController: UIViewController, CUUStartViewDelegate {

let cuuStartView: CUUStartView

init(with options: [CUUStartOption]) {
self.cuuStartView = CUUStartView(frame: CGRect.zero, options: options)
cuuStartView.translatesAutoresizingMaskIntoConstraints = false

super.init(nibName: nil, bundle: nil)
}

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

// MARK: Lifecycle

override func viewDidLoad() {
Expand All @@ -29,14 +42,6 @@ class CUUStartViewController: UIViewController, CUUStartViewDelegate {
view.addConstraints(contentVConstraint)
}

// MARK: - Getters

var cuuStartView : CUUStartView = {
let view = CUUStartView(frame: CGRect.zero)
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()

func didPressContinueButton(with selection: [CUUStartOption]) {
// Activate the kits
CUU.startKits(with: selection)
Expand Down
6 changes: 1 addition & 5 deletions CUU/Classes/FeatureKit/FeatureKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

import Foundation

/**
* Open class to exhibit FeatureKit behavior.
**/
open class FeatureKit {

class FeatureKit {
static var isActive = false

static var activatedFeatures: [CUUFeature]? = []
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- CUU (1.4.0)
- CUU (2.0.0)

DEPENDENCIES:
- CUU (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
CUU: c3131c4092cf76e93f3bcfe3cad6b29041e493fd
CUU: 4355bc6bcb4d7d20a33265f4107f7cf409072e8e

PODFILE CHECKSUM: 1debc30a649e807b99bdee5ee8daf82a78fc04bc

Expand Down

0 comments on commit 3df60db

Please sign in to comment.