mirror of
https://github.com/whoeevee/EeveeSpotifyReborn.git
synced 2026-01-09 00:23:20 +01:00
native popups
This commit is contained in:
39
Sources/EeveeSpotify/Helpers/PopUpHelper.swift
Normal file
39
Sources/EeveeSpotify/Helpers/PopUpHelper.swift
Normal file
@@ -0,0 +1,39 @@
|
||||
import UIKit
|
||||
import Orion
|
||||
import Foundation
|
||||
|
||||
class PopUpHelper {
|
||||
|
||||
static let sharedPresenter = type(
|
||||
of: Dynamic.SPTEncorePopUpPresenter
|
||||
.alloc(interface: SPTEncorePopUpPresenter.self)
|
||||
)
|
||||
.shared()
|
||||
|
||||
static func showPopUp(
|
||||
message: String,
|
||||
buttonText: String
|
||||
) {
|
||||
|
||||
let model = Dynamic.SPTEncorePopUpDialogModel
|
||||
.alloc(interface: SPTEncorePopUpDialogModel.self)
|
||||
.initWithTitle(
|
||||
"EeveeSpotify",
|
||||
description: message,
|
||||
image: nil,
|
||||
primaryButtonTitle: buttonText,
|
||||
secondaryButtonTitle: nil
|
||||
)
|
||||
|
||||
let dialog = Dynamic.SPTEncorePopUpDialog
|
||||
.alloc(interface: SPTEncorePopUpDialog.self)
|
||||
.`init`()
|
||||
|
||||
dialog.update(model)
|
||||
dialog.setEventHandler({
|
||||
sharedPresenter.dismissPopupWithAnimate(true, clearQueue: false, completion: nil)
|
||||
})
|
||||
|
||||
sharedPresenter.presentPopUp(dialog)
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import UIKit
|
||||
import Foundation
|
||||
|
||||
class WindowHelper {
|
||||
|
||||
static let shared = WindowHelper()
|
||||
|
||||
let window: UIWindow
|
||||
let rootViewController: UIViewController
|
||||
|
||||
private init() {
|
||||
self.window = UIApplication.shared.windows.first!
|
||||
self.rootViewController = window.rootViewController!
|
||||
}
|
||||
|
||||
func presentViewController(_ viewController: UIViewController) {
|
||||
rootViewController.present(viewController, animated: true)
|
||||
}
|
||||
|
||||
func showPopup(message: String, buttonText: String) {
|
||||
|
||||
let alert = UIAlertController(title: "EeveeSpotify", message: message, preferredStyle: .alert)
|
||||
|
||||
alert.overrideUserInterfaceStyle = .dark
|
||||
alert.addAction(UIAlertAction(title: buttonText, style: .default))
|
||||
|
||||
presentViewController(alert)
|
||||
}
|
||||
}
|
||||
7
Sources/EeveeSpotify/Models/SPTEncorePopUpDialog.swift
Normal file
7
Sources/EeveeSpotify/Models/SPTEncorePopUpDialog.swift
Normal file
@@ -0,0 +1,7 @@
|
||||
import Foundation
|
||||
|
||||
@objc protocol SPTEncorePopUpDialog {
|
||||
func `init`() -> SPTEncorePopUpDialog
|
||||
func update(_ popUpModel: SPTEncorePopUpDialogModel)
|
||||
func setEventHandler(_ handler: @escaping () -> Void)
|
||||
}
|
||||
11
Sources/EeveeSpotify/Models/SPTEncorePopUpDialogModel.swift
Normal file
11
Sources/EeveeSpotify/Models/SPTEncorePopUpDialogModel.swift
Normal file
@@ -0,0 +1,11 @@
|
||||
import Foundation
|
||||
|
||||
@objc protocol SPTEncorePopUpDialogModel {
|
||||
func initWithTitle(
|
||||
_ title: String,
|
||||
description: String,
|
||||
image: Any?,
|
||||
primaryButtonTitle: String,
|
||||
secondaryButtonTitle: String?
|
||||
) -> SPTEncorePopUpDialogModel
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import Foundation
|
||||
|
||||
@objc protocol SPTEncorePopUpPresenter {
|
||||
static func shared() -> SPTEncorePopUpPresenter
|
||||
func presentPopUp(_ popUp: SPTEncorePopUpDialog)
|
||||
func dismissPopupWithAnimate(_ animate: Bool, clearQueue: Bool, completion: Any?)
|
||||
}
|
||||
@@ -38,7 +38,7 @@ struct EeveeSpotify: Tweak {
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
|
||||
|
||||
WindowHelper.shared.showPopup(
|
||||
PopUpHelper.showPopUp(
|
||||
message: "Please log in and restart the app to get Premium.",
|
||||
buttonText: "Okay!"
|
||||
)
|
||||
@@ -66,7 +66,7 @@ struct EeveeSpotify: Tweak {
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
|
||||
|
||||
WindowHelper.shared.showPopup(
|
||||
PopUpHelper.showPopUp(
|
||||
message: "Unable to apply tweak: \(error)",
|
||||
buttonText: "OK"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user