From f99a41c8f5104b43d81668429a76df4c0cddbd0b Mon Sep 17 00:00:00 2001 From: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> Date: Tue, 19 Dec 2017 12:39:48 -0500 Subject: [PATCH] messages: support links This patch adds support for url links. Change-Id: I3d4291952d593d63d966abc16e00bd3890abf1ea Reviewed-by: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> --- Ring/Cartfile | 1 + Ring/Cartfile.resolved | 1 + Ring/Ring.xcodeproj/project.pbxproj | 6 ++++++ .../Conversation/Cells/MessageCell.swift | 3 ++- .../Conversation/Cells/MessageCellReceived.xib | 2 +- .../Conversation/Cells/MessageCellSent.xib | 12 ++++++------ .../Conversation/ConversationViewController.swift | 4 ++++ 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Ring/Cartfile b/Ring/Cartfile index a49a381e1..23bdf1b9c 100644 --- a/Ring/Cartfile +++ b/Ring/Cartfile @@ -7,3 +7,4 @@ github "ViccAlexander/Chameleon" github "andreamazz/AMPopTip" github "ashleymills/Reachability.swift" github "stephencelis/SQLite.swift" ~> 0.11.4 +github "optonaut/ActiveLabel.swift" diff --git a/Ring/Cartfile.resolved b/Ring/Cartfile.resolved index c02fcfa12..6e0345bb0 100644 --- a/Ring/Cartfile.resolved +++ b/Ring/Cartfile.resolved @@ -9,3 +9,4 @@ github "ashleymills/Reachability.swift" "v4.1.0" github "pkluz/PKHUD" "5.0.0" github "realm/realm-cocoa" "v3.0.1" github "stephencelis/SQLite.swift" "0.11.4" +github "optonaut/ActiveLabel.swift" "0.8.0" diff --git a/Ring/Ring.xcodeproj/project.pbxproj b/Ring/Ring.xcodeproj/project.pbxproj index 4fa08ea45..c270b320d 100644 --- a/Ring/Ring.xcodeproj/project.pbxproj +++ b/Ring/Ring.xcodeproj/project.pbxproj @@ -91,6 +91,7 @@ 0E403F811F7D797300C80BC2 /* MessageCellGenerated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E403F801F7D797300C80BC2 /* MessageCellGenerated.swift */; }; 0E403F831F7D79B000C80BC2 /* MessageCellGenerated.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0E403F821F7D79B000C80BC2 /* MessageCellGenerated.xib */; }; 0E48F9D31FDF150700D6CC08 /* ContactRequestManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E48F9D21FDF150700D6CC08 /* ContactRequestManager.swift */; }; + 0E4909611FE97A94005CAA50 /* ActiveLabel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E4909601FE97A94005CAA50 /* ActiveLabel.framework */; }; 0E6949791FA7E71C0029B60A /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E6949781FA7E71C0029B60A /* BaseViewController.swift */; }; 0E983E6E1FC77C3E0082103E /* ConversationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E983E6D1FC77C3E0082103E /* ConversationModel.swift */; }; 0E9D84491FA7DA6A00C561EB /* ChatTabBarItemViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E9D84481FA7DA6A00C561EB /* ChatTabBarItemViewModel.swift */; }; @@ -337,6 +338,7 @@ 0E403F801F7D797300C80BC2 /* MessageCellGenerated.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageCellGenerated.swift; sourceTree = "<group>"; }; 0E403F821F7D79B000C80BC2 /* MessageCellGenerated.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MessageCellGenerated.xib; sourceTree = "<group>"; }; 0E48F9D21FDF150700D6CC08 /* ContactRequestManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactRequestManager.swift; sourceTree = "<group>"; }; + 0E4909601FE97A94005CAA50 /* ActiveLabel.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ActiveLabel.framework; path = Carthage/Build/iOS/ActiveLabel.framework; sourceTree = "<group>"; }; 0E6949781FA7E71C0029B60A /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = "<group>"; }; 0E983E6D1FC77C3E0082103E /* ConversationModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationModel.swift; sourceTree = "<group>"; }; 0E9D84481FA7DA6A00C561EB /* ChatTabBarItemViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatTabBarItemViewModel.swift; sourceTree = "<group>"; }; @@ -528,6 +530,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 0E4909611FE97A94005CAA50 /* ActiveLabel.framework in Frameworks */, 0E0FF1A71FC38070003898C2 /* SQLite.framework in Frameworks */, 5C093F011FB495830011D90E /* Differentiator.framework in Frameworks */, 0ED666101F9FED1C00743D42 /* AMPopTip.framework in Frameworks */, @@ -639,6 +642,7 @@ 02AED8171DD4C4B000F740BA /* Frameworks */ = { isa = PBXGroup; children = ( + 0E4909601FE97A94005CAA50 /* ActiveLabel.framework */, 0E0FF1A61FC38070003898C2 /* SQLite.framework */, 5C093F001FB495830011D90E /* Differentiator.framework */, 0ED6660F1F9FED1C00743D42 /* AMPopTip.framework */, @@ -1451,6 +1455,7 @@ "$(SRCROOT)/Carthage/Build/iOS/Reachability.framework", "$(SRCROOT)/Carthage/Build/iOS/Differentiator.framework", "$(SRCROOT)/Carthage/Build/iOS/SQLite.framework", + "$(SRCROOT)/Carthage/Build/iOS/ActiveLabel.framework", ); name = "⚙️ Copy Frameworks"; outputPaths = ( @@ -1467,6 +1472,7 @@ "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/AMPopTip.framework", "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Differentiator.framework", "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/SQLite.framework", + "(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/ActiveLabel.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; diff --git a/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCell.swift b/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCell.swift index 35ed2c780..4d3511dcc 100644 --- a/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCell.swift +++ b/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCell.swift @@ -22,13 +22,14 @@ import UIKit import Reusable import RxSwift +import ActiveLabel class MessageCell: UITableViewCell, NibReusable { @IBOutlet weak var bubble: MessageBubble! @IBOutlet weak var bubbleBottomConstraint: NSLayoutConstraint! @IBOutlet weak var bubbleTopConstraint: NSLayoutConstraint! - @IBOutlet weak var messageLabel: UILabel! + @IBOutlet weak var messageLabel: ActiveLabel! @IBOutlet weak var bottomCorner: UIView! @IBOutlet weak var topCorner: UIView! @IBOutlet weak var timeLabel: UILabel! diff --git a/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCellReceived.xib b/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCellReceived.xib index 6a7be568a..543f28631 100644 --- a/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCellReceived.xib +++ b/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCellReceived.xib @@ -74,7 +74,7 @@ <view clipsSubviews="YES" contentMode="scaleToFill" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="kZJ-Ay-LTR" customClass="MessageBubble" customModule="Ring" customModuleProvider="target"> <rect key="frame" x="64" y="8" width="190.5" height="30.5"/> <subviews> - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label Label Label Label" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lyR-7c-S2k"> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label Label Label Label" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lyR-7c-S2k" customClass="ActiveLabel" customModule="ActiveLabel"> <rect key="frame" x="10" y="8" width="170.5" height="14.5"/> <fontDescription key="fontDescription" type="system" pointSize="16"/> <nil key="highlightedColor"/> diff --git a/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCellSent.xib b/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCellSent.xib index 82afc04e2..a7a4bf03a 100644 --- a/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCellSent.xib +++ b/Ring/Ring/Features/Conversations/Conversation/Cells/MessageCellSent.xib @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES"> <device id="retina4_7" orientation="portrait"> <adaptation id="fullscreen"/> </device> <dependencies> <deployment identifier="iOS"/> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13174"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/> <capability name="Constraints to layout margins" minToolsVersion="6.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> </dependencies> @@ -38,7 +38,7 @@ <view clipsSubviews="YES" contentMode="scaleToFill" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="kZJ-Ay-LTR" customClass="MessageBubble" customModule="Ring" customModuleProvider="target"> <rect key="frame" x="303.5" y="8" width="190.5" height="31"/> <subviews> - <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label Label Label Label" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lyR-7c-S2k"> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label Label Label Label" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lyR-7c-S2k" customClass="ActiveLabel" customModule="ActiveLabel"> <rect key="frame" x="10" y="8" width="170.5" height="15"/> <fontDescription key="fontDescription" name=".AppleSystemUIFont" family=".AppleSystemUIFont" pointSize="16"/> <color key="textColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> @@ -61,21 +61,21 @@ </userDefinedRuntimeAttributes> </view> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="h8N-aw-5lV" userLabel="Right Divider"> - <rect key="frame" x="347.5" y="16" width="138.5" height="1"/> + <rect key="frame" x="347.5" y="19" width="126.5" height="1"/> <color key="backgroundColor" red="0.94117647058823528" green="0.94117647058823528" blue="0.94117647058823528" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <constraints> <constraint firstAttribute="height" constant="1" id="3h1-r8-Nis"/> </constraints> </view> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="2U4-l3-KET" userLabel="Left Divider"> - <rect key="frame" x="24" y="16" width="137.5" height="1"/> + <rect key="frame" x="36" y="19" width="125.5" height="1"/> <color key="backgroundColor" red="0.94117647058823528" green="0.94117647058823528" blue="0.94117647058823528" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <constraints> <constraint firstAttribute="height" constant="1" id="gla-pJ-IsN"/> </constraints> </view> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="11/14/2016 12:34PM" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ogn-wv-fZy" userLabel="Message Time"> - <rect key="frame" x="177.5" y="6" width="154" height="21"/> + <rect key="frame" x="177.5" y="9" width="154" height="21"/> <fontDescription key="fontDescription" type="system" pointSize="17"/> <nil key="textColor"/> <nil key="highlightedColor"/> diff --git a/Ring/Ring/Features/Conversations/Conversation/ConversationViewController.swift b/Ring/Ring/Features/Conversations/Conversation/ConversationViewController.swift index 159b442b3..540dcb59e 100644 --- a/Ring/Ring/Features/Conversations/Conversation/ConversationViewController.swift +++ b/Ring/Ring/Features/Conversations/Conversation/ConversationViewController.swift @@ -346,7 +346,11 @@ class ConversationViewController: UIViewController, UITextFieldDelegate, Storybo let type = messageVM.bubblePosition() let bubbleColor = type == .received ? UIColor.ringMsgCellReceived : UIColor.ringMsgCellSent + cell.messageLabel.enabledTypes = [.url] cell.messageLabel.setTextWithLineSpacing(withText: messageVM.content, withLineSpacing: 2) + cell.messageLabel.handleURLTap { url in + UIApplication.shared.openURL(url) + } cell.topCorner.isHidden = true cell.topCorner.backgroundColor = bubbleColor -- GitLab