瀏覽代碼

very basic text view cells, implement BaseMessageCell

cyberta 5 年之前
父節點
當前提交
384020e104

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

@@ -119,6 +119,7 @@
 		30F9B9EC235F2116006E7ACF /* MessageCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30F9B9EB235F2116006E7ACF /* MessageCounter.swift */; };
 		30FDB70524D1C1000066C48D /* ChatViewControllerNew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30FDB6F824D1C1000066C48D /* ChatViewControllerNew.swift */; };
 		30FDB71F24D8170E0066C48D /* NewTextMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30FDB71E24D8170E0066C48D /* NewTextMessageCell.swift */; };
+		30FDB72124D838240066C48D /* BaseMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30FDB72024D838240066C48D /* BaseMessageCell.swift */; };
 		451CF971F08D38BCECADCB45 /* Pods_deltachat_ios_DcShare.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 546063D4BFB8FD920C4EAA22 /* Pods_deltachat_ios_DcShare.framework */; };
 		6795F63A82E94FF7CD2CEC0F /* Pods_deltachat_iosTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2F7009234DB9408201A6CDCB /* Pods_deltachat_iosTests.framework */; };
 		7070FB9B2101ECBB000DC258 /* NewGroupController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7070FB9A2101ECBB000DC258 /* NewGroupController.swift */; };
@@ -405,6 +406,7 @@
 		30F9B9EB235F2116006E7ACF /* MessageCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageCounter.swift; sourceTree = "<group>"; };
 		30FDB6F824D1C1000066C48D /* ChatViewControllerNew.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatViewControllerNew.swift; sourceTree = "<group>"; };
 		30FDB71E24D8170E0066C48D /* NewTextMessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTextMessageCell.swift; sourceTree = "<group>"; };
+		30FDB72024D838240066C48D /* BaseMessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseMessageCell.swift; sourceTree = "<group>"; };
 		546063D4BFB8FD920C4EAA22 /* Pods_deltachat_ios_DcShare.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_deltachat_ios_DcShare.framework; sourceTree = BUILT_PRODUCTS_DIR; };
 		6241BE1534A653E79AD5D01D /* Pods_deltachat_ios.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_deltachat_ios.framework; sourceTree = BUILT_PRODUCTS_DIR; };
 		7070FB9A2101ECBB000DC258 /* NewGroupController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewGroupController.swift; sourceTree = "<group>"; };
@@ -792,6 +794,7 @@
 			isa = PBXGroup;
 			children = (
 				30FDB71E24D8170E0066C48D /* NewTextMessageCell.swift */,
+				30FDB72024D838240066C48D /* BaseMessageCell.swift */,
 			);
 			path = Cells;
 			sourceTree = "<group>";
@@ -1544,6 +1547,7 @@
 				307D822E241669C7006D2490 /* LocationManager.swift in Sources */,
 				305961F12346125100C80F33 /* ContactMessageCell.swift in Sources */,
 				AE851AD0227DF50900ED86F0 /* GroupChatDetailViewController.swift in Sources */,
+				30FDB72124D838240066C48D /* BaseMessageCell.swift in Sources */,
 				305961D12346125100C80F33 /* Bundle+Extensions.swift in Sources */,
 				305962002346125100C80F33 /* MessagesCollectionView.swift in Sources */,
 				7A451DB01FB1F84900177250 /* AppCoordinator.swift in Sources */,

+ 1 - 0
deltachat-ios/Chat/ChatViewControllerNew.swift

