diff --git a/AnimeGen.xcodeproj/project.pbxproj b/AnimeGen.xcodeproj/project.pbxproj index ca2f163a..5402bb6d 100644 --- a/AnimeGen.xcodeproj/project.pbxproj +++ b/AnimeGen.xcodeproj/project.pbxproj @@ -489,12 +489,11 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = AnimeGen/AnimeGen.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 30; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = 399LMK6Q2Y; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = AnimeGen/Info.plist; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.entertainment"; - INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = "The gallery addition is needed to save images."; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; INFOPLIST_KEY_UIMainStoryboardFile = Main; @@ -524,12 +523,11 @@ CODE_SIGN_ENTITLEMENTS = AnimeGen/AnimeGen.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 30; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = 399LMK6Q2Y; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = AnimeGen/Info.plist; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.entertainment"; - INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = "The gallery addition is needed to save images."; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; INFOPLIST_KEY_UIMainStoryboardFile = Main; diff --git a/AnimeGen.xcodeproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate b/AnimeGen.xcodeproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate index a821b437..edd981df 100644 Binary files a/AnimeGen.xcodeproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate and b/AnimeGen.xcodeproj/project.xcworkspace/xcuserdata/Francesco.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/AnimeGen/Buttons/HearthButton.swift b/AnimeGen/Buttons/HearthButton.swift index 5f162678..8cce71d4 100644 --- a/AnimeGen/Buttons/HearthButton.swift +++ b/AnimeGen/Buttons/HearthButton.swift @@ -30,6 +30,7 @@ extension ViewController { self.animateFeedback() } else { print("Error saving GIF image: \(error?.localizedDescription ?? "")") + self.showAlert(withTitle: "Error Saving Image!", message: "You didn't allow AnimeGen to access the Photo Library.", viewController: self) } } return @@ -46,10 +47,12 @@ extension ViewController { } } - @objc func image(_ image: UIImage, didFinishSavingWithError error: NSError?, contextInfo: UnsafeRawPointer) { + @objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) { if let error = error { print("Error saving image: \(error.localizedDescription)") + self.showAlert(withTitle: "Error Saving Image!", message: "You didn't allow AnimeGen to access the Photo Library.", viewController: self) } else { + self.animateFeedback() print("Image saved successfully") } } diff --git a/AnimeGen/Settings/SettingsPage.swift b/AnimeGen/Settings/SettingsPage.swift index aa7d5c0e..0801bda8 100644 --- a/AnimeGen/Settings/SettingsPage.swift +++ b/AnimeGen/Settings/SettingsPage.swift @@ -30,6 +30,12 @@ struct SettingsPage: View { // Tutorial @State private var isShowingTutorial = false + // Default API + @State private var isPresentingActionSheet = false + @State private var selectedChoiceIndex = 0 + + let choices = ["waifu.im", "pic.re", "waifu.pics", "waifu.it", "nekos.best", "Nekos api", "nekos.moe", "NekoBot", "kyoko", "Purr"] + var body: some View { NavigationView { Form { @@ -67,6 +73,36 @@ struct SettingsPage: View { } Section(header: Text("Api Preferences"), footer: Text("An app restart is necessary to enable or disable the changes.")) { + Button(action: { + isPresentingActionSheet = true + }) { + HStack { + Text("Default API") + .foregroundColor(.primary) + Spacer() + Text(choices[selectedChoiceIndex]) + .foregroundColor(.accentColor) + } + }.actionSheet(isPresented: $isPresentingActionSheet) { + ActionSheet(title: Text("Choose Default API"), buttons: [ + .default(Text("Purr")) { selectedChoiceIndex = 9 }, + .default(Text("kyoko")) { selectedChoiceIndex = 8 }, + .default(Text("NekoBot")) { selectedChoiceIndex = 7 }, + .default(Text("nekos.moe")) { selectedChoiceIndex = 6 }, + .default(Text("Nekos api")) { selectedChoiceIndex = 5 }, + .default(Text("nekos.best")) { selectedChoiceIndex = 4 }, + .default(Text("waifu.it")) { selectedChoiceIndex = 3 }, + .default(Text("waifu.pics")) { selectedChoiceIndex = 2 }, + .default(Text("waifu.im")) { selectedChoiceIndex = 0 }, + .default(Text("pic.re")) { selectedChoiceIndex = 1 }, + .cancel() + ]) + } + .onDisappear { + UserDefaults.standard.set(selectedChoiceIndex, forKey: "SelectedChoiceIndex") + NotificationCenter.default.post(name: Notification.Name("SelectedChoiceChanged"), object: selectedChoiceIndex) + } + Toggle("Display Tags", isOn: Binding( get: { self.tags }, set: { newValue in diff --git a/AnimeGen/ViewController.swift b/AnimeGen/ViewController.swift index 0dd82ebc..4111fe0e 100644 --- a/AnimeGen/ViewController.swift +++ b/AnimeGen/ViewController.swift @@ -45,6 +45,8 @@ class ViewController: UIViewController { var alert = UserDefaults.standard.bool(forKey: "enableDeveloperAlert") + let choices = ["waifu.im", "pic.re", "waifu.pics", "waifu.it", "nekos.best", "Nekos api", "nekos.moe", "NekoBot", "kyoko", "Purr"] + var counter: Int = 0 override func viewDidLoad() { @@ -88,7 +90,7 @@ class ViewController: UIViewController { // Api Button apiButton = UIButton(type: .system) - apiButton.setTitle("pic.re", for: .normal) + apiButton.setTitle("", for: .normal) apiButton.addTarget(self, action: #selector(apiButtonTapped), for: .touchUpInside) apiButton.translatesAutoresizingMaskIntoConstraints = false apiButton.backgroundColor = gradient ? UIColor(red: 0.4, green: 0.3, blue: 0.6, alpha: 1.0) : UIColor.darkGray @@ -288,9 +290,26 @@ class ViewController: UIViewController { animateGradient() } + let selectedChoiceIndex = UserDefaults.standard.integer(forKey: "SelectedChoiceIndex") + apiButton.setTitle(choices[selectedChoiceIndex], for: .normal) + + NotificationCenter.default.addObserver(self, selector: #selector(selectedChoiceChanged(_:)), name: Notification.Name("SelectedChoiceChanged"), object: nil) + loadImageAndTagsFromSelectedAPI() } + + deinit { + NotificationCenter.default.removeObserver(self) + } + + @objc func selectedChoiceChanged(_ notification: Notification) { + guard let selectedIndex = notification.object as? Int else { return } + guard selectedIndex >= 0 && selectedIndex < choices.count else { return } + apiButton.setTitle(choices[selectedIndex], for: .normal) + } + + func loadImageAndTagsFromSelectedAPI() { guard let title = apiButton.title(for: .normal) else { return