Skip to content

Commit

Permalink
Staged files for previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
timbms committed Aug 30, 2024
1 parent 19463c9 commit aa7e0b9
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 29 deletions.
4 changes: 2 additions & 2 deletions OpenHABCore/Sources/OpenHABCore/Model/OpenHABWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protocol Widget: AnyObject {
func flatten(_: [ChildWidget])
}

public class OpenHABWidget: NSObject, MKAnnotation, Identifiable {
public class OpenHABWidget: NSObject, MKAnnotation, Identifiable, ObservableObject {
public enum WidgetType: String {
case chart = "Chart"
case colorpicker = "Colorpicker"
Expand Down Expand Up @@ -86,7 +86,7 @@ public class OpenHABWidget: NSObject, MKAnnotation, Identifiable {
public var labelcolor = ""
public var valuecolor = ""
public var service = ""
public var state = ""
@Published public var state = ""
public var text = ""
public var legend: Bool?
public var encoding = ""
Expand Down
4 changes: 4 additions & 0 deletions openHAB.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
DA07764A234683BC0086C685 /* SwitchRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA077649234683BC0086C685 /* SwitchRow.swift */; };
DA0776F0234788010086C685 /* UserData.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA0776EF234788010086C685 /* UserData.swift */; };
DA0F37D023D4ACC7007EAB48 /* SliderRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA0F37CF23D4ACC7007EAB48 /* SliderRow.swift */; };
DA11B2482C8125E8004D96C9 /* FrameCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA11B2472C8125E8004D96C9 /* FrameCellView.swift */; };
DA15BFBD23C6726400BD8ADA /* ObservableOpenHABDataObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA15BFBC23C6726400BD8ADA /* ObservableOpenHABDataObject.swift */; };
DA19E25B22FD801D002F8F2F /* OpenHABGeneralTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA19E25A22FD801D002F8F2F /* OpenHABGeneralTests.swift */; };
DA21EAE22339621C001AB415 /* Throttler.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA21EAE12339621C001AB415 /* Throttler.swift */; };
Expand Down Expand Up @@ -339,6 +340,7 @@
DA077649234683BC0086C685 /* SwitchRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchRow.swift; sourceTree = "<group>"; };
DA0776EF234788010086C685 /* UserData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserData.swift; sourceTree = "<group>"; };
DA0F37CF23D4ACC7007EAB48 /* SliderRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderRow.swift; sourceTree = "<group>"; };
DA11B2472C8125E8004D96C9 /* FrameCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FrameCellView.swift; sourceTree = "<group>"; };
DA15BFBC23C6726400BD8ADA /* ObservableOpenHABDataObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservableOpenHABDataObject.swift; sourceTree = "<group>"; };
DA19E25A22FD801D002F8F2F /* OpenHABGeneralTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenHABGeneralTests.swift; sourceTree = "<group>"; };
DA1C2E4B230DC28F00FACFB0 /* Appfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Appfile; sourceTree = "<group>"; };
Expand Down Expand Up @@ -897,6 +899,7 @@
DAEAA89E21E6B16600267EA3 /* UITableView.swift */,
DA7E1E47222EB00B002AEFD8 /* PlayerView.swift */,
DA21EAE12339621C001AB415 /* Throttler.swift */,
DA11B2472C8125E8004D96C9 /* FrameCellView.swift */,
);
name = Widgets;
sourceTree = "<group>";
Expand Down Expand Up @@ -1478,6 +1481,7 @@
DF4B84041885A53700F34902 /* OpenHABDataObject.swift in Sources */,
DAC65FC7236EDF3900F4501E /* SpinnerViewController.swift in Sources */,
DF4A02421CF34096006C3456 /* OpenHABDrawerItem.swift in Sources */,
DA11B2482C8125E8004D96C9 /* FrameCellView.swift in Sources */,
DA50C7BF2B0A65300009F716 /* SliderWithSwitchSupportUITableViewCell.swift in Sources */,
DF4A022C1CF315BA006C3456 /* OpenHABDrawerTableViewController.swift in Sources */,
DFDF452F1932032B00A6E581 /* OpenHABLegalViewController.swift in Sources */,
Expand Down
9 changes: 9 additions & 0 deletions openHAB.xcodeproj/xcshareddata/xcschemes/openHAB.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableAddressSanitizer = "YES"
enableASanStackUseAfterReturn = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand All @@ -83,6 +85,13 @@
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
<AdditionalOption
key = "MallocScribble"
value = ""
isEnabled = "YES">
</AdditionalOption>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
28 changes: 22 additions & 6 deletions openHAB/FrameCellView.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
// Copyright (c) 2010-2024 Contributors to the openHAB project
//
// FrameCellView.swift
// openHAB
// See the NOTICE file(s) distributed with this work for additional
// information.
//
// Created by Tim on 29.08.24.
// Copyright © 2024 openHAB e.V. All rights reserved.
// 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 SwiftUI

