Skip to content

Commit

Permalink
Merge pull request #68 from martindaum/public-settingsview
Browse files Browse the repository at this point in the history
Make SettingsView public
  • Loading branch information
kean committed Feb 12, 2022
2 parents f7e7051 + 9bc1df0 commit 9efd7d7
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 85 deletions.
5 changes: 4 additions & 1 deletion Sources/PulseUI/Features/Main/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ extension MainViewModel {
}
#endif
#if os(iOS) || os(tvOS)
case .settings: SettingsView(model: settingsModel, console: consoleModel)
case .settings:
NavigationView {
SettingsView(model: settingsModel, console: consoleModel)
}
#endif
default: fatalError()
}
Expand Down
118 changes: 63 additions & 55 deletions Sources/PulseUI/Features/Settings/SettingsView-ios.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,87 @@ import PulseCore
import UniformTypeIdentifiers

@available(iOS 13.0, *)
struct SettingsView: View {
public struct SettingsView: View {
@ObservedObject var model: SettingsViewModel
@ObservedObject var console: ConsoleViewModel

@State private var isDocumentBrowserPresented = false

var body: some View {
NavigationView {
Form {
if let details = model.details {
Section {
NavigationLink(destination: StoreDetailsView(model: details)) {
HStack {
Image(systemName: "info.circle")
.foregroundColor(Color.primary)
Text("Store Info")
.foregroundColor(Color.primary)
}
public init(store: LoggerStore = .default) {
self.model = SettingsViewModel(store: store)
self.console = ConsoleViewModel(store: store, contentType: .all)
}

init(model: SettingsViewModel, console: ConsoleViewModel) {
self.model = model
self.console = console
}

public var body: some View {
Form {
if let details = model.details {
Section {
NavigationLink(destination: StoreDetailsView(model: details)) {
HStack {
Image(systemName: "info.circle")
.foregroundColor(Color.primary)
Text("Store Info")
.foregroundColor(Color.primary)
}
}
}
}

if !model.isReadonly {
Section {
if #available(iOS 14.0, *) {
Button(action: {
isDocumentBrowserPresented = true
}) {
HStack {
Image(systemName: "doc")
.foregroundColor(Color.primary)
Text("Browse Files")
.foregroundColor(Color.primary)
}
}
.fullScreenCover(isPresented: $isDocumentBrowserPresented) {
DocumentBrowser()
}
}

ButtonRemoveAll(action: console.buttonRemoveAllMessagesTapped)
.disabled(console.messages.isEmpty)
.opacity(console.messages.isEmpty ? 0.33 : 1)
}
if !model.isReadonly {
Section {
if #available(iOS 14.0, *) {
if let model = console.remoteLoggerViewModel {
Section {
RemoteLoggerSettingsView(model: model)
Button(action: {
isDocumentBrowserPresented = true
}) {
HStack {
Image(systemName: "doc")
.foregroundColor(Color.primary)
Text("Browse Files")
.foregroundColor(Color.primary)
}
}
.fullScreenCover(isPresented: $isDocumentBrowserPresented) {
DocumentBrowser()
}
}

ButtonRemoveAll(action: console.buttonRemoveAllMessagesTapped)
.disabled(console.messages.isEmpty)
.opacity(console.messages.isEmpty ? 0.33 : 1)
}
Section(footer: Text("Pulse is funded by the community contributions.")) {
Button(action: {
if let url = URL(string: "https://github.com/sponsors/kean") {
UIApplication.shared.open(url)
}
}) {
HStack {
Image(systemName: "heart.fill")
.foregroundColor(Color.pink)
Text("Sponsor")
.foregroundColor(Color.primary)
Spacer()
Image(systemName: "link")
.foregroundColor(.secondary)
if #available(iOS 14.0, *) {
if let model = console.remoteLoggerViewModel {
Section {
RemoteLoggerSettingsView(model: model)
}
}
}
}
.navigationBarTitle("Settings")
.navigationBarItems(leading: model.onDismiss.map { Button(action: $0) { Image(systemName: "xmark") } })
}.navigationViewStyle(StackNavigationViewStyle())
Section(footer: Text("Pulse is funded by the community contributions.")) {
Button(action: {
if let url = URL(string: "https://github.com/sponsors/kean") {
UIApplication.shared.open(url)
}
}) {
HStack {
Image(systemName: "heart.fill")
.foregroundColor(Color.pink)
Text("Sponsor")
.foregroundColor(Color.primary)
Spacer()
Image(systemName: "link")
.foregroundColor(.secondary)
}
}
}
}
.navigationBarTitle("Settings")
.navigationBarItems(leading: model.onDismiss.map { Button(action: $0) { Image(systemName: "xmark") } })
}
}

Expand Down
65 changes: 36 additions & 29 deletions Sources/PulseUI/Features/Settings/SettingsView-tvos.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,49 @@ struct SettingsView: View {

@State var isSponsorAlertShown = false

var body: some View {
NavigationView {
Form {
if !model.isReadonly {
Section {
ButtonRemoveAll(action: console.buttonRemoveAllMessagesTapped)
.disabled(console.messages.isEmpty)
.opacity(console.messages.isEmpty ? 0.33 : 1)
}
}
public init(store: LoggerStore = .default) {
self.model = SettingsViewModel(store: store)
self.console = ConsoleViewModel(store: store, contentType: .all)
}

init(model: SettingsViewModel, console: ConsoleViewModel) {
self.model = model
self.console = console
}

public var body: some View {
Form {
if !model.isReadonly {
Section {
if let model = console.remoteLoggerViewModel {
Section {
RemoteLoggerSettingsView(model: model)
}
ButtonRemoveAll(action: console.buttonRemoveAllMessagesTapped)
.disabled(console.messages.isEmpty)
.opacity(console.messages.isEmpty ? 0.33 : 1)
}
}
Section {
if let model = console.remoteLoggerViewModel {
Section {
RemoteLoggerSettingsView(model: model)
}
}
Section(footer: Text("Pulse is funded by the community contributions.")) {
Button(action: {
isSponsorAlertShown = true
}) {
HStack {
Image(systemName: "heart.fill")
.foregroundColor(Color.pink)
Text("Sponsor")
.foregroundColor(Color.primary)
Spacer()
Image(systemName: "link")
.foregroundColor(.secondary)
}
}
Section(footer: Text("Pulse is funded by the community contributions.")) {
Button(action: {
isSponsorAlertShown = true
}) {
HStack {
Image(systemName: "heart.fill")
.foregroundColor(Color.pink)
Text("Sponsor")
.foregroundColor(Color.primary)
Spacer()
Image(systemName: "link")
.foregroundColor(.secondary)
}
}
}
.frame(maxWidth: 800)
}
.navigationViewStyle(StackNavigationViewStyle())
.frame(maxWidth: 800)
.alert(isPresented: $isSponsorAlertShown, content: {
Alert(title: Text("Sponsor"), message: Text("Please visit https://github.com/sponsors/kean to sponsor"), dismissButton: .cancel(Text("Ok")))
})
Expand Down

0 comments on commit 9efd7d7

Please sign in to comment.