|
@@ -295,11 +295,11 @@ public class FloatingButton: UIView {
|
|
|
let newButton = UIButton()
|
|
|
newButton.heightAnchor.constraint(equalToConstant: defaultWidthHeightMenuFB).isActive = true
|
|
|
newButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
- DispatchQueue.global().async {
|
|
|
- let data = try? Data(contentsOf: URL(string: Utils.getURLBase() + "get_file_from_path?img=\(icon)")!) //make sure your image in this url does exist, otherwise unwrap in a if let check / try-catch
|
|
|
- DispatchQueue.main.async {
|
|
|
- if data != nil {
|
|
|
- if let image = UIImage(data: data!) {
|
|
|
+ DispatchQueue.global().async {[self] in
|
|
|
+ getDataImageFromUrl(from: URL(string: Utils.getURLBase() + "get_file_from_path?img=" + icon)!) { data, response, error in
|
|
|
+ guard let data = data, error == nil else { return }
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ if let image = UIImage(data: data) {
|
|
|
newButton.setImage(image, for: .normal)
|
|
|
}
|
|
|
}
|
|
@@ -375,11 +375,11 @@ public class FloatingButton: UIView {
|
|
|
newButton.setImage(UIImage(named: mode == MODE_HORIZONTAL_SIDE_TAB ? "pb_button_hrz_more" : mode == MODE_HORIZONTAL_ANIMATION ? "pb_button_hrz_anim_more" : "pb_button_others", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
|
|
|
}
|
|
|
if !icon.isEmpty {
|
|
|
- DispatchQueue.global().async {
|
|
|
- let data = try? Data(contentsOf: URL(string: "https://nexilis.io/get_file?account=\(Nexilis.sAPIKey)&image=\(icon)")!) //make sure your image in this url does exist, otherwise unwrap in a if let check / try-catch
|
|
|
- DispatchQueue.main.async {
|
|
|
- if data != nil {
|
|
|
- newButton.setImage(UIImage(data: data!), for: .normal)
|
|
|
+ DispatchQueue.global().async { [self] in
|
|
|
+ getDataImageFromUrl(from: URL(string: Utils.getURLBase() + "get_file_from_path?img=" + icon)!) { data, response, error in
|
|
|
+ guard let data = data, error == nil else { return }
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ newButton.setImage(UIImage(data: data), for: .normal)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -404,6 +404,13 @@ public class FloatingButton: UIView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private func getDataImageFromUrl(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
|
|
|
+ let urlConfig = URLSessionConfiguration.default
|
|
|
+ let sessionDelegate = SelfSignedURLSessionDelegate()
|
|
|
+ let session = URLSession(configuration: urlConfig, delegate: sessionDelegate, delegateQueue: nil)
|
|
|
+ session.dataTask(with: url, completionHandler: completion).resume()
|
|
|
+ }
|
|
|
+
|
|
|
func getDefaultButton() {
|
|
|
let data = [Nexilis.IDX_NOTIF_CENTER, Nexilis.IDX_CC, Nexilis.IDX_CONVERSATION, Nexilis.IDX_CALL, Nexilis.IDX_STREAM]
|
|
|
for i in 0..<data.count {
|
|
@@ -502,35 +509,37 @@ public class FloatingButton: UIView {
|
|
|
}
|
|
|
|
|
|
@objc func checkCounter() {
|
|
|
- let counter = queryCountCounter()
|
|
|
- if counter > 0 {
|
|
|
- DispatchQueue.main.async { [self] in
|
|
|
- if button_fb2 != nil && !indicatorCounterFB.isDescendant(of: button_fb2) {
|
|
|
- button_fb2.addSubview(indicatorCounterFB)
|
|
|
- indicatorCounterFB.layer.cornerRadius = 7.5
|
|
|
- indicatorCounterFB.layer.masksToBounds = true
|
|
|
- indicatorCounterFB.backgroundColor = .systemRed
|
|
|
- indicatorCounterFB.anchor(top: button_fb2.topAnchor, left: button_fb2.leftAnchor, height: 15, minWidth: 15, maxWidth: 20)
|
|
|
- indicatorCounterFB.addSubview(labelCounterFB)
|
|
|
- labelCounterFB.anchor(left: indicatorCounterFB.leftAnchor, right: indicatorCounterFB.rightAnchor, paddingLeft: 5, paddingRight: 5, centerX: indicatorCounterFB.centerXAnchor, centerY: indicatorCounterFB.centerYAnchor)
|
|
|
- labelCounterFB.font = .systemFont(ofSize: 10)
|
|
|
- labelCounterFB.textColor = .white
|
|
|
- }
|
|
|
- if !indicatorCounterFBBig.isDescendant(of: nexilis_button){
|
|
|
- nexilis_button.addSubview(indicatorCounterFBBig)
|
|
|
- indicatorCounterFBBig.tintColor = .systemRed
|
|
|
- indicatorCounterFBBig.image = UIImage(systemName: "staroflife.circle.fill")
|
|
|
- indicatorCounterFBBig.anchor(top: nexilis_button.topAnchor, left: nexilis_button.leftAnchor, paddingTop: 5, paddingLeft: 5, width: 15, height: 15)
|
|
|
- }
|
|
|
- labelCounterFB.text = "\(counter)"
|
|
|
- }
|
|
|
- } else {
|
|
|
- DispatchQueue.main.async { [self] in
|
|
|
- if button_fb2 != nil && indicatorCounterFB.isDescendant(of: button_fb2) {
|
|
|
- indicatorCounterFB.removeFromSuperview()
|
|
|
+ DispatchQueue.global().async { [self] in
|
|
|
+ let counter = queryCountCounter()
|
|
|
+ if counter > 0 {
|
|
|
+ DispatchQueue.main.async { [self] in
|
|
|
+ if button_fb2 != nil && !indicatorCounterFB.isDescendant(of: button_fb2) {
|
|
|
+ button_fb2.addSubview(indicatorCounterFB)
|
|
|
+ indicatorCounterFB.layer.cornerRadius = 7.5
|
|
|
+ indicatorCounterFB.layer.masksToBounds = true
|
|
|
+ indicatorCounterFB.backgroundColor = .systemRed
|
|
|
+ indicatorCounterFB.anchor(top: button_fb2.topAnchor, left: button_fb2.leftAnchor, height: 15, minWidth: 15, maxWidth: 20)
|
|
|
+ indicatorCounterFB.addSubview(labelCounterFB)
|
|
|
+ labelCounterFB.anchor(left: indicatorCounterFB.leftAnchor, right: indicatorCounterFB.rightAnchor, paddingLeft: 5, paddingRight: 5, centerX: indicatorCounterFB.centerXAnchor, centerY: indicatorCounterFB.centerYAnchor)
|
|
|
+ labelCounterFB.font = .systemFont(ofSize: 10)
|
|
|
+ labelCounterFB.textColor = .white
|
|
|
+ }
|
|
|
+ if !indicatorCounterFBBig.isDescendant(of: nexilis_button){
|
|
|
+ nexilis_button.addSubview(indicatorCounterFBBig)
|
|
|
+ indicatorCounterFBBig.tintColor = .systemRed
|
|
|
+ indicatorCounterFBBig.image = UIImage(systemName: "staroflife.circle.fill")
|
|
|
+ indicatorCounterFBBig.anchor(top: nexilis_button.topAnchor, left: nexilis_button.leftAnchor, paddingTop: 5, paddingLeft: 5, width: 15, height: 15)
|
|
|
+ }
|
|
|
+ labelCounterFB.text = "\(counter)"
|
|
|
}
|
|
|
- if indicatorCounterFBBig.isDescendant(of: nexilis_button) {
|
|
|
- indicatorCounterFBBig.removeFromSuperview()
|
|
|
+ } else {
|
|
|
+ DispatchQueue.main.async { [self] in
|
|
|
+ if button_fb2 != nil && indicatorCounterFB.isDescendant(of: button_fb2) {
|
|
|
+ indicatorCounterFB.removeFromSuperview()
|
|
|
+ }
|
|
|
+ if indicatorCounterFBBig.isDescendant(of: nexilis_button) {
|
|
|
+ indicatorCounterFBBig.removeFromSuperview()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -538,13 +547,11 @@ public class FloatingButton: UIView {
|
|
|
|
|
|
private func queryCountCounter() -> Int32 {
|
|
|
var counter: Int32?
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
|
|
|
- Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "SELECT SUM(counter) FROM MESSAGE_SUMMARY"), cursor.next() {
|
|
|
- counter = cursor.int(forColumnIndex: 0)
|
|
|
- cursor.close()
|
|
|
- }
|
|
|
- })
|
|
|
+ Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
+ if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "SELECT SUM(counter) FROM MESSAGE_SUMMARY"), cursor.next() {
|
|
|
+ counter = cursor.int(forColumnIndex: 0)
|
|
|
+ cursor.close()
|
|
|
+ }
|
|
|
})
|
|
|
return counter ?? 0
|
|
|
}
|