Pārlūkot izejas kodu

add welcome view and delete background asset

alqindiirsyam 2 gadi atpakaļ
vecāks
revīzija
ed549a1067

+ 2 - 2
appbuilder-ios/AppBuilder/AppBuilder.xcodeproj/project.pbxproj

@@ -433,7 +433,7 @@
 				CODE_SIGN_IDENTITY = "Apple Development";
 				CODE_SIGN_STYLE = Automatic;
 				CURRENT_PROJECT_VERSION = 1;
-				DEVELOPMENT_TEAM = WM6NB9V368;
+				DEVELOPMENT_TEAM = ZGNLXSR5ZF;
 				FRAMEWORK_SEARCH_PATHS = (
 					"$(inherited)",
 					"$(PROJECT_DIR)/Frameworks",
@@ -462,7 +462,7 @@
 				CODE_SIGN_IDENTITY = "Apple Development";
 				CODE_SIGN_STYLE = Automatic;
 				CURRENT_PROJECT_VERSION = 1;
-				DEVELOPMENT_TEAM = WM6NB9V368;
+				DEVELOPMENT_TEAM = ZGNLXSR5ZF;
 				FRAMEWORK_SEARCH_PATHS = (
 					"$(inherited)",
 					"$(PROJECT_DIR)/Frameworks",

+ 2 - 3
appbuilder-ios/AppBuilder/AppBuilder/Base.lproj/Main.storyboard

@@ -67,7 +67,7 @@
                         <rect key="frame" x="0.0" y="0.0" width="428" height="926"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
-                            <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="pb_lbackground_1" translatesAutoresizingMaskIntoConstraints="NO" id="BU2-P5-16y">
+                            <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="BU2-P5-16y">
                                 <rect key="frame" x="0.0" y="0.0" width="428" height="926"/>
                             </imageView>
                             <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="oT8-Uw-cgS">
@@ -287,7 +287,7 @@
                         <rect key="frame" x="0.0" y="0.0" width="428" height="926"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
-                            <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="pb_lbackground_1" translatesAutoresizingMaskIntoConstraints="NO" id="rdi-Bn-gaF">
+                            <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="rdi-Bn-gaF">
                                 <rect key="frame" x="0.0" y="0.0" width="428" height="926"/>
                             </imageView>
                             <tableView opaque="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" bouncesZoom="NO" dataMode="prototypes" style="insetGrouped" separatorStyle="default" separatorInsetReference="fromAutomaticInsets" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="5" sectionFooterHeight="5" translatesAutoresizingMaskIntoConstraints="NO" id="gUO-Ws-n00">
@@ -334,7 +334,6 @@
         </scene>
     </scenes>
     <resources>
-        <image name="pb_lbackground_1" width="1204" height="2475"/>
         <systemColor name="systemBackgroundColor">
             <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
         </systemColor>

+ 147 - 2
appbuilder-ios/AppBuilder/AppBuilder/ViewController.swift

@@ -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
+    }
+}

+ 1 - 5
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ChangeDeviceViewController.swift

