Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Files component iOS #6345

Merged
merged 2 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -1356,9 +1356,22 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent*)event
}
else if ([msgtype isEqualToString:kMXMessageTypeFile])
{
body = body? body : [VectorL10n noticeFileAttachment];
// Check attachment validity
if (![self isSupportedAttachment:event])
if ([self isSupportedAttachment:event])
{
body = body? body : [VectorL10n noticeFileAttachment];

NSDictionary *fileInfo = contentToUse[@"info"];
if (fileInfo)
{
NSNumber *fileSize = fileInfo[@"size"];
if (fileSize)
{
body = [NSString stringWithFormat:@"%@ (%@)", body, [MXTools fileSizeToString: fileSize.longValue]];
}
}
}
else
{
MXLogDebug(@"[MXKEventFormatter] Warning: Unsupported attachment %@", event.description);
body = [VectorL10n noticeInvalidAttachment];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ class FileWithoutThumbnailBaseBubbleCell: SizableBaseRoomCell, RoomCellReactions

override func render(_ cellData: MXKCellData!) {
super.render(cellData)

self.fileAttachementView?.titleLabel.attributedText = self.suitableAttributedTextMessage

let attributedText = NSMutableAttributedString(attributedString: self.suitableAttributedTextMessage)
attributedText.addAttributes([.foregroundColor: ThemeService.shared().theme.colors.secondaryContent],
range: NSRange(location: 0, length: attributedText.length))
self.fileAttachementView?.titleLabel.attributedText = attributedText

self.update(theme: ThemeService.shared().theme)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ final class FileWithoutThumbnailCellContentView: UIView, NibLoadable {

// MARK: Outlets

@IBOutlet private weak var iconBackgroundView: UIView!
@IBOutlet private weak var iconImageView: UIImageView!
@IBOutlet private(set) weak var titleLabel: UILabel!

// MARK: Public

var badgeImage: UIImage? {
Expand All @@ -49,17 +50,23 @@ final class FileWithoutThumbnailCellContentView: UIView, NibLoadable {
super.awakeFromNib()

self.layer.masksToBounds = true
self.iconImageView.image = Asset.Images.fileAttachment.image.withRenderingMode(.alwaysTemplate)
self.iconBackgroundView.layer.masksToBounds = true

update(theme: ThemeService.shared().theme)
}

override func layoutSubviews() {
super.layoutSubviews()

self.layer.cornerRadius = BubbleRoomCellLayoutConstants.bubbleCornerRadius
self.iconBackgroundView.layer.cornerRadius = self.iconBackgroundView.bounds.midX
}

// MARK: - Public

func update(theme: Theme) {
self.titleLabel.textColor = theme.textPrimaryColor
self.iconBackgroundView.backgroundColor = theme.roomCellIncomingBubbleBackgroundColor
self.iconImageView.tintColor = theme.colors.secondaryContent
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="System colors in document resources" minToolsVersion="11.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"/>
<view contentMode="scaleToFill" id="8T9-hj-ply" customClass="FileWithoutThumbnailCellContentView" customModule="Riot" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="313" height="42"/>
<rect key="frame" x="0.0" y="0.0" width="313" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="tvT-jE-0OH">
<rect key="frame" x="20" y="15" width="253" height="12"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" image="file_attachment" translatesAutoresizingMaskIntoConstraints="NO" id="Pse-Mu-Gle">
<rect key="frame" x="0.0" y="0.0" width="16" height="12"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" text="Filename.docx" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eCx-a1-1CO">
<rect key="frame" x="32" y="0.0" width="221" height="12"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" systemColor="systemGray2Color"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="mdp-UC-wky">
<rect key="frame" x="12" y="6" width="32" height="32"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" image="file_attachment" translatesAutoresizingMaskIntoConstraints="NO" id="Pse-Mu-Gle">
<rect key="frame" x="12" y="6" width="32" height="32"/>
<constraints>
<constraint firstAttribute="height" constant="32" id="V7S-aN-VMm"/>
<constraint firstAttribute="width" constant="32" id="tLW-tC-XhS"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" text="Filename.docx" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eCx-a1-1CO">
<rect key="frame" x="52" y="13.5" width="221" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" systemColor="systemGray2Color"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.95294117649999999" green="0.97254901959999995" blue="0.99215686270000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="tvT-jE-0OH" secondAttribute="trailing" constant="40" id="At8-ah-N7j"/>
<constraint firstItem="tvT-jE-0OH" firstAttribute="top" secondItem="8T9-hj-ply" secondAttribute="top" constant="15" id="C7r-6f-Bqf"/>
<constraint firstItem="tvT-jE-0OH" firstAttribute="leading" secondItem="8T9-hj-ply" secondAttribute="leading" constant="20" id="Yh6-91-Thq"/>
<constraint firstAttribute="bottom" secondItem="tvT-jE-0OH" secondAttribute="bottom" constant="15" id="yHE-fi-Paj"/>
<constraint firstItem="Pse-Mu-Gle" firstAttribute="top" secondItem="8T9-hj-ply" secondAttribute="top" constant="6" id="6DX-oP-MYH"/>
<constraint firstItem="eCx-a1-1CO" firstAttribute="leading" secondItem="Pse-Mu-Gle" secondAttribute="trailing" constant="8" id="73z-aH-1pr"/>
<constraint firstItem="mdp-UC-wky" firstAttribute="trailing" secondItem="Pse-Mu-Gle" secondAttribute="trailing" id="GNo-nG-I21"/>
<constraint firstAttribute="bottom" secondItem="Pse-Mu-Gle" secondAttribute="bottom" constant="6" id="HvW-1P-u2B"/>
<constraint firstItem="mdp-UC-wky" firstAttribute="top" secondItem="Pse-Mu-Gle" secondAttribute="top" id="QF9-xt-bYe"/>
<constraint firstItem="Pse-Mu-Gle" firstAttribute="leading" secondItem="8T9-hj-ply" secondAttribute="leading" constant="12" id="hSp-8S-ZzS"/>
<constraint firstAttribute="trailing" secondItem="eCx-a1-1CO" secondAttribute="trailing" constant="40" id="o0Y-d1-nWF"/>
<constraint firstItem="mdp-UC-wky" firstAttribute="bottom" secondItem="Pse-Mu-Gle" secondAttribute="bottom" id="ubz-2T-7zP"/>
<constraint firstItem="eCx-a1-1CO" firstAttribute="centerY" secondItem="8T9-hj-ply" secondAttribute="centerY" id="xnb-OL-gFh"/>
<constraint firstItem="mdp-UC-wky" firstAttribute="leading" secondItem="Pse-Mu-Gle" secondAttribute="leading" id="zvT-IB-btm"/>
</constraints>
<nil key="simulatedTopBarMetrics"/>
<nil key="simulatedBottomBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="iconBackgroundView" destination="mdp-UC-wky" id="A7k-W3-TjF"/>
<outlet property="iconImageView" destination="Pse-Mu-Gle" id="pAQ-jI-GDj"/>
<outlet property="titleLabel" destination="eCx-a1-1CO" id="Oj5-X3-Rop"/>
</connections>
<point key="canvasLocation" x="-1454.3478260869567" y="-405.80357142857139"/>
<point key="canvasLocation" x="-1454.3478260869567" y="-402.45535714285711"/>
</view>
</objects>
<resources>
<image name="file_attachment" width="16" height="16"/>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemGray2Color">
<color red="0.68235294117647061" green="0.68235294117647061" blue="0.69803921568627447" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

class FileWithoutThumbnailPlainCell: SizableBaseRoomCell, RoomCellReactionsDisplayable, RoomCellReadMarkerDisplayable, RoomCellThreadSummaryDisplayable {

private(set) var fileAttachementView: FileWithoutThumbnailCellContentView!

override func render(_ cellData: MXKCellData!) {
super.render(cellData)

guard let data = cellData as? RoomBubbleCellData else {
return
}

guard data.attachment.type == .file else {
fatalError("Invalid attachment type passed to a file without thumbnail cell.")
}

let attributedText = NSMutableAttributedString(attributedString: self.suitableAttributedTextMessage)
attributedText.addAttributes([.foregroundColor: ThemeService.shared().theme.colors.secondaryContent],
range: NSRange(location: 0, length: attributedText.length))
self.fileAttachementView.titleLabel.attributedText = attributedText

self.update(theme: ThemeService.shared().theme)
}

override func setupViews() {
super.setupViews()

roomCellContentView?.showSenderInfo = true
roomCellContentView?.showPaginationTitle = false

guard let contentView = roomCellContentView?.innerContentView else {
return
}

fileAttachementView = FileWithoutThumbnailCellContentView.loadFromNib()
contentView.vc_addSubViewMatchingParent(fileAttachementView)
}

override func update(theme: Theme) {
super.update(theme: theme)

guard let fileAttachementView = fileAttachementView else {
return
}

fileAttachementView.update(theme: theme)
fileAttachementView.backgroundColor = theme.colors.quinaryContent
}

override func onContentViewTap(_ sender: UITapGestureRecognizer!) {

if let bubbleData = self.bubbleData, bubbleData.isAttachment {
self.delegate.cell(self, didRecognizeAction: kMXKRoomBubbleCellTapOnAttachmentView, userInfo: nil)
} else {
super.onContentViewTap(sender)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

class FileWithoutThumbnailWithPaginationTitlePlainCell: FileWithoutThumbnailPlainCell {
override func setupViews() {
super.setupViews()

roomCellContentView?.showPaginationTitle = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

class FileWithoutThumbnailWithoutSenderInfoPlainCell: FileWithoutThumbnailPlainCell {
override func setupViews() {
super.setupViews()

roomCellContentView?.showSenderInfo = false
}
}
Loading