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
|
|
|
|
2020-07-23 04:01:02 +02:00
|
|
|
ToolbarItem(placement: .primaryAction) {
|
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-23 04:01:02 +02:00
|
|
|
ToolbarItem(placement: .bottomBar) {
|
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-23 04:01:02 +02:00
|
|
|
ToolbarItem(placement: .bottomBar) {
|
2020-07-04 15:34:15 +02:00
|
|
|
Spacer()
|
2020-07-04 16:34:56 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 04:01:02 +02:00
|
|
|
ToolbarItem(placement: .bottomBar) {
|
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
|
|
|
}
|
|
|
|
|
2020-07-23 04:01:02 +02:00
|
|
|
ToolbarItem(placement: .bottomBar) {
|
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-23 04:01:02 +02:00
|
|
|
ToolbarItem(placement: .bottomBar, content: {
|
2020-07-27 10:09:39 +02:00
|
|
|
Menu(content: {
|
|
|
|
Button { viewModel.sheetToShow = .web } label: { Text("Add Web Feed") }
|
2020-07-27 10:13:07 +02:00
|
|
|
Button { viewModel.sheetToShow = .twitter } label: { Text("Add Twitter Feed") }
|
|
|
|
Button { viewModel.sheetToShow = .reddit } label: { Text("Add Reddit Feed") }
|
2020-07-27 10:09:39 +02:00
|
|
|
Button { viewModel.sheetToShow = .folder } label: { Text("Add Folder") }
|
|
|
|
}, label: {
|
2020-07-14 00:24:40 +02:00
|
|
|
AppAssets.addMenuImage.font(.title3)
|
2020-07-27 10:09:39 +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 {
|
2020-08-13 18:04:39 +02:00
|
|
|
AddWebFeedView(isPresented: $viewModel.showSheet)
|
2020-07-04 15:34:15 +02:00
|
|
|
}
|
2020-07-04 15:36:41 +02:00
|
|
|
if viewModel.sheetToShow == .folder {
|
2020-08-13 18:04:39 +02:00
|
|
|
AddFolderView(isPresented: $viewModel.showSheet)
|
2020-07-04 15:36:41 +02:00
|
|
|
}
|
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
|
|
|
|