Add avatar view and title

This commit is contained in:
langleyd 2021-07-04 10:46:17 +01:00
parent e787d3b695
commit f16d270d6c
7 changed files with 129 additions and 5 deletions

View file

@ -0,0 +1,50 @@
//
// 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 Foundation
import Reusable
struct RoomNotificationSettingsAvatarViewData {
let avatarUrl: String?
let mediaManager: MXMediaManager?
let displayName: String?
let roomId: String
}
class RoomNotificationSettingsAvatarView: UIView, NibLoadable {
@IBOutlet weak var avatarView: MXKImageView!
@IBOutlet weak var nameLabel: UILabel!
func configure(viewData: RoomNotificationSettingsAvatarViewData) {
let avatarImage = AvatarGenerator.generateAvatar(forMatrixItem: viewData.roomId, withDisplayName: viewData.displayName)
if let avatarUrl = viewData.avatarUrl {
avatarView.enableInMemoryCache = true
avatarView.setImageURI(avatarUrl,
withType: nil,
andImageOrientation: .up,
toFitViewSize: avatarView.frame.size,
with: MXThumbnailingMethodCrop,
previewImage: avatarImage,
mediaManager: viewData.mediaManager)
} else {
avatarView.image = avatarImage
}
nameLabel.text = viewData.displayName
}
}

View file

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="18122" 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="18093"/>
<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"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="RoomNotificationSettingsAvatarView" customModule="Riot" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="414" height="192"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<subviews>
<view autoresizesSubviews="NO" clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="q3Z-S1-Py9" customClass="MXKImageView">
<rect key="frame" x="167" y="20" width="80" height="80"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="80" id="tFe-kl-KGy"/>
<constraint firstAttribute="width" constant="80" id="tOu-Mt-atQ"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="40"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pBK-NN-5cI">
<rect key="frame" x="182" y="108" width="50" height="24"/>
<constraints>
<constraint firstAttribute="height" constant="24" id="yzb-2V-G1M"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="20"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="q3Z-S1-Py9" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="20" id="1EV-ZD-9aG"/>
<constraint firstItem="pBK-NN-5cI" firstAttribute="top" secondItem="q3Z-S1-Py9" secondAttribute="bottom" constant="8" id="Rcf-3z-sEY"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="bottom" secondItem="pBK-NN-5cI" secondAttribute="bottom" constant="60" id="V3E-vX-joC"/>
<constraint firstItem="pBK-NN-5cI" firstAttribute="centerX" secondItem="q3Z-S1-Py9" secondAttribute="centerX" id="vNG-KB-1Vd"/>
<constraint firstItem="q3Z-S1-Py9" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="wKJ-BP-2RA"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="avatarView" destination="q3Z-S1-Py9" id="cLO-Y3-6If"/>
<outlet property="nameLabel" destination="pBK-NN-5cI" id="Wt8-Oe-9mK"/>
</connections>
<point key="canvasLocation" x="86.956521739130437" y="99.776785714285708"/>
</view>
</objects>
</document>

View file

