瀏覽代碼

use color scheme for initials circles

Alla Reinsch 7 年之前
父節點
當前提交
dba709478e

+ 3 - 0
deltachat-ios/Constants.swift

@@ -9,6 +9,8 @@
 import UIKit
 import UIKit
 
 
 struct Constants {
 struct Constants {
+    // see: https://core.telegram.org/blackberry/chat
+    static let chatColors:[UIColor] = ["#ee4928", "#41a903", "#e09602", "#0f94ed", "#8f3bf7", "#fc4380", "#00a1c4", "#eb7002"].map {s in UIColor(hexString: s)}
      struct Color {
      struct Color {
         static let bubble = UIColor(netHex: 0xefffde)
         static let bubble = UIColor(netHex: 0xefffde)
     }
     }
@@ -19,3 +21,4 @@ struct Constants {
         static let deltachatImapPasswordKey = "__DELTACHAT_IMAP_PASSWORD_KEY__"
         static let deltachatImapPasswordKey = "__DELTACHAT_IMAP_PASSWORD_KEY__"
     }
     }
 }
 }
+

+ 4 - 0
deltachat-ios/ContactCell.swift

@@ -41,6 +41,10 @@ class ContactCell: UITableViewCell {
         nameLabel.centerYAnchor.constraint(equalTo: initialsLabel.centerYAnchor).isActive = true
         nameLabel.centerYAnchor.constraint(equalTo: initialsLabel.centerYAnchor).isActive = true
     }
     }
     
     
+    func setColor(_ color: UIColor) {
+        self.initialsLabel.backgroundColor = color
+    }
+    
     required init?(coder aDecoder: NSCoder) {
     required init?(coder aDecoder: NSCoder) {
         fatalError("init(coder:) has not been implemented")
         fatalError("init(coder:) has not been implemented")
     }
     }

+ 2 - 0
deltachat-ios/NewChatViewController.swift

@@ -98,6 +98,8 @@ class NewChatViewController: UITableViewController {
         cell.nameLabel.text = contact.name
         cell.nameLabel.text = contact.name
         // cell.detailTextLabel?.text = contact.email
         // cell.detailTextLabel?.text = contact.email
         cell.initialsLabel.text = Utils.getInitials(inputName: contact.name)
         cell.initialsLabel.text = Utils.getInitials(inputName: contact.name)
+        let contactColor = Utils.color(row: contactRow, colors: Constants.chatColors)
+        cell.setColor(contactColor)
         return cell
         return cell
     }
     }
     
     

+ 9 - 0
deltachat-ios/Utils.swift

@@ -10,6 +10,15 @@ import Foundation
 import UIKit
 import UIKit
 
 
 struct Utils {
 struct Utils {
+    static func colorIndex(row: Int, colors:[UIColor]) -> Int {
+        return row % colors.count
+    }
+    
+    static func color(row: Int, colors:[UIColor]) -> UIColor {
+        let index = colorIndex(row: row, colors: colors)
+        return colors[index]
+    }
+    
     static func getContactIds() -> [Int] {
     static func getContactIds() -> [Int] {
         let c_contacts = mrmailbox_get_known_contacts(mailboxPointer, nil)
         let c_contacts = mrmailbox_get_known_contacts(mailboxPointer, nil)
         return Utils.copyAndFreeArray(inputArray: c_contacts)
         return Utils.copyAndFreeArray(inputArray: c_contacts)