فهرست منبع

add NOtification Sound

alqindiirsyam 2 سال پیش
والد
کامیت
e0c04487da

+ 13 - 0
appbuilder-ios/AppBuilder/AppBuilder/FourthTabViewController.swift

@@ -566,6 +566,19 @@ public class FourthTabViewController: UIViewController, UITableViewDelegate, UIT
             navigationController.view.backgroundColor = .mainColor
             navigationController.modalPresentationStyle = .custom
             self.present(navigationController, animated: true)
+        } else if item.title == "Notification Message(s)".localized() || item.title == "Notification Message(s) Group".localized() {
+            let controller = NotificationSound()
+            if item.title != "Notification Message(s)".localized() {
+                controller.isPersonal = false
+            }
+            let navigationController = UINavigationController(rootViewController: controller)
+            navigationController.navigationBar.tintColor = .white
+            navigationController.navigationBar.barTintColor = .mainColor
+            navigationController.navigationBar.isTranslucent = false
+            let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
+            navigationController.navigationBar.titleTextAttributes = textAttributes
+            navigationController.view.backgroundColor = .mainColor
+            self.present(navigationController, animated: true)
         }
     }
     

+ 10 - 3
appbuilder-ios/NexilisLite/NexilisLite/Source/InquiryThread.swift

