Skip to content

Instantly share code, notes, and snippets.

@romanindermuehle
Created July 10, 2023 20:26
Show Gist options
  • Save romanindermuehle/b4821bccd315a5162792cba4212f506e to your computer and use it in GitHub Desktop.
Save romanindermuehle/b4821bccd315a5162792cba4212f506e to your computer and use it in GitHub Desktop.
import SwiftUI
struct AddTreeView: View {
@State private var selectedValue1 = 0
@State private var selectedValue2 = 0.0
@State private var selectedValue3 = 0
@State private var selectedValue4 = 0
@State private var selectedKey: Int?
@State private var selectedValue: String = ""
@State private var selectedIndex: Int? = 1
@State private var currentLocation = false
@Environment(\.dismiss) var dismiss
@State var addTreeViewModel = AddTreeViewModel()
@State private var tariffs = Tariffs()
var body: some View {
NavigationView {
Form {
Section {
Text("Nummer: 1")
Toggle(isOn: $currentLocation) {
Text("Standort speichern")
}.tint(.accentColor)
}
Section {
LazyVGrid(columns: [GridItem(.adaptive(minimum: 60))], spacing: 15) {
ForEach(addTreeViewModel.kindOfWood.indices, id: \.self) { index in
Circle()
.foregroundColor(.accentColor)
.opacity(0.8)
.frame(width: 55, height: 55)
.overlay(
Text(addTreeViewModel.kindOfWood[index])
.fontWeight(.bold)
)
.overlay(
Circle()
.stroke(selectedIndex == index ? Color.gray : Color.clear, lineWidth: 3)
.padding(-5)
)
.onTapGesture {
selectedValue = addTreeViewModel.kindOfWood[index]
selectedIndex = index
}
}
}
}
Section {
LazyVGrid(columns: [GridItem(.adaptive(minimum: 55))], spacing: 15) {
ForEach(tariffs.longTariff.sorted(by: <), id: \.key) { key, value in
Circle()
.foregroundColor(.accentColor)
.opacity(0.8)
.frame(width: 55, height: 55)
.overlay(
Text("\(key)")
.fontWeight(.bold)
)
.overlay(
Circle()
.stroke(selectedKey == key ? Color.gray : Color.clear, lineWidth: 3)
.padding(-5)
)
.onTapGesture {
selectedValue2 = value
print(selectedValue2)
selectedKey = key
}
}
}
HStack {
Text("Volumen")
Spacer()
Text("\(selectedValue2, specifier: "%.2f")m3")
.foregroundColor(.gray)
}
}
Section {
Picker("Waldbesitzer", selection: $selectedValue3) {
Text("Waldbesiter A").tag(0)
Text("Waldbesitzer B").tag(1)
Text("Waldbesitzer C").tag(2)
}
Picker("Bemerkung", selection: $selectedValue4) {
Text("QB Querbaum").tag(0)
Text("Stumpen").tag(1)
Text("Heli").tag(2)
Text("Bodenzug").tag(3)
Text("Ohne Verwertung").tag(4)
Text("Forstschutz A").tag(5)
Text("Forstschutz B").tag(6)
Text("Forstschutz C").tag(7)
Text("Keine").tag(8)
}
}
}
.toolbar {
ToolbarItemGroup(placement: .navigationBarTrailing) {
Button{
print("Done tapped")
} label: {
Text("Fertig")
.fontWeight(.bold)
}
}
ToolbarItem(placement: .principal) {
Text("Baum erfassen")
.fontWeight(.medium)
}
ToolbarItemGroup(placement: .navigationBarLeading) {
Button{
dismiss()
print("Cancel tapped")
} label: {
Text("Abbrechen")
}
}
ToolbarItemGroup(placement: .bottomBar) {
Button {
print("New")
} label: {
HStack {
Image(systemName: "square.and.pencil")
Text("Nächster Eintrag")
}
}
}
}
}
}
}
struct AddTreeView_Previews: PreviewProvider {
static var previews: some View {
AddTreeView()
}
}
import CoreData
import Foundation
class DataController: ObservableObject {
let container = NSPersistentContainer(name: "ForestFlow_Data")
init() {
container.loadPersistentStores { description, error in
if let error = error {
print("Core Data failed to load: \(error.localizedDescription)")
}
}
}
func saveContext() {
if container.viewContext.hasChanges {
do {
try container.viewContext.save()
} catch {
print("An error occurred while saving: \(error)")
}
}
}
}
import SwiftUI
struct ListView: View {
@State private var showSettings = false
@State private var showAddList = false
@State private var showAddTree = false
@State private var showInfo = false
@FetchRequest(sortDescriptors: []) var listEntrie: FetchedResults<ListEntrie>
@Environment(\.managedObjectContext) var moc
var body: some View {
NavigationView {
List(listEntrie) { item in
NavigationLink(destination: TreeListView(listName: item.name ?? "")) {
ListItem(itemName: item.name ?? "")
}
.contextMenu {
Button {
showInfo.toggle()
} label: {
Label("Infos zur Liste anzeigen", systemImage: "info.circle")
}
Button {
print("Deleted")
} label: {
Label("Löschen", systemImage: "trash")
}
}
}
.navigationTitle("Forest Flow")
.toolbar {
ToolbarItemGroup(placement: .navigationBarTrailing) {
Menu {
Button(action: {}) {
Label("Liste bearbeiten", systemImage: "pencil")
}
Divider()
Button(action: { showSettings.toggle() }) {
Label("Einstellungen", systemImage: "gear")
}
} label: {
Image(systemName: "ellipsis.circle")
}
.sheet(isPresented: $showSettings) {
SettingsView()
}
}
ToolbarItemGroup(placement: .navigationBarTrailing) {
Menu {
Button(action: { showAddList.toggle() }) {
Label("Neue Liste", systemImage: "list.bullet.clipboard")
}
Button(action: { showAddTree.toggle() }) {
Label("Neuer Eintrag", systemImage: "square.and.pencil")
}
} label: {
Image(systemName: "plus")
}
.sheet(isPresented: $showAddTree, content: {
AddTreeView()
})
.sheet(isPresented: $showAddList) {
AddListView()
}
.sheet(isPresented: $showInfo) {
InfoListView()
}
}
}
}
}
}
struct ListView_Previews: PreviewProvider {
static var previews: some View {
ListView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment