Parcourir la source

update database open and style setting

alqindiirsyam123 il y a 8 mois
Parent
commit
acc50a93d6

BIN
AppBuilder/.DS_Store


+ 96 - 85
AppBuilder/AppBuilder/FourthTabViewController.swift

@@ -140,116 +140,127 @@ public class FourthTabViewController: UIViewController, UITableViewDelegate, UIT
     
     func makeMenu(imageSignIn: String = ""){
         let isChangeProfile = Utils.getSetProfile()
-        Database.shared.database?.inTransaction({ fmdb, rollback in
-            let idMe = UserDefaults.standard.string(forKey: "me") as String?
-            if let cursorUser = Database.shared.getRecords(fmdb: fmdb, query: "SELECT user_type, image_id, official_account FROM BUDDY where f_pin='\(idMe!)'"), cursorUser.next() {
-                if (User.isInternal(userType: cursorUser.string(forColumnIndex: 0) ?? "") && User.isAdmin(fmdb: fmdb)) || User.isOfficial(official_account: cursorUser.string(forColumnIndex: 2) ?? "") || User.isOfficial(official_account: cursorUser.string(forColumnIndex: 2) ?? "") {
-                    Item.menus["Personal"] = [
-                        Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
-                        Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
-                        Item(icon: UIImage(systemName: "person.crop.rectangle"), title: "Change Admin / Internal Password".localized()),
-                        Item(icon: UIImage(systemName: "laptopcomputer.and.iphone"), title: "Sign-In to Web".localized()),
-                        Item(icon: UIImage(named: "ic_internal", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, title: "Set Internal Account".localized()),
-                        Item(icon: UIImage(named: "pb_call_center", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, title: "Set CS Account".localized()),
-                    ]
-                } else if User.isInternal(userType: cursorUser.string(forColumnIndex: 0) ?? "") || User.isCallCenter(userType: cursorUser.string(forColumnIndex: 0) ?? "") || User.isVerified(official_account: cursorUser.string(forColumnIndex: 2) ?? "") {
-                    Item.menus["Personal"] = [
-                        Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
-                        Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
-                        Item(icon: UIImage(systemName: "laptopcomputer.and.iphone"), title: "Sign-In to Web".localized()),
-                    ]
+        if Database.shared.database == nil {
+            Item.menus["Personal"] = [
+                Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
+                Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
+                Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Sign-Up/Sign-In".localized()),
+            ]
+            if Nexilis.showButtonFB {
+                Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "gearshape.circle"), title: "Configure Floating Button".localized()))
+            }
+        } else {
+            Database.shared.database?.inTransaction({ fmdb, rollback in
+                let idMe = UserDefaults.standard.string(forKey: "me") as String?
+                if let cursorUser = Database.shared.getRecords(fmdb: fmdb, query: "SELECT user_type, image_id, official_account FROM BUDDY where f_pin='\(idMe!)'"), cursorUser.next() {
+                    if (User.isInternal(userType: cursorUser.string(forColumnIndex: 0) ?? "") && User.isAdmin(fmdb: fmdb)) || User.isOfficial(official_account: cursorUser.string(forColumnIndex: 2) ?? "") || User.isOfficial(official_account: cursorUser.string(forColumnIndex: 2) ?? "") {
+                        Item.menus["Personal"] = [
+                            Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
+                            Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
+                            Item(icon: UIImage(systemName: "person.crop.rectangle"), title: "Change Admin / Internal Password".localized()),
+                            Item(icon: UIImage(systemName: "laptopcomputer.and.iphone"), title: "Sign-In to Web".localized()),
+                            Item(icon: UIImage(named: "ic_internal", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, title: "Set Internal Account".localized()),
+                            Item(icon: UIImage(named: "pb_call_center", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, title: "Set CS Account".localized()),
+                        ]
+                    } else if User.isInternal(userType: cursorUser.string(forColumnIndex: 0) ?? "") || User.isCallCenter(userType: cursorUser.string(forColumnIndex: 0) ?? "") || User.isVerified(official_account: cursorUser.string(forColumnIndex: 2) ?? "") {
+                        Item.menus["Personal"] = [
+                            Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
+                            Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
+                            Item(icon: UIImage(systemName: "laptopcomputer.and.iphone"), title: "Sign-In to Web".localized()),
+                        ]
+                    } else {
+                        Item.menus["Personal"] = [
+                            Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
+                            Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
+                            Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
+                        ]
+                    }
+                    if !isChangeProfile {
+                        Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Sign-Up/Sign-In".localized()))
+                    } else if isChangeProfile {
+                        if Nexilis.checkingAccess(key: "backup_restore") {
+                            Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.clockwise.icloud"), title: "Backup & Restore".localized()))
+                        }
+                        if Utils.getLimitValidTrans() == "1" {
+                            Item.menus["Personal"]?.insert(Item(icon: UIImage(systemName: "lessthan.circle"), title: "Validation Transaction Limit".localized()), at: 1)
+                        }
+                    }
+                    let image = cursorUser.string(forColumnIndex: 1)
+                    if image != nil {
+                        if !image!.isEmpty {
+                            do {
+                                let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
+                                let file = documentDir.appendingPathComponent(image!)
+                                if FileManager().fileExists(atPath: file.path) {
+                                    let image = UIImage(contentsOfFile: file.path)
+                                    Item.menus["Personal"]?[0].icon = image?.circleMasked
+                                    if !imageSignIn.isEmpty {
+                                        var dataImage: [AnyHashable : Any] = [:]
+                                        dataImage["name"] = imageSignIn
+                                        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
+                                    }
+                                } else {
+                                    Download().start(forKey: image!) { (name, progress) in
+                                        guard progress == 100 else {
+                                            return
+                                        }
+                                        
+                                        DispatchQueue.main.async {
+                                            let image = UIImage(contentsOfFile: file.path)
+                                            Item.menus["Personal"]?[0].icon = image?.circleMasked
+                                            self.tableView.reloadData()
+                                            if !imageSignIn.isEmpty {
+                                                var dataImage: [AnyHashable : Any] = [:]
+                                                dataImage["name"] = imageSignIn
+                                                NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
+                                            }
+                                        }
+                                    }
+                                }
+                            } catch {}
+                        }
+                    }
+                    cursorUser.close()
                 } else {
                     Item.menus["Personal"] = [
                         Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
-                            Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
+                        Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
                         Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
                     ]
-                }
-                if !isChangeProfile {
-                    Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Sign-Up/Sign-In".localized()))
-                } else if isChangeProfile {
-                    if Nexilis.checkingAccess(key: "backup_restore") {
-                        Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.clockwise.icloud"), title: "Backup & Restore".localized()))
-                    }
-                    if Utils.getLimitValidTrans() == "1" {
-                        Item.menus["Personal"]?.insert(Item(icon: UIImage(systemName: "lessthan.circle"), title: "Validation Transaction Limit".localized()), at: 1)
+                    if Nexilis.showButtonFB {
+                        Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "gearshape.circle"), title: "Configure Floating Button".localized()))
                     }
-                }
-                let image = cursorUser.string(forColumnIndex: 1)
-                if image != nil {
-                    if !image!.isEmpty {
+                    Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Sign-Up/Sign-In".localized()))
+                    if !imageSignIn.isEmpty {
                         do {
                             let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
-                            let file = documentDir.appendingPathComponent(image!)
+                            let file = documentDir.appendingPathComponent(imageSignIn)
                             if FileManager().fileExists(atPath: file.path) {
                                 let image = UIImage(contentsOfFile: file.path)
                                 Item.menus["Personal"]?[0].icon = image?.circleMasked
-                                if !imageSignIn.isEmpty {
-                                    var dataImage: [AnyHashable : Any] = [:]
-                                    dataImage["name"] = imageSignIn
-                                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
-                                }
+                                var dataImage: [AnyHashable : Any] = [:]
+                                dataImage["name"] = imageSignIn
+                                NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
                             } else {
-                                Download().start(forKey: image!) { (name, progress) in
+                                Download().start(forKey: imageSignIn) { (name, progress) in
                                     guard progress == 100 else {
                                         return
                                     }
-
                                     DispatchQueue.main.async {
                                         let image = UIImage(contentsOfFile: file.path)
                                         Item.menus["Personal"]?[0].icon = image?.circleMasked
                                         self.tableView.reloadData()
-                                        if !imageSignIn.isEmpty {
-                                            var dataImage: [AnyHashable : Any] = [:]
-                                            dataImage["name"] = imageSignIn
-                                            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
-                                        }
+                                        var dataImage: [AnyHashable : Any] = [:]
+                                        dataImage["name"] = imageSignIn
+                                        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
                                     }
                                 }
                             }
                         } catch {}
                     }
                 }
-                cursorUser.close()
-            } else {
-                Item.menus["Personal"] = [
-                    Item(icon: UIImage(systemName: "person"), title: "Personal Information".localized()),
-                        Item(icon: UIImage(systemName: "textformat.abc"), title: "Change Language".localized()),
-                    Item(icon: UIImage(systemName: "person.badge.key"), title: "Access Admin / Internal Features".localized()),
-                ]
-                if Nexilis.showButtonFB {
-                    Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "gearshape.circle"), title: "Configure Floating Button".localized()))
-                }
-                Item.menus["Personal"]?.append(Item(icon: UIImage(systemName: "arrow.up.and.person.rectangle.portrait"), title: "Sign-Up/Sign-In".localized()))
-                if !imageSignIn.isEmpty {
-                    do {
-                        let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
-                        let file = documentDir.appendingPathComponent(imageSignIn)
-                        if FileManager().fileExists(atPath: file.path) {
-                            let image = UIImage(contentsOfFile: file.path)
-                            Item.menus["Personal"]?[0].icon = image?.circleMasked
-                            var dataImage: [AnyHashable : Any] = [:]
-                            dataImage["name"] = imageSignIn
-                            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
-                        } else {
-                            Download().start(forKey: imageSignIn) { (name, progress) in
-                                guard progress == 100 else {
-                                    return
-                                }
-                                DispatchQueue.main.async {
-                                    let image = UIImage(contentsOfFile: file.path)
-                                    Item.menus["Personal"]?[0].icon = image?.circleMasked
-                                    self.tableView.reloadData()
-                                    var dataImage: [AnyHashable : Any] = [:]
-                                    dataImage["name"] = imageSignIn
-                                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "imageFBUpdate"), object: nil, userInfo: dataImage)
-                                }
-                            }
-                        }
-                    } catch {}
-                }
-            }
-        })
+            })
+        }
         
         Item.menus["Config"] = [
             Item(icon: UIImage(systemName: "iphone"), title: "Create Your Own App".localized()),

+ 3 - 1
NexilisLite/NexilisLite/Resource/Palio.storyboard

@@ -414,7 +414,7 @@
                     <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="F0a-VD-4oM">
                         <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
-                        <color key="backgroundColor" red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                        <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                         <prototypes>
                             <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="reuseIdentifier" id="RT8-Qa-6dG">
                                 <rect key="frame" x="0.0" y="55.5" width="414" height="43.5"/>
@@ -422,7 +422,9 @@
                                 <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="RT8-Qa-6dG" id="Axr-HY-bpT">
                                     <rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>
                                     <autoresizingMask key="autoresizingMask"/>
+                                    <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                 </tableViewCellContentView>
+                                <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                             </tableViewCell>
                         </prototypes>
                         <connections>

+ 3 - 1
NexilisLite/NexilisLite/Source/MasterKeyUtil.swift

@@ -107,7 +107,9 @@ public class MasterKeyUtil {
             Nexilis.dispatch?.wait()
             Nexilis.dispatch = nil
             if !result {
-                Utils.showAlert(title: "Failed to get Master Key".localized(), message: "Biometric authentication hasn't been set up/Biometric invalid.".localized())
+                DispatchQueue.main.async {
+                    Utils.showAlert(title: "Failed to get Master Key".localized(), message: "Biometric authentication hasn't been set up/Biometric invalid.".localized())
+                }
                 throw NSError(domain: "KeychainError", code: -99, userInfo: nil)
             }
         }

+ 1 - 1
NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -193,7 +193,7 @@ public class Nexilis: NSObject {
                 
                 if let me = User.getMyPin() {
                     if !Utils.getForceAnonymous() && Utils.getSetProfile() {
-                        Database.shared.openDatabase()
+                        _ = Database.shared.openDatabase()
                         Database.shared.database?.inTransaction({ (fmdb, rollback) in
                             do {
                                 if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: "SELECT * FROM BUDDY where f_pin = '\(me)' ") {

+ 5 - 1
NexilisLite/NexilisLite/Source/Utils.swift

@@ -1216,7 +1216,11 @@ public final class Utils {
     
     static func showAlert(title: String, message: String) {
         let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
-        alertController.addAction(UIAlertAction(title: "OK", style: .default))
+        alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: {(_) in
+            if Database.shared.database == nil {
+                exit(979)
+            }
+        }))
         UIApplication.shared.visibleViewController?.present(alertController, animated: true)
     }
 }

+ 3 - 3
NexilisLite/NexilisLite/Source/View/Control/SettingTableViewController.swift

@@ -27,7 +27,7 @@ public class SettingTableViewController: UITableViewController, UIGestureRecogni
     public override func viewDidLoad() {
         super.viewDidLoad()
         
-        self.view.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .black : .white
+//        self.view.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .black : .white
         self.navigationController?.navigationBar.topItem?.backButtonTitle = ""
         
         tableView.delegate = self
@@ -394,7 +394,7 @@ public class SettingTableViewController: UITableViewController, UIGestureRecogni
     
     public override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
         let headerView = UIView()
-        if (section == 2 && Item.menus["Config"]!.count > 0) || section == 3 {
+        if (section == 2 && Item.menus["Config"]!.count > 0) || section == 3 || (section == 1 && Item.menus["Config"]!.count > 0) {
             headerView.backgroundColor = .clear
             
             let lineView = UIView()
@@ -413,7 +413,7 @@ public class SettingTableViewController: UITableViewController, UIGestureRecogni
     }
     
     public override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
-        if section == 2 || section == 3 {
+        if section == 2 || section == 3 || section == 1 {
             return 6
         }
         return 1