struct FrameCellView: View {
@ObservedObject var widget: OpenHABWidget
let gray = Color(UIColor.darkGray)

var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
Text(widget.label.uppercased())
.font(.system(.callout))
.lineLimit(1)
.foregroundColor(Color(.ohSecondaryLabel))
.padding()
.background(gray.edgesIgnoringSafeArea(.all))
.listRowInsets(EdgeInsets()) // Equivalent to separatorInset
.frame(maxWidth: .infinity, alignment: .leading)
}
}

#Preview {
FrameCellView()
let widget = OpenHABWidget()
widget.label = "??"
return FrameCellView(widget: widget)
}
49 changes: 28 additions & 21 deletions openHAB/OpenHABSitemapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class OpenHABSitemapViewController: OpenHABViewController, GenericUITableViewCel
search.isActive && !searchBarIsEmpty
}

var dataSource: UITableViewDiffableDataSource<ViewControllerSection, OpenHABWidget>! = nil
var currentSnapshot: NSDiffableDataSourceSnapshot<ViewControllerSection, OpenHABWidget>! = nil
var dataSource: UITableViewDiffableDataSource<ViewControllerSection, OpenHABWidget>!
var currentSnapshot: NSDiffableDataSourceSnapshot<ViewControllerSection, OpenHABWidget>!

@IBOutlet private var tableView: UITableView!

