Эх сурвалжийг харах

refactored - initialsbadge and intialslabel into one

Bastian van de Wetering 6 жил өмнө
parent
commit
db9bf52b09

+ 4 - 8
deltachat-ios.xcodeproj/project.pbxproj

@@ -52,7 +52,7 @@
 		AE851AC5227C755A00ED86F0 /* Protocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851AC4227C755A00ED86F0 /* Protocols.swift */; };
 		AE851AC7227C776400ED86F0 /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851AC6227C776400ED86F0 /* Location.swift */; };
 		AE851AC9227C77CF00ED86F0 /* Media.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851AC8227C77CF00ED86F0 /* Media.swift */; };
-		AE851ACE227CA54400ED86F0 /* InitialsLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851ACD227CA54300ED86F0 /* InitialsLabel.swift */; };
+		AE851ACE227CA54400ED86F0 /* InitialsBadge.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851ACD227CA54300ED86F0 /* InitialsBadge.swift */; };
 		AE851AD0227DF50900ED86F0 /* GroupChatDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE851ACF227DF50900ED86F0 /* GroupChatDetailViewController.swift */; };
 		AEACE2DD1FB323CA00DCDD78 /* ChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2DC1FB323CA00DCDD78 /* ChatViewController.swift */; };
 		AEACE2DF1FB3246400DCDD78 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2DE1FB3246400DCDD78 /* Message.swift */; };
@@ -61,7 +61,6 @@
 		AEE56D762253431E007DC082 /* AccountSetupController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE56D752253431E007DC082 /* AccountSetupController.swift */; };
 		AEE56D7D2253ADB4007DC082 /* HudHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE56D7C2253ADB4007DC082 /* HudHandler.swift */; };
 		AEE56D80225504DB007DC082 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE56D7F225504DB007DC082 /* Extensions.swift */; };
-		AEE6EC382281AF2D00EDC689 /* InitialsBadge.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC372281AF2D00EDC689 /* InitialsBadge.swift */; };
 		AEE6EC3F2282C59C00EDC689 /* GroupMembersViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC3E2282C59C00EDC689 /* GroupMembersViewController.swift */; };
 		AEE6EC412282DF5700EDC689 /* MailboxViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC402282DF5700EDC689 /* MailboxViewController.swift */; };
 		AEE6EC482283045D00EDC689 /* EditSettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEE6EC472283045D00EDC689 /* EditSettingsController.swift */; };
@@ -134,7 +133,7 @@
 		AE851AC4227C755A00ED86F0 /* Protocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Protocols.swift; sourceTree = "<group>"; };
 		AE851AC6227C776400ED86F0 /* Location.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = "<group>"; };
 		AE851AC8227C77CF00ED86F0 /* Media.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Media.swift; sourceTree = "<group>"; };
-		AE851ACD227CA54300ED86F0 /* InitialsLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitialsLabel.swift; sourceTree = "<group>"; };
+		AE851ACD227CA54300ED86F0 /* InitialsBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitialsBadge.swift; sourceTree = "<group>"; };
 		AE851ACF227DF50900ED86F0 /* GroupChatDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupChatDetailViewController.swift; sourceTree = "<group>"; };
 		AEACE2DC1FB323CA00DCDD78 /* ChatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatViewController.swift; sourceTree = "<group>"; };
 		AEACE2DE1FB3246400DCDD78 /* Message.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
@@ -143,7 +142,6 @@
 		AEE56D752253431E007DC082 /* AccountSetupController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSetupController.swift; sourceTree = "<group>"; };
 		AEE56D7C2253ADB4007DC082 /* HudHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HudHandler.swift; sourceTree = "<group>"; };
 		AEE56D7F225504DB007DC082 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
-		AEE6EC372281AF2D00EDC689 /* InitialsBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitialsBadge.swift; sourceTree = "<group>"; };
 		AEE6EC3E2282C59C00EDC689 /* GroupMembersViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupMembersViewController.swift; sourceTree = "<group>"; };
 		AEE6EC402282DF5700EDC689 /* MailboxViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MailboxViewController.swift; sourceTree = "<group>"; };
 		AEE6EC472283045D00EDC689 /* EditSettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditSettingsController.swift; sourceTree = "<group>"; };
@@ -332,9 +330,8 @@
 				78E45E3B21D3D03700D4B15E /* TextFieldTableViewCell.swift */,
 				789E879C21D6DF86003ED1C5 /* ProgressHud.swift */,
 				AE38B31722672DFC00EC37A1 /* ActionCell.swift */,
