Merge MatrixKit develop with commit hash: b85b736313bec0592bd1cabc68035d97f5331137

This commit is contained in:
SBiOSoftWhare
2021-12-03 11:47:24 +01:00
parent af65f71177
commit f57941177e
475 changed files with 87437 additions and 0 deletions
@@ -0,0 +1,66 @@
/*
Copyright 2015 OpenMarket 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 "MXKTableViewCell.h"
#import "MXKCellRendering.h"
@class MXKImageView;
@class MXKPieChartView;
@class MXSession;
/**
`MXKRoomMemberTableViewCell` instances display a user in the context of the room member list.
*/
@interface MXKRoomMemberTableViewCell : MXKTableViewCell <MXKCellRendering> {
@protected
/**
*/
MXSession *mxSession;
/**
*/
NSString *memberId;
/**
YES when last activity time is displayed and must be refreshed regularly.
*/
BOOL shouldUpdateActivityInfo;
}
@property (strong, nonatomic) IBOutlet MXKImageView *pictureView;
@property (weak, nonatomic) IBOutlet UILabel *userLabel;
@property (weak, nonatomic) IBOutlet UIView *powerContainer;
@property (weak, nonatomic) IBOutlet UIImageView *typingBadge;
/**
The default picture displayed when no picture is available.
*/
@property (nonatomic) UIImage *picturePlaceholder;
/**
Update last activity information if any.
*/
- (void)updateActivityInfo;
/**
Stringify the last activity date/time of the member.
@return a string which described the last activity time of the member.
*/
- (NSString*)lastActiveTime;
@end
@@ -0,0 +1,299 @@
/*
Copyright 2015 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018 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 "MXKRoomMemberTableViewCell.h"
@import MatrixSDK;
#import "MXKAccount.h"
#import "MXKImageView.h"
#import "MXKPieChartView.h"
#import "MXKRoomMemberCellDataStoring.h"
#import "MXKRoomMemberListDataSource.h"
#import "MXKTools.h"
#import "NSBundle+MatrixKit.h"
#import "MXKSwiftHeader.h"
@interface MXKRoomMemberTableViewCell ()
{
NSRange lastSeenRange;
MXKPieChartView* pieChartView;
}
@end
@implementation MXKRoomMemberTableViewCell
- (void)awakeFromNib
{
[super awakeFromNib];
self.typingBadge.image = [NSBundle mxk_imageFromMXKAssetsBundleWithName:@"icon_keyboard"];
}
- (void)customizeTableViewCellRendering
{
[super customizeTableViewCellRendering];
self.pictureView.defaultBackgroundColor = [UIColor clearColor];
}
- (UIImage*)picturePlaceholder
{
return [NSBundle mxk_imageFromMXKAssetsBundleWithName:@"default-profile"];
}
- (void)render:(MXKCellData *)cellData
{
// Sanity check: accept only object of MXKRoomMemberCellData classes or sub-classes
NSParameterAssert([cellData isKindOfClass:[MXKRoomMemberCellData class]]);
MXKRoomMemberCellData *memberCellData = (MXKRoomMemberCellData*)cellData;
if (memberCellData)
{
mxSession = memberCellData.mxSession;
memberId = memberCellData.roomMember.userId;
self.userLabel.text = memberCellData.memberDisplayName;
// Disable by default activity update mechanism (This is required in case of a reused cell).
shouldUpdateActivityInfo = NO;
// User thumbnail
self.pictureView.mediaFolder = kMXMediaManagerAvatarThumbnailFolder;
self.pictureView.enableInMemoryCache = YES;
// Consider here the member avatar is stored unencrypted on Matrix media repo
[self.pictureView setImageURI:memberCellData.roomMember.avatarUrl
withType:nil
andImageOrientation:UIImageOrientationUp
toFitViewSize:self.pictureView.frame.size
withMethod:MXThumbnailingMethodCrop
previewImage:self.picturePlaceholder
mediaManager:mxSession.mediaManager];
// Shade invited users
if (memberCellData.roomMember.membership == MXMembershipInvite)
{
for (UIView *view in self.subviews)
{
view.alpha = 0.3;
}
}
else
{
for (UIView *view in self.subviews)
{
view.alpha = 1;
}
}
// Display the power level pie
[self setPowerContainerValue:memberCellData.powerLevel];
// Prepare presence string and thumbnail border color
NSString* presenceText = nil;
UIColor* thumbnailBorderColor = nil;
// Customize banned and left (kicked) members
if (memberCellData.roomMember.membership == MXMembershipLeave || memberCellData.roomMember.membership == MXMembershipBan)
{
self.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.0];
presenceText = (memberCellData.roomMember.membership == MXMembershipLeave) ? [MatrixKitL10n membershipLeave] : [MatrixKitL10n membershipBan];
}
else
{
self.backgroundColor = [UIColor whiteColor];
// get the user presence and his thumbnail border color
if (memberCellData.roomMember.membership == MXMembershipInvite)
{
thumbnailBorderColor = [UIColor lightGrayColor];
presenceText = [MatrixKitL10n membershipInvite];
}
else
{
// Get the user that corresponds to this member
MXUser *user = [mxSession userWithUserId:memberId];
// existing user ?
if (user)
{
thumbnailBorderColor = [MXKAccount presenceColor:user.presence];
presenceText = [self lastActiveTime];
// Keep last seen range to update it
lastSeenRange = NSMakeRange(self.userLabel.text.length + 2, presenceText.length);
shouldUpdateActivityInfo = (presenceText.length != 0);
}
}
}
// if the thumbnail is defined
if (thumbnailBorderColor)
{
self.pictureView.layer.borderWidth = 2;
self.pictureView.layer.borderColor = thumbnailBorderColor.CGColor;
}
else
{
// remove the border
// else it draws black border
self.pictureView.layer.borderWidth = 0;
}
// and the presence text (if any)
if (presenceText)
{
NSString* extraText = [NSString stringWithFormat:@"(%@)", presenceText];
self.userLabel.text = [NSString stringWithFormat:@"%@ %@", self.userLabel.text, extraText];
NSRange range = [self.userLabel.text rangeOfString:extraText];
UIFont* font = self.userLabel.font;
// Create the attributes
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
font, NSFontAttributeName,
self.userLabel.textColor, NSForegroundColorAttributeName, nil];
NSDictionary *subAttrs = [NSDictionary dictionaryWithObjectsAndKeys:
font, NSFontAttributeName,
[UIColor lightGrayColor], NSForegroundColorAttributeName, nil];
// Create the attributed string (text + attributes)
NSMutableAttributedString *attributedText =[[NSMutableAttributedString alloc] initWithString:self.userLabel.text attributes:attrs];
[attributedText setAttributes:subAttrs range:range];
// Set it in our UILabel and we are done!
[self.userLabel setAttributedText:attributedText];
}
// Set typing badge visibility
if (memberCellData.isTyping)
{
self.typingBadge.hidden = NO;
[self.typingBadge.superview bringSubviewToFront:self.typingBadge];
}
else
{
self.typingBadge.hidden = YES;
}
}
}
+ (CGFloat)heightForCellData:(MXKCellData *)cellData withMaximumWidth:(CGFloat)maxWidth
{
// The height is fixed
return 50;
}
- (NSString*)lastActiveTime
{
NSString* lastActiveTime = nil;
// Get the user that corresponds to this member
MXUser *user = [mxSession userWithUserId:memberId];
if (user)
{
// Prepare last active ago string
lastActiveTime = [MXKTools formatSecondsIntervalFloored:(user.lastActiveAgo / 1000)];
// Check presence
switch (user.presence)
{
case MXPresenceOffline:
{
lastActiveTime = [MatrixKitL10n offline];
break;
}
case MXPresenceUnknown:
{
lastActiveTime = nil;
break;
}
case MXPresenceOnline:
case MXPresenceUnavailable:
default:
break;
}
}
return lastActiveTime;
}
- (void)setPowerContainerValue:(CGFloat)progress
{
// no power level -> hide the pie
if (0 == progress)
{
self.powerContainer.hidden = YES;
return;
}
// display it
self.powerContainer.hidden = NO;
self.powerContainer.backgroundColor = [UIColor clearColor];
if (!pieChartView)
{
pieChartView = [[MXKPieChartView alloc] initWithFrame:self.powerContainer.bounds];
[self.powerContainer addSubview:pieChartView];
}
pieChartView.progress = progress;
}
- (void)updateActivityInfo
{
// Check whether update is required.
if (shouldUpdateActivityInfo)
{
NSString *lastSeen = [self lastActiveTime];
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithAttributedString:self.userLabel.attributedText];
if (lastSeen.length)
{
[attributedText replaceCharactersInRange:lastSeenRange withString:lastSeen];
// Update last seen range
lastSeenRange.length = lastSeen.length;
}
else
{
// remove presence info
lastSeenRange.location -= 1;
lastSeenRange.length += 2;
[attributedText deleteCharactersInRange:lastSeenRange];
shouldUpdateActivityInfo = NO;
}
[self.userLabel setAttributedText:attributedText];
}
}
- (void)layoutSubviews
{
[super layoutSubviews];
// Round image view
[_pictureView.layer setCornerRadius:_pictureView.frame.size.width / 2];
_pictureView.clipsToBounds = YES;
}
@end
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.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"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="50" id="aXI-hs-gNf" customClass="MXKRoomMemberTableViewCell">
<rect key="frame" x="0.0" y="0.0" width="600" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="aXI-hs-gNf" id="q4T-pF-CuP">
<rect key="frame" x="0.0" y="0.0" width="600" height="49"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="CJC-M2-3cz" customClass="MXKImageView">
<rect key="frame" x="8" y="5" width="40" height="40"/>
<color key="backgroundColor" red="0.66666666666666663" green="0.66666666666666663" blue="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" secondItem="CJC-M2-3cz" secondAttribute="height" multiplier="1:1" id="bly-Ea-Vvq"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="userLabel" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="iFy-OK-xut" userLabel="userLabel">
<rect key="frame" x="56" y="5" width="520" height="34"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="W5Z-3a-LW2" userLabel="PowerContainer">
<rect key="frame" x="578" y="18" width="14" height="14"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="14" id="7fi-W6-3Sa"/>
<constraint firstAttribute="width" constant="14" id="imM-WQ-Qgf"/>
</constraints>
</view>
<imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="YAu-wP-WnM" userLabel="typingBadge">
<rect key="frame" x="5" y="0.0" width="20" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="dFN-Im-pSS"/>
<constraint firstAttribute="width" constant="20" id="scT-z6-Uun"/>
</constraints>
</imageView>
</subviews>
<constraints>
<constraint firstItem="YAu-wP-WnM" firstAttribute="leading" secondItem="q4T-pF-CuP" secondAttribute="leading" constant="5" id="5ft-Pb-UJN"/>
<constraint firstAttribute="trailingMargin" secondItem="W5Z-3a-LW2" secondAttribute="trailing" id="74P-LT-vkG"/>
<constraint firstAttribute="bottom" secondItem="CJC-M2-3cz" secondAttribute="bottom" constant="4" id="9qa-86-pGV"/>
<constraint firstItem="iFy-OK-xut" firstAttribute="top" secondItem="q4T-pF-CuP" secondAttribute="top" constant="5" id="A3N-Wc-aBt"/>
<constraint firstItem="YAu-wP-WnM" firstAttribute="top" secondItem="q4T-pF-CuP" secondAttribute="top" id="CZT-v2-b58"/>
<constraint firstAttribute="centerY" secondItem="W5Z-3a-LW2" secondAttribute="centerY" id="IZJ-Xf-g1s"/>
<constraint firstItem="iFy-OK-xut" firstAttribute="leading" secondItem="CJC-M2-3cz" secondAttribute="trailing" constant="8" id="Iq2-M3-vu0"/>
<constraint firstItem="CJC-M2-3cz" firstAttribute="top" secondItem="q4T-pF-CuP" secondAttribute="top" constant="5" id="MZl-z6-Jxx"/>
<constraint firstItem="CJC-M2-3cz" firstAttribute="leading" secondItem="q4T-pF-CuP" secondAttribute="leading" constant="8" id="TJZ-CX-NiF"/>
<constraint firstAttribute="bottom" secondItem="iFy-OK-xut" secondAttribute="bottom" constant="10" id="fKg-iv-O1W"/>
<constraint firstAttribute="trailing" secondItem="iFy-OK-xut" secondAttribute="trailing" constant="24" id="sVQ-oi-McX"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<outlet property="pictureView" destination="CJC-M2-3cz" id="AZY-ZP-KSE"/>
<outlet property="powerContainer" destination="W5Z-3a-LW2" id="Ssq-sC-S6p"/>
<outlet property="typingBadge" destination="YAu-wP-WnM" id="6PS-4m-cB4"/>
<outlet property="userLabel" destination="iFy-OK-xut" id="2Jp-tX-5Jl"/>
</connections>
</tableViewCell>
</objects>
</document>