Browse Source

ran swiftformat

Bastian van de Wetering 4 months ago
parent
commit
1f731df51e

+ 4
- 7
deltachat-ios/AccountSetupController.swift View File

@@ -455,9 +455,6 @@ extension AccountSetupController: UITextFieldDelegate {
455 455
     let currentTag = textField.tag
456 456
 
457 457
     if textField.accessibilityIdentifier == "emailTextField", showOAuthAlertIfNeeded(emailAddress: textField.text ?? "", handleCancel: {
458
-      // special case: email field should check for potential oAuth
459
-
460
-      // this will activate passwordTextField if oAuth-Dialogue was canceled
461 458
       self.passwordCell.textField.becomeFirstResponder()
462 459
     }) {
463 460
       // all the action is defined in if condition
@@ -577,10 +574,10 @@ class AdvancedSectionHeader: UIView {
577 574
 
578 575
  // TODO: to add Eye-icon -> uncomment -> add to inputField.rightView
579 576
  /*
580
-   lazy var makeVisibleIcon: UIImageView = {
581
-   let view = UIImageView(image: )
582
-   return view
583
-   }()
577
+     lazy var makeVisibleIcon: UIImageView = {
578
+     let view = UIImageView(image: )
579
+     return view
580
+     }()
584 581
   */
585 582
  init() {
586 583
  super.init(style: .default, reuseIdentifier: nil)

+ 2
- 2
deltachat-ios/ChatViewController.swift View File

@@ -199,9 +199,9 @@ class ChatViewController: MessagesViewController {
199 199
   override func viewDidLoad() {
200 200
     messagesCollectionView.register(CustomCell.self)
201 201
     super.viewDidLoad()
202
-		self.view.backgroundColor = DCColors.chatBackgroundColor
202
+    view.backgroundColor = DCColors.chatBackgroundColor
203 203
 
204
-		if !MRConfig.configured {
204
+    if !MRConfig.configured {
205 205
       // TODO: display message about nothing being configured
206 206
       return
207 207
     }

+ 38
- 41
deltachat-ios/Colors.swift View File

@@ -9,55 +9,52 @@
9 9
 import UIKit
10 10
 
11 11
 struct DCColors {
12
-	static let primary = UIColor.systemBlue
13
-	// static let accent =
14
-
15
-	static let messagePrimaryColor = UIColor.rgb(red: 220, green: 248, blue: 198)
16
-	static let messageSecondaryColor = UIColor.rgb(red: 245, green: 245, blue: 245)
17
-	static let chatBackgroundColor = UIColor.rgb(red: 236, green: 229, blue: 221)
12
+  static let primary = UIColor.systemBlue
13
+  // static let accent =
18 14
 
15
+  static let messagePrimaryColor = UIColor.rgb(red: 220, green: 248, blue: 198)
16
+  static let messageSecondaryColor = UIColor.rgb(red: 245, green: 245, blue: 245)
17
+  static let chatBackgroundColor = UIColor.rgb(red: 236, green: 229, blue: 221)
19 18
 }
20 19
 
21 20
 enum SystemColor {
22
-
23
-	case red
24
-	case orange
25
-	case yellow
26
-	case green
27
-	case tealBlue
28
-	case blue
29
-	case purple
30
-	case pink
31
-
32
-	var uiColor: UIColor {
33
-		switch self {
34
-		case .red:
35
-			return UIColor(red: 255/255, green: 59/255, blue: 48/255, alpha: 1)
36
-		case .orange:
37
-			return UIColor(red: 255/255, green: 149/255, blue: 0/255, alpha: 1)
38
-		case .yellow:
39
-			return UIColor(red: 255/255, green: 204/255, blue: 0/255, alpha: 1)
40
-		case .green:
41
-			return UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
42
-		case .tealBlue:
43
-			return UIColor(red: 90/255, green: 200/255, blue: 250/255, alpha: 1)
44
-		case .blue:
45
-			return UIColor(red: 0/255, green: 122/255, blue: 255/255, alpha: 1)
46
-		case .purple:
47
-			return UIColor(red: 88/255, green: 86/255, blue: 214/255, alpha: 1)
48
-		case .pink:
49
-			return UIColor(red: 255/255, green: 45/255, blue: 85/255, alpha: 1)
50
-		}
51
-	}
21
+  case red
22
+  case orange
23
+  case yellow
24
+  case green
25
+  case tealBlue
26
+  case blue
27
+  case purple
28
+  case pink
29
+
30
+  var uiColor: UIColor {
31
+    switch self {
32
+    case .red:
33
+      return UIColor(red: 255 / 255, green: 59 / 255, blue: 48 / 255, alpha: 1)
34
+    case .orange:
35
+      return UIColor(red: 255 / 255, green: 149 / 255, blue: 0 / 255, alpha: 1)
36
+    case .yellow:
37
+      return UIColor(red: 255 / 255, green: 204 / 255, blue: 0 / 255, alpha: 1)
38
+    case .green:
39
+      return UIColor(red: 76 / 255, green: 217 / 255, blue: 100 / 255, alpha: 1)
40
+    case .tealBlue:
41
+      return UIColor(red: 90 / 255, green: 200 / 255, blue: 250 / 255, alpha: 1)
42
+    case .blue:
43
+      return UIColor(red: 0 / 255, green: 122 / 255, blue: 255 / 255, alpha: 1)
44
+    case .purple:
45
+      return UIColor(red: 88 / 255, green: 86 / 255, blue: 214 / 255, alpha: 1)
46
+    case .pink:
47
+      return UIColor(red: 255 / 255, green: 45 / 255, blue: 85 / 255, alpha: 1)
48
+    }
49
+  }
52 50
 }
53 51
 
54
-
55 52
 extension UIColor {
56
-	static func rgb(red: CGFloat, green: CGFloat, blue: CGFloat) -> UIColor {
57
-		return UIColor(red: red/255, green: green/255, blue: blue/255, alpha: 1)
58
-	}
53
+  static func rgb(red: CGFloat, green: CGFloat, blue: CGFloat) -> UIColor {
54
+    return UIColor(red: red / 255, green: green / 255, blue: blue / 255, alpha: 1)
55
+  }
59 56
 
60
-	static var systemBlue: UIColor {
57
+  static var systemBlue: UIColor {
61 58
     return UIButton(type: .system).tintColor
62 59
   }
63 60
 }

+ 2
- 2
deltachat-ios/Constants.swift View File

@@ -22,8 +22,8 @@ struct Constants {
22 22
   }
23 23
 
24 24
   // static let primaryColor = UIColor(red: 81 / 255, green: 73 / 255, blue: 255 / 255, alpha: 1)
25
-  //static let messagePrimaryColor = Constants.primaryColor.withAlphaComponent(0.5)
26
- // static let messageSecondaryColor = UIColor(red: 245 / 255, green: 245 / 255, blue: 245 / 255, alpha: 1)
25
+  // static let messagePrimaryColor = Constants.primaryColor.withAlphaComponent(0.5)
26
+  // static let messageSecondaryColor = UIColor(red: 245 / 255, green: 245 / 255, blue: 245 / 255, alpha: 1)
27 27
 
28 28
   static let defaultShadow = UIImage(color: UIColor(hexString: "ff2b82"), size: CGSize(width: 1, height: 1))
29 29
   static let onlineShadow = UIImage(color: UIColor(hexString: "3ed67e"), size: CGSize(width: 1, height: 1))

+ 4
- 4
deltachat-ios/DeviceContactsHandler.swift View File

@@ -11,7 +11,7 @@ import UIKit
11 11
 
12 12
 class DeviceContactsHandler {
13 13
   private let store = CNContactStore()
14
-	weak var contactListDelegate: ContactListDelegate?
14
+  weak var contactListDelegate: ContactListDelegate?
15 15
 
16 16
   private func makeContactString(contacts: [CNContact]) -> String {
17 17
     var contactString: String = ""
@@ -29,7 +29,7 @@ class DeviceContactsHandler {
29 29
     let storedContacts = fetchContactsWithEmailFromDevice()
30 30
     let contactString = makeContactString(contacts: storedContacts)
31 31
     dc_add_address_book(mailboxPointer, contactString)
32
-		contactListDelegate?.deviceContactsImported()
32
+    contactListDelegate?.deviceContactsImported()
33 33
   }
34 34
 
35 35
   private func fetchContactsWithEmailFromDevice() -> [CNContact] {
@@ -61,9 +61,9 @@ class DeviceContactsHandler {
61 61
     switch CNContactStore.authorizationStatus(for: .contacts) {
62 62
     case .authorized:
63 63
       addContactsToCore()
64
-      self.contactListDelegate?.accessGranted()
64
+      contactListDelegate?.accessGranted()
65 65
     case .denied:
66
-      self.contactListDelegate?.accessDenied()
66
+      contactListDelegate?.accessDenied()
67 67
     case .restricted, .notDetermined:
68 68
       store.requestAccess(for: .contacts) { [unowned self] granted, _ in
69 69
         if granted {

+ 105
- 107
deltachat-ios/Extensions/Extensions.swift View File

@@ -9,131 +9,129 @@
9 9
 import UIKit
10 10
 
11 11
 extension String {
12
-	func containsCharacters() -> Bool {
13
-		return !trimmingCharacters(in: [" "]).isEmpty
14
-	}
15
-
16
-	// O(n) - returns indexes of subsequences -> can be used to highlight subsequence within string
17
-	func contains(subSequence: String) -> [Int] {
18
-		if subSequence.count > self.count {
19
-			return []
20
-		}
21
-
22
-		let str = self.lowercased()
23
-		let sub = subSequence.lowercased()
24
-
25
-		var j = 0
26
-
27
-		var foundIndexes: [Int] = []
28
-
29
-		for (index, char) in str.enumerated() {
30
-			if j == sub.count {
31
-				break
32
-			}
33
-
34
-			if char == sub.subScript(j) {
35
-				foundIndexes.append(index)
36
-				j += 1
37
-
38
-			}
39
-		}
40
-		return foundIndexes.count == sub.count ? foundIndexes : []
41
-	}
42
-
43
-	func subScript(_ i: Int) -> Character {
44
-		return self[index(startIndex, offsetBy: i)]
45
-	}
46
-
47
-	func boldAt(indexes: [Int], fontSize: CGFloat) -> NSAttributedString {
48
-		let attributedText = NSMutableAttributedString.init(string: self)
49
-
50
-		for index in indexes {
51
-			if index < 0 || self.count <= index {
52
-				break
53
-			}
54
-			attributedText.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: fontSize), range: NSMakeRange(index, 1))
55
-		}
56
-		return attributedText
57
-	}
12
+  func containsCharacters() -> Bool {
13
+    return !trimmingCharacters(in: [" "]).isEmpty
14
+  }
15
+
16
+  // O(n) - returns indexes of subsequences -> can be used to highlight subsequence within string
17
+  func contains(subSequence: String) -> [Int] {
18
+    if subSequence.count > count {
19
+      return []
20
+    }
21
+
22
+    let str = lowercased()
23
+    let sub = subSequence.lowercased()
24
+
25
+    var j = 0
26
+
27
+    var foundIndexes: [Int] = []
28
+
29
+    for (index, char) in str.enumerated() {
30
+      if j == sub.count {
31
+        break
32
+      }
33
+
34
+      if char == sub.subScript(j) {
35
+        foundIndexes.append(index)
36
+        j += 1
37
+      }
38
+    }
39
+    return foundIndexes.count == sub.count ? foundIndexes : []
40
+  }
41
+
42
+  func subScript(_ i: Int) -> Character {
43
+    return self[index(startIndex, offsetBy: i)]
44
+  }
45
+
46
+  func boldAt(indexes: [Int], fontSize: CGFloat) -> NSAttributedString {
47
+    let attributedText = NSMutableAttributedString(string: self)
48
+
49
+    for index in indexes {
50
+      if index < 0 || count <= index {
51
+        break
52
+      }
53
+      attributedText.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: fontSize), range: NSMakeRange(index, 1))
54
+    }
55
+    return attributedText
56
+  }
58 57
 }
59 58
 
60 59
 extension URL {
61
-	public var queryParameters: [String: String]? {
62
-		guard
63
-			let components = URLComponents(url: self, resolvingAgainstBaseURL: true),
64
-			let queryItems = components.queryItems else { return nil }
65
-		return queryItems.reduce(into: [String: String]()) { result, item in
66
-			result[item.name] = item.value
67
-		}
68
-	}
60
+  public var queryParameters: [String: String]? {
61
+    guard
62
+      let components = URLComponents(url: self, resolvingAgainstBaseURL: true),
63
+      let queryItems = components.queryItems else { return nil }
64
+    return queryItems.reduce(into: [String: String]()) { result, item in
65
+      result[item.name] = item.value
66
+    }
67
+  }
69 68
 }
70 69
 
71 70
 extension Dictionary {
72
-	func percentEscaped() -> String {
73
-		return map { key, value in
74
-			let escapedKey = "\(key)".addingPercentEncoding(withAllowedCharacters: .urlQueryValueAllowed) ?? ""
75
-			let escapedValue = "\(value)".addingPercentEncoding(withAllowedCharacters: .urlQueryValueAllowed) ?? ""
76
-			return escapedKey + "=" + escapedValue
77
-			}
78
-			.joined(separator: "&")
79
-	}
71
+  func percentEscaped() -> String {
72
+    return map { key, value in
73
+      let escapedKey = "\(key)".addingPercentEncoding(withAllowedCharacters: .urlQueryValueAllowed) ?? ""
74
+      let escapedValue = "\(value)".addingPercentEncoding(withAllowedCharacters: .urlQueryValueAllowed) ?? ""
75
+      return escapedKey + "=" + escapedValue
76
+    }
77
+    .joined(separator: "&")
78
+  }
80 79
 }
81 80
 
82 81
 extension CharacterSet {
83
-	static let urlQueryValueAllowed: CharacterSet = {
84
-		let generalDelimitersToEncode = ":#[]@" // does not include "?" or "/" due to RFC 3986 - Section 3.4
85
-		let subDelimitersToEncode = "!$&'()*+,;="
86
-
87
-		var allowed = CharacterSet.urlQueryAllowed
88
-		allowed.remove(charactersIn: "\(generalDelimitersToEncode)\(subDelimitersToEncode)")
89
-		return allowed
90
-	}()
82
+  static let urlQueryValueAllowed: CharacterSet = {
83
+    let generalDelimitersToEncode = ":#[]@" // does not include "?" or "/" due to RFC 3986 - Section 3.4
84
+    let subDelimitersToEncode = "!$&'()*+,;="
85
+
86
+    var allowed = CharacterSet.urlQueryAllowed
87
+    allowed.remove(charactersIn: "\(generalDelimitersToEncode)\(subDelimitersToEncode)")
88
+    return allowed
89
+  }()
91 90
 }
92 91
 
93 92
 extension URLSession {
94
-	func synchronousDataTask(request: URLRequest) -> (Data?, URLResponse?, Error?) {
95
-		var data: Data?
96
-		var response: URLResponse?
97
-		var error: Error?
93
+  func synchronousDataTask(request: URLRequest) -> (Data?, URLResponse?, Error?) {
94
+    var data: Data?
95
+    var response: URLResponse?
96
+    var error: Error?
98 97
 
99
-		let semaphore = DispatchSemaphore(value: 0)
98
+    let semaphore = DispatchSemaphore(value: 0)
100 99
 
101
-		let task = dataTask(with: request) {
102
-			data = $0
103
-			response = $1
104
-			error = $2
100
+    let task = dataTask(with: request) {
101
+      data = $0
102
+      response = $1
103
+      error = $2
105 104
 
106
-			semaphore.signal()
107
-		}
108
-		task.resume()
105
+      semaphore.signal()
106
+    }
107
+    task.resume()
109 108
 
110
-		_ = semaphore.wait(timeout: .distantFuture)
109
+    _ = semaphore.wait(timeout: .distantFuture)
111 110
 
112
-		return (data, response, error)
113
-	}
111
+    return (data, response, error)
112
+  }
114 113
 }
115 114
 
116 115
 extension MRContact {
117
-	func contains(searchText text: String) -> [ContactHighlights] {
118
-
119
-		var nameIndexes = [Int]()
120
-		var emailIndexes = [Int]()
121
-
122
-		let contactString = name + email
123
-		let subsequenceIndexes = contactString.contains(subSequence: text)
124
-
125
-		if !subsequenceIndexes.isEmpty {
126
-			for index in subsequenceIndexes {
127
-				if index < name.count {
128
-					nameIndexes.append(index)
129
-				} else {
130
-					let emailIndex = index - name.count
131
-					emailIndexes.append(emailIndex)
132
-				}
133
-			}
134
-			return [ContactHighlights(contactDetail: .NAME, indexes: nameIndexes), ContactHighlights(contactDetail: .EMAIL, indexes: emailIndexes)]
135
-		} else {
136
-			return []
137
-		}
138
-	}
116
+  func contains(searchText text: String) -> [ContactHighlights] {
117
+    var nameIndexes = [Int]()
118
+    var emailIndexes = [Int]()
119
+
120
+    let contactString = name + email
121
+    let subsequenceIndexes = contactString.contains(subSequence: text)
122
+
123
+    if !subsequenceIndexes.isEmpty {
124
+      for index in subsequenceIndexes {
125
+        if index < name.count {
126
+          nameIndexes.append(index)
127
+        } else {
128
+          let emailIndex = index - name.count
129
+          emailIndexes.append(emailIndex)
130
+        }
131
+      }
132
+      return [ContactHighlights(contactDetail: .NAME, indexes: nameIndexes), ContactHighlights(contactDetail: .EMAIL, indexes: emailIndexes)]
133
+    } else {
134
+      return []
135
+    }
136
+  }
139 137
 }

+ 234
- 239
deltachat-ios/NewChatViewController.swift View File

@@ -16,44 +16,44 @@ protocol ChatDisplayer: class {
16 16
 }
17 17
 
18 18
 class NewChatViewController: UITableViewController {
19
+  private lazy var searchController: UISearchController = {
20
+    let searchController = UISearchController(searchResultsController: nil)
21
+    searchController.searchResultsUpdater = self
22
+    searchController.obscuresBackgroundDuringPresentation = false
23
+    searchController.searchBar.placeholder = "Search Contact"
24
+    return searchController
25
+  }()
26
+
27
+  var contactIds: [Int] = Utils.getContactIds() {
28
+    didSet {
29
+      tableView.reloadData()
30
+    }
31
+  }
19 32
 
20
-	private lazy var searchController: UISearchController = {
21
-		let searchController = UISearchController(searchResultsController: nil)
22
-		searchController.searchResultsUpdater = self
23
-		searchController.obscuresBackgroundDuringPresentation = false
24
-		searchController.searchBar.placeholder = "Search Contact"
25
-		return searchController
26
-	}()
27
-
28
-	var contactIds: [Int] = Utils.getContactIds() {
29
-		didSet {
30
-			tableView.reloadData()
31
-		}
32
-	}
33
-
34
-	// contactWithSearchResults.indexesToHightLight empty by default
35
-	var contacts:[ContactWithSearchResults] {
36
-		return contactIds.map({ return ContactWithSearchResults(contact: MRContact(id: $0), indexesToHighlight: [])})
37
-	}
38
-
39
-	// used when seachbar is active
40
-	var filteredContacts: [ContactWithSearchResults] = []
41
-
42
-	// searchBar active?
43
-	func isFiltering() -> Bool {
44
-		return searchController.isActive && !searchBarIsEmpty()
45
-	}
33
+  // contactWithSearchResults.indexesToHightLight empty by default
34
+  var contacts: [ContactWithSearchResults] {
35
+    return contactIds.map { ContactWithSearchResults(contact: MRContact(id: $0), indexesToHighlight: []) }
36
+  }
37
+
38
+  // used when seachbar is active
39
+  var filteredContacts: [ContactWithSearchResults] = []
40
+
41
+  // searchBar active?
42
+  func isFiltering() -> Bool {
43
+    return searchController.isActive && !searchBarIsEmpty()
44
+  }
46 45
 
47 46
   weak var chatDisplayer: ChatDisplayer?
48 47
 
49 48
   var syncObserver: Any?
50 49
   var hud: ProgressHud?
51 50
 
52
-	lazy var deviceContactHandler: DeviceContactsHandler = {
53
-		let handler = DeviceContactsHandler()
54
-		handler.contactListDelegate = self
55
-		return handler
56
-	}()
51
+  lazy var deviceContactHandler: DeviceContactsHandler = {
52
+    let handler = DeviceContactsHandler()
53
+    handler.contactListDelegate = self
54
+    return handler
55
+  }()
56
+
57 57
   var deviceContactAccessGranted: Bool = false {
58 58
     didSet {
59 59
       tableView.reloadData()
@@ -78,27 +78,26 @@ class NewChatViewController: UITableViewController {
78 78
     navigationItem.rightBarButtonItem = cancelButton
79 79
 
80 80
     deviceContactHandler.importDeviceContacts()
81
-		navigationItem.searchController = searchController
82
-		definesPresentationContext = true // to make sure searchbar will only be shown in this viewController
81
+    navigationItem.searchController = searchController
82
+    definesPresentationContext = true // to make sure searchbar will only be shown in this viewController
83 83
   }
84 84
 
85
-	override func viewWillAppear(_ animated: Bool) {
86
-		super.viewWillAppear(animated)
87
-		self.deviceContactAccessGranted = CNContactStore.authorizationStatus(for: .contacts) == .authorized
88
-		contactIds = Utils.getContactIds()
85
+  override func viewWillAppear(_ animated: Bool) {
86
+    super.viewWillAppear(animated)
87
+    deviceContactAccessGranted = CNContactStore.authorizationStatus(for: .contacts) == .authorized
88
+    contactIds = Utils.getContactIds()
89 89
 
90
-		// this will show the searchbar on launch -> will be set back to true on viewDidAppear
91
-		if #available(iOS 11.0, *) {
92
-			navigationItem.hidesSearchBarWhenScrolling = false
93
-		}
94
-
95
-	}
90
+    // this will show the searchbar on launch -> will be set back to true on viewDidAppear
91
+    if #available(iOS 11.0, *) {
92
+      navigationItem.hidesSearchBarWhenScrolling = false
93
+    }
94
+  }
96 95
 
97 96
   override func viewDidAppear(_ animated: Bool) {
98 97
     super.viewDidAppear(animated)
99
-		if #available(iOS 11.0, *) {
100
-			navigationItem.hidesSearchBarWhenScrolling = true
101
-		}
98
+    if #available(iOS 11.0, *) {
99
+      navigationItem.hidesSearchBarWhenScrolling = true
100
+    }
102 101
 
103 102
     let nc = NotificationCenter.default
104 103
     syncObserver = nc.addObserver(
@@ -140,160 +139,159 @@ class NewChatViewController: UITableViewController {
140 139
   // MARK: - Table view data source
141 140
 
142 141
   override func numberOfSections(in _: UITableView) -> Int {
143
-		return deviceContactAccessGranted ? 2 : 3
142
+    return deviceContactAccessGranted ? 2 : 3
144 143
   }
145 144
 
146 145
   override func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
147
-		if section == 0 {
148
-			return 3
149
-		} else if section == 1 {
150
-			if deviceContactAccessGranted {
151
-				return isFiltering() ? filteredContacts.count : contacts.count
152
-			} else {
153
-				return 1
154
-			}
155
-		} else {
156
-			return isFiltering() ? filteredContacts.count : contacts.count
157
-		}
146
+    if section == 0 {
147
+      return 3
148
+    } else if section == 1 {
149
+      if deviceContactAccessGranted {
150
+        return isFiltering() ? filteredContacts.count : contacts.count
151
+      } else {
152
+        return 1
153
+      }
154
+    } else {
155
+      return isFiltering() ? filteredContacts.count : contacts.count
156
+    }
158 157
   }
159 158
 
160 159
   override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
161
-		let section = indexPath.section
160
+    let section = indexPath.section
162 161
     let row = indexPath.row
163 162
 
164
-		if section == 0 {
165
-			if row == 0 {
166
-				// new group row
167
-				let cell: UITableViewCell
168
-				if let c = tableView.dequeueReusableCell(withIdentifier: "newContactCell") {
169
-					cell = c
170
-				} else {
171
-					cell = UITableViewCell(style: .default, reuseIdentifier: "newContactCell")
172
-				}
173
-				cell.textLabel?.text = "New Group"
174
-				cell.textLabel?.textColor = view.tintColor
175
-
176
-				return cell
177
-			}
178
-			if row == 1 {
179
-				// new contact row
180
-				let cell: UITableViewCell
181
-				if let c = tableView.dequeueReusableCell(withIdentifier: "scanGroupCell") {
182
-					cell = c
183
-				} else {
184
-					cell = UITableViewCell(style: .default, reuseIdentifier: "scanGroupCell")
185
-				}
186
-				cell.textLabel?.text = "Scan Group QR Code"
187
-				cell.textLabel?.textColor = view.tintColor
188
-
189
-				return cell
190
-			}
191
-
192
-			if row == 2 {
193
-				// new contact row
194
-				let cell: UITableViewCell
195
-				if let c = tableView.dequeueReusableCell(withIdentifier: "newContactCell") {
196
-					cell = c
197
-				} else {
198
-					cell = UITableViewCell(style: .default, reuseIdentifier: "newContactCell")
199
-				}
200
-				cell.textLabel?.text = "New Contact"
201
-				cell.textLabel?.textColor = view.tintColor
202
-
203
-				return cell
204
-			}
205
-		} else if section == 1 {
206
-			if deviceContactAccessGranted {
207
-				let cell: ContactCell
208
-				if let c = tableView.dequeueReusableCell(withIdentifier: "contactCell") as? ContactCell {
209
-					cell = c
210
-				} else {
211
-					cell = ContactCell(style: .default, reuseIdentifier: "contactCell")
212
-				}
213
-				let contact: ContactWithSearchResults = isFiltering() ? filteredContacts[row] : contacts[row]
214
-				updateContactCell(cell: cell, contactWithHighlight: contact)
215
-				return cell
216
-			} else {
217
-				let cell: ActionCell
218
-				if let c = tableView.dequeueReusableCell(withIdentifier: "actionCell") as? ActionCell {
219
-					cell = c
220
-				} else {
221
-					cell = ActionCell(style: .default, reuseIdentifier: "actionCell")
222
-				}
223
-				cell.actionTitle = "Import Device Contacts"
224
-				return cell
225
-			}
226
-		} else {
227
-			// section 2
228
-			let cell: ContactCell
229
-			if let c = tableView.dequeueReusableCell(withIdentifier: "contactCell") as? ContactCell {
230
-				cell = c
231
-			} else {
232
-				cell = ContactCell(style: .default, reuseIdentifier: "contactCell")
233
-			}
234
-
235
-			let contact: ContactWithSearchResults = isFiltering() ? filteredContacts[row] : contacts[row]
236
-			updateContactCell(cell: cell, contactWithHighlight: contact)
237
-			return cell
238
-		}
239
-		// will actually never get here but compiler not happy
240
-		return UITableViewCell(style: .default, reuseIdentifier: "cell")
163
+    if section == 0 {
164
+      if row == 0 {
165
+        // new group row
166
+        let cell: UITableViewCell
167
+        if let c = tableView.dequeueReusableCell(withIdentifier: "newContactCell") {
168
+          cell = c
169
+        } else {
170
+          cell = UITableViewCell(style: .default, reuseIdentifier: "newContactCell")
171
+        }
172
+        cell.textLabel?.text = "New Group"
173
+        cell.textLabel?.textColor = view.tintColor
174
+
175
+        return cell
176
+      }
177
+      if row == 1 {
178
+        // new contact row
179
+        let cell: UITableViewCell
180
+        if let c = tableView.dequeueReusableCell(withIdentifier: "scanGroupCell") {
181
+          cell = c
182
+        } else {
183
+          cell = UITableViewCell(style: .default, reuseIdentifier: "scanGroupCell")
184
+        }
185
+        cell.textLabel?.text = "Scan Group QR Code"
186
+        cell.textLabel?.textColor = view.tintColor
187
+
188
+        return cell
189
+      }
190
+
191
+      if row == 2 {
192
+        // new contact row
193
+        let cell: UITableViewCell
194
+        if let c = tableView.dequeueReusableCell(withIdentifier: "newContactCell") {
195
+          cell = c
196
+        } else {
197
+          cell = UITableViewCell(style: .default, reuseIdentifier: "newContactCell")
198
+        }
199
+        cell.textLabel?.text = "New Contact"
200
+        cell.textLabel?.textColor = view.tintColor
201
+
202
+        return cell
203
+      }
204
+    } else if section == 1 {
205
+      if deviceContactAccessGranted {
206
+        let cell: ContactCell
207
+        if let c = tableView.dequeueReusableCell(withIdentifier: "contactCell") as? ContactCell {
208
+          cell = c
209
+        } else {
210
+          cell = ContactCell(style: .default, reuseIdentifier: "contactCell")
211
+        }
212
+        let contact: ContactWithSearchResults = isFiltering() ? filteredContacts[row] : contacts[row]
213
+        updateContactCell(cell: cell, contactWithHighlight: contact)
214
+        return cell
215
+      } else {
216
+        let cell: ActionCell
217
+        if let c = tableView.dequeueReusableCell(withIdentifier: "actionCell") as? ActionCell {
218
+          cell = c
219
+        } else {
220
+          cell = ActionCell(style: .default, reuseIdentifier: "actionCell")
221
+        }
222
+        cell.actionTitle = "Import Device Contacts"
223
+        return cell
224
+      }
225
+    } else {
226
+      // section 2
227
+      let cell: ContactCell
228
+      if let c = tableView.dequeueReusableCell(withIdentifier: "contactCell") as? ContactCell {
229
+        cell = c
230
+      } else {
231
+        cell = ContactCell(style: .default, reuseIdentifier: "contactCell")
232
+      }
233
+
234
+      let contact: ContactWithSearchResults = isFiltering() ? filteredContacts[row] : contacts[row]
235
+      updateContactCell(cell: cell, contactWithHighlight: contact)
236
+      return cell
237
+    }
238
+    // will actually never get here but compiler not happy
239
+    return UITableViewCell(style: .default, reuseIdentifier: "cell")
241 240
   }
242 241
 
243 242
   override func tableView(_: UITableView, didSelectRowAt indexPath: IndexPath) {
244 243
     let row = indexPath.row
245
-		let section = indexPath.section
246
-
247
-		if section == 0 {
248
-			if row == 0 {
249
-				let newGroupController = NewGroupViewController()
250
-				navigationController?.pushViewController(newGroupController, animated: true)
251
-			}
252
-			if row == 1 {
253
-				if UIImagePickerController.isSourceTypeAvailable(.camera) {
254
-					let controller = QrCodeReaderController()
255
-					controller.delegate = self
256
-					present(controller, animated: true, completion: nil)
257
-
258
-				} else {
259
-					let alert = UIAlertController(title: "Camera is not available", message: nil, preferredStyle: .alert)
260
-					alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { _ in
261
-						self.dismiss(animated: true, completion: nil)
262
-					}))
263
-					present(alert, animated: true, completion: nil)
264
-				}
265
-			}
266
-			if row == 2 {
267
-				let newContactController = NewContactController()
268
-				navigationController?.pushViewController(newContactController, animated: true)
269
-			}
270
-		} else if section == 1 {
271
-
272
-			if deviceContactAccessGranted {
273
-				if searchController.isActive {
274
-					// edge case: when searchController is active but searchBar is empty -> filteredContacts is empty, so we fallback to contactIds
275
-					let contactId = isFiltering() ? filteredContacts[row].contact.id : self.contactIds[row]
276
-					searchController.dismiss(animated: false, completion: {
277
-						self.dismiss(animated: false, completion: {
278
-							self.chatDisplayer?.displayNewChat(contactId: contactId)
279
-						})
280
-					})
281
-				} else {
282
-					let contactId = contactIds[row]
283
-					dismiss(animated: false) {
284
-						self.chatDisplayer?.displayNewChat(contactId: contactId)
285
-					}
286
-				}
287
-			} else {
288
-				showSettingsAlert()
289
-			}
290
-		} else {
291
-			let contactIndex = row
292
-			let contactId = contactIds[contactIndex]
293
-			dismiss(animated: false) {
294
-				self.chatDisplayer?.displayNewChat(contactId: contactId)
295
-			}
296
-		}
244
+    let section = indexPath.section
245
+
246
+    if section == 0 {
247
+      if row == 0 {
248
+        let newGroupController = NewGroupViewController()
249
+        navigationController?.pushViewController(newGroupController, animated: true)
250
+      }
251
+      if row == 1 {
252
+        if UIImagePickerController.isSourceTypeAvailable(.camera) {
253
+          let controller = QrCodeReaderController()
254
+          controller.delegate = self
255
+          present(controller, animated: true, completion: nil)
256
+
257
+        } else {
258
+          let alert = UIAlertController(title: "Camera is not available", message: nil, preferredStyle: .alert)
259
+          alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { _ in
260
+            self.dismiss(animated: true, completion: nil)
261
+          }))
262
+          present(alert, animated: true, completion: nil)
263
+        }
264
+      }
265
+      if row == 2 {
266
+        let newContactController = NewContactController()
267
+        navigationController?.pushViewController(newContactController, animated: true)
268
+      }
269
+    } else if section == 1 {
270
+      if deviceContactAccessGranted {
271
+        if searchController.isActive {
272
+          // edge case: when searchController is active but searchBar is empty -> filteredContacts is empty, so we fallback to contactIds
273
+          let contactId = isFiltering() ? filteredContacts[row].contact.id : contactIds[row]
274
+          searchController.dismiss(animated: false, completion: {
275
+            self.dismiss(animated: false, completion: {
276
+              self.chatDisplayer?.displayNewChat(contactId: contactId)
277
+            })
278
+          })
279
+        } else {
280
+          let contactId = contactIds[row]
281
+          dismiss(animated: false) {
282
+            self.chatDisplayer?.displayNewChat(contactId: contactId)
283
+          }
284
+        }
285
+      } else {
286
+        showSettingsAlert()
287
+      }
288
+    } else {
289
+      let contactIndex = row
290
+      let contactId = contactIds[contactIndex]
291
+      dismiss(animated: false) {
292
+        self.chatDisplayer?.displayNewChat(contactId: contactId)
293
+      }
294
+    }
297 295
   }
298 296
 
299 297
   override func tableView(_: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
@@ -308,42 +306,39 @@ class NewChatViewController: UITableViewController {
308 306
     }
309 307
   }
310 308
 
311
-	private func updateContactCell(cell: ContactCell, contactWithHighlight: ContactWithSearchResults) {
312
-
313
-		let contact = contactWithHighlight.contact
309
+  private func updateContactCell(cell: ContactCell, contactWithHighlight: ContactWithSearchResults) {
310
+    let contact = contactWithHighlight.contact
314 311
 
315
-		if let nameHighlightedIndexes = contactWithHighlight.indexesToHighlight.filter({$0.contactDetail == .NAME}).first,
316
-			let emailHighlightedIndexes = contactWithHighlight.indexesToHighlight.filter({$0.contactDetail == .EMAIL}).first {
317
-			// gets here when contact is a result of current search -> highlights relevant indexes
318
-			let nameLabelFontSize = cell.nameLabel.font.pointSize
319
-			let emailLabelFontSize = cell.emailLabel.font.pointSize
312
+    if let nameHighlightedIndexes = contactWithHighlight.indexesToHighlight.filter({ $0.contactDetail == .NAME }).first,
313
+      let emailHighlightedIndexes = contactWithHighlight.indexesToHighlight.filter({ $0.contactDetail == .EMAIL }).first {
314
+      // gets here when contact is a result of current search -> highlights relevant indexes
315
+      let nameLabelFontSize = cell.nameLabel.font.pointSize
316
+      let emailLabelFontSize = cell.emailLabel.font.pointSize
320 317
 
321
-			cell.nameLabel.attributedText = contact.name.boldAt(indexes: nameHighlightedIndexes.indexes, fontSize: nameLabelFontSize)
322
-			cell.emailLabel.attributedText = contact.email.boldAt(indexes: emailHighlightedIndexes.indexes, fontSize: emailLabelFontSize)
323
-		} else {
324
-			cell.nameLabel.text = contact.name
325
-			cell.emailLabel.text = contact.email
326
-		}
327
-		cell.initialsLabel.text = Utils.getInitials(inputName: contact.name)
328
-		cell.setColor(contact.color)
329
-		cell.accessoryType = .detailDisclosureButton
330
-	}
331
-
332
-	private func searchBarIsEmpty() -> Bool {
333
-		return searchController.searchBar.text?.isEmpty ?? true
334
-	}
335
-
336
-	private func filterContentForSearchText(_ searchText: String, scope: String = "All") {
318
+      cell.nameLabel.attributedText = contact.name.boldAt(indexes: nameHighlightedIndexes.indexes, fontSize: nameLabelFontSize)
319
+      cell.emailLabel.attributedText = contact.email.boldAt(indexes: emailHighlightedIndexes.indexes, fontSize: emailLabelFontSize)
320
+    } else {
321
+      cell.nameLabel.text = contact.name
322
+      cell.emailLabel.text = contact.email
323
+    }
324
+    cell.initialsLabel.text = Utils.getInitials(inputName: contact.name)
325
+    cell.setColor(contact.color)
326
+    cell.accessoryType = .detailDisclosureButton
327
+  }
337 328
 
338
-		let contactsWithHighlights:[ContactWithSearchResults] = contacts.map({contact in
339
-			let indexes = contact.contact.contains(searchText: searchText)
340
-			return ContactWithSearchResults(contact: contact.contact, indexesToHighlight: indexes)
341
-		})
329
+  private func searchBarIsEmpty() -> Bool {
330
+    return searchController.searchBar.text?.isEmpty ?? true
331
+  }
342 332
 
343
-		filteredContacts = contactsWithHighlights.filter({!$0.indexesToHighlight.isEmpty})
344
-		tableView.reloadData()
345
-	}
333
+  private func filterContentForSearchText(_ searchText: String, scope _: String = "All") {
334
+    let contactsWithHighlights: [ContactWithSearchResults] = contacts.map { contact in
335
+      let indexes = contact.contact.contains(searchText: searchText)
336
+      return ContactWithSearchResults(contact: contact.contact, indexesToHighlight: indexes)
337
+    }
346 338
 
339
+    filteredContacts = contactsWithHighlights.filter { !$0.indexesToHighlight.isEmpty }
340
+    tableView.reloadData()
341
+  }
347 342
 }
348 343
 
349 344
 extension NewChatViewController: QrCodeReaderDelegate {
@@ -376,10 +371,10 @@ extension NewChatViewController: QrCodeReaderDelegate {
376 371
 }
377 372
 
378 373
 extension NewChatViewController: ContactListDelegate {
379
-	func deviceContactsImported() {
380
-		self.contactIds = Utils.getContactIds()
381
-//		tableView.reloadData()
382
-	}
374
+  func deviceContactsImported() {
375
+    contactIds = Utils.getContactIds()
376
+    //		tableView.reloadData()
377
+  }
383 378
 
384 379
   func accessGranted() {
385 380
     deviceContactAccessGranted = true
@@ -391,9 +386,10 @@ extension NewChatViewController: ContactListDelegate {
391 386
 
392 387
   private func showSettingsAlert() {
393 388
     let alert = UIAlertController(
394
-			title: "Import Contacts from to your device",
395
-			message: "To chat with contacts from your device open the settings menu and enable the Contacts option",
396
-			preferredStyle: .alert)
389
+      title: "Import Contacts from to your device",
390
+      message: "To chat with contacts from your device open the settings menu and enable the Contacts option",
391
+      preferredStyle: .alert
392
+    )
397 393
     alert.addAction(UIAlertAction(title: "Open Settings", style: .default) { _ in
398 394
       UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
399 395
     })
@@ -404,32 +400,31 @@ extension NewChatViewController: ContactListDelegate {
404 400
 }
405 401
 
406 402
 extension NewChatViewController: UISearchResultsUpdating {
407
-
408
-	func updateSearchResults(for searchController: UISearchController) {
409
-		if let searchText = searchController.searchBar.text {
410
-			filterContentForSearchText(searchText)
411
-		}
412
-	}
403
+  func updateSearchResults(for searchController: UISearchController) {
404
+    if let searchText = searchController.searchBar.text {
405
+      filterContentForSearchText(searchText)
406
+    }
407
+  }
413 408
 }
414 409
 
415 410
 protocol ContactListDelegate: class {
416 411
   func accessGranted()
417 412
   func accessDenied()
418
-	func deviceContactsImported()
413
+  func deviceContactsImported()
419 414
 }
420 415
 
421 416
 // TODO: find better name
422 417
 struct ContactHighlights {
423
-	let contactDetail: ContactDetail
424
-	let indexes:[Int]
418
+  let contactDetail: ContactDetail
419
+  let indexes: [Int]
425 420
 }
426 421
 
427 422
 enum ContactDetail {
428
-	case NAME
429
-	case EMAIL
423
+  case NAME
424
+  case EMAIL
430 425
 }
431 426
 
432 427
 struct ContactWithSearchResults {
433
-	let contact: MRContact
434
-	let indexesToHighlight:[ContactHighlights]
428
+  let contact: MRContact
429
+  let indexesToHighlight: [ContactHighlights]
435 430
 }

+ 19
- 19
deltachat-ios/TopViews/ChatListController.swift View File

@@ -11,14 +11,14 @@ import UIKit
11 11
 class ChatListController: UIViewController {
12 12
   var chatList: MRChatList?
13 13
 
14
-	lazy var chatTable: UITableView = {
15
-		let chatTable = UITableView()
16
-		chatTable.dataSource = chatTableDataSource
17
-		chatTableDelegate.chatPresenter = self
18
-		chatTable.delegate = chatTableDelegate
19
-		chatTable.rowHeight = 80
20
-		return chatTable
21
-	}()
14
+  lazy var chatTable: UITableView = {
15
+    let chatTable = UITableView()
16
+    chatTable.dataSource = chatTableDataSource
17
+    chatTableDelegate.chatPresenter = self
18
+    chatTable.delegate = chatTableDelegate
19
+    chatTable.rowHeight = 80
20
+    return chatTable
21
+  }()
22 22
 
23 23
   let chatTableDataSource = ChatTableDataSource()
24 24
   let chatTableDelegate = ChatTableDelegate()
@@ -93,17 +93,17 @@ class ChatListController: UIViewController {
93 93
     newButton.tintColor = DCColors.primary
94 94
     navigationItem.rightBarButtonItem = newButton
95 95
 
96
-		setupChatTable()
97
-	}
98
-
99
-	private func setupChatTable() {
100
-		view.addSubview(chatTable)
101
-		chatTable.translatesAutoresizingMaskIntoConstraints = false
102
-		chatTable.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
103
-		chatTable.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
104
-		chatTable.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
105
-		chatTable.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
106
-	}
96
+    setupChatTable()
97
+  }
98
+
99
+  private func setupChatTable() {
100
+    view.addSubview(chatTable)
101
+    chatTable.translatesAutoresizingMaskIntoConstraints = false
102
+    chatTable.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
103
+    chatTable.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
104
+    chatTable.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
105
+    chatTable.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
106
+  }
107 107
 
108 108
   @objc func didPressNewChat() {
109 109
     let ncv = NewChatViewController()

+ 38
- 42
deltachat-iosTests/deltachat_iosTests.swift View File

@@ -6,61 +6,57 @@
6 6
 //  Copyright © 2019 Jonas Reinsch. All rights reserved.
7 7
 //
8 8
 
9
-import XCTest
10 9
 @testable import deltachat_ios
10
+import XCTest
11 11
 
12 12
 class DeltachatTests: XCTestCase {
13
+  var testContact: MRContact?
13 14
 
14
-	var testContact: MRContact?
15
-
16
-	override func setUp() {
17
-		let contactIds = Utils.getContactIds()
18
-
19
-		let contacts = contactIds.map({ return MRContact(id: $0) })
20
-
21
-		testContact = contacts.filter({$0.name == "John Appleseed"}).first
22
-		// Put setup code here. This method is called before the invocation of each test method in the class.
23
-	}
24
-
25
-	override func tearDown() {
26
-		// Put teardown code here. This method is called after the invocation of each test method in the class.
27
-	}
15
+  override func setUp() {
16
+    let contactIds = Utils.getContactIds()
28 17
 
29
-	func testContactSearchForSubsequences() {
18
+    let contacts = contactIds.map { MRContact(id: $0) }
30 19
 
31
-		// this test will only success if run on a simulator (assuming one of the sample contacts is named John Appleseed)
32
-		guard let appleseedContact = testContact else {
33
-			return
34
-		}
20
+    testContact = contacts.filter { $0.name == "John Appleseed" }.first
21
+    // Put setup code here. This method is called before the invocation of each test method in the class.
22
+  }
35 23
 
36
-		XCTAssert(appleseedContact.name == "John Appleseed", "Test contacts name is John Appleseed")
37
-		XCTAssert(appleseedContact.email == "John-Appleseed@mac.com", "Test contacts email is john.appleseed@mac.com")
24
+  override func tearDown() {
25
+    // Put teardown code here. This method is called after the invocation of each test method in the class.
26
+  }
38 27
 
39
-		let indexDetailA = appleseedContact.contains(searchText: "jmc")
28
+  func testContactSearchForSubsequences() {
29
+    // this test will only success if run on a simulator (assuming one of the sample contacts is named John Appleseed)
30
+    guard let appleseedContact = testContact else {
31
+      return
32
+    }
40 33
 
41
-		XCTAssert(indexDetailA.count == 2)
42
-		XCTAssert(indexDetailA[0].contactDetail == .NAME)
43
-		XCTAssert(indexDetailA[0].indexes == [0])
44
-		XCTAssert(indexDetailA[1].indexes == [15, 17])
34
+    XCTAssert(appleseedContact.name == "John Appleseed", "Test contacts name is John Appleseed")
35
+    XCTAssert(appleseedContact.email == "John-Appleseed@mac.com", "Test contacts email is john.appleseed@mac.com")
45 36
 
46
-		let indexDetailB = appleseedContact.contains(searchText: "joj")
47
-		XCTAssert(indexDetailB[0].indexes == [0, 1])
48
-		XCTAssert(indexDetailB[1].indexes == [0])
37
+    let indexDetailA = appleseedContact.contains(searchText: "jmc")
49 38
 
50
-		let indexDetailC = appleseedContact.contains(searchText: "jojh")
51
-		XCTAssert(indexDetailC[0].indexes == [0, 1])
52
-		XCTAssert(indexDetailC[1].indexes == [0, 2])
39
+    XCTAssert(indexDetailA.count == 2)
40
+    XCTAssert(indexDetailA[0].contactDetail == .NAME)
41
+    XCTAssert(indexDetailA[0].indexes == [0])
42
+    XCTAssert(indexDetailA[1].indexes == [15, 17])
53 43
 
54
-		let indexDetailD = appleseedContact.contains(searchText: "joz")
55
-		XCTAssert(indexDetailD.isEmpty)
56
-	}
44
+    let indexDetailB = appleseedContact.contains(searchText: "joj")
45
+    XCTAssert(indexDetailB[0].indexes == [0, 1])
46
+    XCTAssert(indexDetailB[1].indexes == [0])
57 47
 
48
+    let indexDetailC = appleseedContact.contains(searchText: "jojh")
49
+    XCTAssert(indexDetailC[0].indexes == [0, 1])
50
+    XCTAssert(indexDetailC[1].indexes == [0, 2])
58 51
 
59
-	func testPerformanceExample() {
60
-		// This is an example of a performance test case.
61
-		self.measure {
62
-			// Put the code you want to measure the time of here.
63
-		}
64
-	}
52
+    let indexDetailD = appleseedContact.contains(searchText: "joz")
53
+    XCTAssert(indexDetailD.isEmpty)
54
+  }
65 55
 
56
+  func testPerformanceExample() {
57
+    // This is an example of a performance test case.
58
+    measure {
59
+      // Put the code you want to measure the time of here.
60
+    }
61
+  }
66 62
 }