Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
cranci1 committed Jun 8, 2024
1 parent 08ff909 commit 05cc1da
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
Binary file not shown.
12 changes: 11 additions & 1 deletion AnimeGen/Buttons func/Refresh-API-Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,30 @@ extension ViewController {
let alertController = UIAlertController(title: "Select API", message: nil, preferredStyle: .actionSheet)

let apiOptions: [String]
let choiceIcons: [String]

if #available(iOS 14.0, *) {
apiOptions = developerAPIs ? ["Purr", "kyoko", "n-sfw.com", "nekos.life", "NekoBot", "nekos.moe", "Nekos api", "nekos.best", "Hmtai api", "waifu.it", "waifu.pics", "waifu.im", "pic.re"]
: ["Purr", "n-sfw.com", "nekos.life", "NekoBot", "nekos.moe", "Nekos api", "nekos.best", "waifu.pics", "waifu.im", "pic.re"]

choiceIcons = developerAPIs ? ["Purr", "kyoko", "n-sfw", "nekos.life", "NekoBot", "nekos.moe", "nekosapi", "nekos.best", "Hmtai", "waifu.it", "waifu.pics", "waifu.im", "pic-re"]
: ["Purr", "n-sfw", "nekos.life", "NekoBot", "nekos.moe", "nekosapi", "nekos.best", "waifu.pics", "waifu.im", "pic-re"]
} else {
apiOptions = developerAPIs ? ["Purr", "kyoko", "n-sfw.com", "nekos.life", "NekoBot", "nekos.moe", "nekos.best", "Hmtai api", "waifu.it", "waifu.pics", "waifu.im"]
: ["Purr", "n-sfw.com", "nekos.life", "NekoBot", "nekos.moe", "nekos.best", "waifu.pics", "waifu.im"]

choiceIcons = developerAPIs ? ["Purr", "kyoko", "n-sfw", "nekos.life", "NekoBot", "nekos.moe", "nekos.best", "Hmtai", "waifu.it", "waifu.pics", "waifu.im"]
: ["Purr", "n-sfw", "nekos.life", "NekoBot", "nekos.moe", "nekos.best", "waifu.pics", "waifu.im"]
}

apiOptions.forEach { option in
for (index, option) in apiOptions.enumerated() {
let action = UIAlertAction(title: option, style: .default) { _ in
self.apiButton.setTitle(option, for: .normal)
self.loadImageAndTagsFromSelectedAPI()
}
if index < choiceIcons.count, let icon = UIImage(named: choiceIcons[index]) {
action.setValue(icon.withRenderingMode(.alwaysOriginal), forKey: "image")
}
alertController.addAction(action)
}

Expand Down
59 changes: 32 additions & 27 deletions AnimeGen/Settings/AppPref.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class AppPref: UITableViewController {

var isPresentingActionSheet = false
var selectedChoiceIndex = 0

let choices = ["waifu.im", "pic.re", "waifu.pics", "waifu.it", "nekos.best", "Nekos api", "nekos.moe", "NekoBot", "n-sfw.com", "Purr", "nekos.life"]
let choiceIcons = ["waifu.im", "pic-re", "waifu.pics", "waifu.it", "nekos.best", "nekosapi", "nekos.moe", "NekoBot", "n-sfw", "Purr", "nekos.life"]

@IBOutlet weak var LoadImageSwitch: UISwitch!
@IBOutlet weak var DisplayTags: UISwitch!
Expand All @@ -38,41 +40,44 @@ class AppPref: UITableViewController {
UserDefaults.standard.set(sender.isOn, forKey: "enableTags")
}


@IBAction func switchTagsHide(_ sender: UISwitch) {
let isEnabled = sender.isOn
UserDefaults.standard.set(isEnabled, forKey: "enableTagsHide")
NotificationCenter.default.post(name: Notification.Name("EnableTagsHide"), object: nil, userInfo: ["enableTagsHide": isEnabled])
}

@IBAction func presentActionSheet(_ sender: UIButton) {
isPresentingActionSheet = true
presentChoicesActionSheet()
}
isPresentingActionSheet = true
presentChoicesActionSheet()
}

func presentChoicesActionSheet() {
let actionSheet = UIAlertController(title: "Choose Default API", message: nil, preferredStyle: .actionSheet)

for (index, choice) in choices.enumerated() {
actionSheet.addAction(UIAlertAction(title: choice, style: .default, handler: { _ in
self.updateSelectedChoiceIndex(index)
}))
}

actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))

present(actionSheet, animated: true, completion: nil)
}
func presentChoicesActionSheet() {
let actionSheet = UIAlertController(title: "Choose Default API", message: nil, preferredStyle: .actionSheet)

for (index, choice) in choices.enumerated() {
let action = UIAlertAction(title: choice, style: .default, handler: { _ in
self.updateSelectedChoiceIndex(index)
})
if let icon = UIImage(named: choiceIcons[index]) {
action.setValue(icon.withRenderingMode(.alwaysOriginal), forKey: "image")
}
actionSheet.addAction(action)
}

actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))

present(actionSheet, animated: true, completion: nil)
}

func updateSelectedChoiceIndex(_ index: Int) {
selectedChoiceIndex = index
updateButtonTitle()
UserDefaults.standard.set(selectedChoiceIndex, forKey: "SelectedChoiceIndex")
NotificationCenter.default.post(name: Notification.Name("SelectedChoiceChanged"), object: selectedChoiceIndex)
}
func updateSelectedChoiceIndex(_ index: Int) {
selectedChoiceIndex = index
updateButtonTitle()
UserDefaults.standard.set(selectedChoiceIndex, forKey: "SelectedChoiceIndex")
NotificationCenter.default.post(name: Notification.Name("SelectedChoiceChanged"), object: selectedChoiceIndex)
}

func updateButtonTitle() {
let selectedChoice = choices[selectedChoiceIndex]
APIDefa.setTitle(selectedChoice, for: .normal)
}
func updateButtonTitle() {
let selectedChoice = choices[selectedChoiceIndex]
APIDefa.setTitle(selectedChoice, for: .normal)
}
}

0 comments on commit 05cc1da

Please sign in to comment.