-
Notifications
You must be signed in to change notification settings - Fork 437
[NEW] Attachments supporting message headers #2254
Changes from all commits
87c1255
5d2e7bb
aab3284
920377b
d975a2e
ea459ea
2b06c0d
c465f1b
9940273
faf9f33
c90d8dc
c3d8984
ee81656
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // | ||
| // BaseFileMessageCell.swift | ||
| // Rocket.Chat | ||
| // | ||
| // Created by Filipe Alvarenga on 16/10/18. | ||
| // Copyright © 2018 Rocket.Chat. All rights reserved. | ||
| // | ||
|
|
||
| import UIKit | ||
| import RocketChatViewController | ||
|
|
||
| class BaseFileMessageCell: MessageHeaderCell { | ||
| weak var delegate: ChatMessageCellProtocol? | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // | ||
| // BaseImageMessageCell.swift | ||
| // Rocket.Chat | ||
| // | ||
| // Created by Filipe Alvarenga on 16/10/18. | ||
| // Copyright © 2018 Rocket.Chat. All rights reserved. | ||
| // | ||
|
|
||
| import UIKit | ||
|
|
||
| class BaseImageMessageCell: MessageHeaderCell { | ||
| weak var delegate: ChatMessageCellProtocol? | ||
|
|
||
| func loadImage(on imageView: UIImageView, startLoadingBlock: () -> Void, stopLoadingBlock: @escaping () -> Void) { | ||
| guard let viewModel = viewModel?.base as? ImageMessageChatItem else { | ||
| return | ||
| } | ||
|
|
||
| if let imageURL = viewModel.imageURL { | ||
| startLoadingBlock() | ||
| ImageManager.loadImage(with: imageURL, into: imageView) { _, _ in | ||
| stopLoadingBlock() | ||
|
|
||
| // TODO: In case of error, show some error placeholder | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Todo Violation: TODOs should be resolved (In case of error, show some er...). (todo) |
||
| } | ||
| } else { | ||
| // TODO: Load some error placeholder | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Todo Violation: TODOs should be resolved (Load some error placeholder). (todo) |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| // | ||
| // BaseTextAttachmentMessageCell.swift | ||
| // Rocket.Chat | ||
| // | ||
| // Created by Filipe Alvarenga on 16/10/18. | ||
| // Copyright © 2018 Rocket.Chat. All rights reserved. | ||
| // | ||
|
|
||
| import UIKit | ||
|
|
||
| class BaseTextAttachmentMessageCell: MessageHeaderCell { | ||
| weak var delegate: ChatMessageCellProtocol? | ||
|
|
||
| var subtitleHeightConstraint: NSLayoutConstraint! | ||
| var emptySubtitleHeightConstraint: NSLayoutConstraint! | ||
| var avatarLeadingInitialConstant: CGFloat = 0 | ||
| var avatarWidthInitialConstant: CGFloat = 0 | ||
| var textContainerLeadingInitialConstant: CGFloat = 0 | ||
| var statusViewLeadingInitialConstant: CGFloat = 0 | ||
| var statusViewWidthInitialConstant: CGFloat = 0 | ||
| var fieldsStackViewLeadingInitialConstant: CGFloat = 0 | ||
| var fieldsStackViewTrailingInitialConstant: CGFloat = 0 | ||
| var textContainerTrailingInitialConstant: CGFloat = 0 | ||
| var fieldsStackTopInitialConstant: CGFloat = 0 | ||
| var fieldsStackHeightInitialConstant: CGFloat = 0 | ||
| var subtitleHeightInitialConstant: CGFloat = 0 | ||
| var subtitleTopInitialConstant: CGFloat = 0 | ||
| var fieldLabelWidth: CGFloat { | ||
| return | ||
| UIScreen.main.bounds.width - | ||
| avatarLeadingInitialConstant - | ||
| avatarWidthInitialConstant - | ||
| textContainerLeadingInitialConstant - | ||
| statusViewLeadingInitialConstant - | ||
| statusViewWidthInitialConstant - | ||
| fieldsStackViewLeadingInitialConstant - | ||
| fieldsStackViewTrailingInitialConstant - | ||
| textContainerTrailingInitialConstant - | ||
| adjustedHorizontalInsets | ||
| } | ||
|
|
||
| func configure(stackView: UIStackView) -> CGFloat { | ||
| guard let viewModel = viewModel?.base as? TextAttachmentChatItem else { | ||
| return 0 | ||
| } | ||
|
|
||
| let maxSize = CGSize(width: fieldLabelWidth, height: .greatestFiniteMagnitude) | ||
| var stackViewHeight: CGFloat = 0 | ||
| var attachmentFieldViews: [AttachmentFieldView] = [] | ||
|
|
||
| reset(stackView: stackView) | ||
|
|
||
| for attachmentField in viewModel.attachment.fields { | ||
| guard let attachmentFieldView = AttachmentFieldView.instantiateFromNib() else { | ||
| continue | ||
| } | ||
|
|
||
| let attributedValue = NSMutableAttributedString(string: attachmentField.value).transformMarkdown(with: theme) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line Length Violation: Line should be 120 characters or less: currently 121 characters (line_length) |
||
| attachmentFieldView.field.text = attachmentField.title | ||
| attachmentFieldView.value.attributedText = attributedValue | ||
|
|
||
| let valueTextHeight = attachmentFieldView.value.sizeThatFits(maxSize).height | ||
| let fieldViewHeight = attachmentFieldView.fieldHeightConstraint.constant + | ||
| attachmentFieldView.valueTopConstraint.constant + | ||
| valueTextHeight | ||
|
|
||
| stackViewHeight += fieldViewHeight | ||
| attachmentFieldView.contentSize = CGSize(width: fieldLabelWidth, height: fieldViewHeight) | ||
| attachmentFieldView.invalidateIntrinsicContentSize() | ||
| attachmentFieldViews.append(attachmentFieldView) | ||
| } | ||
|
|
||
| stackViewHeight += stackView.spacing * CGFloat(attachmentFieldViews.count - 1) | ||
|
|
||
| attachmentFieldViews.forEach { view in | ||
| stackView.addArrangedSubview(view) | ||
| } | ||
|
|
||
| return stackViewHeight | ||
| } | ||
|
|
||
| func reset(stackView: UIStackView) { | ||
| stackView.arrangedSubviews.forEach { subview in | ||
| stackView.removeArrangedSubview(subview) | ||
| subview.removeFromSuperview() | ||
| } | ||
| } | ||
|
|
||
| @objc func didTapTextContainerView() { | ||
| guard | ||
| let viewModel = viewModel, | ||
| let textAttachmentViewModel = viewModel.base as? TextAttachmentChatItem | ||
| else { | ||
| return | ||
| } | ||
|
|
||
| textAttachmentViewModel.toggleAttachmentFields() | ||
| delegate?.viewDidCollapseChange(viewModel: viewModel) | ||
| } | ||
| } | ||
|
|
||
| extension BaseTextAttachmentMessageCell: UIGestureRecognizerDelegate { | ||
| func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line Length Violation: Line should be 120 characters or less: currently 146 characters (line_length) |
||
| return false | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // | ||
| // FileMessageCell.swift | ||
| // Rocket.Chat | ||
| // | ||
| // Created by Filipe Alvarenga on 28/09/18. | ||
| // Copyright © 2018 Rocket.Chat. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
| import RocketChatViewController | ||
|
|
||
| final class FileCell: BaseFileMessageCell, SizingCell { | ||
| static let identifier = String(describing: FileCell.self) | ||
|
|
||
| static let sizingCell: UICollectionViewCell & ChatCell = { | ||
| guard let cell = FileCell.instantiateFromNib() else { | ||
| return FileCell() | ||
| } | ||
|
|
||
| return cell | ||
| }() | ||
|
|
||
| @IBOutlet weak var fileButton: UIButton! | ||
|
|
||
| override func configure() { | ||
| guard let viewModel = viewModel?.base as? FileMessageChatItem else { | ||
| return | ||
| } | ||
|
|
||
| fileButton.setTitle(viewModel.attachment.title, for: .normal) | ||
| } | ||
|
|
||
| @IBAction func didTapFileButton() { | ||
| guard let viewModel = viewModel?.base as? FileMessageChatItem else { | ||
| return | ||
| } | ||
|
|
||
| delegate?.openFileFromCell(attachment: viewModel.attachment) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> | ||
| <device id="retina4_7" orientation="portrait"> | ||
| <adaptation id="fullscreen"/> | ||
| </device> | ||
| <dependencies> | ||
| <deployment identifier="iOS"/> | ||
| <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/> | ||
| <capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
| <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
| </dependencies> | ||
| <objects> | ||
| <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> | ||
| <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
| <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="o5P-P6-s4x" customClass="FileCell" customModule="Rocket_Chat" customModuleProvider="target"> | ||
| <rect key="frame" x="0.0" y="0.0" width="375" height="56"/> | ||
| <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> | ||
| <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO"> | ||
| <rect key="frame" x="0.0" y="0.0" width="375" height="56"/> | ||
| <autoresizingMask key="autoresizingMask"/> | ||
| <subviews> | ||
| <button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Fef-tc-ORb"> | ||
| <rect key="frame" x="70" y="0.0" width="271" height="56"/> | ||
| <color key="backgroundColor" red="0.88235294117647056" green="0.89803921568627454" blue="0.90980392156862744" alpha="1" colorSpace="calibratedRGB"/> | ||
| <constraints> | ||
| <constraint firstAttribute="height" constant="56" id="gpU-z9-wYR"/> | ||
| </constraints> | ||
| <fontDescription key="fontDescription" type="system" weight="semibold" pointSize="16"/> | ||
| <inset key="contentEdgeInsets" minX="10" minY="0.0" maxX="0.0" maxY="0.0"/> | ||
| <inset key="titleEdgeInsets" minX="5" minY="0.0" maxX="0.0" maxY="0.0"/> | ||
| <state key="normal" title="Button" image="iconFilesGeneric"> | ||
| <color key="titleColor" red="0.12156862745098039" green="0.13725490196078433" blue="0.16078431372549018" alpha="1" colorSpace="calibratedRGB"/> | ||
| </state> | ||
| <userDefinedRuntimeAttributes> | ||
| <userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius"> | ||
| <integer key="value" value="4"/> | ||
| </userDefinedRuntimeAttribute> | ||
| </userDefinedRuntimeAttributes> | ||
| <connections> | ||
| <action selector="didTapFileButton" destination="o5P-P6-s4x" eventType="touchUpInside" id="1Nh-fb-C6j"/> | ||
| </connections> | ||
| </button> | ||
| </subviews> | ||
| </view> | ||
| <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | ||
| <constraints> | ||
| <constraint firstItem="Fef-tc-ORb" firstAttribute="top" secondItem="o5P-P6-s4x" secondAttribute="top" id="HRd-k5-91W"/> | ||
| <constraint firstAttribute="bottom" secondItem="Fef-tc-ORb" secondAttribute="bottom" id="k3J-kZ-5HF"/> | ||
| <constraint firstItem="Fef-tc-ORb" firstAttribute="leading" secondItem="o5P-P6-s4x" secondAttribute="leading" constant="70" id="oxc-gc-1iG"/> | ||
| <constraint firstAttribute="trailing" secondItem="Fef-tc-ORb" secondAttribute="trailing" constant="34" id="uT0-rI-ArF"/> | ||
| </constraints> | ||
| <viewLayoutGuide key="safeArea" id="Jgr-GV-nUi"/> | ||
| <size key="customSize" width="375" height="76"/> | ||
| <connections> | ||
| <outlet property="fileButton" destination="Fef-tc-ORb" id="MCe-oe-aH8"/> | ||
| </connections> | ||
| <point key="canvasLocation" x="109.59999999999999" y="-44.977511244377816"/> | ||
| </collectionViewCell> | ||
| </objects> | ||
| <resources> | ||
| <image name="iconFilesGeneric" width="20" height="20"/> | ||
| </resources> | ||
| </document> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line Length Violation: Line should be 120 characters or less: currently 128 characters (line_length)