Skip to content

Commit

Permalink
Double to select the sitemap for watch
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Oct 13, 2024
1 parent df4eeb5 commit cf07f2e
Showing 1 changed file with 150 additions and 70 deletions.
220 changes: 150 additions & 70 deletions openHAB/DrawerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,104 +86,184 @@ struct ConnectionView: View {
}

struct DrawerView: View {
@State private var sitemaps: [OpenHABSitemap] = []
@State private var uiTiles: [OpenHABUiTile] = []
@State private var selectedSection: Int?
@State private var connectedUrl: String = "Not connected" // Default label text
@ObservedObject private var networkTracker = NetworkTracker.shared

var openHABUsername = ""
var openHABPassword = ""

var onDismiss: (TargetController) -> Void
@Environment(\.dismiss) private var dismiss
struct MainSectionView: View {
var openHABIconwidth: CGFloat
var onDismiss: (TargetController) -> Void
var dismiss: DismissAction

// App wide data access
var appData: OpenHABDataObject? {
AppDelegate.appDelegate.appData
var body: some View {
Section(header: Text("Main")) {
HStack {
Image("openHABIcon")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: openHABIconwidth)
Text("Home")
}
.onTapGesture {
dismiss()
onDismiss(.webview)
}
}
}
}

@ScaledMetric var openHABIconwidth = 20.0
@ScaledMetric var tilesIconwidth = 20.0
@ScaledMetric var sitemapIconwidth = 20.0
struct TilesSectionView: View {
var uiTiles: [OpenHABUiTile]
var tilesIconwidth: CGFloat
var onDismiss: (TargetController) -> Void
var dismiss: DismissAction

var body: some View {
VStack {
List {
Section(header: Text("Main")) {
var body: some View {
Section(header: Text("Tiles")) {
ForEach(uiTiles, id: \.url) { tile in
HStack {
Image("openHABIcon")
.resizable()
ImageView(url: tile.imageUrl)
.aspectRatio(contentMode: .fit)
.frame(width: openHABIconwidth)
Text("Home")
.frame(width: tilesIconwidth)
Text(tile.name)
}
.onTapGesture {
dismiss()
onDismiss(.webview)
onDismiss(.tile(tile.url))
}
}
}
}
}

Section(header: Text("Tiles")) {
ForEach(uiTiles, id: \.url) { tile in
HStack {
ImageView(url: tile.imageUrl)
.aspectRatio(contentMode: .fit)
.frame(width: tilesIconwidth)
Text(tile.name)
}
.onTapGesture {
dismiss()
onDismiss(.tile(tile.url))
// Handle double-tap gesture for selecting or deselecting the sitemap for the watch
struct SitemapsSectionView: View {
var sitemaps: [OpenHABSitemap]
var sitemapIconwidth: CGFloat
var appData: OpenHABDataObject?
@Binding var sitemapForWatch: OpenHABSitemap?
var onDismiss: (TargetController) -> Void
var dismiss: DismissAction

var body: some View {
Section(header: Text("Sitemaps")) {
ForEach(sitemaps, id: \.name) { sitemap in
SitemapRowView(
sitemap: sitemap,
sitemapIconwidth: sitemapIconwidth,
appData: appData,
isWatchSitemap: sitemap.name == sitemapForWatch?.name,
onDismiss: onDismiss,
dismiss: dismiss
)
.onTapGesture(count: 2) {
if sitemap.name == sitemapForWatch?.name {
sitemapForWatch = nil
Preferences.sitemapForWatch = ""
} else {
sitemapForWatch = sitemap
Preferences.sitemapForWatch = sitemap.name
}
}
}
}
}
}

Section(header: Text("Sitemaps")) {
ForEach(sitemaps, id: \.name) { sitemap in
HStack {
let url = Endpoint.iconForDrawer(rootUrl: appData?.openHABRootUrl ?? "", icon: sitemap.icon).url
KFImage(url).placeholder { Image("openHABIcon").resizable() }
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: sitemapIconwidth)
Text(sitemap.label)
}
.onTapGesture {
dismiss()
onDismiss(.sitemap(sitemap.name))
}
}
struct SitemapRowView: View {
var sitemap: OpenHABSitemap
var sitemapIconwidth: CGFloat
var appData: OpenHABDataObject?
var isWatchSitemap: Bool
var onDismiss: (TargetController) -> Void
var dismiss: DismissAction

var body: some View {
HStack {
let url = Endpoint.iconForDrawer(rootUrl: appData?.openHABRootUrl ?? "", icon: sitemap.icon).url
KFImage(url).placeholder { Image("openHABIcon").resizable() }
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: sitemapIconwidth)
Text(sitemap.label)
if isWatchSitemap {
Spacer()
Image(systemSymbol: .applewatchWatchface)
}
}
.onTapGesture {
dismiss()
onDismiss(.sitemap(sitemap.name))
}
}
}

struct SystemSectionView: View {
var openHABIconwidth: CGFloat
var onDismiss: (TargetController) -> Void
var dismiss: DismissAction

var body: some View {
Section(header: Text("System")) {
HStack {
Image(systemSymbol: .gear)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: openHABIconwidth)
Text(LocalizedStringKey("settings"))
}
.onTapGesture {
dismiss()
onDismiss(.settings)
}

Section(header: Text("System")) {
if Preferences.remoteUrl.contains("openhab.org"), !Preferences.demomode {
HStack {
Image(systemSymbol: .gear)
Image(systemSymbol: .bell)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: openHABIconwidth)
Text(LocalizedStringKey("settings"))
Text(LocalizedStringKey("notifications"))
}
.onTapGesture {
dismiss()
onDismiss(.settings)
}

if Preferences.remoteUrl.contains("openhab.org"), !Preferences.demomode {
HStack {
Image(systemSymbol: .bell)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: openHABIconwidth)
Text(LocalizedStringKey("notifications"))
}
.onTapGesture {
dismiss()
onDismiss(.notifications)
}
onDismiss(.notifications)
}
}
}
}
}

@State private var sitemaps: [OpenHABSitemap] = []
@State private var uiTiles: [OpenHABUiTile] = []
@State private var selectedSection: Int?
@State private var connectedUrl: String = "Not connected" // Default label text
@ObservedObject private var networkTracker = NetworkTracker.shared

var openHABUsername = ""
var openHABPassword = ""

var onDismiss: (TargetController) -> Void
@Environment(\.dismiss) private var dismiss

// App wide data access
var appData: OpenHABDataObject? {
AppDelegate.appDelegate.appData
}

@ScaledMetric var openHABIconwidth = 20.0
@ScaledMetric var tilesIconwidth = 20.0
@ScaledMetric var sitemapIconwidth = 20.0

@State private var sitemapForWatch: OpenHABSitemap?

var body: some View {
VStack {
List {
MainSectionView(openHABIconwidth: openHABIconwidth, onDismiss: onDismiss, dismiss: dismiss)

TilesSectionView(uiTiles: uiTiles, tilesIconwidth: tilesIconwidth, onDismiss: onDismiss, dismiss: dismiss)

SitemapsSectionView(sitemaps: sitemaps, sitemapIconwidth: sitemapIconwidth, appData: appData, sitemapForWatch: $sitemapForWatch, onDismiss: onDismiss, dismiss: dismiss)

SystemSectionView(openHABIconwidth: openHABIconwidth, onDismiss: onDismiss, dismiss: dismiss)
}
.listStyle(.inset)
.onAppear(perform: loadData)

Expand Down

0 comments on commit cf07f2e

Please sign in to comment.