123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721 |
- //
- // ProfileViewController.swift
- // Qmera
- //
- // Created by Yayan Dwi on 17/09/21.
- //
- import UIKit
- import NotificationBannerSwift
- import nuSDKService
- public class ProfileViewController: UITableViewController {
-
- @IBOutlet weak var profile: UIImageView!
-
- @IBOutlet weak var call: UIButton!
- @IBOutlet weak var video: UIButton!
- @IBOutlet weak var message: UIButton!
- @IBOutlet weak var viewUserType: UIView!
- @IBOutlet weak var imageUserType: UIImageView!
- @IBOutlet weak var labelUserType: UILabel!
- @IBOutlet weak var buttonGroup: UIStackView!
- @IBOutlet weak var myViewGroup: UIView!
- @IBOutlet weak var switchPrivateAccount: UISwitch!
- @IBOutlet weak var buttonEditPass: UIButton!
- @IBOutlet weak var switchAcceptCall: UISwitch!
- @IBOutlet weak var buttonHistoryCC: UIButton!
- @IBOutlet weak var viewFriend: UIView!
- @IBOutlet weak var countFriend: UILabel!
- @IBOutlet weak var labelPrivateAccount: UILabel!
- @IBOutlet weak var labelChangePassword: UILabel!
- @IBOutlet weak var labelAcceptCall: UILabel!
-
- private var imageVideoPicker : ImageVideoPicker!
-
- public enum Flag {
- case me
- case friend
- case invite
- }
-
- var user: User?
-
- public var data: String = ""
-
- public var flag: Flag = Flag.friend
-
- var name: String = ""
-
- var picture: String = ""
-
- var checkReadMessage: (() -> ())?
-
- public var isDismiss: (() -> ())?
-
- public var dismissImage: ((UIImage, String) -> ())?
-
- var fromRootViewController = false
-
- var isBNI = false
-
- var fromListFriend = false
-
- var isLoadingAddFriend = false
-
- var publicBanner = FloatingNotificationBanner()
-
- private func reload() {
- if let user = self.user {
- self.navigationController?.navigationBar.topItem?.title = "\(user.firstName) \(user.lastName)"
- self.navigationController?.navigationBar.setNeedsLayout()
- self.title = "\(user.firstName) \(user.lastName)"
- if !user.thumb.isEmpty {
- self.profile.setImage(name: user.thumb)
- }
- } else {
- getData { user in
- self.user = user
- DispatchQueue.main.async {
- guard let user = user else {
- return
- }
- if let me = UserDefaults.standard.string(forKey: "me"), me == self.data || self.flag == Flag.me {
- Database.shared.database?.inTransaction({ fmdb, rollback in
- let idMe = UserDefaults.standard.string(forKey: "me")!
- if let cursorCount = Database.shared.getRecords(fmdb: fmdb, query: "select COUNT(*) from BUDDY where f_pin <> '\(idMe)' and first_name NOT LIKE 'USR%' "), cursorCount.next() {
- let count = cursorCount.string(forColumnIndex: 0)!
- self.countFriend.text = count + " " + "Friends".localized()
- self.countFriend.font = .systemFont(ofSize: 12)
- self.viewFriend.layer.cornerRadius = 5.0
- self.viewFriend.clipsToBounds = true
- self.viewFriend.isHidden = false
-
- self.viewFriend.isUserInteractionEnabled = true
- self.viewFriend.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.friendsTapped)))
- cursorCount.close()
- }
- })
- }
- if User.isOfficialRegular(official_account: user.official ?? "") || User.isOfficial(official_account: user.official ?? "") || User.isVerified(official_account: user.official ?? "") || User.isCallCenter(userType: user.userType ?? "") || User.isInternal(userType: user.userType ?? "") {
- self.viewUserType.layer.cornerRadius = 5.0
- self.viewUserType.clipsToBounds = true
- self.viewUserType.isHidden = false
- if User.isOfficialRegular(official_account: user.official ?? "") || User.isOfficial(official_account: user.official ?? "") {
- self.imageUserType.image = UIImage(named: "ic_official_flag", in: Bundle.resourceBundle(for: DigiX.self), with: nil)
- self.labelUserType.text = "Official".localized()
- } else if User.isVerified(official_account: user.official ?? "") {
- self.imageUserType.image = UIImage(named: "ic_verified", in: Bundle.resourceBundle(for: DigiX.self), with: nil)
- self.labelUserType.text = "Verified".localized()
- } else if User.isCallCenter(userType: user.userType ?? "") {
- let dataCategory = CategoryCC.getDataFromServiceId(service_id: user.ex_offmp!)
- self.imageUserType.image = UIImage(named: "pb_call_center", in: Bundle.resourceBundle(for: DigiX.self), with: nil)
- // if dataCategory != nil {
- // self.labelUserType.text = "Call Center (\(dataCategory!.service_name))".localized()
- // } else {
- self.labelUserType.text = "Call Center".localized()
- // }
- // self.buttonHistoryCC.isHidden = true
- }
- }
- self.navigationController?.navigationBar.topItem?.title = "\(user.firstName) \(user.lastName)"
- self.navigationController?.navigationBar.setNeedsLayout()
- self.title = "\(user.firstName) \(user.lastName)"
- if !user.thumb.isEmpty {
- self.profile.setImage(name: user.thumb)
- }
- }
- }
- }
- }
-
- private func getData(completion: @escaping (User?) -> ()) {
- DispatchQueue.global().async {
- var r: User?
- r = User.getData(pin: self.data)
- Database.shared.database?.inTransaction({ fmdb, rollback in
- let idMe = UserDefaults.standard.string(forKey: "me")!
- if let cursorCount = Database.shared.getRecords(fmdb: fmdb, query: "select COUNT(*) from BUDDY where f_pin <> '\(idMe)' and first_name NOT LIKE 'USR%' "), cursorCount.next() {
- DispatchQueue.main.async {
- self.countFriend.text = cursorCount.string(forColumnIndex: 0) ?? "" + " " + "Friends".localized()
- }
- cursorCount.close()
- }
- })
- completion(r)
- }
- }
-
- public override func viewWillDisappear(_ animated: Bool) {
- if self.isMovingFromParent {
- self.checkReadMessage?()
- }
- }
-
- public override func viewWillAppear(_ animated: Bool) {
- if navigationController?.navigationBar.backgroundColor != .clear {
- navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
- navigationController?.navigationBar.tintColor = .white
- navigationItem.rightBarButtonItem?.tintColor = .white
- } else {
- navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
- }
- if fromListFriend {
- if let me = UserDefaults.standard.string(forKey: "me"), me == self.data || self.flag == Flag.me {
- Database.shared.database?.inTransaction({ fmdb, rollback in
- let idMe = UserDefaults.standard.string(forKey: "me")!
- if let cursorCount = Database.shared.getRecords(fmdb: fmdb, query: "select COUNT(*) from BUDDY where f_pin <> '\(idMe)' and first_name NOT LIKE 'USR%' "), cursorCount.next() {
- let count = cursorCount.string(forColumnIndex: 0)!
- self.countFriend.text = count + " " + "Friends".localized()
- cursorCount.close()
- }
- })
- }
- }
- }
-
- public override func viewDidDisappear(_ animated: Bool) {
- navigationController?.navigationBar.titleTextAttributes = nil
- }
-
- public override func viewDidAppear(_ animated: Bool) {
- if let me = UserDefaults.standard.string(forKey: "me"), me == data || flag == Flag.me || flag == Flag.friend {
- reload()
- }
- }
-
- public override func viewDidLoad() {
- super.viewDidLoad()
-
- pullBuddy()
-
- profile.circle()
- profile.contentMode = .scaleAspectFill
-
- profile.isUserInteractionEnabled = true
- profile.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(profileTapped)))
-
- self.view.backgroundColor = .white
-
- if fromRootViewController {
- navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(didTapExit(sender:)))
- }
- let myData = User.getData(pin: self.data)
- labelPrivateAccount.text = "Private Account Mode".localized()
- labelChangePassword.text = "Change Password".localized()
- labelAcceptCall.text = "Accept Call".localized()
- buttonHistoryCC.setTitle("Call Center History".localized(), for: .normal)
- navigationController?.navigationBar.topItem?.backButtonTitle = "Back".localized()
- if let me = UserDefaults.standard.string(forKey: "me"), me == data || flag == Flag.me {
- buttonGroup.removeFromSuperview()
- navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Edit".localized(), style: .plain, target: self, action: #selector(didTapEdit(sender:)))
- imageVideoPicker = ImageVideoPicker(presentationController: self, delegate: self)
- buttonEditPass.addTarget(self, action: #selector(editPassword(sender:)), for: .touchUpInside)
- buttonHistoryCC.addTarget(self, action: #selector(historyCC(sender:)), for: .touchUpInside)
- if myData?.privacy_flag == "1" {
- switchPrivateAccount.setOn(true, animated: false)
- }
- if myData?.offline_mode == "1" {
- switchAcceptCall.setOn(false, animated: false)
- }
- switchPrivateAccount.addTarget(self, action: #selector(privateAccountSwitch), for: .valueChanged)
- switchAcceptCall.addTarget(self, action: #selector(acceptCallSwitch), for: .valueChanged)
- } else if flag == Flag.invite {
- navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(didTapAdd(sender:)))
- call.isEnabled = false
- video.isEnabled = false
- message.isEnabled = false
- myViewGroup.removeFromSuperview()
- buttonGroup.removeFromSuperview()
- title = name
- profile.setImage(name: picture)
- } else if flag == Flag.friend {
- navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "person.crop.circle.badge.xmark"), style: .plain, target: self, action: #selector(didTapUnfriend(sender:)))
- if !isBNI {
- call.addTarget(self, action: #selector(call(sender:)), for: .touchUpInside)
- video.addTarget(self, action: #selector(video(sender:)), for: .touchUpInside)
- message.addTarget(self, action: #selector(chat(sender:)), for: .touchUpInside)
- } else {
- call.isEnabled = false
- video.isEnabled = false
- message.isEnabled = false
- buttonGroup.removeFromSuperview()
- }
- myViewGroup.removeFromSuperview()
- }
- }
-
- @objc func acceptCallSwitch(mySwitch: UISwitch) {
- let value = mySwitch.isOn
- if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
- publicBanner.show()
- self.switchPrivateAccount.setOn(!value, animated: true)
- return
- }
- DispatchQueue.global().async {
- let tMessage = CoreMessage_TMessageBank.getChangePersonInfo_New(p_f_pin: self.data)
- tMessage.mBodies[CoreMessage_TMessageKey.OFFLINE_MODE] = value ? "0" : "1"
- if let resp = DigiX.writeAndWait(message: tMessage) {
- if resp.isOk() {
- Database.shared.database?.inTransaction({ (fmdb, rollback) in
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "BUDDY", cvalues: [
- "offline_mode" : value ? "0" : "1"
- ], _where: "f_pin = '\(self.data)'")
- })
- DispatchQueue.main.async { [self] in
- let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: "Successfully changed".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
- publicBanner.show()
- }
- } else {
- DispatchQueue.main.async { [self] in
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: "Unable to access servers".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
- publicBanner.show()
- self.switchPrivateAccount.setOn(!value, animated: true)
- }
- }
- }
- }
- }
-
- @objc func privateAccountSwitch(mySwitch: UISwitch) {
- let value = mySwitch.isOn
- if !CheckConnection.isConnectedToNetwork() || API.nGetCLXConnState() == 0 {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
- publicBanner.show()
- self.switchPrivateAccount.setOn(!value, animated: true)
- return
- }
- DispatchQueue.global().async {
- let tMessage = CoreMessage_TMessageBank.getChangePersonInfo_New(p_f_pin: self.data)
- tMessage.mBodies[CoreMessage_TMessageKey.PRIVACY_FLAG] = value ? "1" : "0"
- if let resp = DigiX.writeAndWait(message: tMessage) {
- if resp.isOk() {
- Database.shared.database?.inTransaction({ (fmdb, rollback) in
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "BUDDY", cvalues: [
- "privacy_flag" : value ? "1" : "0"
- ], _where: "f_pin = '\(self.data)'")
- })
- DispatchQueue.main.async { [self] in
- let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: "Successfully changed".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
- publicBanner.show()
- }
- } else {
- DispatchQueue.main.async { [self] in
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: "Unable to access servers".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
- publicBanner.show()
- self.switchPrivateAccount.setOn(!value, animated: true)
- }
- }
- }
- }
- }
-
- @objc func editPassword(sender: Any) {
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "changePWD") as! ChangePasswordViewController
- navigationController?.show(controller, sender: nil)
- }
-
- @objc func historyCC(sender: Any) {
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "myHistoryCC") as! HistoryCCViewController
- if user?.userType == "24" {
- controller.isOfficer = true
- } else {
- controller.isOfficer = false
- }
- navigationController?.show(controller, sender: nil)
- }
-
- @objc func call(sender: Any) {
- let myData = User.getData(pin: self.data)
- if myData?.ex_block == "1" || myData?.ex_block == "-1" {
- var title = "You blocked this user".localized()
- if myData?.ex_block == "-1" {
- title = "You have been blocked by this user".localized()
- }
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: title, subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
- publicBanner.show()
- return
- }
- if !CheckConnection.isConnectedToNetwork() {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
- publicBanner.show()
- return
- }
- let controller = QmeraAudioViewController()
- controller.user = user
- controller.isOutgoing = true
- controller.modalPresentationStyle = .overCurrentContext
- present(controller, animated: true, completion: nil)
- }
-
- @objc func video(sender: Any) {
- let myData = User.getData(pin: self.data)
- if myData?.ex_block == "1" || myData?.ex_block == "-1" {
- var title = "You blocked this user".localized()
- if myData?.ex_block == "-1" {
- title = "You have been blocked by this user".localized()
- }
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: title, subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
- publicBanner.show()
- return
- }
- if !CheckConnection.isConnectedToNetwork() {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: "Check your connection".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
- publicBanner.show()
- return
- }
- if let user = user {
- let videoVC = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "videoVCQmera") as! QmeraVideoViewController
- videoVC.fPin = user.pin
- self.show(videoVC, sender: nil)
- }
- }
-
- @objc func chat(sender: Any) {
- if let _ = previousViewController as? EditorPersonal {
- navigationController?.popViewController(animated: true)
- return
- }
- if let user = self.user {
- let editorPersonalVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
- editorPersonalVC.hidesBottomBarWhenPushed = true
- editorPersonalVC.unique_l_pin = user.pin
- navigationController?.show(editorPersonalVC, sender: nil)
- }
- }
-
- private func addFriend(completion: @escaping (Bool) -> ()) {
- DispatchQueue.global().async {
- guard !self.data.isEmpty else {
- completion(false)
- return
- }
- if let response = DigiX.writeAndWait(message: CoreMessage_TMessageBank.getAddFriendQRCode(fpin: self.data)), response.isOk() {
- completion(true)
- } else {
- completion(false)
- }
- }
- }
-
- private func unFriend(completion: @escaping (Bool) -> ()) {
- DispatchQueue.global().async {
- guard !self.data.isEmpty else {
- completion(false)
- return
- }
- if let response = DigiX.writeSync(message: CoreMessage_TMessageBank.removeFriend(lpin: self.user!.pin)), response.isOk() {
- completion(true)
- } else {
- completion(false)
- }
- }
- }
-
- func didTapProfile() {
- if let userImage = user?.thumb {
- if !userImage.isEmpty {
- let firstAlert = LibAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
- firstAlert.addAction(UIAlertAction(title: "Change Profile Picture".localized(), style: .default, handler: { action in
- let alert = LibAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
- alert.addAction(UIAlertAction(title: "Take Photo".localized(), style: .default, handler: { action in
- self.imageVideoPicker.present(source: .imageCamera)
- }))
- alert.addAction(UIAlertAction(title: "Choose Photo".localized(), style: .default, handler: { action in
- self.imageVideoPicker.present(source: .imageAlbum)
- }))
- alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: { action in
-
- }))
- self.navigationController?.present(alert, animated: true)
- }))
- firstAlert.addAction(UIAlertAction(title: "Remove Profile Picture".localized(), style: .default, handler: { action in
- if let response = DigiX.writeAndWait(message: CoreMessage_TMessageBank.getChangePersonImage(thumb_id: "")), response.isOk() {
- guard let me = UserDefaults.standard.string(forKey: "me") else {
- return
- }
- Database.shared.database?.inTransaction({ fmdb, rollback in
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "BUDDY", cvalues: ["image_id": ""], _where: "f_pin = '\(me)'")
- })
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "updateFifthTab"), object: nil, userInfo: nil)
-
- DispatchQueue.main.async { [self] in
- self.profile.image = UIImage(systemName: "person.circle.fill")!
- self.profile.backgroundColor = .white
- self.user?.thumb = ""
- let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: "Successfully removed profile picture".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
- publicBanner.show()
- self.dismissImage?(UIImage(systemName: "person.circle.fill")!, "")
- }
- }
- }))
- firstAlert.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: nil))
- self.navigationController?.present(firstAlert, animated: true)
- } else {
- let alert = LibAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
- alert.addAction(UIAlertAction(title: "Take Photo".localized(), style: .default, handler: { action in
- self.imageVideoPicker.present(source: .imageCamera)
- }))
- alert.addAction(UIAlertAction(title: "Choose Photo".localized(), style: .default, handler: { action in
- self.imageVideoPicker.present(source: .imageAlbum)
- }))
- alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: { action in
-
- }))
- self.navigationController?.present(alert, animated: true)
- }
- }
- }
-
- @objc func didTapAdd(sender: Any) {
- if isLoadingAddFriend {
- return
- }
- DigiX.showLoader()
- isLoadingAddFriend = true
- addFriend { result in
- DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
- DigiX.hideLoader { [self] in
- if result {
- let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: "Successfully add friend".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
- publicBanner.show()
- self.isDismiss?()
- self.navigationController?.popViewController(animated: true)
- } else {
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: "Server busy, please try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
- publicBanner.show()
- self.isLoadingAddFriend = false
- }
- }
- })
- }
- }
-
- @objc func didTapUnfriend(sender: Any) {
- if call != nil {
- call.isEnabled = false
- video.isEnabled = false
- message.isEnabled = false
- }
- DigiX.shared.stateUnfriend = self.data
- let alert = LibAlertController(title: "", message: "Are you sure to unfriend".localized() + " \(self.user!.fullName)", preferredStyle: .alert)
- alert.addAction(UIAlertAction(title: "Cancel".localized(), style: UIAlertAction.Style.default, handler: {(_) in
- if self.call != nil {
- self.call.isEnabled = true
- self.video.isEnabled = true
- self.message.isEnabled = true
- }
- DigiX.shared.stateUnfriend = ""
- } ))
- alert.addAction(UIAlertAction(title: "Delete".localized(), style: .destructive, handler: {(_) in
- DigiX.showLoader()
- self.unFriend { result in
- DispatchQueue.main.async { [self] in
- if result {
- Database.shared.database?.inTransaction({ (fmdb, rollback) in
- if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select * from BUDDY where f_pin = '\(self.data)'"), cursor.next() {
- _ = Database.shared.deleteRecord(fmdb: fmdb, table: "BUDDY", _where: "f_pin = '\(self.data)'")
- _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", _where: "l_pin='\(self.data)'")
- _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE", _where: "(f_pin='\(self.data)' or l_pin='\(self.data)') and message_scope_id='3'")
- cursor.close()
- }
- DigiX.hideLoader(completion: {
- if self.previousViewController is GroupDetailViewController || self.isBNI {
- self.isDismiss?()
- self.navigationController?.popViewController(animated: true)
- } else {
- if let editor = self.previousViewController as? EditorPersonal {
- editor.afterUnfriend()
- } else if let editor = self.previousViewController as? EditorGroup {
- editor.afterUnfriend()
- }
- self.navigationController?.popToRootViewController(animated: true)
- }
- DigiX.shared.stateUnfriend = ""
- })
- })
- } else {
- if self.call != nil {
- self.call.isEnabled = true
- self.video.isEnabled = true
- self.message.isEnabled = true
- }
- DigiX.shared.stateUnfriend = ""
- DigiX.hideLoader(completion: {})
- let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: "Server busy, please try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
- publicBanner.show()
- }
- }
- }
- }))
- self.present(alert, animated: true, completion: nil)
- }
-
- @objc func didTapExit(sender: Any) {
- self.dismiss(animated: true, completion: nil)
- }
-
- @objc func didTapEdit(sender: Any) {
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "changeNameView") as! ChangeNameTableViewController
- controller.data = data
- controller.isDismiss = {
- self.getData { user in
- self.user = user
- DispatchQueue.main.async {
- guard let user = user else {
- return
- }
- self.title = "\(user.firstName) \(user.lastName)"
- if !user.thumb.isEmpty {
- self.profile.setImage(name: user.thumb)
- }
- }
- }
- let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
- imageView.tintColor = .white
- self.publicBanner.dismiss()
- self.publicBanner = FloatingNotificationBanner(title: "Successfully changed name".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
- self.publicBanner.show()
- }
- navigationItem.backButtonTitle = ""
- navigationController?.show(controller, sender: nil)
- }
-
- @objc func profileTapped() {
- if let me = UserDefaults.standard.string(forKey: "me"), me == data || flag == Flag.me {
- didTapProfile()
- }
- }
-
- @objc func friendsTapped() {
- if let me = UserDefaults.standard.string(forKey: "me"), me == data || flag == Flag.me {
- let controller = QmeraCallContactViewController()
- controller.isInviteCC = true
- controller.listFriends = true
- show(controller, sender: nil)
- fromListFriend = true
- }
- }
-
- public override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- if indexPath.section == 1 {
- if let me = UserDefaults.standard.string(forKey: "me"), me == data || flag == Flag.me {
- return 170
- }
- return 56
- }
- return 200
- }
-
- private func pullBuddy() {
- if let me = UserDefaults.standard.string(forKey: "me") {
- DispatchQueue.global().async {
- let _ = DigiX.write(message: CoreMessage_TMessageBank.getBatchBuddiesInfos(p_f_pin: me, last_update: 0))
- }
- }
- }
- }
- extension ProfileViewController: ImageVideoPickerDelegate {
-
- public func didSelect(imagevideo: Any?) {
- if let info = imagevideo as? [UIImagePickerController.InfoKey: Any], let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
- guard let me = UserDefaults.standard.string(forKey: "me") else {
- return
- }
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: {
- DigiX.showLoader()
- DispatchQueue.global().async {
- let resize = image.resize(target: CGSize(width: 800, height: 600))
- let documentDir = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
- let fileDir = documentDir.appendingPathComponent("THUMB_\(me)\(Date().currentTimeMillis().toHex())")
- if !FileManager.default.fileExists(atPath: fileDir.path), let data = resize.jpegData(compressionQuality: 0.8) {
- try! data.write(to: fileDir)
- Network().upload(name: fileDir.lastPathComponent) { result, progress in
- guard result, progress == 100 else {
- return
- }
- if let response = DigiX.writeAndWait(message: CoreMessage_TMessageBank.getChangePersonImage(thumb_id: fileDir.lastPathComponent)), response.isOk() {
- Database.shared.database?.inTransaction({ fmdb, rollback in
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "BUDDY", cvalues: ["image_id": fileDir.lastPathComponent], _where: "f_pin = '\(me)'")
- })
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "updateFifthTab"), object: nil, userInfo: nil)
-
- DispatchQueue.main.async {
- DigiX.hideLoader(completion: { [self] in
- self.profile.image = image
- let imageView = UIImageView(image: UIImage(systemName: "checkmark.circle.fill"))
- self.user?.thumb = fileDir.lastPathComponent
- imageView.tintColor = .white
- publicBanner.dismiss()
- publicBanner = FloatingNotificationBanner(title: "Successfully changed profile picture".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .success, colors: nil, iconPosition: .center)
- publicBanner.show()
- self.dismissImage?(image, fileDir.lastPathComponent)
- })
- }
- } else {
- DigiX.hideLoader(completion: {})
- }
- }
- } else {
- DigiX.hideLoader(completion: {})
- }
- }
- })
- }
- }
-
- }
- //let auto = UserDefaults.standard.bool(forKey: "autoDownload")
- //if auto {
- // DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
- // let objectTapAuto = ObjectGesture()
- // objectTapAuto.image_id = imageChat
- // self.contentMessageTapped(objectTap)
- // })
- //}
|