Commit c8af47bf authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Kateryna Kostiuk
Browse files

avatars: observe on main thread and unwrap optionals when initializing



- Prevents crashes when successive navigations to the invite view are made, due to
  large amounts of nameservice queries.

Change-Id: I0ba462d9038abb42623ad3732a69c8e315a41f55
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent e7bb5dd7
......@@ -22,22 +22,22 @@ import Foundation
// Colors from material.io
let avatarColors = [
UIColor(hexString: "#f44336"), // Red
UIColor(hexString: "#e91e63"), // Pink
UIColor(hexString: "#9c27b0"), // Purple
UIColor(hexString: "#673ab7"), // Deep Purple
UIColor(hexString: "#3f51b5"), // Indigo
UIColor(hexString: "#2196f3"), // Blue
UIColor(hexString: "#00bcd4"), // Cyan
UIColor(hexString: "#009688"), // Teal
UIColor(hexString: "#4caf50"), // Green
UIColor(hexString: "#8bc34a"), // Light Green
UIColor(hexString: "#9e9e9e"), // Grey
UIColor(hexString: "#cddc39"), // Lime
UIColor(hexString: "#ffc107"), // Amber
UIColor(hexString: "#ff5722"), // Deep Orange
UIColor(hexString: "#795548"), // Brown
UIColor(hexString: "#607d8b") // Blue Grey
UIColor(hexString: "#f44336")!, // Red
UIColor(hexString: "#e91e63")!, // Pink
UIColor(hexString: "#9c27b0")!, // Purple
UIColor(hexString: "#673ab7")!, // Deep Purple
UIColor(hexString: "#3f51b5")!, // Indigo
UIColor(hexString: "#2196f3")!, // Blue
UIColor(hexString: "#00bcd4")!, // Cyan
UIColor(hexString: "#009688")!, // Teal
UIColor(hexString: "#4caf50")!, // Green
UIColor(hexString: "#8bc34a")!, // Light Green
UIColor(hexString: "#9e9e9e")!, // Grey
UIColor(hexString: "#cddc39")!, // Lime
UIColor(hexString: "#ffc107")!, // Amber
UIColor(hexString: "#ff5722")!, // Deep Orange
UIColor(hexString: "#795548")!, // Brown
UIColor(hexString: "#607d8b")! // Blue Grey
];
let defaultAvatarColor = UIColor(hexString: "808080")
let defaultAvatarColor = UIColor(hexString: "808080")!
......@@ -78,13 +78,14 @@ class ContactRequestsViewController: UIViewController, StoryboardBased, ViewMode
// UIColor that observes "best Id" prefix
self.backgroundColorObservable = item.userName.asObservable()
.observeOn(MainScheduler.instance)
.map { name in
let scanner = Scanner(string: name.toMD5HexString().prefixString())
var index: UInt64 = 0
if scanner.scanHexInt64(&index) {
return avatarColors[Int(index)]!
return avatarColors[Int(index)]
}
return defaultAvatarColor!
return defaultAvatarColor
}
// Set placeholder avatar to backgroundColorObservable
......
......@@ -136,13 +136,14 @@ class SmartlistViewController: UIViewController, StoryboardBased, ViewModelBased
// UIColor that observes "best Id" prefix
self.backgroundColorObservable = item.userName.asObservable()
.observeOn(MainScheduler.instance)
.map { name in
let scanner = Scanner(string: name.toMD5HexString().prefixString())
var index: UInt64 = 0
if scanner.scanHexInt64(&index) {
return avatarColors[Int(index)]!
return avatarColors[Int(index)]
}
return defaultAvatarColor!
return defaultAvatarColor
}
// Set placeholder avatar to backgroundColorObservable
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment