Reaction history: Implement screen.

This commit is contained in:
SBiOSoftWhare 2019-07-30 17:15:55 +02:00
parent f8cdb2afd6
commit 8c83e1d51d
7 changed files with 380 additions and 0 deletions

View file

@ -295,6 +295,7 @@
"room_event_action_edit" = "Edit";
"room_event_action_reaction_show_all" = "Show all";
"room_event_action_reaction_show_less" = "Show less";
"room_event_action_reaction_history" = "Reaction history";
"room_warning_about_encryption" = "End-to-end encryption is in beta and may not be reliable.\n\nYou should not yet trust it to secure data.\n\nDevices will not yet be able to decrypt history from before they joined the room.\n\nEncrypted messages will not be visible on clients that do not yet implement encryption.";
"room_event_failed_to_send" = "Failed to send";
"room_action_send_photo_or_video" = "Send photo or video";
@ -928,3 +929,6 @@
"emoji_picker_objects_category" = "Objects";
"emoji_picker_symbols_category" = "Symbols";
"emoji_picker_flags_category" = "Flags";
// MARK: Reaction history
"reaction_history_title" = "Reactions";

View file

@ -82,6 +82,11 @@ internal enum StoryboardScene {
internal static let initialScene = InitialSceneType<Riot.KeyBackupSetupSuccessFromRecoveryKeyViewController>(storyboard: KeyBackupSetupSuccessFromRecoveryKeyViewController.self)
}
internal enum ReactionHistoryViewController: StoryboardType {
internal static let storyboardName = "ReactionHistoryViewController"
internal static let initialScene = InitialSceneType<Riot.ReactionHistoryViewController>(storyboard: ReactionHistoryViewController.self)
}
internal enum RoomContextualMenuViewController: StoryboardType {
internal static let storyboardName = "RoomContextualMenuViewController"

View file

@ -1406,6 +1406,10 @@ internal enum VectorL10n {
internal static var rageShakePrompt: String {
return VectorL10n.tr("Vector", "rage_shake_prompt")
}
/// Reactions
internal static var reactionHistoryTitle: String {
return VectorL10n.tr("Vector", "reaction_history_title")
}
/// Read Receipts List
internal static var readReceiptsList: String {
return VectorL10n.tr("Vector", "read_receipts_list")
@ -1818,6 +1822,10 @@ internal enum VectorL10n {
internal static var roomEventActionQuote: String {
return VectorL10n.tr("Vector", "room_event_action_quote")
}
/// Reaction history
internal static var roomEventActionReactionHistory: String {
return VectorL10n.tr("Vector", "room_event_action_reaction_history")
}
/// Show all
internal static var roomEventActionReactionShowAll: String {
return VectorL10n.tr("Vector", "room_event_action_reaction_show_all")

View file

@ -0,0 +1,44 @@
/*
Copyright 2014 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 UIKit
import Reusable
final class ReactionHistoryViewCell: UITableViewCell, NibReusable, Themable {
// MARK: - Properties
@IBOutlet private weak var reactionLabel: UILabel!
@IBOutlet private weak var userDisplayNameLabel: UILabel!
@IBOutlet private weak var timestampLabel: UILabel!
// MARK: - Public
func fill(with viewData: ReactionHistoryViewData) {
self.reactionLabel.text = viewData.reaction
self.userDisplayNameLabel.text = viewData.userDisplayName
self.timestampLabel.text = viewData.dateString
}
func update(theme: Theme) {
self.backgroundColor = theme.backgroundColor
self.reactionLabel.textColor = theme.textPrimaryColor
self.userDisplayNameLabel.textColor = theme.textPrimaryColor
self.timestampLabel.textColor = theme.textSecondaryColor
}
}

View file

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<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"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="46" id="KGk-i7-Jjw" customClass="ReactionHistoryViewCell" customModule="Riot" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="578" height="46"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="578" height="45.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="252" horizontalCompressionResistancePriority="752" text="😀" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="sgX-dJ-kCR">
<rect key="frame" x="20" y="10" width="24" height="25.5"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" text="user name" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Vcy-eW-DCg">
<rect key="frame" x="54" y="13" width="460.5" height="19.5"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="20:30" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Euk-Mr-DGp">
<rect key="frame" x="524.5" y="15.5" width="33.5" height="14.5"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="sgX-dJ-kCR" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" priority="750" constant="10" id="1d4-Pd-ffp"/>
<constraint firstItem="Vcy-eW-DCg" firstAttribute="leading" secondItem="sgX-dJ-kCR" secondAttribute="trailing" constant="10" id="2Se-Si-LeY"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="Vcy-eW-DCg" secondAttribute="bottom" constant="10" id="AKa-IS-sS3"/>
<constraint firstAttribute="bottom" secondItem="sgX-dJ-kCR" secondAttribute="bottom" priority="750" constant="10" id="Bq1-yU-Eju"/>
<constraint firstItem="sgX-dJ-kCR" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="20" id="Gnp-Pg-a5X"/>
<constraint firstItem="Vcy-eW-DCg" firstAttribute="centerY" secondItem="sgX-dJ-kCR" secondAttribute="centerY" id="N2F-Pw-CRB"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="sgX-dJ-kCR" secondAttribute="bottom" constant="10" id="SQg-Iz-ZA6"/>
<constraint firstItem="Euk-Mr-DGp" firstAttribute="leading" secondItem="Vcy-eW-DCg" secondAttribute="trailing" constant="10" id="W4s-gm-wXT"/>
<constraint firstAttribute="trailing" secondItem="Euk-Mr-DGp" secondAttribute="trailing" constant="20" id="c1y-WQ-DmA"/>
<constraint firstItem="sgX-dJ-kCR" firstAttribute="top" relation="greaterThanOrEqual" secondItem="H2p-sc-9uM" secondAttribute="top" constant="10" id="k6s-g1-TzX"/>
<constraint firstItem="Vcy-eW-DCg" firstAttribute="top" relation="greaterThanOrEqual" secondItem="H2p-sc-9uM" secondAttribute="top" constant="10" id="qRt-N3-3rj"/>
<constraint firstItem="Euk-Mr-DGp" firstAttribute="centerY" secondItem="sgX-dJ-kCR" secondAttribute="centerY" id="zNz-zT-nFd"/>
</constraints>
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
<connections>
<outlet property="reactionLabel" destination="sgX-dJ-kCR" id="gGv-pT-xAa"/>
<outlet property="timestampLabel" destination="Euk-Mr-DGp" id="ZCp-Og-Tar"/>
<outlet property="userDisplayNameLabel" destination="Vcy-eW-DCg" id="v95-in-PbT"/>
</connections>
<point key="canvasLocation" x="-71.014492753623188" y="79.017857142857139"/>
</tableViewCell>
</objects>
</document>

View file

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="V8j-Lb-PgC">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Reaction History View Controller-->
<scene sceneID="mt5-wz-YKA">
<objects>
<viewController extendedLayoutIncludesOpaqueBars="YES" automaticallyAdjustsScrollViewInsets="NO" id="V8j-Lb-PgC" customClass="ReactionHistoryViewController" customModule="Riot" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="EL9-GA-lwo">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" allowsSelection="NO" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="HkR-sa-Jjv">
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<connections>
<outlet property="dataSource" destination="V8j-Lb-PgC" id="NeJ-vG-i82"/>
<outlet property="delegate" destination="V8j-Lb-PgC" id="Ddg-k9-R6c"/>
</connections>
</tableView>
</subviews>
<color key="backgroundColor" red="0.94509803921568625" green="0.96078431372549022" blue="0.97254901960784312" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="HkR-sa-Jjv" firstAttribute="top" secondItem="bFg-jh-JZB" secondAttribute="top" id="8aH-El-E6A"/>
<constraint firstAttribute="trailing" secondItem="HkR-sa-Jjv" secondAttribute="trailing" id="L5p-CX-oPq"/>
<constraint firstItem="HkR-sa-Jjv" firstAttribute="leading" secondItem="EL9-GA-lwo" secondAttribute="leading" id="Vo4-SY-4qi"/>
<constraint firstAttribute="bottom" secondItem="HkR-sa-Jjv" secondAttribute="bottom" id="kdK-64-7jj"/>
</constraints>
<viewLayoutGuide key="safeArea" id="bFg-jh-JZB"/>
</view>
<connections>
<outlet property="tableView" destination="HkR-sa-Jjv" id="PHl-xo-AGs"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="zK0-v6-7Wt" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-3198" y="-647"/>
</scene>
</scenes>
</document>

View file

@ -0,0 +1,206 @@
// File created from ScreenTemplate
// $ createScreen.sh ReactionHistory ReactionHistory
/*
Copyright 2019 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
final class ReactionHistoryViewController: UIViewController {
// MARK: - Constants
private enum TableView {
static let estimatedRowHeight: CGFloat = 21.0
static let contentInset = UIEdgeInsets(top: 10.0, left: 0.0, bottom: 10.0, right: 0.0)
}
// MARK: - Properties
// MARK: Outlets
@IBOutlet private weak var tableView: UITableView!
// MARK: Private
private var viewModel: ReactionHistoryViewModelType!
private var theme: Theme!
private var errorPresenter: MXKErrorPresentation!
private var activityPresenter: ActivityIndicatorPresenter!
private var isViewAppearedOnce: Bool = false
private var reactionHistoryViewDataList: [ReactionHistoryViewData] = []
// MARK: - Setup
class func instantiate(with viewModel: ReactionHistoryViewModelType) -> ReactionHistoryViewController {
let viewController = StoryboardScene.ReactionHistoryViewController.initialScene.instantiate()
viewController.viewModel = viewModel
viewController.theme = ThemeService.shared().theme
return viewController
}
// MARK: - Life cycle
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.title = VectorL10n.reactionHistoryTitle
self.viewModel.viewDelegate = self
self.activityPresenter = ActivityIndicatorPresenter()
self.errorPresenter = MXKErrorAlertPresentation()
self.setupViews()
self.registerThemeServiceDidChangeThemeNotification()
self.update(theme: self.theme)
self.viewModel.process(viewAction: .loadMore)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if self.isViewAppearedOnce == false {
self.isViewAppearedOnce = true
}
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return self.theme.statusBarStyle
}
// MARK: - Private
private func update(theme: Theme) {
self.theme = theme
self.view.backgroundColor = theme.headerBackgroundColor
self.tableView.backgroundColor = theme.backgroundColor
if let navigationBar = self.navigationController?.navigationBar {
theme.applyStyle(onNavigationBar: navigationBar)
}
}
private func registerThemeServiceDidChangeThemeNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .themeServiceDidChangeTheme, object: nil)
}
@objc private func themeDidChange() {
self.update(theme: ThemeService.shared().theme)
}
private func setupTableView() {
self.tableView.contentInset = TableView.contentInset
self.tableView.rowHeight = UITableView.automaticDimension
self.tableView.estimatedRowHeight = TableView.estimatedRowHeight
self.tableView.register(cellType: ReactionHistoryViewCell.self)
self.tableView.tableFooterView = UIView()
}
private func setupViews() {
let closeBarButtonItem = MXKBarButtonItem(title: VectorL10n.close, style: .plain) { [weak self] in
self?.closeButtonAction()
}
self.navigationItem.rightBarButtonItem = closeBarButtonItem
self.setupTableView()
}
private func render(viewState: ReactionHistoryViewState) {
switch viewState {
case .loading:
self.renderLoading()
case .loaded(reactionHistoryViewDataList: let reactionHistoryViewDataList, allDataLoaded: let allDataLoaded):
self.renderLoaded(reactionHistoryViewDataList: reactionHistoryViewDataList, allDataLoaded: allDataLoaded)
case .error(let error):
self.render(error: error)
}
}
private func renderLoading() {
self.activityPresenter.presentActivityIndicator(on: self.view, animated: true)
}
private func renderLoaded(reactionHistoryViewDataList: [ReactionHistoryViewData], allDataLoaded: Bool) {
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
self.reactionHistoryViewDataList = reactionHistoryViewDataList
self.tableView.reloadData()
}
private func render(error: Error) {
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
self.errorPresenter.presentError(from: self, forError: error, animated: true, handler: nil)
}
// MARK: - Actions
private func closeButtonAction() {
self.viewModel.process(viewAction: .close)
}
}
// MARK: - UITableViewDataSource
extension ReactionHistoryViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.reactionHistoryViewDataList.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let reactionHistoryCell = tableView.dequeueReusableCell(for: indexPath, cellType: ReactionHistoryViewCell.self)
let reactionHistoryViewData = self.reactionHistoryViewDataList[indexPath.row]
reactionHistoryCell.update(theme: self.theme)
reactionHistoryCell.fill(with: reactionHistoryViewData)
return reactionHistoryCell
}
}
// MARK: - UITableViewDelegate
extension ReactionHistoryViewController: UITableViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard self.isViewAppearedOnce else {
return
}
// Check if a scroll beyond scroll view content occurs
let distanceFromBottom = scrollView.contentSize.height - scrollView.contentOffset.y
if distanceFromBottom < scrollView.frame.size.height {
self.viewModel.process(viewAction: .loadMore)
}
}
}
// MARK: - ReactionHistoryViewModelViewDelegate
extension ReactionHistoryViewController: ReactionHistoryViewModelViewDelegate {
func reactionHistoryViewModel(_ viewModel: ReactionHistoryViewModelType, didUpdateViewState viewSate: ReactionHistoryViewState) {
self.render(viewState: viewSate)
}
}