Skip to content

Commit

Permalink
Add multiple recycles
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonCat4012 committed Oct 8, 2024
1 parent 07dab26 commit ace4e90
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
4 changes: 4 additions & 0 deletions VGApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
F1B2733429B613DC00E841F4 /* ItemViewmodel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1B2733329B613DC00E841F4 /* ItemViewmodel.swift */; };
F1B2733629B61D4400E841F4 /* IconManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1B2733529B61D4400E841F4 /* IconManager.swift */; };
F1B2733829B61EE700E841F4 /* ItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1B2733729B61EE700E841F4 /* ItemCell.swift */; };
F1D675BF2CB51D76001B9FD6 /* ButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1D675BE2CB51D76001B9FD6 /* ButtonStyle.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -82,6 +83,7 @@
F1B2733329B613DC00E841F4 /* ItemViewmodel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemViewmodel.swift; sourceTree = "<group>"; };
F1B2733529B61D4400E841F4 /* IconManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconManager.swift; sourceTree = "<group>"; };
F1B2733729B61EE700E841F4 /* ItemCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemCell.swift; sourceTree = "<group>"; };
F1D675BE2CB51D76001B9FD6 /* ButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonStyle.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -162,6 +164,7 @@
F1B2733529B61D4400E841F4 /* IconManager.swift */,
F1AAD8B52A6183C7006F51FB /* StringExtension.swift */,
F1AAD8B12A617E46006F51FB /* DateExtension.swift */,
F1D675BE2CB51D76001B9FD6 /* ButtonStyle.swift */,
);
path = Util;
sourceTree = "<group>";
Expand Down Expand Up @@ -359,6 +362,7 @@
F1B2733829B61EE700E841F4 /* ItemCell.swift in Sources */,
F12680752A477F6E007931B6 /* AppData+CoreDataProperties.swift in Sources */,
DDEBB40E27B5BB9F004D80BB /* Util.swift in Sources */,
F1D675BF2CB51D76001B9FD6 /* ButtonStyle.swift in Sources */,
F12680712A477F6E007931B6 /* Item+CoreDataProperties.swift in Sources */,
F12680732A477F6E007931B6 /* RecycleItem+CoreDataProperties.swift in Sources */,
F1678A192979BAE600F676A4 /* ListDetailView.swift in Sources */,
Expand Down
20 changes: 17 additions & 3 deletions VGApp/Tabs/ItemsList/ItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,29 @@ struct Itemview: View {
.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())
}

Spacer()

ForEach(Array(vm.typeArr.enumerated()), id: \.offset) { _, type in
Button {
vm.addRecyle(type)
vm.setUsedRecyleTypesArr()
} label: {
Text(Util.recTypeName(type)).frame(minWidth: 200, maxWidth: .infinity)
}.buttonStyle(.bordered)
Text(Util.recTypeName(type)).frame(maxWidth: .infinity)
}.buttonStyle(RecycleOptionButtonStyle())
}
.padding(.bottom, 30).frame(maxWidth: .infinity)
Spacer()
}
.padding()
}
Expand Down
9 changes: 8 additions & 1 deletion VGApp/Tabs/ItemsList/ItemViewmodel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ItemViewmodel: ObservableObject {
@Published var typeArr: [RecycleTypes] = []
@Published var usedRecycleTypes: [RecycleTypes] = []
@Published var recycleDict: [RecycleTypes: Int] = [:]
@Published var recycleCount: Int = 1

@Published var showDeleteAlert = false

Expand Down Expand Up @@ -94,9 +95,15 @@ class ItemViewmodel: ObservableObject {
}

func addRecyle(_ type: RecycleTypes) {
CoreData.addRecycle(list!, type: type)
guard let list = list else { return }
for _ in 1...recycleCount {
CoreData.addRecycle(list, type: type)
}
recycleCount = 1
Util.save()
withAnimation { showsSheet = false }
// updateViews()
setUsedRecyleTypesArr()
}

func createItem() {
Expand Down
29 changes: 29 additions & 0 deletions VGApp/Util/ButtonStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// ButtonStyle.swift
// VGApp
//
// Created by Kiara on 08.10.24.
//

import SwiftUI

struct RecycleButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.padding()
.background(Color.accentColor)
.foregroundStyle(.black)
.clipShape(RoundedRectangle(cornerRadius: 8))
.frame(width: 40, height: 40)
}
}

struct RecycleOptionButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.padding()
.background(Color.accentColor)
.foregroundStyle(.black)
.clipShape(RoundedRectangle(cornerRadius: 8))
}
}

0 comments on commit ace4e90

Please sign in to comment.