rollback toolbar

GlobalData conform Equatable
Change the conditions for some screens onAppear
This commit is contained in:
PangMo5 2021-05-29 18:12:49 +09:00
parent 039d2aef0f
commit e1dba314df
6 changed files with 102 additions and 72 deletions

View File

@ -19,6 +19,16 @@ class GlobalData: ObservableObject {
@Published var isInNetwork: Bool = true;
}
extension GlobalData: Equatable {
static func == (lhs: GlobalData, rhs: GlobalData) -> Bool {
lhs.user == rhs.user
&& lhs.authToken == rhs.authToken
&& lhs.server == rhs.server
&& lhs.authHeader == rhs.authHeader
}
}
extension UIDevice {
var hasNotch: Bool {
let bottom = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.safeAreaInsets.bottom ?? 0

View File

@ -24,7 +24,7 @@ struct LibraryFilterView: View {
@State
var library: String
@Binding
var filter: Filter
@State
@ -147,13 +147,17 @@ struct LibraryFilterView: View {
}
}.onAppear(perform: onAppear)
.navigationBarTitle("Filters", displayMode: .inline)
.navigationBarItems(leading: Button {
presentationMode.wrappedValue.dismiss()
} label: {
HStack {
Text("Back").font(.callout)
.toolbar {
ToolbarItemGroup(placement: .navigationBarLeading) {
Button {
presentationMode.wrappedValue.dismiss()
} label: {
HStack {
Text("Back").font(.callout)
}
}
}
})
}
}
}
}

View File

@ -34,9 +34,12 @@ struct LibraryListView: View {
}
}
.navigationTitle("All Media")
.navigationBarItems(trailing:
NavigationLink(destination: LazyView { LibrarySearchView(viewModel: .init(filter: .init())) }) {
Image(systemName: "magnifyingglass")
})
.toolbar {
ToolbarItemGroup(placement: .navigationBarTrailing) {
NavigationLink(destination: LazyView { LibrarySearchView(viewModel: .init(filter: .init())) }) {
Image(systemName: "magnifyingglass")
}
}
}
}
}

View File