@@ -19,11 +19,7 @@ public class ChangeDeviceViewController: UIViewController {
     public override func viewDidLoad() {
         super.viewDidLoad()
         
-        let randomInt = 1
-        let image = UIImage(named: "pb_lbackground_\(randomInt)")
-        if image != nil {
-            self.view.backgroundColor = UIColor.init(patternImage: image!)
-        }
+        self.view.backgroundColor = .white
 
         self.title = "Login".localized()
         navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Submit".localized(), style: .plain, target: self, action: #selector(didTapSubmit(sender:)))

+ 1 - 5
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ChangeNamePassswordViewController.swift

@@ -25,11 +25,7 @@ public class ChangeNamePassswordViewController: UIViewController {
     public override func viewDidLoad() {
         super.viewDidLoad()
         
-        let randomInt = 1
-        let image = UIImage(named: "pb_lbackground_\(randomInt)")
-        if image != nil {
-            self.view.backgroundColor = UIColor.init(patternImage: image!)
-        }
+        self.view.backgroundColor = .white
 
         self.title = "Change Profile".localized()
         if !fromSetting {

+ 1 - 5
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/HistoryCCViewController.swift

@@ -19,11 +19,7 @@ public class HistoryCCViewController: UITableViewController, QLPreviewController
         super.viewDidLoad()
         self.title = "Call Center History".localized()
         
-        let randomInt = Int.random(in: 5..<11)
-        let image = UIImage(named: "lbackground_\(randomInt)")
-        if image != nil {
-            self.view.backgroundColor = UIColor.init(patternImage: image!)
-        }
+        self.view.backgroundColor = .white
         
     }
     

+ 1 - 5
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ProfileViewController.swift

@@ -166,11 +166,7 @@ public class ProfileViewController: UITableViewController {
         profile.isUserInteractionEnabled = true
         profile.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(profileTapped)))
         
-        let randomInt = 1
-        let image = UIImage(named: "pb_lbackground_\(randomInt)")
-        if image != nil {
-            self.view.backgroundColor = UIColor.init(patternImage: image!)
-        }
+        self.view.backgroundColor = .white
         
         if fromRootViewController {
             navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(didTapExit(sender:)))

+ 1 - 7
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ScannerViewController.swift

@@ -36,13 +36,7 @@ class ScannerViewController: UIViewController, QRScannerViewDelegate {
     override func viewDidLoad() {
         super.viewDidLoad()
         
-        let randomInt = Int.random(in: 5..<11)
-        let image = UIImage(named: "lbackground_\(randomInt)")
-        if image != nil {
-            self.view.backgroundColor = UIColor.init(patternImage: image!)
-        } else {
-            self.view.backgroundColor = .white
-        }
+        self.view.backgroundColor = .white
 
         self.title = "Scan QR Code".localized()
         navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel".localized(), style: .plain, target: self, action: #selector(cancel(sender:)))

+ 55 - 54
src/mainIOS.py

@@ -232,60 +232,61 @@ def change_logo(c_code_path, lib_dest, logo, logo_float=None):
 
 
 def change_background(c_code_path, background):
-    assets_dir = os.path.join(c_code_path, "Assets.xcassets")
-    img_src_path_1 = os.path.join(assets_dir, "pb_lbackground_1.imageset")
-    if isinstance(background, str):
-        background = background.split(",")
-        for i, b in enumerate(background):
-            n = i + 1
-            print(b)
-            img_src_path = os.path.join(assets_dir, "pb_lbackground_{}.imageset".format(n))
-            print(img_src_path)
-            if n != 1:
-                shutil.copytree(img_src_path_1,img_src_path)
-            os.remove(os.path.join(img_src_path,"pb_lbackground_1.png"))
-            contents_json = os.path.join(img_src_path, "Contents.json")
-            with open(contents_json, "r") as f:
-                file_source = f.read()
-            replaced = file_source.replace("lbackground_1", "lbackground_{}".format(n))
-            with open(contents_json, "w") as f:
-                f.write(replaced)
-            img_path = os.path.join(img_src_path, "pb_lbackground_{}.png".format(n))
-            # try:
-            #     background_url = requests.get('https://newuniverse.io/dashboardv2/uploads/background/{}'.format(b))
-            #     with open(img_path, "wb") as f:
-            #         f.write(background_url.content)
-            #     with open(img_path, "rb") as f:
-            #         l = Image.open(f)
-            #         l = l.resize((600, 1250))
-            #     l.save(img_path, "PNG")
-            # except:
-            try:
-                background_path = os.path.join(app.asset_folder, "background", "{}".format(b))
-                with open(background_path, "rb") as f:
-                    l = Image.open(f)
-                    l = l.resize((600, 1250))
-                l.save(img_path, "PNG")
-            except:
-                print("error background: {}".format(b))
-                return
-        second_tab = os.path.join(c_code_path, "SecondTabViewController.swift")
-        fourth_tab = os.path.join(c_code_path, "FourthTabViewController.swift")
-        with open(second_tab, "r") as f:
-            file_source = f.read()
-        replaced = file_source.replace("1..<2", "1..<{}".format(len(background) + 1))
-        with open(second_tab, "w") as f:
-            f.write(replaced)
-        with open(fourth_tab, "r") as f:
-            file_source = f.read()
-        replaced = file_source.replace("1..<2", "1..<{}".format(len(background) + 1))
-        with open(fourth_tab, "w") as f:
-            f.write(replaced)
-    else:
-        img_path = os.path.join(img_src_path_1, "pb_lbackground_1.png")
-        logo = Image.open(background)
-        logo = logo.resize((600, 1250))
-        logo.save(img_path, "PNG")
+    # assets_dir = os.path.join(c_code_path, "Assets.xcassets")
+    # img_src_path_1 = os.path.join(assets_dir, "pb_lbackground_1.imageset")
+    # if isinstance(background, str):
+    #     background = background.split(",")
+    #     for i, b in enumerate(background):
+    #         n = i + 1
+    #         print(b)
+    #         img_src_path = os.path.join(assets_dir, "pb_lbackground_{}.imageset".format(n))
+    #         print(img_src_path)
+    #         if n != 1:
+    #             shutil.copytree(img_src_path_1,img_src_path)
+    #         os.remove(os.path.join(img_src_path,"pb_lbackground_1.png"))
+    #         contents_json = os.path.join(img_src_path, "Contents.json")
+    #         with open(contents_json, "r") as f:
+    #             file_source = f.read()
+    #         replaced = file_source.replace("lbackground_1", "lbackground_{}".format(n))
+    #         with open(contents_json, "w") as f:
+    #             f.write(replaced)
+    #         img_path = os.path.join(img_src_path, "pb_lbackground_{}.png".format(n))
+    #         # try:
+    #         #     background_url = requests.get('https://newuniverse.io/dashboardv2/uploads/background/{}'.format(b))
+    #         #     with open(img_path, "wb") as f:
+    #         #         f.write(background_url.content)
+    #         #     with open(img_path, "rb") as f:
+    #         #         l = Image.open(f)
+    #         #         l = l.resize((600, 1250))
+    #         #     l.save(img_path, "PNG")
+    #         # except:
+    #         try:
+    #             background_path = os.path.join(app.asset_folder, "background", "{}".format(b))
+    #             with open(background_path, "rb") as f:
+    #                 l = Image.open(f)
+    #                 l = l.resize((600, 1250))
+    #             l.save(img_path, "PNG")
+    #         except:
+    #             print("error background: {}".format(b))
+    #             return
+    #     second_tab = os.path.join(c_code_path, "SecondTabViewController.swift")
+    #     fourth_tab = os.path.join(c_code_path, "FourthTabViewController.swift")
+    #     with open(second_tab, "r") as f:
+    #         file_source = f.read()
+    #     replaced = file_source.replace("1..<2", "1..<{}".format(len(background) + 1))
+    #     with open(second_tab, "w") as f:
+    #         f.write(replaced)
+    #     with open(fourth_tab, "r") as f:
+    #         file_source = f.read()
+    #     replaced = file_source.replace("1..<2", "1..<{}".format(len(background) + 1))
+    #     with open(fourth_tab, "w") as f:
+    #         f.write(replaced)
+    # else:
+    #     img_path = os.path.join(img_src_path_1, "pb_lbackground_1.png")
+    #     logo = Image.open(background)
+    #     logo = logo.resize((600, 1250))
+    #     logo.save(img_path, "PNG")
+    pass
 
 
 def change_fb(lib_dest, fb_icon):