mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-29 04:36:58 +02:00
Update theming and footer
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// 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 RoomNotificationSettingsFooter: UITableViewHeaderFooterView {
|
||||
|
||||
struct State {
|
||||
let showEncryptedNotice: Bool
|
||||
let showAccountLink: Bool
|
||||
}
|
||||
|
||||
@IBOutlet weak var label: UILabel!
|
||||
|
||||
func update(footerState: State) {
|
||||
|
||||
// let paragraphStyle = NSMutableParagraphStyle()
|
||||
// paragraphStyle.lineHeightMultiple = 1.16
|
||||
// let paragraphAttributes: [NSAttributedString.Key: Any] = [
|
||||
// NSAttributedString.Key.kern: -0.08,
|
||||
// NSAttributedString.Key.paragraphStyle: paragraphStyle,
|
||||
// NSAttributedString.Key.font: UIFont.systemFont(ofSize: 13.0)
|
||||
// ]
|
||||
|
||||
// Don't include link until global settings in place
|
||||
// let linkStr = VectorL10n.roomNotifsSettingsAccountSettings
|
||||
// let formatStr = VectorL10n.roomNotifsSettingsManageNotifications(linkStr)
|
||||
//
|
||||
// let formattedStr = String(format: formatStr, arguments: [linkStr])
|
||||
// let footer0 = NSMutableAttributedString(string: formattedStr, attributes: paragraphAttributes)
|
||||
// let linkRange = (footer0.string as NSString).range(of: linkStr)
|
||||
// footer0.addAttribute(NSAttributedString.Key.link, value: Constants.linkToAccountSettings, range: linkRange)
|
||||
if footerState.showEncryptedNotice {
|
||||
label.text = VectorL10n.roomNotifsSettingsEncryptedRoomNotice
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension RoomNotificationSettingsFooter: NibReusable {}
|
||||
extension RoomNotificationSettingsFooter: Themable {
|
||||
|
||||
func update(theme: Theme) {
|
||||
contentView.backgroundColor = theme.headerBackgroundColor
|
||||
label.textColor = theme.headerTextSecondaryColor
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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="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="default" indentationWidth="10" id="Ecs-Zf-2tR" customClass="RoomNotificationSettingsFooter" customModule="Riot" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="76"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Ecs-Zf-2tR" id="f2j-NO-hdS">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="76"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xlF-dY-Ud8">
|
||||
<rect key="frame" x="20" y="16" width="374" height="44"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="xlF-dY-Ud8" firstAttribute="bottom" secondItem="f2j-NO-hdS" secondAttribute="bottom" constant="-16" id="BWu-8S-Qnj"/>
|
||||
<constraint firstItem="xlF-dY-Ud8" firstAttribute="top" secondItem="f2j-NO-hdS" secondAttribute="top" constant="16" id="Lpw-g0-S41"/>
|
||||
<constraint firstItem="xlF-dY-Ud8" firstAttribute="leading" secondItem="f2j-NO-hdS" secondAttribute="leadingMargin" id="Zf5-c0-agj"/>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="xlF-dY-Ud8" secondAttribute="trailing" id="wIa-z6-N5E"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
<connections>
|
||||
<outlet property="label" destination="xlF-dY-Ud8" id="qhR-4x-7Yt"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="37" y="-210"/>
|
||||
</tableViewCell>
|
||||
</objects>
|
||||
</document>
|
||||
+25
-91
@@ -36,22 +36,14 @@ final class RoomNotificationSettingsViewController: UIViewController {
|
||||
private var errorPresenter: MXKErrorPresentation!
|
||||
private var activityPresenter: ActivityIndicatorPresenter!
|
||||
|
||||
private enum RowType {
|
||||
case plain
|
||||
}
|
||||
|
||||
private struct Row {
|
||||
var type: RowType
|
||||
var setting: RoomNotificationState
|
||||
var text: String?
|
||||
var accessoryType: UITableViewCell.AccessoryType = .none
|
||||
var cellState: RoomNotificationSettingsCell.State
|
||||
var action: (() -> Void)?
|
||||
}
|
||||
|
||||
private struct Section {
|
||||
var header: String?
|
||||
var rows: [Row]
|
||||
var footer: NSAttributedString?
|
||||
var footerState: RoomNotificationSettingsFooter.State
|
||||
}
|
||||
|
||||
private var sections: [Section] = [] {
|
||||
@@ -104,6 +96,7 @@ final class RoomNotificationSettingsViewController: UIViewController {
|
||||
if let navigationBar = navigationController?.navigationBar {
|
||||
theme.applyStyle(onNavigationBar: navigationBar)
|
||||
}
|
||||
mainTableView.reloadData()
|
||||
}
|
||||
|
||||
private func registerThemeServiceDidChangeThemeNotification() {
|
||||
@@ -127,6 +120,10 @@ final class RoomNotificationSettingsViewController: UIViewController {
|
||||
navigationItem.leftBarButtonItem = cancelBarButtonItem
|
||||
}
|
||||
navigationItem.rightBarButtonItem = doneBarButtonItem
|
||||
mainTableView.register(cellType: RoomNotificationSettingsCell.self)
|
||||
mainTableView.register(headerFooterViewType: RoomNotificationSettingsFooter.self)
|
||||
mainTableView.sectionFooterHeight = UITableView.automaticDimension
|
||||
mainTableView.estimatedSectionFooterHeight = 50
|
||||
}
|
||||
|
||||
private func render(viewState: RoomNotificationSettingsViewStateType) {
|
||||
@@ -142,36 +139,14 @@ final class RoomNotificationSettingsViewController: UIViewController {
|
||||
|
||||
private func updateSections() {
|
||||
let rows = viewState.notificationOptions.map({ (setting) -> Row in
|
||||
return Row(type: .plain,
|
||||
setting: setting,
|
||||
text: setting.title,
|
||||
accessoryType: viewState.notificationState == setting ? .checkmark : .none,
|
||||
let cellState = RoomNotificationSettingsCell.State(notificicationState: setting, selected: viewState.notificationState == setting)
|
||||
return Row(cellState: cellState,
|
||||
action: {
|
||||
self.viewModel.process(viewAction: .selectNotificationState(setting))
|
||||
})
|
||||
})
|
||||
|
||||
let paragraphStyle = NSMutableParagraphStyle()
|
||||
paragraphStyle.lineHeightMultiple = 1.16
|
||||
let paragraphAttributes: [NSAttributedString.Key: Any] = [
|
||||
NSAttributedString.Key.kern: -0.08,
|
||||
NSAttributedString.Key.paragraphStyle: paragraphStyle,
|
||||
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 13.0)
|
||||
]
|
||||
|
||||
// Don't include link until global settings in place
|
||||
// let linkStr = VectorL10n.roomNotifsSettingsAccountSettings
|
||||
// let formatStr = VectorL10n.roomNotifsSettingsManageNotifications(linkStr)
|
||||
//
|
||||
// let formattedStr = String(format: formatStr, arguments: [linkStr])
|
||||
// let footer0 = NSMutableAttributedString(string: formattedStr, attributes: paragraphAttributes)
|
||||
// let linkRange = (footer0.string as NSString).range(of: linkStr)
|
||||
// footer0.addAttribute(NSAttributedString.Key.link, value: Constants.linkToAccountSettings, range: linkRange)
|
||||
var footer0: NSAttributedString?
|
||||
if viewState.roomEncrypted {
|
||||
footer0 = NSAttributedString(string: VectorL10n.roomNotifsSettingsEncryptedRoomNotice, attributes: paragraphAttributes)
|
||||
}
|
||||
let section0 = Section(header: nil, rows: rows, footer: footer0)
|
||||
let footerState = RoomNotificationSettingsFooter.State(showEncryptedNotice: viewState.roomEncrypted, showAccountLink: false)
|
||||
let section0 = Section(rows: rows, footerState: footerState)
|
||||
sections = [
|
||||
section0
|
||||
]
|
||||
@@ -191,29 +166,15 @@ extension RoomNotificationSettingsViewController: UITableViewDataSource {
|
||||
|
||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let row = sections[indexPath.section].rows[indexPath.row]
|
||||
let cell: RoomNotificationSettingsCell = tableView.dequeueReusableCell(for: indexPath)
|
||||
cell.update(state: row.cellState)
|
||||
cell.update(theme: theme)
|
||||
return cell
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
|
||||
|
||||
switch row.type {
|
||||
case .plain:
|
||||
var cell: UITableViewCell! = tableView.dequeueReusableCell(withIdentifier: Constants.plainStyleCellReuseIdentifier)
|
||||
if cell == nil {
|
||||
cell = UITableViewCell(style: .value1, reuseIdentifier: Constants.plainStyleCellReuseIdentifier)
|
||||
}
|
||||
cell.textLabel?.font = .systemFont(ofSize: 17)
|
||||
cell.detailTextLabel?.font = .systemFont(ofSize: 16)
|
||||
cell.textLabel?.text = row.text
|
||||
if row.accessoryType == .checkmark {
|
||||
cell.accessoryView = UIImageView(image: Asset.Images.checkmark.image)
|
||||
} else {
|
||||
cell.accessoryView = nil
|
||||
cell.accessoryType = row.accessoryType
|
||||
}
|
||||
cell.textLabel?.textColor = theme.textPrimaryColor
|
||||
cell.detailTextLabel?.textColor = theme.textSecondaryColor
|
||||
cell.backgroundColor = theme.backgroundColor
|
||||
cell.contentView.backgroundColor = .clear
|
||||
cell.tintColor = theme.tintColor
|
||||
return cell
|
||||
}
|
||||
return UITableView.automaticDimension
|
||||
}
|
||||
|
||||
}
|
||||
@@ -227,28 +188,14 @@ extension RoomNotificationSettingsViewController: UITableViewDelegate {
|
||||
cell.selectedBackgroundView?.backgroundColor = theme.selectedBackgroundColor
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
||||
return sections[section].header
|
||||
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
|
||||
guard let footerView: RoomNotificationSettingsFooter = tableView.dequeueReusableHeaderFooterView() else { return nil }
|
||||
let footerState = sections[section].footerState
|
||||
footerView.update(footerState: footerState)
|
||||
footerView.update(theme: theme)
|
||||
return footerView
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
||||
return sections[section].footer?.string
|
||||
}
|
||||
|
||||
// func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
|
||||
// if sections[section].footer == nil {
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// let view = tableView.dequeueReusableHeaderFooterView(RiotTableViewHeaderFooterView.self)
|
||||
//
|
||||
// view?.textView.attributedText = sections[section].footer
|
||||
// view?.update(theme: theme)
|
||||
// view?.delegate = self
|
||||
//
|
||||
// return view
|
||||
// }
|
||||
|
||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
|
||||
@@ -265,16 +212,3 @@ extension RoomNotificationSettingsViewController: RoomNotificationSettingsViewMo
|
||||
render(viewState: viewSate)
|
||||
}
|
||||
}
|
||||
|
||||
extension RoomNotificationState {
|
||||
var title: String {
|
||||
switch self {
|
||||
case .all:
|
||||
return VectorL10n.roomNotifsSettingsAllMessages
|
||||
case .mentionsOnly:
|
||||
return VectorL10n.roomNotifsSettingsMentionsAndKeywords
|
||||
case .mute:
|
||||
return VectorL10n.roomNotifsSettingsNone
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// 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 RoomNotificationSettingsCell: UITableViewCell {
|
||||
|
||||
struct State {
|
||||
let notificicationState: RoomNotificationState
|
||||
let selected: Bool
|
||||
}
|
||||
|
||||
func update(state: State) {
|
||||
textLabel?.font = .systemFont(ofSize: 17)
|
||||
detailTextLabel?.font = .systemFont(ofSize: 16)
|
||||
textLabel?.text = state.notificicationState.title
|
||||
if state.selected {
|
||||
accessoryView = UIImageView(image: Asset.Images.checkmark.image)
|
||||
} else {
|
||||
accessoryView = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension RoomNotificationSettingsCell: Reusable {}
|
||||
|
||||
extension RoomNotificationSettingsCell: Themable {
|
||||
func update(theme: Theme) {
|
||||
textLabel?.textColor = theme.textPrimaryColor
|
||||
detailTextLabel?.textColor = theme.textSecondaryColor
|
||||
backgroundColor = theme.backgroundColor
|
||||
contentView.backgroundColor = .clear
|
||||
tintColor = theme.tintColor
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate extension RoomNotificationState {
|
||||
var title: String {
|
||||
switch self {
|
||||
case .all:
|
||||
return VectorL10n.roomNotifsSettingsAllMessages
|
||||
case .mentionsOnly:
|
||||
return VectorL10n.roomNotifsSettingsMentionsAndKeywords
|
||||
case .mute:
|
||||
return VectorL10n.roomNotifsSettingsNone
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user