From 612483e7f07f498fd2626e0654657ae9bfc9bbaa Mon Sep 17 00:00:00 2001 From: Trey t Date: Thu, 10 Mar 2022 11:29:47 -0600 Subject: [PATCH] popup for nsfw content --- Shared/AppDelegate.swift | 4 ++- Shared/Models/UserDefaultsStore.swift | 1 + .../views/CustomizeView/CustomizeView.swift | 31 +++++++++++++++---- en.lproj/Localizable.strings | 4 +++ 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Shared/AppDelegate.swift b/Shared/AppDelegate.swift index c396472..f5aae45 100644 --- a/Shared/AppDelegate.swift +++ b/Shared/AppDelegate.swift @@ -18,11 +18,13 @@ class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { // PersistenceController.shared.clearDB() // PersistenceController.shared.deleteLast(numberOfEntries: 5) +// GroupUserDefaults.groupDefaults.set(false, forKey: UserDefaultsStore.Keys.showNSFW.rawValue) + + PersistenceController.shared.removeNoForDates() PersistenceController.shared.fillInMissingDates() UNUserNotificationCenter.current().delegate = self - let theme = UserDefaultsStore.theme() UIPageControl.appearance().currentPageIndicatorTintColor = UIColor(textColor) UIPageControl.appearance().pageIndicatorTintColor = UIColor.systemGray diff --git a/Shared/Models/UserDefaultsStore.swift b/Shared/Models/UserDefaultsStore.swift index 8bfa69e..d983abd 100644 --- a/Shared/Models/UserDefaultsStore.swift +++ b/Shared/Models/UserDefaultsStore.swift @@ -22,6 +22,7 @@ class UserDefaultsStore { case customMoodTint case customMoodTintUpdateNumber case textColor + case showNSFW case contentViewCurrentSelectedHeaderViewBackDays case contentViewHeaderTag diff --git a/Shared/views/CustomizeView/CustomizeView.swift b/Shared/views/CustomizeView/CustomizeView.swift index 9e639c5..a164822 100644 --- a/Shared/views/CustomizeView/CustomizeView.swift +++ b/Shared/views/CustomizeView/CustomizeView.swift @@ -19,8 +19,11 @@ struct CustomizeView: View { @AppStorage(UserDefaultsStore.Keys.customMoodTintUpdateNumber.rawValue, store: GroupUserDefaults.groupDefaults) private var customMoodTintUpdateNumber: Int = 0 @AppStorage(UserDefaultsStore.Keys.textColor.rawValue, store: GroupUserDefaults.groupDefaults) private var textColor: Color = .black - + + @AppStorage(UserDefaultsStore.Keys.showNSFW.rawValue, store: GroupUserDefaults.groupDefaults) private var showNSFW: Bool = false + @State private var sampleListEntry = PersistenceController.shared.randomEntries(count: 1).first! + @State private var showOver18Alert = false @StateObject private var customMoodTint = UserDefaultsStore.getCustomMoodTint() @@ -213,7 +216,6 @@ struct CustomizeView: View { RoundedRectangle(cornerRadius: 10, style: .continuous) .fill(imagePack == images ? theme.currentTheme.bgColor : .clear) .padding([.top, .bottom], -3) - ) .onTapGesture { let impactMed = UIImpactFeedbackGenerator(style: .heavy) @@ -403,10 +405,27 @@ struct CustomizeView: View { .padding(5) ) .onTapGesture { - let impactMed = UIImpactFeedbackGenerator(style: .heavy) - impactMed.impactOccurred() - personalityPack = aPack - LocalNotification.rescheduleNotifiations() + if aPack.rawValue == PersonalityPack.Rude.rawValue && !showNSFW { + showOver18Alert = true + } else { + let impactMed = UIImpactFeedbackGenerator(style: .heavy) + impactMed.impactOccurred() + personalityPack = aPack + LocalNotification.rescheduleNotifiations() + } + } + .blur(radius: aPack.rawValue == PersonalityPack.Rude.rawValue && !showNSFW ? 5 : 0) + .alert(isPresented: $showOver18Alert) { + let primaryButton = Alert.Button.default(Text(String(localized: "customize_view_over18alert_ok"))) { + showNSFW = true + } + let secondaryButton = Alert.Button.cancel(Text(String(localized: "customize_view_over18alert_no"))) { + showNSFW = false + } + return Alert(title: Text(String(localized: "customize_view_over18alert_title")), + message: Text(String(localized: "customize_view_over18alert_body")), + primaryButton: primaryButton, + secondaryButton: secondaryButton) } if aPack.rawValue != (PersonalityPack.allCases.sorted(by: { $0.rawValue > $1.rawValue }).first?.rawValue) ?? 0 { Divider() diff --git a/en.lproj/Localizable.strings b/en.lproj/Localizable.strings index 7c7502b..067a0f1 100644 --- a/en.lproj/Localizable.strings +++ b/en.lproj/Localizable.strings @@ -78,6 +78,10 @@ "customize_view_view_change_icon" = "Change App Icon"; "customize_view_view_text_color" = "Text Color"; "customize_view_view_example_row" = "Example row"; +"customize_view_over18alert_title" = "Are you over 18?"; +"customize_view_over18alert_body" = "Some of this is explicit, are you over 18?"; +"customize_view_over18alert_ok" = "Sure"; +"customize_view_over18alert_no" = "Nah, I'm good"; "create_widget_view_left_eye" = "Left Eye"; "create_widget_view_right_eye" = "Right Eye";