mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 00:52:43 +02:00
Merge branch 'develop' into voip_design_updates
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
//
|
||||
// Copyright 2021 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 UIKit
|
||||
|
||||
@objcMembers
|
||||
class RoomTypingBubbleCell: MXKTableViewCell, Themable {
|
||||
// MARK: - Constants
|
||||
|
||||
private enum Constants {
|
||||
static let maxPictureCount = 4
|
||||
static let pictureSize: CGFloat = 24
|
||||
static let pictureMaxMargin: CGFloat = 16
|
||||
static let pictureMinMargin: CGFloat = 8
|
||||
}
|
||||
|
||||
// MARK: - Outlets
|
||||
|
||||
@IBOutlet private weak var additionalUsersLabel: UILabel!
|
||||
@IBOutlet private weak var additionalUsersLabelLeadingConstraint: NSLayoutConstraint!
|
||||
@IBOutlet private weak var dotsView: DotsView!
|
||||
@IBOutlet private weak var dotsViewLeadingConstraint: NSLayoutConstraint!
|
||||
|
||||
// MARK: - members
|
||||
|
||||
private var userPictureViews: [MXKImageView] = []
|
||||
|
||||
// MARK: - Lifecycle
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
|
||||
update(theme: ThemeService.shared().theme)
|
||||
}
|
||||
|
||||
override func prepareForReuse() {
|
||||
super.prepareForReuse()
|
||||
|
||||
for pictureView in userPictureViews {
|
||||
pictureView.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
dotsView.isHidden = userPictureViews.count == 0
|
||||
|
||||
guard userPictureViews.count > 0 else {
|
||||
return
|
||||
}
|
||||
|
||||
additionalUsersLabel?.sizeToFit()
|
||||
|
||||
var pictureViewsMaxX: CGFloat = 0
|
||||
var xOffset: CGFloat = 0
|
||||
for pictureView in userPictureViews {
|
||||
pictureView.center = CGPoint(x: Constants.pictureMaxMargin + xOffset + pictureView.bounds.midX, y: self.bounds.midY)
|
||||
xOffset += round(pictureView.bounds.maxX * 2 / 3)
|
||||
pictureViewsMaxX = pictureView.frame.maxX
|
||||
}
|
||||
|
||||
let leftMagin: CGFloat = pictureViewsMaxX + (userPictureViews.count == 1 ? Constants.pictureMaxMargin : Constants.pictureMinMargin)
|
||||
additionalUsersLabelLeadingConstraint.constant = leftMagin
|
||||
|
||||
dotsViewLeadingConstraint?.constant = additionalUsersLabel.text.isEmptyOrNil == true ? leftMagin : leftMagin + 8 + additionalUsersLabel.frame.width
|
||||
}
|
||||
|
||||
// MARK: - Overrides
|
||||
|
||||
override class func defaultReuseIdentifier() -> String {
|
||||
return String(describing: self)
|
||||
}
|
||||
|
||||
override class func nib() -> UINib {
|
||||
return UINib(nibName: String(describing: self), bundle: nil)
|
||||
}
|
||||
|
||||
// MARK: - Themable
|
||||
|
||||
func update(theme: Theme) {
|
||||
additionalUsersLabel.textColor = theme.textSecondaryColor
|
||||
dotsView.highlightedDotColor = theme.textTertiaryColor
|
||||
dotsView.dotColor = theme.textSecondaryColor
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Business methods
|
||||
|
||||
func updateTypingUsers(_ typingUsers: [TypingUserInfo], mediaManager: MXMediaManager) {
|
||||
for pictureView in userPictureViews {
|
||||
pictureView.removeFromSuperview()
|
||||
}
|
||||
userPictureViews = []
|
||||
|
||||
for user in typingUsers {
|
||||
if userPictureViews.count >= Constants.maxPictureCount {
|
||||
break
|
||||
}
|
||||
|
||||
let pictureView = MXKImageView(frame: CGRect(x: 0, y: 0, width: Constants.pictureSize, height: Constants.pictureSize))
|
||||
pictureView.layer.masksToBounds = true
|
||||
pictureView.layer.cornerRadius = pictureView.bounds.midX
|
||||
|
||||
let defaultavatarImage = AvatarGenerator.generateAvatar(forMatrixItem: user.userId, withDisplayName: user.displayName)
|
||||
pictureView.setImageURI(user.avatarUrl, withType: nil, andImageOrientation: .up, toFitViewSize: pictureView.bounds.size, with: MXThumbnailingMethodCrop, previewImage: defaultavatarImage, mediaManager: mediaManager)
|
||||
|
||||
userPictureViews.append(pictureView)
|
||||
self.contentView.addSubview(pictureView)
|
||||
}
|
||||
|
||||
switch typingUsers.count {
|
||||
case 0:
|
||||
additionalUsersLabel.text = nil
|
||||
case 1:
|
||||
additionalUsersLabel.text = firstUserNameFor(typingUsers)
|
||||
default:
|
||||
additionalUsersLabel.text = VectorL10n.roomMultipleTypingNotification(firstUserNameFor(typingUsers) ?? "")
|
||||
}
|
||||
self.setNeedsLayout()
|
||||
}
|
||||
|
||||
private func firstUserNameFor(_ typingUsers: Array<TypingUserInfo>) -> String? {
|
||||
guard let firstUser = typingUsers.first else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return firstUser.displayName.isEmptyOrNil ? firstUser.userId : firstUser.displayName
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
|
||||
<device id="retina6_1" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
|
||||
<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"/>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" id="nQB-23-kip" customClass="RoomTypingBubbleCell" customModule="Riot" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="nQB-23-kip" id="vRo-3W-dC9">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="+3" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4KE-u0-T4p">
|
||||
<rect key="frame" x="20" y="13" width="18.5" height="18"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="15"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Bn5-WN-DQs" customClass="DotsView" customModule="Riot" customModuleProvider="target">
|
||||
<rect key="frame" x="38" y="13" width="91" height="18"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
</view>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="4KE-u0-T4p" firstAttribute="leading" secondItem="vRo-3W-dC9" secondAttribute="leading" constant="20" symbolic="YES" id="PFN-Ig-2NK"/>
|
||||
<constraint firstItem="Bn5-WN-DQs" firstAttribute="leading" secondItem="vRo-3W-dC9" secondAttribute="leading" constant="38" id="hmq-dH-neQ"/>
|
||||
<constraint firstItem="Bn5-WN-DQs" firstAttribute="centerY" secondItem="vRo-3W-dC9" secondAttribute="centerY" id="jup-hc-eNQ"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
<constraints>
|
||||
<constraint firstItem="4KE-u0-T4p" firstAttribute="centerY" secondItem="nQB-23-kip" secondAttribute="centerY" id="hBP-OB-KGd"/>
|
||||
</constraints>
|
||||
<connections>
|
||||
<outlet property="additionalUsersLabel" destination="4KE-u0-T4p" id="SVG-Oa-aHI"/>
|
||||
<outlet property="additionalUsersLabelLeadingConstraint" destination="PFN-Ig-2NK" id="4Wr-XS-XXp"/>
|
||||
<outlet property="dotsView" destination="Bn5-WN-DQs" id="QqF-bu-Pbm"/>
|
||||
<outlet property="dotsViewLeadingConstraint" destination="hmq-dH-neQ" id="6hM-Sc-pCc"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="166.66666666666669" y="20.758928571428569"/>
|
||||
</tableViewCell>
|
||||
</objects>
|
||||
</document>
|
||||
Reference in New Issue
Block a user