2020-06-30 15:22:23 +02:00
|
|
|
//
|
2020-07-05 21:45:19 +02:00
|
|
|
// SidebarToolbarModifier.swift
|
2020-06-30 15:22:23 +02:00
|
|
|
// Multiplatform iOS
|
|
|
|
//
|
|
|
|
// Created by Stuart Breckenridge on 30/6/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
2020-07-05 21:45:19 +02:00
|
|
|
struct SidebarToolbarModifier: ViewModifier {
|
2020-07-03 18:06:43 +02:00
|
|
|
|
2020-07-16 04:24:22 +02:00
|
|
|
@EnvironmentObject private var refreshProgress: RefreshProgressModel
|
2020-07-06 14:18:50 +02:00
|
|
|
@EnvironmentObject private var defaults: AppDefaults
|
2020-07-15 19:56:19 +02:00
|
|
|
@EnvironmentObject private var sidebarModel: SidebarModel
|
2020-07-04 15:34:15 +02:00
|
|
|
@StateObject private var viewModel = SidebarToolbarModel()
|
2020-07-03 18:06:43 +02:00
|
|
|
|
2020-07-04 16:01:01 +02:00
|
|
|
@ViewBuilder func body(content: Content) -> some View {
|
|
|
|
#if os(iOS)
|
2020-07-04 15:34:15 +02:00
|
|
|
content
|
|
|
|
.toolbar {
|
2020-07-05 22:11:45 +02:00
|
|
|
|
|
|
|
ToolbarItem(placement: .navigation) {
|
2020-07-14 00:24:40 +02:00
|
|
|
Button {
|
2020-07-12 17:52:42 +02:00
|
|
|
withAnimation {
|
|
|
|
sidebarModel.isReadFiltered.toggle()
|
|
|
|
}
|
2020-07-14 00:24:40 +02:00
|
|
|
} label: {
|
2020-07-12 17:52:42 +02:00
|
|
|
if sidebarModel.isReadFiltered {
|
|
|
|
AppAssets.filterActiveImage.font(.title3)
|
|
|
|
} else {
|
|
|
|
AppAssets.filterInactiveImage.font(.title3)
|
|
|
|
}
|
2020-07-14 00:24:40 +02:00
|
|
|
}
|
|
|
|
.help(sidebarModel.isReadFiltered ? "Show Read Feeds" : "Filter Read Feeds")
|
2020-07-05 22:11:45 +02:00
|
|
|
}
|
|
|
|
|
2020-07-04 15:34:15 +02:00
|
|
|
ToolbarItem(placement: .automatic) {
|
2020-07-14 00:24:40 +02:00
|
|
|
Button {
|
2020-07-04 15:34:15 +02:00
|
|
|
viewModel.sheetToShow = .settings
|
2020-07-14 00:24:40 +02:00
|
|
|
} label: {
|
|
|
|
AppAssets.settingsImage.font(.title3)
|
|
|
|
}
|
|
|
|
.help("Settings")
|
2020-07-04 15:34:15 +02:00
|
|
|
}
|
2020-07-03 18:06:43 +02:00
|
|
|
|
2020-07-04 16:34:56 +02:00
|
|
|
ToolbarItem {
|
2020-07-04 15:34:15 +02:00
|
|
|
Spacer()
|
2020-07-04 16:34:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ToolbarItem(placement: .automatic) {
|
2020-07-16 04:24:22 +02:00
|
|
|
switch refreshProgress.state {
|
|
|
|
case .refreshProgress(let progress):
|
|
|
|
ProgressView(value: progress)
|
|
|
|
.frame(width: 100)
|
|
|
|
case .lastRefreshDateText(let text):
|
|
|
|
Text(text)
|
|
|
|
.lineLimit(1)
|
|
|
|
.font(.caption)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
case .none:
|
|
|
|
EmptyView()
|
|
|
|
}
|
2020-07-04 16:34:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ToolbarItem {
|
2020-07-04 15:34:15 +02:00
|
|
|
Spacer()
|
2020-07-04 16:34:56 +02:00
|
|
|
}
|
2020-07-03 18:06:43 +02:00
|
|
|
|
2020-07-04 15:34:15 +02:00
|
|
|
ToolbarItem(placement: .automatic, content: {
|
2020-07-14 00:24:40 +02:00
|
|
|
Button {
|
2020-07-04 15:34:15 +02:00
|
|
|
viewModel.showActionSheet = true
|
2020-07-14 00:24:40 +02:00
|
|
|
} label: {
|
|
|
|
AppAssets.addMenuImage.font(.title3)
|
|
|
|
}
|
2020-07-04 15:34:15 +02:00
|
|
|
.help("Add")
|
|
|
|
.actionSheet(isPresented: $viewModel.showActionSheet) {
|
|
|
|
ActionSheet(title: Text("Add"), buttons: [
|
|
|
|
.cancel(),
|
|
|
|
.default(Text("Add Web Feed"), action: { viewModel.sheetToShow = .web }),
|
|
|
|
.default(Text("Add Twitter Feed")),
|
|
|
|
.default(Text("Add Reddit Feed")),
|
2020-07-04 15:36:41 +02:00
|
|
|
.default(Text("Add Folder"), action: { viewModel.sheetToShow = .folder })
|
2020-07-04 15:34:15 +02:00
|
|
|
])
|
|
|
|
}
|
2020-07-02 23:18:59 +02:00
|
|
|
})
|
2020-07-04 15:34:15 +02:00
|
|
|
|
2020-07-03 17:43:20 +02:00
|
|
|
}
|
2020-07-04 15:34:15 +02:00
|
|
|
.sheet(isPresented: $viewModel.showSheet, onDismiss: { viewModel.sheetToShow = .none }) {
|
|
|
|
if viewModel.sheetToShow == .web {
|
|
|
|
AddWebFeedView()
|
|
|
|
}
|
2020-07-04 15:36:41 +02:00
|
|
|
if viewModel.sheetToShow == .folder {
|
|
|
|
AddFolderView()
|
|
|
|
}
|
2020-07-04 15:34:15 +02:00
|
|
|
if viewModel.sheetToShow == .settings {
|
2020-07-17 16:18:10 +02:00
|
|
|
SettingsView()
|
|
|
|
.preferredColorScheme(AppDefaults.userInterfaceColorScheme)
|
2020-07-04 15:34:15 +02:00
|
|
|
}
|
2020-07-03 18:06:43 +02:00
|
|
|
}
|
2020-07-04 16:01:01 +02:00
|
|
|
#else
|
|
|
|
content
|
|
|
|
.toolbar {
|
|
|
|
ToolbarItem {
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2020-07-04 15:34:15 +02:00
|
|
|
}
|
2020-06-30 15:22:23 +02:00
|
|
|
}
|
|
|
|
|
2020-07-04 15:34:15 +02:00
|
|
|
|