@ -27,6 +27,7 @@ struct LibrarySearchView: View {
var horizontalSizeClass: UserInterfaceSizeClass?
func onAppear() {
guard viewModel.globalData != globalData else { return }
recalcTracks()
viewModel.globalData = globalData
}

View File

@ -21,8 +21,8 @@ struct LibraryView: View {
@State
private var showFiltersPopover: Bool = false
@State
private var showSearchPopover: Bool = false
private var showingSearchView: Bool = false
private var title: String
@State
@ -34,6 +34,7 @@ struct LibraryView: View {
}
func onAppear() {
guard viewModel.globalData != globalData else { return }
recalcTracks()
viewModel.globalData = globalData
}
@ -78,33 +79,35 @@ struct LibraryView: View {
Text("Empty Response")
}
}
.overrideViewPreference(.unspecified)
// .overrideViewPreference(.unspecified)
.onAppear(perform: onAppear)
.navigationTitle(title)
.navigationBarItems(trailing: HStack {
if !viewModel.isHiddenPreviousButton {
.toolbar {
ToolbarItemGroup(placement: .navigationBarTrailing) {
if !viewModel.isHiddenPreviousButton {
Button {
viewModel.requestPreviousPage()
} label: {
Image(systemName: "chevron.left")
}
}
if !viewModel.isHiddenNextButton {
Button {
viewModel.requestNextPage()
} label: {
Image(systemName: "chevron.right")
}
}
NavigationLink(destination: LazyView { LibrarySearchView(viewModel: .init(filter: viewModel.filter)) }) {
Image(systemName: "magnifyingglass")
}
Button {
viewModel.requestPreviousPage()
showFiltersPopover = true
} label: {
Image(systemName: "chevron.left")
Image(systemName: "line.horizontal.3.decrease")
}
}
if !viewModel.isHiddenNextButton {
Button {
viewModel.requestNextPage()
} label: {
Image(systemName: "chevron.right")
}
}
NavigationLink(destination: LazyView { LibrarySearchView(viewModel: .init(filter: viewModel.filter)) }) {
Image(systemName: "magnifyingglass")
}
Button {
showFiltersPopover = true
} label: {
Image(systemName: "line.horizontal.3.decrease")
}
})
}
.sheet(isPresented: self.$showFiltersPopover) {
LibraryFilterView(library: viewModel.filter.parentID ?? "", filter: $viewModel.filter)
.environmentObject(self.globalData)

View File

@ -5,34 +5,44 @@
// Created by Aiden Vigue on 4/29/21.
//
import SwiftUI
import CoreData
import SwiftUI
struct SettingsView: View {
@ObservedObject var viewModel: SettingsViewModel
@ObservedObject
var viewModel: SettingsViewModel
@Binding
var close: Bool
@Environment(\.managedObjectContext)
private var viewContext
@EnvironmentObject
var globalData: GlobalData
@EnvironmentObject
var jsi: justSignedIn
@State
private var username: String = ""
@State
private var inNetworkStreamBitrate: Int = 40_000_000
@State
private var outOfNetworkStreamBitrate: Int = 40_000_000
@State
private var autoSelectSubtitles: Bool = false
@State
private var autoSelectSubtitlesLangcode: String = "none"
@Binding var close: Bool;
@Environment(\.managedObjectContext) private var viewContext
@EnvironmentObject var globalData: GlobalData
@EnvironmentObject var jsi: justSignedIn
@State private var username: String = "";
@State private var inNetworkStreamBitrate: Int = 40000000;
@State private var outOfNetworkStreamBitrate: Int = 40000000;
@State private var autoSelectSubtitles: Bool = false;
@State private var autoSelectSubtitlesLangcode: String = "none";
func onAppear() {
_username.wrappedValue = globalData.user?.username ?? "";
_username.wrappedValue = globalData.user?.username ?? ""
let defaults = UserDefaults.standard
_inNetworkStreamBitrate.wrappedValue = defaults.integer(forKey: "InNetworkBandwidth");
_outOfNetworkStreamBitrate.wrappedValue = defaults.integer(forKey: "OutOfNetworkBandwidth");
_autoSelectSubtitles.wrappedValue = defaults.bool(forKey: "AutoSelectSubtitles");
_autoSelectSubtitlesLangcode.wrappedValue = defaults.string(forKey: "AutoSelectSubtitlesLangcode") ?? "";
_inNetworkStreamBitrate.wrappedValue = defaults.integer(forKey: "InNetworkBandwidth")
_outOfNetworkStreamBitrate.wrappedValue = defaults.integer(forKey: "OutOfNetworkBandwidth")
_autoSelectSubtitles.wrappedValue = defaults.bool(forKey: "AutoSelectSubtitles")
_autoSelectSubtitlesLangcode.wrappedValue = defaults.string(forKey: "AutoSelectSubtitlesLangcode") ?? ""
}
var body: some View {
NavigationView() {
Form() {
NavigationView {
Form {
Section(header: Text("Playback settings")) {
Picker("Default local quality", selection: $inNetworkStreamBitrate) {
ForEach(self.viewModel.bitrates, id: \.self) { bitrate in
@ -42,7 +52,7 @@ struct SettingsView: View {
let defaults = UserDefaults.standard
defaults.setValue(_inNetworkStreamBitrate.wrappedValue, forKey: "InNetworkBandwidth")
}
Picker("Default remote quality", selection: $outOfNetworkStreamBitrate) {
ForEach(self.viewModel.bitrates, id: \.self) { bitrate in
Text(bitrate.name).tag(bitrate.value)
@ -52,19 +62,17 @@ struct SettingsView: View {
defaults.setValue(_outOfNetworkStreamBitrate.wrappedValue, forKey: "OutOfNetworkBandwidth")
}
}
Section(header: Text("Accessibility")) {
Toggle("Automatically show subtitles", isOn: $autoSelectSubtitles).onChange(of: autoSelectSubtitles, perform: { _ in
let defaults = UserDefaults.standard
defaults.setValue(autoSelectSubtitles, forKey: "AutoSelectSubtitles")
})
Picker("Language preferences", selection: $autoSelectSubtitlesLangcode) {
}
Picker("Language preferences", selection: $autoSelectSubtitlesLangcode) {}
}
Section() {
HStack() {
Section {
HStack {
Text("Signed in as \(username)").foregroundColor(.primary)
Spacer()
Button {
@ -76,7 +84,7 @@ struct SettingsView: View {
} catch _ as NSError {
// TODO: handle the error
}
let fetchRequest2: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "SignedInUser")
let deleteRequest2 = NSBatchDeleteRequest(fetchRequest: fetchRequest2)
@ -85,7 +93,7 @@ struct SettingsView: View {
} catch _ as NSError {
// TODO: handle the error
}
globalData.server = nil
globalData.user = nil
globalData.authToken = ""
@ -101,14 +109,15 @@ struct SettingsView: View {
}
.navigationBarTitle("Settings", displayMode: .inline)
.navigationBarItems(leading:
Button {
close = false
} label: {
HStack() {
Text("Back").font(.callout)
}
})
.toolbar {
ToolbarItemGroup(placement: .navigationBarLeading) {
Button {
close = false
} label: {
Text("Back").font(.callout)
}
}
}
}.onAppear(perform: onAppear)
}
}