|
@@ -12,6 +12,7 @@ import AVFoundation
|
|
|
import SwiftUI
|
|
|
import Speech
|
|
|
import Alamofire
|
|
|
+import WebKit
|
|
|
|
|
|
class ViewController: UITabBarController, UITabBarControllerDelegate {
|
|
|
let playerController = AVPlayerViewController()
|
|
@@ -42,6 +43,11 @@ class ViewController: UITabBarController, UITabBarControllerDelegate {
|
|
|
public static var alwaysHideButton = false
|
|
|
static var listPullFB: [String] = []
|
|
|
static var datePullFB: Date?
|
|
|
+ let welcomeVC = UIViewController()
|
|
|
+ var termVC: UIViewController?
|
|
|
+ let welcomeDesc = UILabel()
|
|
|
+ let termText = "Read our Terms of Service. Tap \"Agree and Continue\" to accept Terms of Service.".localized()
|
|
|
+ let term = "Terms of Service.".localized()
|
|
|
|
|
|
public static var def: ViewController?
|
|
|
|
|
@@ -382,8 +388,110 @@ class ViewController: UITabBarController, UITabBarControllerDelegate {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- override func viewDidAppear(_ animated: Bool) {
|
|
|
-
|
|
|
+ override func viewWillAppear(_ animated: Bool) {
|
|
|
+ let acceptTerm = PrefsUtil.getTerms()
|
|
|
+ if !acceptTerm {
|
|
|
+ showWelocomeView()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func showWelocomeView() {
|
|
|
+ if let viewWelcome = welcomeVC.view {
|
|
|
+ viewWelcome.backgroundColor = .white
|
|
|
+ let welcomeTitle = UILabel()
|
|
|
+ welcomeTitle.text = "Welcome to".localized() + " " + (Bundle.main.displayName ?? "")
|
|
|
+ welcomeTitle.font = .systemFont(ofSize: 25, weight: .bold)
|
|
|
+ viewWelcome.addSubview(welcomeTitle)
|
|
|
+ welcomeTitle.anchor(top: viewWelcome.safeAreaLayoutGuide.topAnchor, left: viewWelcome.safeAreaLayoutGuide.leftAnchor, paddingTop: 10, paddingLeft: 10)
|
|
|
+
|
|
|
+ let logoImage = UIImageView()
|
|
|
+ logoImage.image = UIImage(named: "pb_icon")
|
|
|
+ viewWelcome.addSubview(logoImage)
|
|
|
+ logoImage.anchor(centerX: viewWelcome.centerXAnchor, centerY: viewWelcome.centerYAnchor, width: 200, height: 200)
|
|
|
+
|
|
|
+ let containerButton = UIView()
|
|
|
+ viewWelcome.addSubview(containerButton)
|
|
|
+ containerButton.anchor(left: viewWelcome.safeAreaLayoutGuide.leftAnchor, bottom: viewWelcome.safeAreaLayoutGuide.bottomAnchor, paddingLeft: 10, paddingBottom: 10, minHeight: 40)
|
|
|
+ containerButton.rightAnchor.constraint(lessThanOrEqualTo: viewWelcome.safeAreaLayoutGuide.rightAnchor, constant: -10).isActive = true
|
|
|
+ containerButton.isUserInteractionEnabled = true
|
|
|
+ let tapgestureAgree = UITapGestureRecognizer(target: self, action: #selector(tappedOnAgree(_ :)))
|
|
|
+ tapgestureAgree.numberOfTapsRequired = 1
|
|
|
+ containerButton.addGestureRecognizer(tapgestureAgree)
|
|
|
+
|
|
|
+ let imageAgree = UIImageView()
|
|
|
+ imageAgree.image = UIImage(systemName: "arrow.forward.circle")
|
|
|
+ imageAgree.tintColor = .mainColor
|
|
|
+ containerButton.addSubview(imageAgree)
|
|
|
+ imageAgree.anchor(left: containerButton.leftAnchor, centerY: containerButton.centerYAnchor, width: 40, height: 40)
|
|
|
+
|
|
|
+ let titleAgree = UILabel()
|
|
|
+ titleAgree.text = "Agree and Continue".localized()
|
|
|
+ titleAgree.textColor = .mainColor
|
|
|
+ containerButton.addSubview(titleAgree)
|
|
|
+ titleAgree.anchor(left: imageAgree.rightAnchor, right: containerButton.rightAnchor, paddingLeft: 5, centerY: containerButton.centerYAnchor)
|
|
|
+
|
|
|
+ let formattedText = String.format(strings: [term], inString: termText)
|
|
|
+ welcomeDesc.isUserInteractionEnabled = true
|
|
|
+ welcomeDesc.attributedText = formattedText
|
|
|
+ welcomeDesc.numberOfLines = 0
|
|
|
+ viewWelcome.addSubview(welcomeDesc)
|
|
|
+ welcomeDesc.anchor(left: viewWelcome.safeAreaLayoutGuide.leftAnchor, bottom: containerButton.topAnchor, right: viewWelcome.rightAnchor, paddingLeft: 10, paddingBottom: 10, paddingRight: 10)
|
|
|
+ let tapgesture = UITapGestureRecognizer(target: self, action: #selector(tappedOnLabelTerms(_ :)))
|
|
|
+ tapgesture.numberOfTapsRequired = 1
|
|
|
+ welcomeDesc.addGestureRecognizer(tapgesture)
|
|
|
+
|
|
|
+ }
|
|
|
+ welcomeVC.modalPresentationStyle = .fullScreen
|
|
|
+ welcomeVC.modalTransitionStyle = .crossDissolve
|
|
|
+ self.present(welcomeVC, animated: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ func showWebviewTerm() {
|
|
|
+ termVC = UIViewController()
|
|
|
+ if let viewTerm = termVC!.view {
|
|
|
+ let webView = WKWebView()
|
|
|
+ let url = URL (string: "https://newuniverse.io/newuniverse-tos")
|
|
|
+ let requestObj = URLRequest(url: url!)
|
|
|
+ webView.load(requestObj)
|
|
|
+ viewTerm.addSubview(webView)
|
|
|
+ webView.anchor(top: viewTerm.safeAreaLayoutGuide.topAnchor, left: viewTerm.safeAreaLayoutGuide.leftAnchor, bottom: viewTerm.safeAreaLayoutGuide.bottomAnchor, right: viewTerm.safeAreaLayoutGuide.rightAnchor)
|
|
|
+ }
|
|
|
+ let navigationController = UINavigationController(rootViewController: termVC!)
|
|
|
+ navigationController.navigationBar.tintColor = .mainColor
|
|
|
+ navigationController.navigationBar.barTintColor = .white
|
|
|
+ navigationController.navigationBar.isTranslucent = false
|
|
|
+ let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.mainColor]
|
|
|
+ navigationController.navigationBar.titleTextAttributes = textAttributes
|
|
|
+ navigationController.view.backgroundColor = .white
|
|
|
+ termVC!.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Close".localized(), style: .plain, target: self, action: #selector(closeTerm))
|
|
|
+ welcomeVC.present(navigationController, animated: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func closeTerm() {
|
|
|
+ termVC!.dismiss(animated: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func tappedOnLabelTerms(_ gesture: UITapGestureRecognizer) {
|
|
|
+ let termString = termText as NSString
|
|
|
+ let termRange = termString.range(of: term)
|
|
|
+
|
|
|
+ let tapLocation = gesture.location(in: welcomeDesc)
|
|
|
+ let index = welcomeDesc.indexOfAttributedTextCharacterAtPoint(point: tapLocation)
|
|
|
+
|
|
|
+ if checkRange(termRange, contain: index) == true {
|
|
|
+ showWebviewTerm()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func tappedOnAgree(_ gesture: UITapGestureRecognizer) {
|
|
|
+ PrefsUtil.setTerms(value: true)
|
|
|
+ welcomeVC.dismiss(animated: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ func checkRange(_ range: NSRange, contain index: Int) -> Bool {
|
|
|
+ return index > range.location && index < range.location + range.length
|
|
|
}
|
|
|
|
|
|
@objc func middleBtnTapped() {
|
|
@@ -853,3 +961,40 @@ extension UIImage {
|
|
|
return image
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+extension String {
|
|
|
+ static func format(strings: [String],
|
|
|
+ italicFont: UIFont = UIFont.italicSystemFont(ofSize: 12),
|
|
|
+ italicColor: UIColor = UIColor.systemGreen,
|
|
|
+ inString string: String,
|
|
|
+ font: UIFont = UIFont.systemFont(ofSize: 12),
|
|
|
+ color: UIColor = UIColor.black) -> NSAttributedString {
|
|
|
+ let attributedString =
|
|
|
+ NSMutableAttributedString(string: string,
|
|
|
+ attributes: [
|
|
|
+ NSAttributedString.Key.font: font,
|
|
|
+ NSAttributedString.Key.foregroundColor: color])
|
|
|
+ let italicFontAttribute = [NSAttributedString.Key.font: italicFont, NSAttributedString.Key.foregroundColor: italicColor]
|
|
|
+ for italic in strings {
|
|
|
+ attributedString.addAttributes(italicFontAttribute, range: (string as NSString).range(of: italic))
|
|
|
+ }
|
|
|
+ return attributedString
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension UILabel {
|
|
|
+ func indexOfAttributedTextCharacterAtPoint(point: CGPoint) -> Int {
|
|
|
+ assert(self.attributedText != nil, "This method is developed for attributed string")
|
|
|
+ let textStorage = NSTextStorage(attributedString: self.attributedText!)
|
|
|
+ let layoutManager = NSLayoutManager()
|
|
|
+ textStorage.addLayoutManager(layoutManager)
|
|
|
+ let textContainer = NSTextContainer(size: self.frame.size)
|
|
|
+ textContainer.lineFragmentPadding = 0
|
|
|
+ textContainer.maximumNumberOfLines = self.numberOfLines
|
|
|
+ textContainer.lineBreakMode = self.lineBreakMode
|
|
|
+ layoutManager.addTextContainer(textContainer)
|
|
|
+
|
|
|
+ let index = layoutManager.characterIndex(for: point, in: textContainer, fractionOfDistanceBetweenInsertionPoints: nil)
|
|
|
+ return index
|
|
|
+ }
|
|
|
+}
|