diff --git a/openHAB.xcodeproj/project.pbxproj b/openHAB.xcodeproj/project.pbxproj index 2ae25261..075eb939 100644 --- a/openHAB.xcodeproj/project.pbxproj +++ b/openHAB.xcodeproj/project.pbxproj @@ -68,7 +68,6 @@ 93F8065027AE7A830035A6B0 /* SideMenu in Frameworks */ = {isa = PBXBuildFile; productRef = 93F8064F27AE7A830035A6B0 /* SideMenu */; }; 93F8065327AE7B580035A6B0 /* SVGKit in Frameworks */ = {isa = PBXBuildFile; productRef = 93F8065227AE7B580035A6B0 /* SVGKit */; }; A07ED02E2402EE6E006588FE /* OpenHABWatchTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = A07ED02D2402EE6E006588FE /* OpenHABWatchTracker.swift */; }; - A07EF7A02230C0A30040919F /* OpenHABClientCertificatesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A07EF79F2230C0A20040919F /* OpenHABClientCertificatesViewController.swift */; }; A3F4C3A51A49A5940019A09F /* MainLaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = A3F4C3A41A49A5940019A09F /* MainLaunchScreen.xib */; }; B7D5ECE121499E55001B0EC6 /* MapViewTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7D5ECE021499E55001B0EC6 /* MapViewTableViewCell.swift */; }; DA0749DE23E0B5950057FA83 /* ColorPickerRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA0749DD23E0B5950057FA83 /* ColorPickerRow.swift */; }; @@ -126,7 +125,6 @@ DAC9AF4924F966FA006DAE93 /* LazyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAC9AF4824F966FA006DAE93 /* LazyView.swift */; }; DACB636227D3FC6500041931 /* error.png in Resources */ = {isa = PBXBuildFile; fileRef = DACB636127D3FC6500041931 /* error.png */; }; DACB636327D3FC6500041931 /* error.png in Resources */ = {isa = PBXBuildFile; fileRef = DACB636127D3FC6500041931 /* error.png */; }; - DAEAA89B21E2611000267EA3 /* OpenHABNotificationsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAEAA89A21E2611000267EA3 /* OpenHABNotificationsViewController.swift */; }; DAEAA89D21E6B06400267EA3 /* ReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAEAA89C21E6B06300267EA3 /* ReusableView.swift */; }; DAEAA89F21E6B16600267EA3 /* UITableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAEAA89E21E6B16600267EA3 /* UITableView.swift */; }; DAF0A28B2C56E3A300A14A6A /* RollershutterCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAF0A28A2C56E3A300A14A6A /* RollershutterCell.swift */; }; @@ -150,13 +148,9 @@ DAF4581823DC4A050018B495 /* ImageRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAF4581723DC4A050018B495 /* ImageRow.swift */; }; DAF4581E23DC60020018B495 /* ImageRawRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAF4581D23DC60020018B495 /* ImageRawRow.swift */; }; DAF4F6C0222734D300C24876 /* NewImageUITableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAF4F6BF222734D200C24876 /* NewImageUITableViewCell.swift */; }; - DF05EF121D00696200DD646D /* DrawerUITableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF05EF111D00696200DD646D /* DrawerUITableViewCell.swift */; }; DF05FF231896BD2D00FF2F9B /* SelectionUITableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF05FF221896BD2D00FF2F9B /* SelectionUITableViewCell.swift */; }; - DF06F1F618FE7A160011E7B9 /* OpenHABSelectionTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF06F1F518FE7A160011E7B9 /* OpenHABSelectionTableViewController.swift */; }; DF06F1FC18FEC2020011E7B9 /* ColorPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF06F1FB18FEC2020011E7B9 /* ColorPickerViewController.swift */; }; DF1B302D1CF5C667009C921C /* OpenHABNotification.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF1B302C1CF5C667009C921C /* OpenHABNotification.swift */; }; - DF4A022C1CF315BA006C3456 /* OpenHABDrawerTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF4A022B1CF315BA006C3456 /* OpenHABDrawerTableViewController.swift */; }; - DF4A02421CF34096006C3456 /* OpenHABDrawerItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF4A02411CF34096006C3456 /* OpenHABDrawerItem.swift */; }; DF4B84041885A53700F34902 /* OpenHABDataObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF4B84031885A53700F34902 /* OpenHABDataObject.swift */; }; DF4B84071885AE0E00F34902 /* blankicon.png in Resources */ = {isa = PBXBuildFile; fileRef = DF4B84061885AE0E00F34902 /* blankicon.png */; }; DF4B84131886DAC400F34902 /* FrameUITableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF4B84121886DAC400F34902 /* FrameUITableViewCell.swift */; }; @@ -324,7 +318,6 @@ 938BF9D224EFD0B700E6B52F /* UIViewController+Localization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Localization.swift"; sourceTree = ""; }; 938EDCE022C4FEB800661CA1 /* ScaleAspectFitImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScaleAspectFitImageView.swift; sourceTree = ""; }; A07ED02D2402EE6E006588FE /* OpenHABWatchTracker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = OpenHABWatchTracker.swift; path = "openHABWatch Extension/OpenHABWatchTracker.swift"; sourceTree = SOURCE_ROOT; }; - A07EF79F2230C0A20040919F /* OpenHABClientCertificatesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenHABClientCertificatesViewController.swift; sourceTree = ""; }; A3F4C3A41A49A5940019A09F /* MainLaunchScreen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = MainLaunchScreen.xib; path = ../MainLaunchScreen.xib; sourceTree = ""; }; B7D5ECE021499E55001B0EC6 /* MapViewTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapViewTableViewCell.swift; sourceTree = ""; }; DA0749DD23E0B5950057FA83 /* ColorPickerRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPickerRow.swift; sourceTree = ""; }; @@ -427,7 +420,6 @@ DAD488B3287DDDFE00414693 /* nb */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nb; path = Resources/nb.lproj/Intents.strings; sourceTree = ""; }; DAD488B4287DDDFF00414693 /* nb */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nb; path = nb.lproj/Localizable.strings; sourceTree = ""; }; DAD488B5287DDDFF00414693 /* nb */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nb; path = nb.lproj/InfoPlist.strings; sourceTree = ""; }; - DAEAA89A21E2611000267EA3 /* OpenHABNotificationsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenHABNotificationsViewController.swift; sourceTree = ""; }; DAEAA89C21E6B06300267EA3 /* ReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReusableView.swift; sourceTree = ""; }; DAEAA89E21E6B16600267EA3 /* UITableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITableView.swift; sourceTree = ""; }; DAF0A28A2C56E3A300A14A6A /* RollershutterCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RollershutterCell.swift; sourceTree = ""; }; @@ -449,13 +441,9 @@ DAF4581723DC4A050018B495 /* ImageRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageRow.swift; sourceTree = ""; }; DAF4581D23DC60020018B495 /* ImageRawRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageRawRow.swift; sourceTree = ""; }; DAF4F6BF222734D200C24876 /* NewImageUITableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewImageUITableViewCell.swift; sourceTree = ""; }; - DF05EF111D00696200DD646D /* DrawerUITableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DrawerUITableViewCell.swift; sourceTree = ""; }; DF05FF221896BD2D00FF2F9B /* SelectionUITableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectionUITableViewCell.swift; sourceTree = ""; }; - DF06F1F518FE7A160011E7B9 /* OpenHABSelectionTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenHABSelectionTableViewController.swift; sourceTree = ""; }; DF06F1FB18FEC2020011E7B9 /* ColorPickerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorPickerViewController.swift; sourceTree = ""; }; DF1B302C1CF5C667009C921C /* OpenHABNotification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenHABNotification.swift; sourceTree = ""; }; - DF4A022B1CF315BA006C3456 /* OpenHABDrawerTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenHABDrawerTableViewController.swift; sourceTree = ""; }; - DF4A02411CF34096006C3456 /* OpenHABDrawerItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenHABDrawerItem.swift; sourceTree = ""; }; DF4B84031885A53700F34902 /* OpenHABDataObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenHABDataObject.swift; sourceTree = ""; }; DF4B84061885AE0E00F34902 /* blankicon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = blankicon.png; sourceTree = ""; }; DF4B84121886DAC400F34902 /* FrameUITableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FrameUITableViewCell.swift; sourceTree = ""; }; @@ -782,16 +770,6 @@ path = Views; sourceTree = ""; }; - DA6B2EF32C89D2F200DF77CF /* Obsolete */ = { - isa = PBXGroup; - children = ( - DF06F1F518FE7A160011E7B9 /* OpenHABSelectionTableViewController.swift */, - A07EF79F2230C0A20040919F /* OpenHABClientCertificatesViewController.swift */, - DAEAA89A21E2611000267EA3 /* OpenHABNotificationsViewController.swift */, - ); - name = Obsolete; - sourceTree = ""; - }; DAE238252806E5C800196467 /* Recovered References */ = { isa = PBXGroup; children = ( @@ -846,29 +824,9 @@ path = Utils; sourceTree = ""; }; - DF4A02291CF3157B006C3456 /* Drawer (obsolete) */ = { - isa = PBXGroup; - children = ( - DF4A02411CF34096006C3456 /* OpenHABDrawerItem.swift */, - DF4A022B1CF315BA006C3456 /* OpenHABDrawerTableViewController.swift */, - DF4A022D1CF315D3006C3456 /* Widgets */, - ); - name = "Drawer (obsolete)"; - sourceTree = ""; - }; - DF4A022D1CF315D3006C3456 /* Widgets */ = { - isa = PBXGroup; - children = ( - DF05EF111D00696200DD646D /* DrawerUITableViewCell.swift */, - ); - name = Widgets; - sourceTree = ""; - }; DF4B83FD18857FA100F34902 /* UI */ = { isa = PBXGroup; children = ( - DF4A02291CF3157B006C3456 /* Drawer (obsolete) */, - DA6B2EF32C89D2F200DF77CF /* Obsolete */, 653B54C1285E714900298ECD /* OpenHABViewController.swift */, 653B54BF285C0AC700298ECD /* OpenHABRootViewController.swift */, 65570A7C2476D16A00D524EA /* OpenHABWebViewController.swift */, @@ -1492,7 +1450,6 @@ DF06F1FC18FEC2020011E7B9 /* ColorPickerViewController.swift in Sources */, 1224F78F228A89FD00750965 /* WatchMessageService.swift in Sources */, DAA42BAC21DC984A00244B2A /* WebUITableViewCell.swift in Sources */, - DF05EF121D00696200DD646D /* DrawerUITableViewCell.swift in Sources */, DF4B84131886DAC400F34902 /* FrameUITableViewCell.swift in Sources */, DF4B84161886EACA00F34902 /* GenericUITableViewCell.swift in Sources */, 935B484625342B8E00E44CF0 /* URL+Static.swift in Sources */, @@ -1504,18 +1461,14 @@ DF4B84041885A53700F34902 /* OpenHABDataObject.swift in Sources */, DAC65FC7236EDF3900F4501E /* SpinnerViewController.swift in Sources */, DA9F81872C85020F00B47B72 /* RTFTextView.swift in Sources */, - DF4A02421CF34096006C3456 /* OpenHABDrawerItem.swift in Sources */, DA6B2EF12C87B59000DF77CF /* NotificationsView.swift in Sources */, DA50C7BF2B0A65300009F716 /* SliderWithSwitchSupportUITableViewCell.swift in Sources */, - DF4A022C1CF315BA006C3456 /* OpenHABDrawerTableViewController.swift in Sources */, DA5ED9BE2C850955004875E0 /* ClientCertificatesViewModel.swift in Sources */, DA21EAE22339621C001AB415 /* Throttler.swift in Sources */, DAF4F6C0222734D300C24876 /* NewImageUITableViewCell.swift in Sources */, - DAEAA89B21E2611000267EA3 /* OpenHABNotificationsViewController.swift in Sources */, DF1B302D1CF5C667009C921C /* OpenHABNotification.swift in Sources */, DA6B2EEF2C861BC900DF77CF /* DrawerView.swift in Sources */, 938BF9D324EFD0B700E6B52F /* UIViewController+Localization.swift in Sources */, - DF06F1F618FE7A160011E7B9 /* OpenHABSelectionTableViewController.swift in Sources */, DAA42BA821DC97E000244B2A /* NotificationTableViewCell.swift in Sources */, DAF0A28F2C56F1EE00A14A6A /* ColorPickerCell.swift in Sources */, 6595667E28E0BE8E00E8A53B /* MulticastDelegate.swift in Sources */, @@ -1530,7 +1483,6 @@ DFA16EBB18883DE500EDB0BB /* SliderUITableViewCell.swift in Sources */, DFA13CB418872EBD006355C3 /* SwitchUITableViewCell.swift in Sources */, DFFD8FD118EDBD4F003B502A /* UICircleButton.swift in Sources */, - A07EF7A02230C0A30040919F /* OpenHABClientCertificatesViewController.swift in Sources */, 938BF9C624EFCC0700E6B52F /* UILabel+Localization.swift in Sources */, DA5ED9C02C8509C2004875E0 /* ClientCertificatesView.swift in Sources */, 653B54C0285C0AC700298ECD /* OpenHABRootViewController.swift in Sources */, diff --git a/openHAB/DrawerUITableViewCell.swift b/openHAB/DrawerUITableViewCell.swift deleted file mode 100644 index 0efe0d91..00000000 --- a/openHAB/DrawerUITableViewCell.swift +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2010-2024 Contributors to the openHAB project -// -// See the NOTICE file(s) distributed with this work for additional -// information. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License 2.0 which is available at -// http://www.eclipse.org/legal/epl-2.0 -// -// SPDX-License-Identifier: EPL-2.0 - -import os.log -import UIKit - -class DrawerUITableViewCell: UITableViewCell { - @IBOutlet private(set) var customTextLabel: UILabel! - @IBOutlet private(set) var customImageView: UIImageView! - - required init?(coder: NSCoder) { - os_log("DrawerUITableViewCell initWithCoder", log: .viewCycle, type: .info) - super.init(coder: coder) - - separatorInset = .zero - } - - // This is to fix possible different sizes of user icons - we fix size and position of UITableViewCell icons - override func layoutSubviews() { - super.layoutSubviews() - imageView?.frame = CGRect(x: 14, y: 6, width: 30, height: 30) - } -} diff --git a/openHAB/DrawerView.swift b/openHAB/DrawerView.swift index b4754603..291428a1 100644 --- a/openHAB/DrawerView.swift +++ b/openHAB/DrawerView.swift @@ -71,7 +71,6 @@ struct ImageView: View { struct DrawerView: View { @State private var sitemaps: [OpenHABSitemap] = [] @State private var uiTiles: [OpenHABUiTile] = [] - @State private var drawerItems: [OpenHABDrawerItem] = [] @State private var selectedSection: Int? var openHABUsername = "" @@ -197,11 +196,8 @@ struct DrawerView: View { case .label: sitemaps.sort { $0.label < $1.label } case .name: sitemaps.sort { $0.name < $1.name } } - - drawerItems.removeAll() case let .failure(error): os_log("%{PUBLIC}@", log: .default, type: .error, error.localizedDescription) - drawerItems.removeAll() } } } diff --git a/openHAB/Main.storyboard b/openHAB/Main.storyboard index ed7c98d2..74fd991d 100644 --- a/openHAB/Main.storyboard +++ b/openHAB/Main.storyboard @@ -615,66 +615,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -707,9 +647,6 @@ - - - @@ -733,35 +670,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -780,67 +688,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/openHAB/OpenHABClientCertificatesViewController.swift b/openHAB/OpenHABClientCertificatesViewController.swift deleted file mode 100644 index da74346f..00000000 --- a/openHAB/OpenHABClientCertificatesViewController.swift +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2010-2024 Contributors to the openHAB project -// -// See the NOTICE file(s) distributed with this work for additional -// information. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License 2.0 which is available at -// http://www.eclipse.org/legal/epl-2.0 -// -// SPDX-License-Identifier: EPL-2.0 - -import OpenHABCore -import os.log -import UIKit - -class OpenHABClientCertificatesViewController: UITableViewController { - static let tableViewCellIdentifier = "ClientCertificatesCell" - - var clientCertificates: [SecIdentity] = [] - - required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - } - - override func viewDidLoad() { - super.viewDidLoad() - navigationItem.title = NSLocalizedString("client_certificates", comment: "") - os_log("OpenHABClientCertificatesViewController viewDidLoad", log: .default, type: .info) - - tableView.tableFooterView = UIView() - tableView.allowsMultipleSelectionDuringEditing = false - } - - override func viewWillAppear(_ animated: Bool) { - super.viewDidAppear(animated) - - tableView.reloadData() - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - // Return the number of rows in the section. - NetworkConnection.shared.clientCertificateManager.clientIdentities.count - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: OpenHABClientCertificatesViewController.tableViewCellIdentifier, for: indexPath) - cell.textLabel?.text = NetworkConnection.shared.clientCertificateManager.getIdentityName(index: indexPath.row) - return cell - } - - override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { - if editingStyle == UITableViewCell.EditingStyle.delete { - let status = NetworkConnection.shared.clientCertificateManager.deleteFromKeychain(index: indexPath.row) - if status == noErr { - tableView.deleteRows(at: [indexPath], with: .fade) - } - } - } -} diff --git a/openHAB/OpenHABDrawerItem.swift b/openHAB/OpenHABDrawerItem.swift deleted file mode 100644 index 6b7e36ec..00000000 --- a/openHAB/OpenHABDrawerItem.swift +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2010-2024 Contributors to the openHAB project -// -// See the NOTICE file(s) distributed with this work for additional -// information. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License 2.0 which is available at -// http://www.eclipse.org/legal/epl-2.0 -// -// SPDX-License-Identifier: EPL-2.0 - -import Foundation -import SFSafeSymbols - -enum OpenHABDrawerItem { - case settings - case notifications - - var localizedString: String { - switch self { - case .settings: - NSLocalizedString("settings", comment: "") - case .notifications: - NSLocalizedString("notifications", comment: "") - } - } - - var icon: SFSymbol { - switch self { - case .notifications: .bell - case .settings: .gear - } - } - - static func openHABDrawerItem(localizedString: String) -> OpenHABDrawerItem { - switch localizedString { - case OpenHABDrawerItem.settings.localizedString: - OpenHABDrawerItem.settings - case OpenHABDrawerItem.notifications.localizedString: - OpenHABDrawerItem.notifications - default: - OpenHABDrawerItem.settings - } - } -} diff --git a/openHAB/OpenHABDrawerTableViewController.swift b/openHAB/OpenHABDrawerTableViewController.swift deleted file mode 100644 index a546f900..00000000 --- a/openHAB/OpenHABDrawerTableViewController.swift +++ /dev/null @@ -1,310 +0,0 @@ -// Copyright (c) 2010-2024 Contributors to the openHAB project -// -// See the NOTICE file(s) distributed with this work for additional -// information. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License 2.0 which is available at -// http://www.eclipse.org/legal/epl-2.0 -// -// SPDX-License-Identifier: EPL-2.0 - -import OpenHABCore -import os.log -import SafariServices -import SFSafeSymbols -import UIKit - -class OpenHABDrawerTableViewController: UITableViewController { - static let tableViewCellIdentifier = "DrawerCell" - - var sitemaps: [OpenHABSitemap] = [] - var uiTiles: [OpenHABUiTile] = [] - var openHABUsername = "" - var openHABPassword = "" - var drawerItems: [OpenHABDrawerItem] = [] - weak var delegate: ModalHandler? - - // App wide data access - var appData: OpenHABDataObject? { - AppDelegate.appDelegate.appData - } - - init() { - super.init(nibName: nil, bundle: nil) - } - - required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - } - - override func viewDidLoad() { - super.viewDidLoad() - tableView.tableFooterView = UIView() - drawerItems = [] - sitemaps = [] - loadSettings() - setStandardDrawerItems() - os_log("OpenHABDrawerTableViewController did load", log: .viewCycle, type: .info) - } - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - os_log("OpenHABDrawerTableViewController viewWillAppear", log: .viewCycle, type: .info) - - NetworkConnection.sitemaps(openHABRootUrl: appData?.openHABRootUrl ?? "") { response in - switch response.result { - case let .success(data): - os_log("Sitemap response", log: .viewCycle, type: .info) - - self.sitemaps = deriveSitemaps(data) - - if self.sitemaps.last?.name == "_default", self.sitemaps.count > 1 { - self.sitemaps = Array(self.sitemaps.dropLast()) - } - - // Sort the sitemaps according to Settings selection. - switch SortSitemapsOrder(rawValue: Preferences.sortSitemapsby) ?? .label { - case .label: self.sitemaps.sort { $0.label < $1.label } - case .name: self.sitemaps.sort { $0.name < $1.name } - } - - self.drawerItems.removeAll() - self.setStandardDrawerItems() - self.tableView.reloadData() - case let .failure(error): - os_log("%{PUBLIC}@", log: .default, type: .error, error.localizedDescription) - self.drawerItems.removeAll() - self.setStandardDrawerItems() - self.tableView.reloadData() - } - } - - NetworkConnection.uiTiles(openHABRootUrl: appData?.openHABRootUrl ?? "") { response in - switch response.result { - case .success: - UIApplication.shared.isNetworkActivityIndicatorVisible = false - os_log("ui tiles response", log: .viewCycle, type: .info) - guard let responseData = response.data else { - os_log("Error: did not receive data", log: OSLog.remoteAccess, type: .info) - return - } - do { - self.uiTiles = try JSONDecoder().decode([OpenHABUiTile].self, from: responseData) - self.tableView.reloadData() - } catch { - os_log("Error: did not receive data %{PUBLIC}@", log: OSLog.remoteAccess, type: .info, error.localizedDescription) - } - case let .failure(error): - UIApplication.shared.isNetworkActivityIndicatorVisible = false - os_log("%{PUBLIC}@", log: .default, type: .error, error.localizedDescription) - } - } - } - - override func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - tableView.reloadData() - os_log("RightDrawerViewController viewDidAppear", log: .viewCycle, type: .info) - os_log("Sitemap count: %d", log: .viewCycle, type: .info, Int(sitemaps.count)) - os_log("Menu items count: %d", log: .viewCycle, type: .info, Int(drawerItems.count)) - } - - override func viewDidDisappear(_ animated: Bool) { - super.viewDidDisappear(animated) // Call the super class implementation. - os_log("RightDrawerViewController viewDidDisappear", log: .viewCycle, type: .info) - } - - // MARK: - Table view data source - - override func numberOfSections(in tableView: UITableView) -> Int { - 4 - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - switch section { - case 0: - 1 - case 1: - uiTiles.count - case 2: - sitemaps.count - case 3: - drawerItems.count - default: - 0 - } - } - - override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { - switch section { - case 0: - "Main" - case 1: - "Tiles" - case 2: - "Sitemaps" - case 3: - "System" - default: - "Unknown" - } - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = (tableView.dequeueReusableCell(withIdentifier: OpenHABDrawerTableViewController.tableViewCellIdentifier) as? DrawerUITableViewCell)! - cell.customImageView.subviews.forEach { $0.removeFromSuperview() } - cell.accessoryView = nil - switch indexPath.section { - case 0: - cell.customTextLabel?.text = "Home" - cell.customImageView.image = UIImage(named: "openHABIcon") - if let currentView = appData?.currentView { - // if we already are on the webview, pressing this again will force a refresh - if case .webview = currentView { - cell.accessoryView = UIImageView(image: UIImage(named: "arrow.triangle.2.circlepath")) - } - } - case 1: - let imageView = UIImageView(frame: cell.customImageView.bounds) - let tile = uiTiles[indexPath.row] - cell.customTextLabel?.text = tile.name - let passedURL = tile.imageUrl - // Dependent on $OPENHAB_CONF/services/runtime.cfg - // Can either be an absolute URL, a path (sometimes malformed) or the content to be displayed (for imageURL) - if !passedURL.isEmpty { - switch passedURL { - case _ where passedURL.hasPrefix("data:image"): - if let imageData = Data(base64Encoded: passedURL.deletingPrefix("data:image/png;base64,"), options: .ignoreUnknownCharacters) { - imageView.image = UIImage(data: imageData) - } // data;image/png;base64, - case _ where passedURL.hasPrefix("http"): - os_log("Loading %{PUBLIC}@", log: .default, type: .info, String(describing: passedURL)) - imageView.kf.setImage(with: URL(string: passedURL), placeholder: UIImage(named: "openHABIcon")) - default: - if let builtURL = Endpoint.resource(openHABRootUrl: appData?.openHABRootUrl ?? "", path: passedURL.prepare()).url { - os_log("Loading %{PUBLIC}@", log: .default, type: .info, String(describing: builtURL)) - imageView.kf.setImage(with: builtURL, placeholder: UIImage(named: "openHABIcon")) - } - } - } else { - imageView.image = UIImage(named: "openHABIcon") - } - cell.customImageView.image = imageView.image - case 2: - if !sitemaps.isEmpty { - let siteMapIndex = indexPath.row - let imageView = UIImageView(frame: cell.customImageView.bounds) - - cell.customTextLabel?.text = sitemaps[siteMapIndex].label - if !sitemaps[siteMapIndex].icon.isEmpty { - if let iconURL = Endpoint.iconForDrawer(rootUrl: appData?.openHABRootUrl ?? "", icon: sitemaps[siteMapIndex].icon).url { - imageView.kf.setImage(with: iconURL, placeholder: UIImage(named: "openHABIcon")) - } - } else { - imageView.image = UIImage(named: "openHABIcon") - } - cell.customImageView.image = imageView.image - } - case 3: - // Then menu items - let drawerItem = drawerItems[indexPath.row] - cell.customTextLabel?.text = drawerItem.localizedString - switch drawerItem { - case .notifications: - cell.customImageView.image = UIImage(systemSymbol: .bell) - case .settings: - cell.customImageView.image = UIImage(systemSymbol: .gear) - } - default: - break - } - cell.separatorInset = UIEdgeInsets(top: 0, left: 60, bottom: 0, right: 0) - - cell.preservesSuperviewLayoutMargins = false - cell.layoutMargins = .zero - - return cell - } - - override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - 44 - } - - override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - // open a alert with an OK and cancel button - os_log("Clicked on drawer section %d row %d", log: .viewCycle, type: .info, indexPath.section, indexPath.row) - - tableView.deselectRow(at: indexPath, animated: false) - // First sitemaps - switch indexPath.section { - case 0: - dismiss(animated: true) { - self.delegate?.modalDismissed(to: .webview) - } - case 1: - let passedURL = uiTiles[indexPath.row].url - // Dependent on $OPENHAB_CONF/services/runtime.cfg - // Can either be an absolute URL, a path (sometimes malformed) - if !passedURL.isEmpty { - switch passedURL { - case _ where passedURL.hasPrefix("http"): - openURL(url: URL(string: passedURL)) - default: - let builtURL = Endpoint.resource(openHABRootUrl: appData?.openHABRootUrl ?? "", path: passedURL.prepare()) - openURL(url: builtURL.url) - } - } - case 2: - if !sitemaps.isEmpty { - let sitemap = sitemaps[indexPath.row] - Preferences.defaultSitemap = sitemap.name - appData?.sitemapViewController?.pageUrl = "" - dismiss(animated: true) { - os_log("self delegate %d", log: .viewCycle, type: .info, self.delegate != nil) - self.delegate?.modalDismissed(to: .sitemap("")) - } - } - case 3: - // Then menu items - let drawerItem = drawerItems[indexPath.row] - - switch drawerItem { - case .settings: - dismiss(animated: true) { - self.delegate?.modalDismissed(to: .settings) - } - case .notifications: - dismiss(animated: true) { - self.delegate?.modalDismissed(to: .notifications) - } - } - default: - break - } - } - - private func setStandardDrawerItems() { - // check if we are using my.openHAB, add notifications menu item then - // Actually this should better test whether the host of the remoteUrl is on openhab.org - if Preferences.remoteUrl.contains("openhab.org"), !Preferences.demomode { - drawerItems.append(.notifications) - } - // Settings always go last - drawerItems.append(.settings) - } - - func loadSettings() { - openHABUsername = Preferences.username - openHABPassword = Preferences.password - } - - private func openURL(url: URL?) { - if let url { - let config = SFSafariViewController.Configuration() - config.entersReaderIfAvailable = true - let vc = SFSafariViewController(url: url, configuration: config) - present(vc, animated: true) - } - } -} diff --git a/openHAB/OpenHABNotificationsViewController.swift b/openHAB/OpenHABNotificationsViewController.swift deleted file mode 100644 index c78ecdca..00000000 --- a/openHAB/OpenHABNotificationsViewController.swift +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright (c) 2010-2024 Contributors to the openHAB project -// -// See the NOTICE file(s) distributed with this work for additional -// information. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License 2.0 which is available at -// http://www.eclipse.org/legal/epl-2.0 -// -// SPDX-License-Identifier: EPL-2.0 - -import OpenHABCore -import os.log -import SideMenu -import UIKit - -class OpenHABNotificationsViewController: UITableViewController { - static let tableViewCellIdentifier = "NotificationCell" - - var notifications: NSMutableArray = [] - var openHABRootUrl = "" - var openHABUsername = "" - var openHABPassword = "" - - var appData: OpenHABDataObject? { - AppDelegate.appDelegate.appData - } - - override func viewDidLoad() { - super.viewDidLoad() - notifications = [] - tableView.tableFooterView = UIView() - refreshControl = UIRefreshControl() - refreshControl?.addTarget(self, action: #selector(OpenHABNotificationsViewController.handleRefresh(_:)), for: .valueChanged) - if let refreshControl { - tableView.refreshControl = refreshControl - } - - navigationItem.largeTitleDisplayMode = .never - } - - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - loadSettings() - loadNotifications() - } - - func loadNotifications() { - NetworkConnection.notification(urlString: Preferences.remoteUrl) { response in - switch response.result { - case let .success(data): - do { - let decoder = JSONDecoder() - decoder.dateDecodingStrategy = .formatted(DateFormatter.iso8601Full) - let codingDatas = try data.decoded(as: [OpenHABNotification.CodingData].self, using: decoder) - self.notifications = [] - for codingDatum in codingDatas { - self.notifications.add(codingDatum.openHABNotification) - } - } catch { - os_log("%{PUBLIC}@ ", log: .default, type: .error, error.localizedDescription) - } - - self.refreshControl?.endRefreshing() - self.tableView.reloadData() - - case let .failure(error): - os_log("%{PUBLIC}@", log: .default, type: .error, error.localizedDescription) - self.refreshControl?.endRefreshing() - } - } - } - - @objc - func handleRefresh(_ refreshControl: UIRefreshControl?) { - os_log("Refresh pulled", log: .default, type: .info) - loadNotifications() - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - notifications.count - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: OpenHABNotificationsViewController.tableViewCellIdentifier) as? NotificationTableViewCell - guard let notification = notifications[indexPath.row] as? OpenHABNotification else { return UITableViewCell() } - - cell?.customTextLabel?.text = notification.message - - if let timeStamp = notification.created { - let dateFormatter = DateFormatter() - dateFormatter.dateStyle = .medium - dateFormatter.timeStyle = .medium - dateFormatter.timeZone = TimeZone.current - cell?.customDetailTextLabel?.text = dateFormatter.string(from: timeStamp) - } - - if let iconUrl = Endpoint.icon( - rootUrl: appData!.openHABRootUrl, - version: appData!.openHABVersion, - icon: notification.icon, - state: "", - iconType: .png, - iconColor: "" - ).url { - cell?.imageView?.kf.setImage( - with: iconUrl, - placeholder: UIImage(named: "openHABIcon") - ) - } - - if cell?.responds(to: #selector(setter: NotificationTableViewCell.preservesSuperviewLayoutMargins)) ?? false { - cell?.preservesSuperviewLayoutMargins = false - } - // Explictly set your cell's layout margins - if cell?.responds(to: #selector(setter: NotificationTableViewCell.layoutMargins)) ?? false { - cell?.layoutMargins = .zero - } - cell?.separatorInset = UIEdgeInsets(top: 0, left: 60, bottom: 0, right: 0) - return cell! - } - - override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - // open a alert with an OK and cancel button - tableView.deselectRow(at: indexPath, animated: false) - } - - func loadSettings() { - appData?.openHABUsername = Preferences.username - appData?.openHABPassword = Preferences.password - } -} - -extension UIBarButtonItem { - static func menuButton(_ target: Any?, action: Selector, imageName: String) -> UIBarButtonItem { - let button = UIButton(type: .system) - button.setImage(UIImage(named: imageName), for: .normal) - button.addTarget(target, action: action, for: .touchUpInside) - - let menuBarItem = UIBarButtonItem(customView: button) - menuBarItem.customView?.translatesAutoresizingMaskIntoConstraints = false - menuBarItem.customView?.heightAnchor.constraint(equalToConstant: 24).isActive = true - menuBarItem.customView?.widthAnchor.constraint(equalToConstant: 24).isActive = true - - return menuBarItem - } -} diff --git a/openHAB/OpenHABSelectionTableViewController.swift b/openHAB/OpenHABSelectionTableViewController.swift deleted file mode 100644 index a03f5bd9..00000000 --- a/openHAB/OpenHABSelectionTableViewController.swift +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) 2010-2024 Contributors to the openHAB project -// -// See the NOTICE file(s) distributed with this work for additional -// information. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License 2.0 which is available at -// http://www.eclipse.org/legal/epl-2.0 -// -// SPDX-License-Identifier: EPL-2.0 - -import OpenHABCore -import os.log -import UIKit - -// swiftlint:disable:next type_name -public protocol OpenHABSelectionTableViewControllerDelegate: NSObjectProtocol { - func didSelectWidgetMapping(_ selectedMapping: Int) -} - -class OpenHABSelectionTableViewController: UITableViewController { - static let tableViewCellIdentifier = "SelectionCell" - - var mappings: [AnyHashable] = [] - weak var delegate: OpenHABSelectionTableViewControllerDelegate? - var selectionItem: OpenHABItem? - - required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - } - - override func viewDidLoad() { - super.viewDidLoad() - - os_log("I have %d mappings", log: .viewCycle, type: .info, mappings.count) - - // Uncomment the following line to preserve selection between presentations. - // self.clearsSelectionOnViewWillAppear = NO; - - // Uncomment the following line to display an Edit button in the navigation bar for this view controller. - // self.navigationItem.rightBarButtonItem = self.editButtonItem; - } - - // MARK: - Table view data source - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - mappings.count - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: OpenHABSelectionTableViewController.tableViewCellIdentifier, for: indexPath) - if let mapping = mappings[indexPath.row] as? OpenHABWidgetMapping { - cell.textLabel?.text = mapping.label - if selectionItem?.state == mapping.command { - os_log("This item is selected", log: .viewCycle, type: .info) - cell.accessoryType = .checkmark - } else { - cell.accessoryType = .none - } - } - return cell - } - - override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - os_log("Selected mapping %d", log: .viewCycle, type: .info, indexPath.row) - - delegate?.didSelectWidgetMapping(indexPath.row) - navigationController?.popViewController(animated: true) - } -} diff --git a/openHAB/OpenHABSitemapViewController.swift b/openHAB/OpenHABSitemapViewController.swift index 81398052..2247b89d 100644 --- a/openHAB/OpenHABSitemapViewController.swift +++ b/openHAB/OpenHABSitemapViewController.swift @@ -540,17 +540,6 @@ extension OpenHABSitemapViewController: OpenHABTrackerDelegate { } } -// MARK: - OpenHABSelectionTableViewControllerDelegate - -extension OpenHABSitemapViewController: OpenHABSelectionTableViewControllerDelegate { - // send command on selected selection widget mapping - func didSelectWidgetMapping(_ selectedMappingIndex: Int) { - let selectedWidget: OpenHABWidget? = relevantPage?.widgets[selectedWidgetRow] - let selectedMapping: OpenHABWidgetMapping? = selectedWidget?.mappingsOrItemOptions[selectedMappingIndex] - sendCommand(selectedWidget?.item, commandToSend: selectedMapping?.command) - } -} - // MARK: - UISearchResultsUpdating extension OpenHABSitemapViewController: UISearchResultsUpdating {