-				AE851ACD227CA54300ED86F0 /* InitialsLabel.swift */,
+				AE851ACD227CA54300ED86F0 /* InitialsBadge.swift */,
 				AE25F08F22807AD800CDEA66 /* GroupNameCell.swift */,
-				AEE6EC372281AF2D00EDC689 /* InitialsBadge.swift */,
 				AE728F14229D5C390047565B /* PhotoPickerAlertAction.swift */,
 				AE52EA18229EB53C00C586C9 /* ContactDetailHeader.swift */,
 			);
@@ -652,8 +649,7 @@
 				AE38B31A2267328200EC37A1 /* Colors.swift in Sources */,
 				789E879621D6CB58003ED1C5 /* QrCodeReaderController.swift in Sources */,
 				7A451DBE1FB4AD0700177250 /* Wrapper.swift in Sources */,
-				AE851ACE227CA54400ED86F0 /* InitialsLabel.swift in Sources */,
-				AEE6EC382281AF2D00EDC689 /* InitialsBadge.swift in Sources */,
+				AE851ACE227CA54400ED86F0 /* InitialsBadge.swift in Sources */,
 				70B8882E2091B8550074812E /* ContactCell.swift in Sources */,
 				7A451D941FB1B1DB00177250 /* wrapper.c in Sources */,
 				7092474120B3869500AF8799 /* ContactDetailViewController.swift in Sources */,

+ 1 - 1
deltachat-ios/Controller/ChatViewController.swift

