add localized strings to custom widget view

edit save / use buttons for custom widget
This commit is contained in:
Trey t
2022-02-27 15:58:47 -06:00
parent 0ff2ef8fba
commit 2e92d89faf
3 changed files with 42 additions and 62 deletions

View File

@@ -173,36 +173,5 @@ class UserDefaultsStore {
fatalError("error saving") 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")
}
}
} }

View File

@@ -106,7 +106,7 @@ struct CreateWidgetView: View {
HStack(alignment: .center) { HStack(alignment: .center) {
Spacer() Spacer()
VStack(alignment: .center) { VStack(alignment: .center) {
Menu("Left Eye") { Menu(String(localized: "create_widget_view_left_eye")) {
ForEach(CustomWidgetEyeOptions.allCases, id: \.self) { option in ForEach(CustomWidgetEyeOptions.allCases, id: \.self) { option in
Button(action: { Button(action: {
update(eye: .left, eyeOption: option) update(eye: .left, eyeOption: option)
@@ -119,7 +119,7 @@ struct CreateWidgetView: View {
} }
Spacer() Spacer()
VStack(alignment: .center) { VStack(alignment: .center) {
Menu("Right Eye") { Menu(String(localized: "create_widget_view_right_eye")) {
ForEach(CustomWidgetEyeOptions.allCases, id: \.self) { option in ForEach(CustomWidgetEyeOptions.allCases, id: \.self) { option in
Button(action: { Button(action: {
update(eye: .right, eyeOption: option) update(eye: .right, eyeOption: option)
@@ -132,7 +132,7 @@ struct CreateWidgetView: View {
} }
Spacer() Spacer()
VStack(alignment: .center) { VStack(alignment: .center) {
Menu("Mouth") { Menu(String(localized: "create_widget_view_mouth")) {
ForEach(CustomWidgetMouthOptions.allCases, id: \.self) { option in ForEach(CustomWidgetMouthOptions.allCases, id: \.self) { option in
Button(action: { Button(action: {
update(mouthOption: option) update(mouthOption: option)
@@ -186,21 +186,21 @@ struct CreateWidgetView: View {
VStack { VStack {
HStack(spacing: 0) { HStack(spacing: 0) {
VStack(alignment: .center) { VStack(alignment: .center) {
Text("background") Text(String(localized: "create_widget_background_color"))
ColorPicker("", selection: $customWidget.bgColor) ColorPicker("", selection: $customWidget.bgColor)
.labelsHidden() .labelsHidden()
} }
.frame(minWidth: 0, maxWidth: .infinity) .frame(minWidth: 0, maxWidth: .infinity)
VStack(alignment: .center) { VStack(alignment: .center) {
Text("Inner") Text(String(localized: "create_widget_inner_color"))
ColorPicker("", selection: $customWidget.innerColor) ColorPicker("", selection: $customWidget.innerColor)
.labelsHidden() .labelsHidden()
} }
.frame(minWidth: 0, maxWidth: .infinity) .frame(minWidth: 0, maxWidth: .infinity)
VStack(alignment: .center) { VStack(alignment: .center) {
Text("Face Outline") Text(String(localized: "create_widget_face_outline_color"))
ColorPicker("", selection: $customWidget.circleStrokeColor) ColorPicker("", selection: $customWidget.circleStrokeColor)
.labelsHidden() .labelsHidden()
} }
@@ -209,21 +209,21 @@ struct CreateWidgetView: View {
HStack(spacing: 0) { HStack(spacing: 0) {
VStack(alignment: .center) { VStack(alignment: .center) {
Text("Left Eye") Text(String(localized: "create_widget_view_left_eye_color"))
ColorPicker("", selection: $customWidget.leftEyeColor) ColorPicker("", selection: $customWidget.leftEyeColor)
.labelsHidden() .labelsHidden()
} }
.frame(minWidth: 0, maxWidth: .infinity) .frame(minWidth: 0, maxWidth: .infinity)
VStack(alignment: .center) { VStack(alignment: .center) {
Text("right eye") Text(String(localized: "create_widget_view_right_eye_color"))
ColorPicker("", selection: $customWidget.rightEyeColor) ColorPicker("", selection: $customWidget.rightEyeColor)
.labelsHidden() .labelsHidden()
} }
.frame(minWidth: 0, maxWidth: .infinity) .frame(minWidth: 0, maxWidth: .infinity)
VStack(alignment: .center) { VStack(alignment: .center) {
Text("mouth") Text(String(localized: "create_widget_view_mouth_color"))
ColorPicker("", selection: $customWidget.mouthColor) ColorPicker("", selection: $customWidget.mouthColor)
.labelsHidden() .labelsHidden()
} }
@@ -253,12 +253,12 @@ struct CreateWidgetView: View {
.background(.blue) .background(.blue)
Button(action: { Button(action: {
UserDefaultsStore.saveCustomWidget(widgetModel: customWidget, inUse: true) UserDefaultsStore.saveCustomWidget(widgetModel: customWidget, inUse: false)
let impactMed = UIImpactFeedbackGenerator(style: .heavy) let impactMed = UIImpactFeedbackGenerator(style: .heavy)
impactMed.impactOccurred() impactMed.impactOccurred()
dismiss() dismiss()
}, label: { }, label: {
Text("Save") Text(String(localized: "create_widget_save"))
.font(.title) .font(.title)
.fontWeight(.bold) .fontWeight(.bold)
.foregroundColor(Color(UIColor.white)) .foregroundColor(Color(UIColor.white))
@@ -268,23 +268,23 @@ struct CreateWidgetView: View {
.frame(height: 40) .frame(height: 40)
.background(.green) .background(.green)
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 { 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: { Button(action: {
UserDefaultsStore.deleteCustomWidget(withUUID: customWidget.uuid) UserDefaultsStore.deleteCustomWidget(withUUID: customWidget.uuid)
let impactMed = UIImpactFeedbackGenerator(style: .heavy) let impactMed = UIImpactFeedbackGenerator(style: .heavy)
@@ -299,7 +299,6 @@ struct CreateWidgetView: View {
.frame(height: 40) .frame(height: 40)
.frame(minWidth: 0, maxWidth: .infinity) .frame(minWidth: 0, maxWidth: .infinity)
.background(.orange) .background(.orange)
} }
} }
} }

View File

@@ -76,3 +76,15 @@
"customize_view_custom_widget_title" = "Custom Widgets"; "customize_view_custom_widget_title" = "Custom Widgets";
"customize_view_background_title" = "Pick a theme"; "customize_view_background_title" = "Pick a theme";
"customize_view_view_change_icon" = "Change App Icon"; "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";