Skip to content

Commit

Permalink
Addressing openhab#670 - Different sort orders on sitemaps (openhab#672)
Browse files Browse the repository at this point in the history
* Addressing  openhab#670 - Different sort orders on sitemaps
* Including localizations

Signed-off-by: Tim Müller-Seydlitz <[email protected]>
  • Loading branch information
timbms authored Jun 19, 2022
1 parent c333f01 commit 3896b9a
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 29 deletions.
5 changes: 5 additions & 0 deletions OpenHABCore/Sources/OpenHABCore/Util/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public enum IconType: Int {
case svg
}

public enum SortSitemapsOrder: Int {
case label
case name
}

public struct Endpoint {
let baseURL: String
let path: String
Expand Down
2 changes: 1 addition & 1 deletion OpenHABCore/Sources/OpenHABCore/Util/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public enum Preferences {

@UserDefaultURL("localUrl", defaultValue: "") public static var localUrl: String
@UserDefaultURL("remoteUrl", defaultValue: "https://myopenhab.org") public static var remoteUrl: String

@UserDefault("username", defaultValue: "test") public static var username: String
@UserDefault("password", defaultValue: "test") public static var password: String
@UserDefault("alwaysSendCreds", defaultValue: false) public static var alwaysSendCreds: Bool
Expand All @@ -89,6 +88,7 @@ public enum Preferences {
@UserDefault("iconType", defaultValue: 0) public static var iconType: Int
@UserDefault("defaultSitemap", defaultValue: "demo") public static var defaultSitemap: String
@UserDefault("sendCrashReports", defaultValue: false) public static var sendCrashReports: Bool
@UserDefault("sortSitemapsBy", defaultValue: 0) public static var sortSitemapsby: Int

// MARK: - Private

Expand Down
63 changes: 48 additions & 15 deletions openHAB/Main.storyboard

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions openHAB/OpenHABDrawerTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ class OpenHABDrawerTableViewController: UITableViewController {
self.sitemaps = Array(self.sitemaps.dropLast())
}

// Sort the sitemaps alphabetically.
self.sitemaps.sort { $0.label < $1.label }
// 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()
if self.drawerTableType == .withStandardMenuEntries {
self.setStandardDrawerItems()
Expand Down
11 changes: 8 additions & 3 deletions openHAB/OpenHABSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class OpenHABSettingsViewController: UITableViewController, UITextFieldDelegate
var settingsIconType: IconType = .png
var settingsRealTimeSliders = false
var settingsSendCrashReports = false
var settingsSortSitemapsBy: SortSitemapsOrder = .label

var appData: OpenHABDataObject? {
AppDelegate.appDelegate.appData
Expand All @@ -46,6 +47,7 @@ class OpenHABSettingsViewController: UITableViewController, UITextFieldDelegate
@IBOutlet private var realTimeSlidersSwitch: UISwitch!
@IBOutlet private var sendCrashReportsSwitch: UISwitch!
@IBOutlet private var sendCrashReportsDummy: UIButton!
@IBOutlet private var sortSitemapsBy: UISegmentedControl!

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Expand Down Expand Up @@ -158,7 +160,7 @@ class OpenHABSettingsViewController: UITableViewController, UITextFieldDelegate
ret = 6
}
case 1:
ret = 11
ret = 12
default:
ret = 10
}
Expand Down Expand Up @@ -227,6 +229,7 @@ class OpenHABSettingsViewController: UITableViewController, UITextFieldDelegate
realTimeSlidersSwitch?.isOn = settingsRealTimeSliders
sendCrashReportsSwitch?.isOn = settingsSendCrashReports
iconSegmentedControl?.selectedSegmentIndex = settingsIconType.rawValue
sortSitemapsBy?.selectedSegmentIndex = settingsSortSitemapsBy.rawValue
if settingsDemomode == true {
disableConnectionSettings()
} else {
Expand All @@ -245,8 +248,8 @@ class OpenHABSettingsViewController: UITableViewController, UITextFieldDelegate
settingsIdleOff = Preferences.idleOff
settingsRealTimeSliders = Preferences.realTimeSliders
settingsSendCrashReports = Preferences.sendCrashReports
let rawSettingsIconType = Preferences.iconType
settingsIconType = IconType(rawValue: rawSettingsIconType) ?? .png
settingsIconType = IconType(rawValue: Preferences.iconType) ?? .png
settingsSortSitemapsBy = SortSitemapsOrder(rawValue: Preferences.sortSitemapsby) ?? .label
}

func updateSettings() {
Expand All @@ -262,6 +265,7 @@ class OpenHABSettingsViewController: UITableViewController, UITextFieldDelegate
settingsRealTimeSliders = realTimeSlidersSwitch?.isOn ?? false
settingsSendCrashReports = sendCrashReportsSwitch?.isOn ?? false
settingsIconType = IconType(rawValue: iconSegmentedControl.selectedSegmentIndex) ?? .png
settingsSortSitemapsBy = SortSitemapsOrder(rawValue: sortSitemapsBy.selectedSegmentIndex) ?? .label
}

func saveSettings() {
Expand All @@ -276,6 +280,7 @@ class OpenHABSettingsViewController: UITableViewController, UITextFieldDelegate
Preferences.realTimeSliders = settingsRealTimeSliders
Preferences.iconType = settingsIconType.rawValue
Preferences.sendCrashReports = settingsSendCrashReports
Preferences.sortSitemapsby = settingsSortSitemapsBy.rawValue

WatchMessageService.singleton.syncPreferencesToWatch()
}
Expand Down
1 change: 0 additions & 1 deletion openHAB/OpenHABWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ extension OpenHABWebViewController: WKNavigationDelegate {

func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge,
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {

os_log("Challenge.protectionSpace.authtenticationMethod: %{PUBLIC}@", log: .wkwebview, type: .info, String(describing: challenge.protectionSpace.authenticationMethod))

if let url = modifyUrl(orig: URL(string: openHABRootUrl)), challenge.protectionSpace.host == url.host {
Expand Down
2 changes: 2 additions & 0 deletions openHAB/Resources/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@
"on" = "an";
"off" = "aus";
"empty" = "leer";
"sortSitemapsBy" = "Sortiere Sitemaps nach";

1 change: 1 addition & 0 deletions openHAB/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@
"on" = "on";
"off" = "off";
"empty" = "empty";
"sortSitemapsBy" = "Sort sitemaps by";
1 change: 1 addition & 0 deletions openHAB/Resources/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@
"on" = "on";
"off" = "off";
"empty" = "empty";
"sortSitemapsBy" = "Sort sitemaps by";
1 change: 1 addition & 0 deletions openHAB/Resources/fi.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@
"on" = "on";
"off" = "off";
"empty" = "empty";
"sortSitemapsBy" = "Sort sitemaps by";
1 change: 1 addition & 0 deletions openHAB/Resources/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@
"on" = "on";
"off" = "off";
"empty" = "empty";
"sortSitemapsBy" = "Sort sitemaps by";
1 change: 1 addition & 0 deletions openHAB/Resources/it.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@
"on" = "on";
"off" = "off";
"empty" = "empty";
"sortSitemapsBy" = "Sort sitemaps by";
1 change: 1 addition & 0 deletions openHAB/Resources/nl.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@
"on" = "on";
"off" = "off";
"empty" = "empty";
"sortSitemapsBy" = "Sort sitemaps by";
1 change: 1 addition & 0 deletions openHAB/Resources/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@
"on" = "on";
"off" = "off";
"empty" = "empty";
"sortSitemapsBy" = "Sort sitemaps by";
15 changes: 8 additions & 7 deletions openHABTestsSwift/OpenHABEndPoint.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Copyright (c) 2010-2022 Contributors to the openHAB project
//
// OpenHABEndPoint.swift
// openHABTestsSwift
// See the NOTICE file(s) distributed with this work for additional
// information.
//
// Created by Tim Müller-Seydlitz on 10.06.22.
// Copyright © 2022 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 XCTest

class OpenHABEndPoint: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
Expand All @@ -28,9 +30,8 @@ class OpenHABEndPoint: XCTestCase {

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
measure {
// Put the code you want to measure the time of here.
}
}

}

0 comments on commit 3896b9a

Please sign in to comment.