-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
acd291c
commit b4f7e8f
Showing
19 changed files
with
1,634 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// AuthService.swift | ||
// Industrial_APP | ||
// | ||
// Created by User on 2024/1/3. | ||
// | ||
|
||
import Foundation | ||
import Firebase | ||
|
||
|
||
|
||
class AuthService{ | ||
|
||
@Published var userSession: FirebaseAuth.User? | ||
|
||
static let shared = AuthService() | ||
init(){ | ||
self.userSession = Auth.auth().currentUser | ||
} | ||
@MainActor | ||
func login(withEmail email: String, password: String) async throws{ | ||
do { | ||
let result = try await Auth.auth().signIn(withEmail: email, password: password) | ||
self.userSession = result.user | ||
} catch { | ||
print("DEBUG: Failed to login user with error \(error.localizedDescription)") | ||
} | ||
|
||
} | ||
|
||
|
||
func signout(){ | ||
try? Auth.auth().signOut() | ||
self.userSession = nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// ContentView.swift | ||
// Industrial_APP | ||
// | ||
// Created by User on 2023/12/29. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
@StateObject var viewModel = ContentViewModel() | ||
|
||
var body: some View { | ||
Group{ | ||
if viewModel.userSession == nil { | ||
Login() | ||
} else { | ||
MainTabView() | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
ContentView() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// ContentView.swift | ||
// Industrial_APP | ||
// | ||
// Created by User on 2023/12/29. | ||
// | ||
|
||
import Foundation | ||
import Firebase | ||
import Combine | ||
|
||
@MainActor | ||
class ContentViewModel: ObservableObject{ | ||
|
||
private let service = AuthService.shared | ||
private var cancellables = Set<AnyCancellable>() | ||
|
||
@Published var userSession : FirebaseAuth.User? | ||
init(){ | ||
setupSubscribers() | ||
} | ||
func setupSubscribers(){ | ||
service.$userSession.sink{[weak self] userSession in | ||
self?.userSession = userSession | ||
} | ||
.store(in: &cancellables) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import SwiftUI | ||
|
||
struct Cost: View { | ||
@State private var directLabor = DirectLabor() | ||
@State private var rawMaterial = RawMaterial() | ||
@State private var totalCost = 0.0 | ||
|
||
var body: some View { | ||
NavigationView { | ||
VStack { | ||
Form { | ||
Section(header: Text("Direct Labor")) { | ||
LaborTextField(title: "Radial Cut", value: $directLabor.radialCut) | ||
LaborTextField(title: "Planing", value: $directLabor.planing) | ||
LaborTextField(title: "Treatment", value: $directLabor.treatment) | ||
LaborTextField(title: "Four Sides Planing", value: $directLabor.fourSidesPlaning) | ||
LaborTextField(title: "Carving Glue", value: $directLabor.carvingGlue) | ||
LaborTextField(title: "Sanding", value: $directLabor.sanding) | ||
} | ||
|
||
Section(header: Text("Raw Material")) { | ||
MaterialTextField(title: "Bamboo", value: $rawMaterial.bamboo) | ||
MaterialTextField(title: "Caustic Soda", value: $rawMaterial.causticSoda) | ||
MaterialTextField(title: "Borax", value: $rawMaterial.borax) | ||
MaterialTextField(title: "Boric Acid", value: $rawMaterial.boricAcid) | ||
MaterialTextField(title: "Gas Consumption", value: $rawMaterial.gasConsumption) | ||
MaterialTextField(title: "Hydrogen Peroxide", value: $rawMaterial.hydrogenPeroxide) | ||
MaterialTextField(title: "Sodium Salt", value: $rawMaterial.sodiumSalt) | ||
MaterialTextField(title: "QR 500", value: $rawMaterial.qr500) | ||
MaterialTextField(title: "QR 1000", value: $rawMaterial.qr1000) | ||
MaterialTextField(title: "Glue", value: $rawMaterial.glue) | ||
MaterialTextField(title: "Oil", value: $rawMaterial.oil) | ||
MaterialTextField(title: "Sandpaper 36", value: $rawMaterial.sandpaper36) | ||
MaterialTextField(title: "Sandpaper 40", value: $rawMaterial.sandpaper40) | ||
} | ||
} | ||
|
||
Button(action: calculateTotalCost) { | ||
Text("Calculate Total Cost") | ||
.foregroundColor(.white) | ||
.padding() | ||
.frame(maxWidth: .infinity) | ||
.background(Color.blue) | ||
.cornerRadius(10) | ||
} | ||
.padding() | ||
|
||
Text("Total Cost: $\(totalCost, specifier: "%.2f")") | ||
.padding() | ||
} | ||
.navigationBarTitle("Cost Calculator", displayMode: .inline) | ||
} | ||
} | ||
|
||
func calculateTotalCost() { | ||
let directLaborCost = calculateDirectLaborCost() | ||
let rawMaterialCost = calculateRawMaterialCost() | ||
totalCost = directLaborCost + rawMaterialCost | ||
} | ||
|
||
func calculateDirectLaborCost() -> Double { | ||
let radialCutCost = calculateCost(for: directLabor.radialCut, with: 26.98) | ||
let planingCost = calculateCost(for: directLabor.planing, with: 17.58) | ||
let treatmentCost = calculateCost(for: directLabor.treatment, with: 33.60) | ||
let fourSidesPlaningCost = calculateCost(for: directLabor.fourSidesPlaning, with: 23.17) | ||
let carvingGlueCost = calculateCost(for: directLabor.carvingGlue, with: 42.69) | ||
let sandingCost = calculateCost(for: directLabor.sanding, with: 0.0) | ||
return radialCutCost + planingCost + treatmentCost + fourSidesPlaningCost + carvingGlueCost + sandingCost | ||
} | ||
|
||
func calculateRawMaterialCost() -> Double { | ||
let bambooCost = calculateCost(for: rawMaterial.bamboo, with: 15.0) | ||
let causticSodaCost = calculateCost(for: rawMaterial.causticSoda, with: 16.0) | ||
let boraxCost = calculateCost(for: rawMaterial.borax, with: 24.0) | ||
let boricAcidCost = calculateCost(for: rawMaterial.boricAcid, with: 24.0) | ||
let gasConsumptionCost = calculateCost(for: rawMaterial.gasConsumption, with: 24.0) | ||
let hydrogenPeroxideCost = calculateCost(for: rawMaterial.hydrogenPeroxide, with: 100.0) | ||
let sodiumSaltCost = calculateCost(for: rawMaterial.sodiumSalt, with: 12.5) | ||
let qr500Cost = calculateCost(for: rawMaterial.qr500, with: 145.0) | ||
let qr1000Cost = calculateCost(for: rawMaterial.qr1000, with: 145.0) | ||
let glueCost = calculateCost(for: rawMaterial.glue, with: 35.8) | ||
let oilCost = calculateCost(for: rawMaterial.oil, with: 78.2) | ||
let sandpaper36Cost = calculateCost(for: rawMaterial.sandpaper36, with: 0.0) | ||
let sandpaper40Cost = calculateCost(for: rawMaterial.sandpaper40, with: 0.0) | ||
return bambooCost + causticSodaCost + boraxCost + boricAcidCost + gasConsumptionCost + hydrogenPeroxideCost + sodiumSaltCost + qr500Cost + qr1000Cost + glueCost + oilCost + sandpaper36Cost + sandpaper40Cost | ||
} | ||
|
||
func calculateCost(for value: String, with unitCost: Double) -> Double { | ||
let cost = Double(value) ?? 0 | ||
return cost * unitCost | ||
} | ||
} | ||
|
||
struct LaborTextField: View { | ||
var title: String | ||
@Binding var value: String | ||
|
||
var body: some View { | ||
TextField(title, text: $value) | ||
.keyboardType(.decimalPad) | ||
} | ||
} | ||
|
||
struct MaterialTextField: View { | ||
var title: String | ||
@Binding var value: String | ||
|
||
var body: some View { | ||
TextField(title, text: $value) | ||
.keyboardType(.decimalPad) | ||
} | ||
} | ||
|
||
struct DirectLabor { | ||
var radialCut = "" | ||
var planing = "" | ||
var treatment = "" | ||
var fourSidesPlaning = "" | ||
var carvingGlue = "" | ||
var sanding = "" | ||
} | ||
|
||
struct RawMaterial { | ||
var bamboo = "" | ||
var causticSoda = "" | ||
var borax = "" | ||
var boricAcid = "" | ||
var gasConsumption = "" | ||
var hydrogenPeroxide = "" | ||
var sodiumSalt = "" | ||
var qr500 = "" | ||
var qr1000 = "" | ||
var glue = "" | ||
var oil = "" | ||
var sandpaper36 = "" | ||
var sandpaper40 = "" | ||
} | ||
|
||
struct Cost_Previews: PreviewProvider { | ||
static var previews: some View { | ||
Cost() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>API_KEY</key> | ||
<string>AIzaSyCTJBH3Lc8z9LqoWM3F26S4gL3fugUOVys</string> | ||
<key>GCM_SENDER_ID</key> | ||
<string>453251036409</string> | ||
<key>PLIST_VERSION</key> | ||
<string>1</string> | ||
<key>BUNDLE_ID</key> | ||
<string>Shawn.Industrial-APP</string> | ||
<key>PROJECT_ID</key> | ||
<string>bambuproject-22fb4</string> | ||
<key>STORAGE_BUCKET</key> | ||
<string>bambuproject-22fb4.appspot.com</string> | ||
<key>IS_ADS_ENABLED</key> | ||
<false></false> | ||
<key>IS_ANALYTICS_ENABLED</key> | ||
<false></false> | ||
<key>IS_APPINVITE_ENABLED</key> | ||
<true></true> | ||
<key>IS_GCM_ENABLED</key> | ||
<true></true> | ||
<key>IS_SIGNIN_ENABLED</key> | ||
<true></true> | ||
<key>GOOGLE_APP_ID</key> | ||
<string>1:453251036409:ios:607fa8fb90a11b34d69e28</string> | ||
</dict> | ||
</plist> |
Oops, something went wrong.