-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedactedViewController.swift
229 lines (190 loc) · 7.87 KB
/
RedactedViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//
// RedactedViewController.swift
// [Redacted]
//
// Created by [Redacted] on [Redacted]-[Redacted]-[Redacted].
// Copyright (c) 2015 [Redacted] All rights reserved.
// THIS VERSION EXISTS SOLELY FOR /r/pokemondev
//
import UIKit
class RedactedViewController: UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
var pickerData: [[String]] = [[""],[""]]
var prefix: String = ""
var suffix: String = ""
@IBOutlet weak var redactedLabel: UILabel!
@IBOutlet weak var pickRedacted: UIPickerView!
@IBOutlet weak var redactedShow: UITextView!
@IBOutlet weak var redactedType: UISegmentedControl!
@IBAction func shareHistory(sender: AnyObject) {
let list: String = redacted.showSavedList()
let controller = UIActivityViewController(activityItems: [list], applicationActivities: nil)
self.presentViewController(controller, animated: true, completion: nil)
}
// action to clear the history/list
@IBAction func clearHistory(sender: AnyObject) {
redacted.savedReadacted = [""]
updateLabel()
}
// action to update display based on type change
@IBAction func changeType(sender: AnyObject) {
switch redactedType.selectedSegmentIndex
{
case 0:
pickRedacted.dataSource = self
pickRedacted.delegate = self
pickerData = redacted.sendCombinedList()
resetPickerSelection()
pickRedacted.reloadAllComponents()
updateLabel()
;
case 1:
fallthrough;
case 2:
fallthrough;
case 3:
pickRedacted.dataSource = self
pickRedacted.delegate = self
pickerData = redacted.sendPrefixList()
pickRedacted.reloadAllComponents()
resetPickerSelection()
updateLabel()
;
default:
break;
}
}
let redacted = RedactedBrain()
override func viewDidLoad() {
pickerData = redacted.sendCombinedList()
super.viewDidLoad()
pickRedacted.dataSource = self
pickRedacted.delegate = self
pickRedacted.reloadAllComponents()
}
// action to generate a redacted while ensuring it keeps track of the tab you are in
func regenerate() {
prefix = pickerData[0][pickRedacted.selectedRowInComponent(0)]
if redactedType.selectedSegmentIndex == 0 {
suffix = pickerData[1][pickRedacted.selectedRowInComponent(1)]
if prefix == "" && suffix == "" {
prefix = redacted.generatePrefixRedacted()
suffix = redacted.generateSuffixRedacted()
} else if prefix == "" && suffix != "" {
prefix = redacted.generatePrefixRedacted()
} else if prefix != "" && suffix == "" {
suffix = redacted.generateSuffixRedacted()
} else if prefix != "" && suffix != "" {
resetPickerSelection()
prefix = redacted.generatePrefixRedacted()
suffix = redacted.generateSuffixRedacted()
}
} else if redactedType.selectedSegmentIndex == 1 {
suffix = "kit"
if prefix == "" {
prefix = redacted.generatePrefixRedacted()
} else if prefix != "" {
resetPickerSelection()
prefix = redacted.generatePrefixRedacted()
}
} else if redactedType.selectedSegmentIndex == 2 {
suffix = "paw"
if prefix == "" {
prefix = redacted.generatePrefixRedacted()
} else if prefix != "" {
resetPickerSelection()
prefix = redacted.generatePrefixRedacted()
}
} else if redactedType.selectedSegmentIndex == 3 {
suffix = "star"
if prefix == "" {
prefix = redacted.generatePrefixRedacted()
} else if prefix != "" {
resetPickerSelection()
prefix = redacted.generatePrefixRedacted()
}
}
redactedLabel.text = prefix + suffix
}
// action to activate redacted generation from button
@IBAction func generateRedacted() {
regenerate()
}
// action to write to the "History" Log
@IBAction func saveRedacted() {
// This "if" needs to be replaced with seperate function. It's current purpose is to ensure no garbage is written to savedRedacteds list
if redactedLabel.text != "" && redactedLabel.text != " " && redactedLabel.text != "Press Generate" && redactedLabel.text != nil && prefix != "" && suffix != "" && redacted.savedRedacteds.contains(redactedLabel.text!) != true{
let redactedDisplay = redactedLabel.text
redacted.savedRedacteds.append(redactedDisplay!)
redactedShow.text = "\(redacted.showSavedList())"
}
}
// action to move the picker back to "" if there are 2 parts of a redacted already selected BEFORE generation
func resetPickerSelection() {
if pickRedacted.numberOfComponents == 1 {
pickRedacted.selectRow(0, inComponent: 0, animated: true)
} else if pickRedacted.numberOfComponents == 2 {
pickRedacted.selectRow(0, inComponent: 0, animated: true)
pickRedacted.selectRow(0, inComponent: 1, animated: true)
}
}
//MARK -Instance Methods
func updateLabel() {
prefix = pickerData[0][pickRedacted.selectedRowInComponent(0)]
if redactedType.selectedSegmentIndex == 0 {
suffix = pickerData[1][pickRedacted.selectedRowInComponent(1)]
// pickerData = redacted.sendCombinedList()
// pickRedacted.reloadAllComponents()
if prefix + suffix != "" {
redactedLabel.text = prefix + suffix
} else {
redactedLabel.text = "Press Generate"
}
} else if redactedType.selectedSegmentIndex == 1 {
suffix = "kit"
// pickerData = redacted.sendPrefixList()
// pickRedacted.reloadAllComponents()
if prefix != "" {
redactedLabel.text = prefix + suffix
} else {
redactedLabel.text = "Press Generate"
}
} else if redactedType.selectedSegmentIndex == 2 {
suffix = "paw"
// pickerData = redacted.sendPrefixList()
// pickRedacted.reloadAllComponents()
if prefix != "" {
redactedLabel.text = prefix + suffix
} else {
redactedLabel.text = "Press Generate"
}
} else if redactedType.selectedSegmentIndex == 3 {
suffix = "star"
// pickerData = redacted.sendPrefixList()
// pickRedacted.reloadAllComponents()
if prefix != "" {
redactedLabel.text = prefix + suffix
} else {
redactedLabel.text = "Press Generate"
}
}
if redacted.dirty == true {
redactedShow.text = redacted.showSavedList()
redacted.dirty = false
}
}
//MARK: - Delegates and data sources
//MARK: Data Sources
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return pickerData.count
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData[component].count
}
//MARK: Delegates
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerData[component][row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
updateLabel()
}
}