@@ -84,7 +84,7 @@ class ChatViewController: MessagesViewController {
 		if let image = chat.profileImage {
 			navigationItem.rightBarButtonItem = UIBarButtonItem(image: image, style: .done, target: self, action: #selector(chatProfilePressed))
 		} else {
-			let initialsLabel = InitialsLabel(name: chat.name, color: chat.color, size: 28)
+			let initialsLabel =  InitialsBadge(name: chat.name, color: chat.color, size: 28)
 			navigationItem.rightBarButtonItem = UIBarButtonItem(customView: initialsLabel)
 		}
 

+ 1 - 1
deltachat-ios/Controller/EditGroupViewController.swift

@@ -35,7 +35,7 @@ class EditGroupViewController: UITableViewController {
 		self.chat = chat
 		super.init(style: .grouped)
 		groupNameCell.inputField.text = chat.name
-		groupNameCell.groupBadge.setText(chat.name)
+		groupNameCell.groupBadge.setName(chat.name)
 		groupNameCell.groupBadge.setColor(chat.color)
 	}
 

+ 3 - 3
deltachat-ios/View/GroupNameCell.swift

@@ -14,10 +14,10 @@ class GroupLabelCell: UITableViewCell {
   var onTextChanged: ((String) -> Void)? // use this callback to update editButton in navigationController
 
   lazy var groupBadge: InitialsBadge = {
-    let badge = InitialsBadge(frame: .zero)
+    let badge = InitialsBadge(size: groupBadgeSize)
     badge.layer.cornerRadius = groupBadgeSize / 2
     badge.clipsToBounds = true
-    badge.setColor(UIColor.lightGray)
+		badge.setColor(UIColor.lightGray)
     return badge
   }()
 
@@ -61,7 +61,7 @@ class GroupLabelCell: UITableViewCell {
 
   @objc func nameFieldChanged() {
     let groupName = inputField.text ?? ""
-    groupBadge.setText(groupName)
+    groupBadge.setName(groupName)
     onTextChanged?(groupName)
   }
 

+ 19 - 30
deltachat-ios/View/InitialsBadge.swift

@@ -1,30 +1,28 @@
 //
-//  IntitialsBadge.swift
+//  InitialsLabel.swift
 //  deltachat-ios
 //
-//  Created by Bastian van de Wetering on 07.05.19.
+//  Created by Bastian van de Wetering on 03.05.19.
 //  Copyright © 2019 Jonas Reinsch. All rights reserved.
 //
 
-import UIKit
-
-// shall be used for contactCell/ groups
 
-class InitialsBadge: UIView {
-  private lazy var label: UILabel = {
-    let label = UILabel()
-    label.textAlignment = NSTextAlignment.center
-    label.textColor = UIColor.white
-    label.font = UIFont.systemFont(ofSize: 22)
-    // label.adjustsFontSizeToFitWidth = true
-    return label
-  }()
+import UIKit
 
-  override init(frame: CGRect) {
-    super.init(frame: frame)
-    setupSubviews()
+class InitialsBadge: UILabel {
+  convenience init(name: String, color: UIColor, size: CGFloat) {
+    self.init(size: size)
+    setName(name)
+    setColor(color)
+  }
 
-    layer.cornerRadius = frame.width / 2
+  init(size: CGFloat) {
+    super.init(frame: CGRect(x: 0, y: 0, width: size, height: size))
+    textAlignment = NSTextAlignment.center
+    textColor = UIColor.white
+    adjustsFontSizeToFitWidth = true
+    let initialsLabelCornerRadius = size / 2
+    layer.cornerRadius = initialsLabelCornerRadius
     clipsToBounds = true
   }
 
@@ -32,21 +30,12 @@ class InitialsBadge: UIView {
     fatalError("init(coder:) has not been implemented")
   }
 
-  private func setupSubviews() {
-    addSubview(label)
-    label.translatesAutoresizingMaskIntoConstraints = false
-    label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 2).isActive = true
-    label.topAnchor.constraint(equalTo: topAnchor, constant: 2).isActive = true
-    label.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -2).isActive = true
-    label.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -2).isActive = true
+  func setName(_ name: String) {
+    text = Utils.getInitials(inputName: name)
   }
 
   func setColor(_ color: UIColor) {
     backgroundColor = color
   }
-
-  func setText(_ text: String) {
-    let initials = Utils.getInitials(inputName: text)
-    label.text = initials
-  }
 }
+

+ 0 - 39
deltachat-ios/View/InitialsLabel.swift

@@ -1,39 +0,0 @@
-//
-//  InitialsLabel.swift
-//  deltachat-ios
-//
-//  Created by Bastian van de Wetering on 03.05.19.
-//  Copyright © 2019 Jonas Reinsch. All rights reserved.
-//
-
-import UIKit
-
-class InitialsLabel: UILabel {
-  convenience init(name: String, color: UIColor, size: CGFloat) {
-    self.init(size: size)
-    set(name: name)
-    set(color: color)
-  }
-
-  init(size: CGFloat) {
-    super.init(frame: CGRect(x: 0, y: 0, width: size, height: size))
-    textAlignment = NSTextAlignment.center
-    textColor = UIColor.white
-    adjustsFontSizeToFitWidth = true
-    let initialsLabelCornerRadius = size / 2
-    layer.cornerRadius = initialsLabelCornerRadius
-    clipsToBounds = true
-  }
-
-  required init?(coder _: NSCoder) {
-    fatalError("init(coder:) has not been implemented")
-  }
-
-  func set(name: String) {
-    text = Utils.getInitials(inputName: name)
-  }
-
-  func set(color: UIColor) {
-    backgroundColor = color
-  }
-}