Add ServiceTermsModalTableHeaderView to ServiceTermsModalScreenViewController.

This commit is contained in:
Doug
2021-09-15 11:53:30 +01:00
parent 43866e63aa
commit 59a6826815
8 changed files with 251 additions and 41 deletions
@@ -47,6 +47,8 @@ final class ServiceTermsModalScreenViewController: UIViewController {
private var activityPresenter: ActivityIndicatorPresenter!
private var policies: [MXLoginPolicyData] = []
private var tableHeaderView: ServiceTermsModalTableHeaderView!
// MARK: - Setup
@@ -97,6 +99,8 @@ final class ServiceTermsModalScreenViewController: UIViewController {
descriptionLabel.font = theme.fonts.body
descriptionLabel.textColor = theme.colors.secondaryContent
tableHeaderView.update(theme: theme)
footerLabel.font = theme.fonts.footnote.withSize(13)
footerLabel.textColor = theme.colors.secondaryContent
@@ -125,6 +129,8 @@ final class ServiceTermsModalScreenViewController: UIViewController {
self.titleLabel.text = VectorL10n.serviceTermsModalTitleMessage
self.footerLabel.text = VectorL10n.serviceTermsModalFooter
self.tableHeaderView.serviceURLLabel.text = viewModel.serviceUrl
self.acceptButton.setTitle(VectorL10n.serviceTermsModalAcceptButton, for: .normal)
self.acceptButton.setTitle(VectorL10n.serviceTermsModalAcceptButton, for: .highlighted)
@@ -135,8 +141,10 @@ final class ServiceTermsModalScreenViewController: UIViewController {
if self.viewModel.serviceType == MXServiceTypeIdentityService {
self.descriptionLabel.text = VectorL10n.serviceTermsModalDescriptionIdentityServer
self.tableHeaderView.titleLabel.text = VectorL10n.serviceTermsModalTableHeaderIdentityServer
} else {
self.descriptionLabel.text = VectorL10n.serviceTermsModalDescriptionIntegrationManager
self.tableHeaderView.titleLabel.text = VectorL10n.serviceTermsModalTableHeaderIntegrationManager
// TODO: Set a different image for the integration manager.
}
}
@@ -148,6 +156,9 @@ final class ServiceTermsModalScreenViewController: UIViewController {
self.tableView.alwaysBounceVertical = false
self.tableView.backgroundColor = .clear
self.tableView.register(TableViewCellWithCheckBoxAndLabel.nib(), forCellReuseIdentifier: TableViewCellWithCheckBoxAndLabel.defaultReuseIdentifier())
tableHeaderView = ServiceTermsModalTableHeaderView.instantiate()
self.tableView.tableHeaderView = tableHeaderView
}
private func render(viewState: ServiceTermsModalScreenViewState) {
@@ -220,9 +231,8 @@ extension ServiceTermsModalScreenViewController: ServiceTermsModalScreenViewMode
extension ServiceTermsModalScreenViewController: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
// The first section contains the server's URL. Then use individual
// sections for each policy so the cells aren't grouped together.
return 1 + policies.count
// Use individual sections for each policy so the cells aren't grouped together.
return policies.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
@@ -230,47 +240,19 @@ extension ServiceTermsModalScreenViewController: UITableViewDataSource {
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
// The first section has header text. Modify the rest to reduce cell spacing.
return section == 0 ? 20 : 8
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return section == 0 ? "Identity Server Terms" : nil
// Reduce the height between sections to only be the footer height value.
return CGFloat.leastNormalMagnitude
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
// Reduce the height between sections to only be the header height value.
return CGFloat.leastNormalMagnitude
// Modify the footer size to reduce cell spacing.
return 8.0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
return identityServerURLCell(forRowAt: indexPath)
} else {
return policyCell(forRowAt: indexPath)
}
}
// TODO: Handle this in the integration manager too
private func identityServerURLCell(forRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: Constants.cellReuseIdentifier, for: indexPath)
cell.textLabel?.text = viewModel.serviceUrl
cell.textLabel?.font = theme.fonts.callout
cell.textLabel?.textColor = theme.colors.secondaryContent
cell.accessoryView = nil
cell.backgroundColor = .clear
cell.selectionStyle = .none
return cell
}
private func policyCell(forRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: Constants.cellReuseIdentifier, for: indexPath)
let policyIndex = indexPath.section - 1
let policy = policies[policyIndex]
let policy = policies[indexPath.section]
cell.textLabel?.text = policy.name
cell.textLabel?.textColor = theme.colors.primaryContent
@@ -285,12 +267,8 @@ extension ServiceTermsModalScreenViewController: UITableViewDataSource {
}
extension ServiceTermsModalScreenViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
return indexPath.section > 0 ? indexPath : nil
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let policy = policies[indexPath.section - 1]
let policy = policies[indexPath.section]
viewModel.process(viewAction: .display(policy))
tableView.deselectRow(at: indexPath, animated: true)
}
@@ -0,0 +1,49 @@
//
// 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
import Reusable
class ServiceTermsModalTableHeaderView: UIView, NibLoadable, Themable {
// MARK: - Properties
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var serviceURLLabel: UILabel!
// MARK: - Setup
static func instantiate() -> Self {
let view = Self.loadFromNib()
view.translatesAutoresizingMaskIntoConstraints = false
view.update(theme: ThemeService.shared().theme)
return view
}
func update(theme: Theme) {
titleLabel.font = theme.fonts.footnote
titleLabel.textColor = theme.colors.secondaryContent
serviceURLLabel.font = theme.fonts.callout
serviceURLLabel.textColor = theme.colors.secondaryContent
}
// MARK: - Action
@IBAction private func buttonAction(_ sender: Any) {
}
}
@@ -0,0 +1,66 @@
<?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="ServiceTermsModalTableHeaderView" customModule="Riot" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="328" height="72"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Server Terms" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nQB-Sg-E1U">
<rect key="frame" x="16" y="0.0" width="80.5" height="24"/>
<constraints>
<constraint firstAttribute="height" constant="24" id="Lab-Gt-CFg"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="https://domain.com" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nYB-Yu-HV9">
<rect key="frame" x="16" y="24" width="141" height="36"/>
<constraints>
<constraint firstAttribute="height" constant="36" id="ggs-su-fvA"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ztE-u7-qV6">
<rect key="frame" x="292" y="1" width="20" height="22"/>
<state key="normal" image="information_button"/>
<connections>
<action selector="buttonAction:" destination="iN0-l3-epB" eventType="touchUpInside" id="EeS-ya-xp5"/>
</connections>
</button>
</subviews>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="nYB-Yu-HV9" secondAttribute="bottom" constant="12" id="1MG-vA-cVG"/>
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="ztE-u7-qV6" secondAttribute="trailing" constant="16" id="C1f-Ex-0Ip"/>
<constraint firstItem="ztE-u7-qV6" firstAttribute="centerY" secondItem="nQB-Sg-E1U" secondAttribute="centerY" id="C86-gf-hip"/>
<constraint firstItem="ztE-u7-qV6" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="nQB-Sg-E1U" secondAttribute="trailing" constant="8" symbolic="YES" id="Gtr-PA-pv5"/>
<constraint firstItem="nQB-Sg-E1U" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="16" id="Uci-Xz-AGE"/>
<constraint firstItem="nYB-Yu-HV9" firstAttribute="top" secondItem="nQB-Sg-E1U" secondAttribute="bottom" id="VCK-IC-YUJ"/>
<constraint firstItem="nYB-Yu-HV9" firstAttribute="leading" secondItem="nQB-Sg-E1U" secondAttribute="leading" id="epR-po-phu"/>
<constraint firstItem="nQB-Sg-E1U" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" id="mOs-ee-5dI"/>
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="serviceURLLabel" destination="nYB-Yu-HV9" id="2dD-hK-MjJ"/>
<outlet property="titleLabel" destination="nQB-Sg-E1U" id="PfB-Sr-6fE"/>
</connections>
<point key="canvasLocation" x="40.579710144927539" y="37.834821428571423"/>
</view>
</objects>
<resources>
<image name="information_button" width="20" height="20"/>
</resources>
</document>