@@ -23,14 +23,21 @@ class InquiryThread {
     
     init() {
         Database.shared.database?.inTransaction({ (fmdb, rollback) in
-            if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select status, message from INQUIRY") {
+            if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select status, message, id from INQUIRY") {
                 while cursor.next() {
                     let status = cursor.int(forColumnIndex: 0)
                     if status == 1 {
                         continue
                     }
-                    if let message = cursor.string(forColumnIndex: 1) {
-                        addQueue(message: TMessage(data: message))
+                    if let cursorMessage = Database.shared.getRecords(fmdb: fmdb, query: "select message_id from MESSAGE where message_id = '\(cursor.string(forColumnIndex: 2)!)'") {
+                        if cursorMessage.next() {
+                            if let message = cursor.string(forColumnIndex: 1) {
+                                addQueue(message: TMessage(data: message))
+                            }
+                        } else {
+                            _ = Database.shared.deleteRecord(fmdb: fmdb, table: "INQUIRY", _where: "id = '\(cursor.string(forColumnIndex: 2)!)'")
+                        }
+                        cursorMessage.close()
                     }
                 }
                 cursor.close()

+ 26 - 0
appbuilder-ios/NexilisLite/NexilisLite/Source/Model/NotifSound.swift

@@ -0,0 +1,26 @@
+//
+//  NotifSound.swift
+//  NexilisLite
+//
+//  Created by Akhmad Al Qindi Irsyam on 28/11/22.
+//
+
+import Foundation
+
+public class NotifSound: Model {
+    public var id: Int
+    public var name: String
+    public var isSelected: Bool
+    public var description: String
+    
+    public init(id: Int, name: String, isSelected: Bool = false) {
+        self.id = id
+        self.name = name
+        self.isSelected = isSelected
+        self.description = ""
+    }
+    
+    public static func == (lhs: NotifSound, rhs: NotifSound) -> Bool {
+        return lhs.id == rhs.id
+    }
+}

+ 15 - 2
appbuilder-ios/NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -2817,11 +2817,24 @@ extension Nexilis: MessageDelegate {
                     
                     floating.show(queuePosition: .front, bannerPosition: .top, queue: NotificationBannerQueue(maxBannersOnScreenSimultaneously: 1), on: nil, edgeInsets: UIEdgeInsets(top: 8.0, left: 8.0, bottom: 0, right: 8.0), cornerRadius: 8.0, shadowColor: .clear, shadowOpacity: .zero, shadowBlurRadius: .zero, shadowCornerRadius: .zero, shadowOffset: .zero, shadowEdgeInsets: nil)
                     let vibrateMode = UserDefaults.standard.bool(forKey: "vibrateMode")
-                    var systemSoundID: SystemSoundID = 1007
+                    var soundId = UserDefaults.standard.string(forKey: "notifSoundPersonal") ?? ""
+                    if message.getBody(key: CoreMessage_TMessageKey.MESSAGE_SCOPE_ID) == "4" {
+                        soundId = UserDefaults.standard.string(forKey: "notifSoundGroup") ?? ""
+                    }
+                    var systemSoundID: SystemSoundID!
+                    if soundId.isEmpty {
+                        systemSoundID = 1007
+                    } else {
+                        systemSoundID = SystemSoundID(Int(soundId.components(separatedBy: ":")[0])!)
+                    }
                     if vibrateMode {
                         AudioServicesPlaySystemSound(systemSoundID)
                     } else {
-                        let url = URL(fileURLWithPath: "/System/Library/Audio/UISounds/sms-received1.caf")
+                        var nameSound = "sms-received1"
+                        if systemSoundID != 1007 {
+                            nameSound = soundId.components(separatedBy: ":")[1]
+                        }
+                        let url = URL(fileURLWithPath: "/System/Library/Audio/UISounds/\(nameSound).caf")
                         AudioServicesCreateSystemSoundID(url as CFURL, &systemSoundID)
                         AudioServicesPlaySystemSound(systemSoundID)
                     }

+ 110 - 0
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/NotificationSound.swift

@@ -0,0 +1,110 @@
+//
+//  NotificationSound.swift
+//  NexilisLite
+//
+//  Created by Akhmad Al Qindi Irsyam on 28/11/22.
+//
+
+import UIKit
+import AVFoundation
+
+public class NotificationSound: UIViewController, UITableViewDelegate, UITableViewDataSource {
+    
+    public var isPersonal = true
+    let tableView = UITableView()
+    var data: [NotifSound] = []
+    var isSelectedSound = 0
+
+    public override func viewDidLoad() {
+        super.viewDidLoad()
+
+        self.view.backgroundColor = .white
+        
+        view.addSubview(tableView)
+        tableView.translatesAutoresizingMaskIntoConstraints = false
+        tableView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor).isActive = true
+        tableView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
+        tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
+        tableView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
+        
+        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cellNotifSound")
+        
+        tableView.delegate = self
+        tableView.dataSource = self
+
+        self.title = "Notification Message(s)".localized()
+        if !isPersonal {
+            self.title = "Notification Message(s) Group".localized()
+        }
+        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel".localized(), style: .plain, target: self, action: #selector(cancel(sender:)))
+        
+        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Save".localized(), style: .plain, target: self, action: #selector(save(sender:)))
+        data.append(NotifSound(id: 1007, name: "sms-received1 (Default)", isSelected: false))
+        data.append(NotifSound(id: 1008, name: "sms-received2", isSelected: false))
+        data.append(NotifSound(id: 1009, name: "sms-received3", isSelected: false))
+        data.append(NotifSound(id: 1010, name: "sms-received4", isSelected: false))
+        data.append(NotifSound(id: 1013, name: "sms-received5", isSelected: false))
+        data.append(NotifSound(id: 1014, name: "sms-received6", isSelected: false))
+        var selectedSound = UserDefaults.standard.string(forKey: "notifSoundPersonal") ?? ""
+        if !isPersonal {
+            selectedSound = UserDefaults.standard.string(forKey: "notifSoundGroup") ?? ""
+        }
+        if !selectedSound.isEmpty {
+            let selectedSoundId = Int(selectedSound.components(separatedBy: ":")[0])
+            let idx = data.firstIndex(where: {$0.id == selectedSoundId})
+            if idx != nil {
+                data[idx!].isSelected = true
+                isSelectedSound = selectedSoundId!
+            } else {
+                data[0].isSelected = true
+                isSelectedSound = 1007
+            }
+        } else {
+            data[0].isSelected = true
+            isSelectedSound = 1007
+        }
+    }
+    
+    @objc func cancel(sender: Any) {
+        navigationController?.dismiss(animated: true, completion: nil)
+    }
+    
+    @objc func save(sender: Any) {
+        let idx = data.firstIndex(where: {$0.id == isSelectedSound})
+        if isPersonal {
+            UserDefaults.standard.set("\(data[idx!].id):\(data[idx!].name)", forKey: "notifSoundPersonal")
+        } else {
+            UserDefaults.standard.set("\(data[idx!].id):\(data[idx!].name)", forKey: "notifSoundGroup")
+        }
+        navigationController?.dismiss(animated: true, completion: nil)
+    }
+    
+    // MARK: - Table view data source
+    
+    public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+        let idx = data.firstIndex(where: {$0.id == isSelectedSound})
+        data[idx!].isSelected = false
+        
+        let idxNew = data.firstIndex(where: {$0.id == data[indexPath.row].id})
+        data[idxNew!].isSelected = true
+        isSelectedSound = data[indexPath.row].id
+        
+        let systemSoundID: SystemSoundID = SystemSoundID(isSelectedSound)
+        AudioServicesPlaySystemSound(systemSoundID)
+        tableView.reloadData()
+    }
+
+    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+        return data.count
+    }
+
+    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+        let cell = tableView.dequeueReusableCell(withIdentifier: "cellNotifSound", for: indexPath)
+        var content = cell.defaultContentConfiguration()
+        content.text = data[indexPath.row].name
+        cell.contentConfiguration = content
+        cell.accessoryType = data[indexPath.row].isSelected ? .checkmark : .none
+        cell.selectionStyle = .none
+        return cell
+    }
+}