Ferrite-backup/Ferrite/Views/ComponentViews/Settings/PluginList/SettingsPluginListView.swift
kingbri 20c55316b0 Kodi: Add multi-server support
Multiple servers can be added to Ferrite to playback from any Kodi
server that the user wants. This also adds the ability to have
friendly names which makes it easier to select what server to play on.

Each server shows the user whether it's online or not through Kodi's
JSONRPC ping method.

Signed-off-by: kingbri <bdashore3@proton.me>
2023-03-18 16:30:27 -04:00

107 lines
3.9 KiB
Swift

//
// SettingsSourceListView.swift
// Ferrite
//
// Created by Brian Dashore on 7/25/22.
//
import SwiftUI
struct SettingsPluginListView: View {
let backgroundContext = PersistenceController.shared.backgroundContext
@EnvironmentObject var navModel: NavigationViewModel
@FetchRequest(
entity: PluginList.entity(),
sortDescriptors: []
) var pluginLists: FetchedResults<PluginList>
@State private var presentEditSheet = false
var body: some View {
ZStack {
if pluginLists.isEmpty {
EmptyInstructionView(title: "No Lists", message: "Add a source list using the + button in the top-right")
} else {
List {
ForEach(pluginLists, id: \.self) { pluginList in
VStack(alignment: .leading, spacing: 5) {
Text(pluginList.name)
Group {
Text(pluginList.author)
Text("ID: \(pluginList.id)")
.font(.caption)
}
.foregroundColor(.secondary)
}
.padding(.vertical, 2)
.contextMenu {
Button {
navModel.selectedPluginList = pluginList
presentEditSheet.toggle()
} label: {
Text("Edit")
Image(systemName: "pencil")
}
if #available(iOS 15.0, *) {
Button(role: .destructive) {
PersistenceController.shared.delete(pluginList, context: backgroundContext)
} label: {
Text("Remove")
Image(systemName: "trash")
}
} else {
Button {
PersistenceController.shared.delete(pluginList, context: backgroundContext)
} label: {
Text("Remove")
Image(systemName: "trash")
}
}
}
}
.onDelete { offsets in
for index in offsets {
if let list = pluginLists[safe: index] {
PersistenceController.shared.delete(list, context: backgroundContext)
}
}
}
}
.listStyle(.insetGrouped)
.inlinedList(inset: -20)
}
}
.sheet(isPresented: $presentEditSheet) {
if #available(iOS 16, *) {
PluginListEditorView()
.presentationDetents([.medium])
} else {
PluginListEditorView()
.environmentObject(navModel)
}
}
.navigationTitle("Plugin Lists")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
navModel.selectedPluginList = nil
presentEditSheet.toggle()
} label: {
Image(systemName: "plus")
}
}
}
}
}
struct SettingsPluginListView_Previews: PreviewProvider {
static var previews: some View {
SettingsPluginListView()
}
}