@ -36,9 +36,15 @@ final class RoomNotificationSettingsCoordinator: RoomNotificationSettingsCoordin
// MARK: - Setup // MARK: - Setup
init(room: MXRoom) { init(room: MXRoom, showAvatar: Bool = true) {
let repository = RoomNotificationSettingsService(room: room) let repository = RoomNotificationSettingsService(room: room)
let roomNotificationSettingsViewModel = RoomNotificationSettingsViewModel(roomNotificationRepository: repository, roomEncrypted: room.summary.isEncrypted)
let avatarData = showAvatar ? RoomNotificationSettingsAvatarViewData(
avatarUrl: room.summary.avatar,
mediaManager: room.mxSession.mediaManager,
displayName: room.summary.displayname,
roomId: room.roomId) : nil
let roomNotificationSettingsViewModel = RoomNotificationSettingsViewModel(roomNotificationRepository: repository, roomEncrypted: room.summary.isEncrypted, avatarViewData: avatarData)
let roomNotificationSettingsViewController = RoomNotificationSettingsViewController.instantiate(with: roomNotificationSettingsViewModel) let roomNotificationSettingsViewController = RoomNotificationSettingsViewController.instantiate(with: roomNotificationSettingsViewModel)
self.roomNotificationSettingsViewModel = roomNotificationSettingsViewModel self.roomNotificationSettingsViewModel = roomNotificationSettingsViewModel
self.roomNotificationSettingsViewController = roomNotificationSettingsViewController self.roomNotificationSettingsViewController = roomNotificationSettingsViewController

View file

@ -34,6 +34,9 @@ final class RoomNotificationSettingsViewController: UIViewController {
private var theme: Theme! private var theme: Theme!
private var errorPresenter: MXKErrorPresentation! private var errorPresenter: MXKErrorPresentation!
private var activityPresenter: ActivityIndicatorPresenter! private var activityPresenter: ActivityIndicatorPresenter!
private lazy var avatarView: RoomNotificationSettingsAvatarView = {
RoomNotificationSettingsAvatarView.loadFromNib()
}()
private struct Row { private struct Row {
var cellState: RoomNotificationSettingsCell.State var cellState: RoomNotificationSettingsCell.State
@ -107,6 +110,8 @@ final class RoomNotificationSettingsViewController: UIViewController {
} }
private func setupViews() { private func setupViews() {
self.title = VectorL10n.roomDetailsNotifs
let doneBarButtonItem = MXKBarButtonItem(title: VectorL10n.roomNotifsSettingsDoneAction, style: .plain) { [weak self] in let doneBarButtonItem = MXKBarButtonItem(title: VectorL10n.roomNotifsSettingsDoneAction, style: .plain) { [weak self] in
self?.viewModel.process(viewAction: .save) self?.viewModel.process(viewAction: .save)
} }
@ -133,6 +138,10 @@ final class RoomNotificationSettingsViewController: UIViewController {
activityPresenter.removeCurrentActivityIndicator(animated: true) activityPresenter.removeCurrentActivityIndicator(animated: true)
} }
self.viewState = viewState self.viewState = viewState
if let avatarData = viewState.avatarData {
mainTableView.tableHeaderView = avatarView
avatarView.configure(viewData: avatarData)
}
updateSections() updateSections()
} }

View file

@ -39,11 +39,11 @@ final class RoomNotificationSettingsViewModel: RoomNotificationSettingsViewModel
// MARK: - Setup // MARK: - Setup
init(roomNotificationRepository: RoomNotificationSettingsServiceType, roomEncrypted: Bool) { init(roomNotificationRepository: RoomNotificationSettingsServiceType, roomEncrypted: Bool, avatarViewData: RoomNotificationSettingsAvatarViewData?) {
self.roomNotificationRepository = roomNotificationRepository self.roomNotificationRepository = roomNotificationRepository
let notificationState = Self.mapNotificationStateOnRead(encrypted: roomEncrypted, state: roomNotificationRepository.notificationState) let notificationState = Self.mapNotificationStateOnRead(encrypted: roomEncrypted, state: roomNotificationRepository.notificationState)
self.state = RoomNotificationSettingsViewState(roomEncrypted: roomEncrypted, saving: false, notificationState: notificationState) self.state = RoomNotificationSettingsViewState(roomEncrypted: roomEncrypted, saving: false, notificationState: notificationState, avatarData: avatarViewData)
self.roomNotificationRepository.observeNotificationState { [weak self] state in self.roomNotificationRepository.observeNotificationState { [weak self] state in
guard let self = self else { return } guard let self = self else { return }

View file

@ -30,6 +30,7 @@ struct RoomNotificationSettingsViewState: RoomNotificationSettingsViewStateType
return RoomNotificationState.allCases return RoomNotificationState.allCases
} }
} }
let avatarData: RoomNotificationSettingsAvatarViewData?
} }
protocol RoomNotificationSettingsViewStateType { protocol RoomNotificationSettingsViewStateType {
@ -37,4 +38,5 @@ protocol RoomNotificationSettingsViewStateType {
var roomEncrypted: Bool { get } var roomEncrypted: Bool { get }
var notificationOptions: [RoomNotificationState] { get } var notificationOptions: [RoomNotificationState] { get }
var notificationState: RoomNotificationState { get } var notificationState: RoomNotificationState { get }
var avatarData: RoomNotificationSettingsAvatarViewData? { get }
} }

View file

@ -138,7 +138,7 @@ final class RoomInfoCoordinator: NSObject, RoomInfoCoordinatorType {
} }
private func createRoomNotificationSettingsCoordinator() -> RoomNotificationSettingsCoordinator { private func createRoomNotificationSettingsCoordinator() -> RoomNotificationSettingsCoordinator {
let coordinator = RoomNotificationSettingsCoordinator(room: room) let coordinator = RoomNotificationSettingsCoordinator(room: room, showAvatar: false)
coordinator.delegate = self coordinator.delegate = self
return coordinator return coordinator
} }