Skip to content

Commit

Permalink
change UI of addRecycles
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonCat4012 committed Oct 8, 2024
1 parent ace4e90 commit 460258c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 27 deletions.
73 changes: 47 additions & 26 deletions VGApp/Tabs/ItemsList/ItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,35 +156,56 @@ struct Itemview: View {
}

func newRecycleView() -> some View {
VStack {
Text("newRecycle_title").font(.title)
.padding(.bottom, 20)
.padding(.top, 20)

HStack {
Button("-") {
if vm.recycleCount > 1 {
vm.recycleCount -= 1
}
}.buttonStyle(RecycleButtonStyle()).disabled(vm.recycleCount <= 1)
Text(String(vm.recycleCount)).frame(minWidth: 60)
Button("+") {
vm.recycleCount += 1
}.buttonStyle(RecycleButtonStyle())
NavigationView(content: {
VStack {
HStack {
Button("-") {
if vm.recycleCount > 1 {
vm.recycleCount -= 1
}
}.buttonStyle(RecycleButtonStyle()).disabled(vm.recycleCount <= 1)
Text(String(vm.recycleCount)).frame(minWidth: 60)
Button("+") {
vm.recycleCount += 1
}.buttonStyle(RecycleButtonStyle())
}.padding(.top, 20)

Spacer()

ForEach(Array(vm.typeArr.enumerated()), id: \.offset) { _, type in
Button {
vm.addRecyle(type)
} label: {
HStack {
IconManager.get_recycle_image(type)
.resizable()
.frame(width: 15, height: 15)
.colorMultiply(.gray)

Text(Util.recTypeName(type))
.frame(height: 15)
.frame(maxWidth: .infinity)
}
}.buttonStyle(RecycleOptionButtonStyle())
}
.frame(maxWidth: .infinity)
navigationStyling("newRecycle_title".localized)
}

.padding()
})
}

@ViewBuilder
func navigationStyling(_ title: String) -> some View {
if #available(iOS 16.0, *) {
Spacer()

ForEach(Array(vm.typeArr.enumerated()), id: \.offset) { _, type in
Button {
vm.addRecyle(type)
} label: {
Text(Util.recTypeName(type)).frame(maxWidth: .infinity)
}.buttonStyle(RecycleOptionButtonStyle())
}
.padding(.bottom, 30).frame(maxWidth: .infinity)
.navigationTitle(title)
.toolbarBackground(
Color.accentColor, for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)
} else {
Spacer()
.navigationTitle(title)
}
.padding()
}
}
1 change: 0 additions & 1 deletion VGApp/Tabs/ItemsList/ItemViewmodel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ class ItemViewmodel: ObservableObject {
recycleCount = 1
Util.save()
withAnimation { showsSheet = false }
// updateViews()
setUsedRecyleTypesArr()
}

Expand Down
18 changes: 18 additions & 0 deletions VGApp/Util/IconManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,22 @@ struct IconManager {
return getIcon("crate")
}
}

static func get_recycle_image(_ type: RecycleTypes) -> Image {
var img: Image?

switch type {
case .yoghurtglass:
img = icons["yogurt"]
case .bottle:
img = icons["glass"]
case .crate:
img = icons["crate"]
}

guard let img = img else {
return Image(systemName: "questionmark.diamond")
}
return img
}
}

0 comments on commit 460258c

Please sign in to comment.