Skip to content

Commit

Permalink
imrpovemtns (idk)
Browse files Browse the repository at this point in the history
  • Loading branch information
cranci1 committed May 22, 2024
1 parent 495f8af commit 8c8627a
Show file tree
Hide file tree
Showing 15 changed files with 264 additions and 258 deletions.
12 changes: 4 additions & 8 deletions AnimeGen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
136BD7E82BE7E24100ED23AE /* Developer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 136BD7E72BE7E24100ED23AE /* Developer.swift */; };
1393C3A92BEBC94300704137 /* AppPreff.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1393C3A62BEBC94300704137 /* AppPreff.swift */; };
1393C3AA2BEBC94300704137 /* Dev-History.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1393C3A72BEBC94300704137 /* Dev-History.swift */; };
1393C3AB2BEBC94300704137 /* moe-kyoko.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1393C3A82BEBC94300704137 /* moe-kyoko.swift */; };
139C35072BFCE1A9003A1CA1 /* Contentsss.swift in Sources */ = {isa = PBXBuildFile; fileRef = 139C35062BFCE1A9003A1CA1 /* Contentsss.swift */; };
1393C3AB2BEBC94300704137 /* moe-content.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1393C3A82BEBC94300704137 /* moe-content.swift */; };
13A8496B2BF479DA009A9442 /* n-sfw.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A8496A2BF479DA009A9442 /* n-sfw.swift */; };
13A8496E2BF4F0E7009A9442 /* FrameWorksCredits.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A8496D2BF4F0E7009A9442 /* FrameWorksCredits.swift */; };
13A849702BF4F118009A9442 /* Contributor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13A8496F2BF4F118009A9442 /* Contributor.swift */; };
Expand Down Expand Up @@ -76,8 +75,7 @@
136BD7E72BE7E24100ED23AE /* Developer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Developer.swift; sourceTree = "<group>"; };
1393C3A62BEBC94300704137 /* AppPreff.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppPreff.swift; sourceTree = "<group>"; };
1393C3A72BEBC94300704137 /* Dev-History.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dev-History.swift"; sourceTree = "<group>"; };
1393C3A82BEBC94300704137 /* moe-kyoko.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "moe-kyoko.swift"; sourceTree = "<group>"; };
139C35062BFCE1A9003A1CA1 /* Contentsss.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Contentsss.swift; sourceTree = "<group>"; };
1393C3A82BEBC94300704137 /* moe-content.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "moe-content.swift"; sourceTree = "<group>"; };
13A8496A2BF479DA009A9442 /* n-sfw.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "n-sfw.swift"; sourceTree = "<group>"; };
13A8496D2BF4F0E7009A9442 /* FrameWorksCredits.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FrameWorksCredits.swift; sourceTree = "<group>"; };
13A8496F2BF4F118009A9442 /* Contributor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Contributor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -275,8 +273,7 @@
children = (
1393C3A62BEBC94300704137 /* AppPreff.swift */,
1393C3A72BEBC94300704137 /* Dev-History.swift */,
1393C3A82BEBC94300704137 /* moe-kyoko.swift */,
139C35062BFCE1A9003A1CA1 /* Contentsss.swift */,
1393C3A82BEBC94300704137 /* moe-content.swift */,
);
path = NotificationCenter;
sourceTree = "<group>";
Expand Down Expand Up @@ -364,7 +361,7 @@
13A849702BF4F118009A9442 /* Contributor.swift in Sources */,
13D4FBF42BE76FC000BC3D1C /* Activity.swift in Sources */,
13D4FC2D2BE7719700BC3D1C /* Secrets.swift in Sources */,
1393C3AB2BEBC94300704137 /* moe-kyoko.swift in Sources */,
1393C3AB2BEBC94300704137 /* moe-content.swift in Sources */,
136BD7E42BE7DFEE00ED23AE /* AppPref.swift in Sources */,
13D4FBEB2BE76D0600BC3D1C /* ImageExtensions.swift in Sources */,
13D4FBE92BE768C100BC3D1C /* HeartButton.swift in Sources */,
Expand All @@ -385,7 +382,6 @@
1393C3AA2BEBC94300704137 /* Dev-History.swift in Sources */,
13D4FC1C2BE770EC00BC3D1C /* purr.swift in Sources */,
13D4FC292BE7710500BC3D1C /* HmtaiReader.swift in Sources */,
139C35072BFCE1A9003A1CA1 /* Contentsss.swift in Sources */,
136BD7E82BE7E24100ED23AE /* Developer.swift in Sources */,
13D4FBF02BE76D4000BC3D1C /* popup-Banner.swift in Sources */,
13D4FC2A2BE7710500BC3D1C /* HmtaiSender.swift in Sources */,
Expand Down
49 changes: 26 additions & 23 deletions AnimeGen/Buttons func/HeartButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,44 @@ extension ViewController {

@IBAction func heartButtonTapped() {
guard let image = imageView.image else {
showAlert(withTitle: "No Image", message: "There is no image to save.", viewController: self)
return
}

if let data = image.imageData,
let source = CGImageSourceCreateWithData(data as CFData, nil),
let utType = CGImageSourceGetType(source),
UTTypeConformsTo(utType, kUTTypeGIF) {

PHPhotoLibrary.shared().performChanges {
let creationRequest = PHAssetCreationRequest.forAsset()
creationRequest.addResource(with: .photo, data: data, options: nil)
} completionHandler: { (success, error) in
if success {
print("GIF image saved to Photos library")
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
}

if let imageData = image.jpegData(compressionQuality: 1.0),
let uiImage = UIImage(data: imageData) {

DispatchQueue.main.async {
UIImageWriteToSavedPhotosAlbum(uiImage, self, #selector(self.image(_:didFinishSavingWithError:contextInfo:)), nil)
}
saveGIFImage(data: data)
} else if let imageData = image.jpegData(compressionQuality: 1.0),
let uiImage = UIImage(data: imageData) {
saveJPEGImage(uiImage: uiImage)
} else {
print("Error converting image to JPEG format")
}
}

@objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
private func saveGIFImage(data: Data) {
PHPhotoLibrary.shared().performChanges {
let creationRequest = PHAssetCreationRequest.forAsset()
creationRequest.addResource(with: .photo, data: data, options: nil)
} completionHandler: { [weak self] success, error in
guard let self = self else { return }
if success {
print("GIF image saved to Photos library")
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)
}
}
}

private func saveJPEGImage(uiImage: UIImage) {
UIImageWriteToSavedPhotosAlbum(uiImage, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
}

@objc private 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)
Expand Down
13 changes: 6 additions & 7 deletions AnimeGen/Buttons func/HistoryButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ import SwiftUI
extension ViewController {

@IBAction func historyButtonTapped() {
let history = HistoryView()
let hostingController = UIHostingController(rootView: history)

let historyView = HistoryView()
let hostingController = UIHostingController(rootView: historyView)
present(hostingController, animated: true, completion: nil)
}

func addToHistory(image: UIImage) {
if HistoryTrue {
ImageHistory.addImage(image)
guard HistoryTrue else {
print("History is disabled.")
return
}
ImageHistory.addImage(image)
}

}

61 changes: 25 additions & 36 deletions AnimeGen/Buttons func/Refresh-API-Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,14 @@ extension ViewController {

@IBAction func refreshButtonTapped() {
guard let title = apiButton.title(for: .normal) else {
print("API button has no title.")
return
}

switch title {
case "pic.re":
loadImageFromPicRe()
showPopUpBanner(message: "This API is not supported on your iOS version!", viewController: self) {
if #available(iOS 14.0, *) {
// nothing here cuz ios 14+ 💪
} else {
self.apiButton.setTitle("waifu.im", for: .normal)
self.loadImageFromWaifuIm()
}
}
handleUnsupportedAPIBanner()
case "waifu.im":
loadImageFromWaifuIm()
case "waifu.it":
Expand All @@ -33,18 +27,11 @@ extension ViewController {
loadImageFromNekosBest()
case "waifu.pics":
loadImageFromWaifuPics()
case "Hmtai api":
case "Hmtai api", "Hmtai":
startHmtaiLoader()
case "Nekos api":
loadImageFromNekosapi()
showPopUpBanner(message: "This API is not supported on your iOS version!", viewController: self) {
if #available(iOS 14.0, *) {
// nothing here cuz ios 14+ 💪
} else {
self.apiButton.setTitle("waifu.im", for: .normal)
self.loadImageFromWaifuIm()
}
}
handleUnsupportedAPIBanner()
case "nekos.moe":
loadImageFromNekosMoe()
case "kyoko":
Expand All @@ -53,48 +40,50 @@ extension ViewController {
loadImageFromPurr()
case "NekoBot":
loadImageFromNekoBot()
case "Hmtai":
startHmtaiLoader()
case "n-sfw.com":
loadImageFromNSFW()
default:
break
print("Unknown API: \(title)")
}
}

private func handleUnsupportedAPIBanner() {
showPopUpBanner(message: "This API is not supported on your iOS version!", viewController: self) {
if #available(iOS 14.0, *) {
//nothing cuz iOS 14 is strong frfr
} else {
self.apiButton.setTitle("waifu.im", for: .normal)
self.loadImageFromWaifuIm()
}
}
}

@objc func apiButtonTapped() {
let alertController = UIAlertController(title: "Select API", message: nil, preferredStyle: .actionSheet)

var apiOptions: [String]
let apiOptions: [String]

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

for option in apiOptions {
apiOptions.forEach { option in
let action = UIAlertAction(title: option, style: .default) { _ in
self.apiButton.setTitle(option, for: .normal)
self.loadImageAndTagsFromSelectedAPI()
}
alertController.addAction(action)
}

let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(cancelAction)

alertController.popoverPresentationController?.sourceView = apiButton
alertController.popoverPresentationController?.sourceRect = apiButton.bounds
present(alertController, animated: true, completion: nil)
}

}
21 changes: 12 additions & 9 deletions AnimeGen/Buttons func/RewindButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ extension ViewController {
}

@objc func rewindButtonTapped() {
if currentPosition > 0 {
currentPosition -= 1
let (previousImage, previousTags) = imageHistory[currentPosition]
DispatchQueue.main.async {
self.imageView.image = previousImage
self.updateUIWithTags(previousTags)
self.animateImageChange(with: previousImage)
}
guard currentPosition > 0 else {
print("No previous images to rewind to.")
return
}

currentPosition -= 1
let (previousImage, previousTags) = imageHistory[currentPosition]

DispatchQueue.main.async {
self.imageView.image = previousImage
self.updateUIWithTags(previousTags)
self.animateImageChange(with: previousImage)
}
}

}
25 changes: 15 additions & 10 deletions AnimeGen/Buttons func/Web-Share.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,29 @@ import UIKit
extension ViewController {

@objc func webButtonTapped() {
if let urlString = currentImageURL, let url = URL(string: urlString) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
guard let urlString = currentImageURL, let url = URL(string: urlString) else {
print("Invalid URL string: \(currentImageURL ?? "nil")")
showAlert(withTitle: "Error", message: "The URL is invalid.", viewController: self)
return
}

UIApplication.shared.open(url, options: [:]) { success in
if !success {
print("Failed to open URL: \(url)")
self.showAlert(withTitle: "Error", message: "Failed to open the URL.", viewController: self)
}
}
}

@objc func shareButtonTapped() {
guard let currentImage = imageView.image else {
print("No image available for sharing.")
showAlert(withTitle: "Error", message: "No image available for sharing.", viewController: self)
return
}

let shareController = UIActivityViewController(
activityItems: [currentImage],
applicationActivities: nil
)

shareController.popoverPresentationController?.sourceView = view
present(shareController, animated: true, completion: nil)
let shareController = UIActivityViewController(activityItems: [currentImage], applicationActivities: nil)
shareController.popoverPresentationController?.sourceView = view
present(shareController, animated: true, completion: nil)
}

}
25 changes: 8 additions & 17 deletions AnimeGen/NotificationCenter/AppPreff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,26 @@ import UIKit
extension ViewController {

@objc func handleGradient(_ notification: Notification) {
guard let userInfo = notification.userInfo,
let isEnabled = userInfo["enablegradient"] as? Bool else {
return
handleNotification(notification, key: "enablegradient") { isEnabled in
self.gradient = isEnabled
}
self.gradient = isEnabled
}

@objc func handleTime(_ notification: Notification) {
guard let userInfo = notification.userInfo,
let isEnabled = userInfo["enableTime"] as? Bool else {
return
handleNotification(notification, key: "enableTime") { isEnabled in
self.activity = isEnabled
}
self.activity = isEnabled
}

@objc func handleGestures(_ notification: Notification) {
guard let userInfo = notification.userInfo,
let isEnabled = userInfo["enableGestures"] as? Bool else {
return
handleNotification(notification, key: "enableGestures") { isEnabled in
self.gestures = isEnabled
}
self.gestures = isEnabled
}

@objc func handleLightMode(_ notification: Notification) {
guard let userInfo = notification.userInfo,
let isEnabled = userInfo["enabledLightMode"] as? Bool else {
return
handleNotification(notification, key: "enabledLightMode") { isEnabled in
self.lightmode = isEnabled
}
self.lightmode = isEnabled
}

}
19 changes: 0 additions & 19 deletions AnimeGen/NotificationCenter/Contentsss.swift

This file was deleted.

Loading

0 comments on commit 8c8627a

Please sign in to comment.