@@ -115,6 +115,7 @@ class ChatViewControllerNew: UITableViewController {
     override func viewDidLoad() {
 
         tableView.register(NewTextMessageCell.self, forCellReuseIdentifier: "text")
+        tableView.rowHeight = UITableView.automaticDimension
         //messagesCollectionView.register(InfoMessageCell.self)
         super.viewDidLoad()
         if !dcContext.isConfigured() {

+ 88 - 0
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -0,0 +1,88 @@
+import UIKit
+import DcCore
+public class BaseMessageCell: UITableViewCell {
+
+    static var defaultPadding: CGFloat = 12
+
+    lazy var avatarView: InitialsBadge = {
+        let view = InitialsBadge(size: 28)
+        view.setColor(UIColor.gray)
+        view.translatesAutoresizingMaskIntoConstraints = false
+        return view
+    }()
+
+    lazy var topLabel: UILabel = {
+        let label = UILabel()
+        label.translatesAutoresizingMaskIntoConstraints = false
+        label.text = "title"
+        label.font = UIFont.preferredFont(for: .caption1, weight: .regular)
+        return label
+    }()
+
+    lazy var mainContentView: UIStackView = {
+        let view = UIStackView()
+        view.translatesAutoresizingMaskIntoConstraints = false
+        view.axis = .horizontal
+        return view
+    }()
+
+    lazy var bottomContentView: UIStackView = {
+        let view = UIStackView(arrangedSubviews: [bottomLabel])
+        view.translatesAutoresizingMaskIntoConstraints = false
+        view.axis = .horizontal
+        return view
+    }()
+    lazy var bottomLabel: UILabel = {
+        let label = UILabel()
+        label.translatesAutoresizingMaskIntoConstraints = false
+        label.font = UIFont.preferredFont(for: .caption1, weight: .regular)
+        return label
+    }()
+
+    private lazy var contentContainer: UIStackView = {
+        let view = UIStackView(arrangedSubviews: [topLabel, mainContentView, bottomContentView])
+        view.translatesAutoresizingMaskIntoConstraints = false
+        view.axis = .vertical
+        return view
+    }()
+
+    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
+        super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
+        setupSubviews()
+    }
+
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+
+    func setupSubviews() {
+        contentView.addSubview(avatarView)
+        contentView.addSubview(contentContainer)
+
+        contentView.addConstraints([
+            avatarView.constraintAlignTopTo(contentView, paddingTop: defaultPadding),
+            avatarView.constraintAlignLeadingTo(contentView),
+            avatarView.constraintAlignBottomTo(contentView, paddingBottom: defaultPadding, priority: .defaultLow),
+            contentContainer.constraintToTrailingOf(avatarView, paddingLeading: defaultPadding),
+            contentContainer.constraintAlignTrailingTo(contentView, paddingTrailing: defaultPadding),
+            contentContainer.constraintAlignTopTo(contentView, paddingTop: defaultPadding),
+            contentContainer.constraintAlignBottomTo(contentView, paddingBottom: defaultPadding)
+        ])
+    }
+    
+    func update(msg: DcMsg) {
+        topLabel.text = msg.fromContact.displayName
+        avatarView.setName(msg.fromContact.displayName)
+        avatarView.setColor(msg.fromContact.color)
+    }
+
+    override public func prepareForReuse() {
+        textLabel?.text = nil
+        textLabel?.attributedText = nil
+        topLabel.text = nil
+        avatarView.reset()
+
+    }
+    
+}

+ 18 - 28
deltachat-ios/Chat/Views/Cells/NewTextMessageCell.swift

@@ -2,41 +2,31 @@ import Foundation
 import DcCore
 import UIKit
 
-class NewTextMessageCell: UITableViewCell {
-
-    lazy var avatarView: InitialsBadge = {
-        let view = InitialsBadge(size: 28)
-        view.translatesAutoresizingMaskIntoConstraints = false
-        return view
+class NewTextMessageCell: BaseMessageCell {
+
+    lazy var messageLabel: UILabel = {
+        let label = UILabel()
+        label.translatesAutoresizingMaskIntoConstraints = false
+        label.numberOfLines = 0
+        label.lineBreakMode = .byWordWrapping
+        return label
     }()
 
-    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
-           super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
-           setupSubviews()
-       }
-
-       required init?(coder: NSCoder) {
-           fatalError("init(coder:) has not been implemented")
-       }
-
-    func setupSubviews() {
-        contentView.addSubview(avatarView)
-        contentView.addConstraints([
-            avatarView.constraintAlignTopTo(contentView, priority: .defaultLow),
-            avatarView.constraintAlignLeadingTo(contentView),
-            avatarView.constraintAlignBottomTo(contentView, priority: .defaultLow),
-            avatarView.constraintCenterYTo(contentView, priority: .defaultHigh)
-        ])
+    override func setupSubviews() {
+        super.setupSubviews()
+        mainContentView.addArrangedSubview(messageLabel)
+        mainContentView.axis = .horizontal
     }
 
-    func update(msg: DcMsg) {
-        textLabel?.text = msg.text
-        avatarView.setName(msg.fromContact.displayName)
+    override func update(msg: DcMsg) {
+        super.update(msg: msg)
+        messageLabel.text = msg.text
     }
 
     override func prepareForReuse() {
-        textLabel?.text = nil
+        super.prepareForReuse()
+        messageLabel.text = nil
+        messageLabel.attributedText = nil
     }
-
     
 }