From 2e92d89fafec2cf27ff1bd0f54e365265f79fe47 Mon Sep 17 00:00:00 2001 From: Trey t Date: Sun, 27 Feb 2022 15:58:47 -0600 Subject: [PATCH] add localized strings to custom widget view edit save / use buttons for custom widget --- Shared/Models/UserDefaultsStore.swift | 31 ---------- .../views/CustomIcon/CreateWidgetView.swift | 61 +++++++++---------- en.lproj/Localizable.strings | 12 ++++ 3 files changed, 42 insertions(+), 62 deletions(-) diff --git a/Shared/Models/UserDefaultsStore.swift b/Shared/Models/UserDefaultsStore.swift index 6b74042..f50d5e2 100644 --- a/Shared/Models/UserDefaultsStore.swift +++ b/Shared/Models/UserDefaultsStore.swift @@ -173,36 +173,5 @@ class UserDefaultsStore { fatalError("error saving") } } - - @discardableResult - static func makeWidgetCurrent(withUUID uuid: String) -> [CustomWidgetModel] { - do { - let existingWidgets = getCustomWidgets() - - if let foundWidget = existingWidgets.first(where: { - $0.uuid == uuid - }) { - existingWidgets.forEach({ - $0.inUse = false - }) - - foundWidget.inUse = true - } else { - if let first = existingWidgets.first { - first.inUse = true - } - } - - existingWidgets.forEach({ - $0.isSaved = true - }) - - let data = try JSONEncoder().encode(existingWidgets) - GroupUserDefaults.groupDefaults.set(data, forKey: UserDefaultsStore.Keys.customWidget.rawValue) - return UserDefaultsStore.getCustomWidgets() - } catch { - fatalError("error saving") - } - } } diff --git a/Shared/views/CustomIcon/CreateWidgetView.swift b/Shared/views/CustomIcon/CreateWidgetView.swift index ad866b0..0fe1b94 100644 --- a/Shared/views/CustomIcon/CreateWidgetView.swift +++ b/Shared/views/CustomIcon/CreateWidgetView.swift @@ -12,11 +12,11 @@ struct CreateWidgetView: View { @Environment(\.dismiss) var dismiss @StateObject private var customWidget: CustomWidgetModel - + @State private var mouth: CustomWidgetMouthOptions = CustomWidgetMouthOptions.defaultOption - + @State var widgetView: CustomWidgetView - + private var randomElements: [AnyView] init(customWidget: CustomWidgetModel, randomElements: [AnyView] = [AnyView]()) { @@ -106,7 +106,7 @@ struct CreateWidgetView: View { HStack(alignment: .center) { Spacer() VStack(alignment: .center) { - Menu("Left Eye") { + Menu(String(localized: "create_widget_view_left_eye")) { ForEach(CustomWidgetEyeOptions.allCases, id: \.self) { option in Button(action: { update(eye: .left, eyeOption: option) @@ -119,7 +119,7 @@ struct CreateWidgetView: View { } Spacer() VStack(alignment: .center) { - Menu("Right Eye") { + Menu(String(localized: "create_widget_view_right_eye")) { ForEach(CustomWidgetEyeOptions.allCases, id: \.self) { option in Button(action: { update(eye: .right, eyeOption: option) @@ -132,7 +132,7 @@ struct CreateWidgetView: View { } Spacer() VStack(alignment: .center) { - Menu("Mouth") { + Menu(String(localized: "create_widget_view_mouth")) { ForEach(CustomWidgetMouthOptions.allCases, id: \.self) { option in Button(action: { update(mouthOption: option) @@ -186,21 +186,21 @@ struct CreateWidgetView: View { VStack { HStack(spacing: 0) { VStack(alignment: .center) { - Text("background") + Text(String(localized: "create_widget_background_color")) ColorPicker("", selection: $customWidget.bgColor) .labelsHidden() } .frame(minWidth: 0, maxWidth: .infinity) VStack(alignment: .center) { - Text("Inner") + Text(String(localized: "create_widget_inner_color")) ColorPicker("", selection: $customWidget.innerColor) .labelsHidden() } .frame(minWidth: 0, maxWidth: .infinity) VStack(alignment: .center) { - Text("Face Outline") + Text(String(localized: "create_widget_face_outline_color")) ColorPicker("", selection: $customWidget.circleStrokeColor) .labelsHidden() } @@ -209,21 +209,21 @@ struct CreateWidgetView: View { HStack(spacing: 0) { VStack(alignment: .center) { - Text("Left Eye") + Text(String(localized: "create_widget_view_left_eye_color")) ColorPicker("", selection: $customWidget.leftEyeColor) .labelsHidden() } .frame(minWidth: 0, maxWidth: .infinity) VStack(alignment: .center) { - Text("right eye") + Text(String(localized: "create_widget_view_right_eye_color")) ColorPicker("", selection: $customWidget.rightEyeColor) .labelsHidden() } .frame(minWidth: 0, maxWidth: .infinity) VStack(alignment: .center) { - Text("mouth") + Text(String(localized: "create_widget_view_mouth_color")) ColorPicker("", selection: $customWidget.mouthColor) .labelsHidden() } @@ -253,12 +253,12 @@ struct CreateWidgetView: View { .background(.blue) Button(action: { - UserDefaultsStore.saveCustomWidget(widgetModel: customWidget, inUse: true) + UserDefaultsStore.saveCustomWidget(widgetModel: customWidget, inUse: false) let impactMed = UIImpactFeedbackGenerator(style: .heavy) impactMed.impactOccurred() dismiss() }, label: { - Text("Save") + Text(String(localized: "create_widget_save")) .font(.title) .fontWeight(.bold) .foregroundColor(Color(UIColor.white)) @@ -268,23 +268,23 @@ struct CreateWidgetView: View { .frame(height: 40) .background(.green) - if customWidget.isSaved { - Button(action: { - UserDefaultsStore.makeWidgetCurrent(withUUID: customWidget.uuid) - let impactMed = UIImpactFeedbackGenerator(style: .heavy) - impactMed.impactOccurred() - dismiss() - }, label: { - Text("Use") - .font(.title) - .fontWeight(.bold) - .foregroundColor(Color(UIColor.white)) - - }) - .frame(height: 40) - .frame(minWidth: 0, maxWidth: .infinity) - .background(.pink) + Button(action: { + UserDefaultsStore.saveCustomWidget(widgetModel: customWidget, inUse: true) + let impactMed = UIImpactFeedbackGenerator(style: .heavy) + impactMed.impactOccurred() + dismiss() + }, label: { + Text(String(localized: "create_widget_use")) + .font(.title) + .fontWeight(.bold) + .foregroundColor(Color(UIColor.white)) + }) + .frame(height: 40) + .frame(minWidth: 0, maxWidth: .infinity) + .background(.pink) + + if customWidget.isSaved { Button(action: { UserDefaultsStore.deleteCustomWidget(withUUID: customWidget.uuid) let impactMed = UIImpactFeedbackGenerator(style: .heavy) @@ -299,7 +299,6 @@ struct CreateWidgetView: View { .frame(height: 40) .frame(minWidth: 0, maxWidth: .infinity) .background(.orange) - } } } diff --git a/en.lproj/Localizable.strings b/en.lproj/Localizable.strings index 1dbabae..31f12db 100644 --- a/en.lproj/Localizable.strings +++ b/en.lproj/Localizable.strings @@ -76,3 +76,15 @@ "customize_view_custom_widget_title" = "Custom Widgets"; "customize_view_background_title" = "Pick a theme"; "customize_view_view_change_icon" = "Change App Icon"; + +"create_widget_view_left_eye" = "Left Eye"; +"create_widget_view_right_eye" = "Right Eye"; +"create_widget_view_mouth" = "Mouth"; +"create_widget_background_color" = "Background"; +"create_widget_inner_color" = "Inner"; +"create_widget_face_outline_color" = "Face Outline"; +"create_widget_view_left_eye_color" = "Left Eye"; +"create_widget_view_right_eye_color" = "Right Eye"; +"create_widget_view_mouth_color" = "Mouth"; +"create_widget_save" = "Save"; +"create_widget_use" = "Use";