Expand Down Expand Up @@ -334,19 +334,17 @@ class OpenHABSitemapViewController: OpenHABViewController, GenericUITableViewCel
if !NetworkConnection.atmosphereTrackingId.isEmpty {
os_log("Found X-Atmosphere-tracking-id: %{PUBLIC}@", log: .remoteAccess, type: .info, NetworkConnection.atmosphereTrackingId)
}
var openHABSitemapPage: OpenHABSitemapPage?
do {
// Self-executing closure
// Inspired by https://www.swiftbysundell.com/posts/inline-types-and-functions-in-swift
openHABSitemapPage = try {
currentPage = try {
let sitemapPageCodingData = try data.decoded(as: OpenHABSitemapPage.CodingData.self)
return sitemapPageCodingData.openHABSitemapPage
}()
} catch {
os_log("Should not throw %{PUBLIC}@", log: OSLog.remoteAccess, type: .error, error.localizedDescription)
}

currentPage = openHABSitemapPage
if isFiltering {
filterContentForSearchText(search.searchBar.text)
}
Expand Down Expand Up @@ -563,8 +561,9 @@ extension OpenHABSitemapViewController: ColorPickerCellDelegate {
if let colorPickerViewController = storyboard?.instantiateViewController(withIdentifier: "ColorPickerViewController") as? ColorPickerViewController,
let cell,
let indexPath = tableView.indexPath(for: cell),

let widget = dataSource.itemIdentifier(for: indexPath) {
// let widgetId = dataSource.itemIdentifier(for: indexPath),
// let widget = relevantPage?.widgets[widgetId] {
colorPickerViewController.title = widget.labelText
colorPickerViewController.widget = widget

Expand All @@ -577,10 +576,10 @@ extension OpenHABSitemapViewController {
private func makeDataSource() -> UITableViewDiffableDataSource<ViewControllerSection, OpenHABWidget> {
// Code from cellForItemAt transplanted into cell provider closure

UITableViewDiffableDataSource<ViewControllerSection, OpenHABWidget>(tableView: tableView) { [weak self] (tableView: UITableView, indexPath: IndexPath, widget: OpenHABWidget) -> UITableViewCell? in
UITableViewDiffableDataSource<ViewControllerSection, OpenHABWidget>(tableView: tableView) { [unowned self] (tableView: UITableView, indexPath: IndexPath, widget: OpenHABWidget) -> UITableViewCell? in

let cell: UITableViewCell

// guard let widget = self?.relevantPage?.widgets[widgetId] else { return nil }
switch widget.type {
case .frame:
cell = tableView.dequeueReusableCell(for: indexPath, cellType: FrameUITableViewCell.self)
Expand Down Expand Up @@ -631,17 +630,17 @@ extension OpenHABSitemapViewController {
}

var iconColor = widget.iconColor
if iconColor.isEmpty, self?.traitCollection.userInterfaceStyle == .dark {
if iconColor.isEmpty, traitCollection.userInterfaceStyle == .dark {
iconColor = "white"
}
// No icon is needed for image, video, frame and web widgets
if !((cell is NewImageUITableViewCell) || (cell is VideoUITableViewCell) || (cell is FrameUITableViewCell) || (cell is WebUITableViewCell)) {
if let urlc = Endpoint.icon(
rootUrl: self?.openHABRootUrl ?? "",
version: self?.appData?.openHABVersion ?? 2,
rootUrl: openHABRootUrl ?? "",
version: appData?.openHABVersion ?? 2,
icon: widget.icon,
state: widget.iconState(),
iconType: self?.iconType ?? .svg,
iconType: iconType ?? .svg,
iconColor: iconColor
).url {
var imageRequest = URLRequest(url: urlc)
Expand Down Expand Up @@ -679,25 +678,28 @@ extension OpenHABSitemapViewController {

// Check if this is not the last row in the widgets list
// TODO: Switch to separator layout guide https://developer.apple.com/videos/play/wwdc2020/10026/
// if indexPath.row < (self?.relevantPage?.widgets.count ?? 1) - 1 {
// let nextWidget: OpenHABWidget? = self?.relevantPage?.widgets[indexPath.row + 1]
// if let type = nextWidget?.type, type.isAny(of: .frame, .image, .video, .webview, .chart) {
// cell.separatorInset = UIEdgeInsets.zero
// } else if !(widget.type == .frame) {
// cell.separatorInset = UIEdgeInsets(top: 0, left: 60, bottom: 0, right: 0)
// }
// }
if indexPath.row < (relevantPage?.widgets.count ?? 1) - 1 {
let nextRow = indexPath.index(after: indexPath.row)
let nextIndexPath = IndexPath(row: nextRow, section: indexPath.section)
let nextWidget = dataSource.itemIdentifier(for: nextIndexPath)
if let type = nextWidget?.type, type.isAny(of: .frame, .image, .video, .webview, .chart) {
cell.separatorInset = UIEdgeInsets.zero
} else if !(widget.type == .frame) {
cell.separatorInset = UIEdgeInsets(top: 0, left: 60, bottom: 0, right: 0)
}
}

return cell
}
}

/// - Tag: WiFiUpdate
func updateUI(animated: Bool = false) {
currentSnapshot = NSDiffableDataSourceSnapshot<ViewControllerSection, OpenHABWidget>()
currentSnapshot = NSDiffableDataSourceSnapshot<ViewControllerSection, OpenHABWidget>() // Changed
currentSnapshot.appendSections([.main])
if let relevantPage {
currentSnapshot.appendItems(Array(relevantPage.widgets.values), toSection: .main)
// currentSnapshot.appendItems(relevantPage.widgets.map(\.value.widgetId), toSection: .main)
}
dataSource.apply(currentSnapshot, animatingDifferences: animated)
}
Expand All @@ -712,6 +714,9 @@ extension OpenHABSitemapViewController: UITableViewDelegate { // }, UITableViewD

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
guard let widget = dataSource.itemIdentifier(for: indexPath) else { return 44.0 }

// guard let widgetId = dataSource.itemIdentifier(for: indexPath), let widget = relevantPage?.widgets[widgetId] else { return 44.0 }

switch widget.type {
case .frame:
return !widget.label.isEmpty ? 35.0 : 0
Expand Down Expand Up @@ -744,6 +749,8 @@ extension OpenHABSitemapViewController: UITableViewDelegate { // }, UITableViewD
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let widget = dataSource.itemIdentifier(for: indexPath) else { return }

// guard let widgetId = dataSource.itemIdentifier(for: indexPath), let widget = relevantPage?.widgets[widgetId] else { return }

if widget.linkedPage != nil {
if let link = widget.linkedPage?.link {
os_log("Selected %{PUBLIC}@", log: .viewCycle, type: .info, link)
Expand Down

0 comments on commit aa7e0b9

Please sign in to comment.