Amrit
4 years ago
9 changed files with 1 additions and 314 deletions
-
4GME Remit.xcodeproj/project.pbxproj
-
11GME Remit/AppDelegate.swift
-
19GME Remit/Modules/Home/User Interface/View/HomeViewController.swift
-
4GME Remit/Modules/ManageAgreement/User Interface/View/ManageAgreementViewController.swift
-
4GME Remit/Modules/RegisterModules/UserAuthentication/NewRegister/User Interface/View/NewRegisterViewController.swift
-
1GME Remit/Modules/RemittanceModules/DomesticModules/DomesticRemit/User Interface/View/DomesticRemitViewController.swift
-
2GME Remit/Modules/SplashScreen/User Interface/View/SplashScreen.storyboard
-
15GME Remit/Modules/SplashScreen/User Interface/View/SplashScreenViewController.swift
-
255GME Remit/Utilities/CSManagement.swift
@ -1,255 +0,0 @@ |
|||||
// |
|
||||
// CSManagement.swift |
|
||||
// GME Remit |
|
||||
// |
|
||||
// Created by InKwon James Kim on 2020/01/08. |
|
||||
// Copyright © 2020 Gobal Money Express Co. Ltd. All rights reserved. |
|
||||
// |
|
||||
import ChannelIO |
|
||||
#if DEBUG |
|
||||
import FLEX |
|
||||
#endif |
|
||||
class CSManagement { |
|
||||
enum IconType { |
|
||||
case original |
|
||||
case call |
|
||||
} |
|
||||
|
|
||||
private let target: UIViewController |
|
||||
private var csButton: UIBarButtonItem? |
|
||||
private var badgeTarget: UIView? |
|
||||
|
|
||||
var messageCount = 0 { |
|
||||
didSet { |
|
||||
var appearance = BadgeAppearance() |
|
||||
|
|
||||
let message = messageCount != 0 ? "\(messageCount)" : nil |
|
||||
|
|
||||
appearance.backgroundColor = .themeWhiteRed |
|
||||
appearance.textColor = .themeRedWhite |
|
||||
|
|
||||
csButton?.badge(text: message, appearance: appearance) |
|
||||
|
|
||||
badgeTarget?.badge(text: message, appearance: appearance) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
var chatIsBooted: Bool { |
|
||||
return ChannelIO.isBooted |
|
||||
} |
|
||||
|
|
||||
init(_ target: UIViewController, badgeTarget: UIView? = nil) { |
|
||||
self.target = target |
|
||||
self.badgeTarget = badgeTarget |
|
||||
} |
|
||||
|
|
||||
func getCSButton(with type: IconType) -> UIBarButtonItem? { |
|
||||
switch type { |
|
||||
case .original: |
|
||||
let supportImage = UIImage(named: "ic_support")?.withRenderingMode(.alwaysOriginal) |
|
||||
|
|
||||
csButton = UIBarButtonItem( |
|
||||
image: supportImage, |
|
||||
style: .plain, |
|
||||
target: self, |
|
||||
action: #selector(touch(_:)) |
|
||||
) |
|
||||
return csButton |
|
||||
|
|
||||
case .call: |
|
||||
let supportImage = UIImage(named: "call")?.withRenderingMode(.alwaysTemplate) |
|
||||
|
|
||||
csButton = UIBarButtonItem( |
|
||||
image: supportImage, |
|
||||
style: .plain, |
|
||||
target: self, |
|
||||
action: #selector(touch(_:)) |
|
||||
) |
|
||||
|
|
||||
csButton?.tintColor = .red |
|
||||
|
|
||||
return csButton |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
func setNavigationRightBarbutton(type: IconType) { |
|
||||
target.navigationItem.rightBarButtonItem = getCSButton(with: type) |
|
||||
} |
|
||||
|
|
||||
func setChannelIO() { |
|
||||
let settings = ChannelPluginSettings() |
|
||||
settings.pluginKey = "24dc2dfd-3ed1-4953-b395-a2255ed41dae" |
|
||||
settings.userId = GMEDB.shared.user.string(.userId) |
|
||||
|
|
||||
let profile = Profile() |
|
||||
|
|
||||
let username = GMEDB.shared.user.string(.fullName) |
|
||||
let email = GMEDB.shared.user.string(.email) |
|
||||
|
|
||||
profile |
|
||||
.set(name: username ?? "") |
|
||||
.set(email: email ?? "") |
|
||||
|
|
||||
ChannelIO.delegate = self |
|
||||
ChannelIO.boot(with:settings, profile: profile) {[weak self] (completion, _) in |
|
||||
var message = "channelIO_error_message_text".localized() |
|
||||
|
|
||||
switch completion { |
|
||||
case .success: |
|
||||
ChannelIO.open(animated: true) |
|
||||
return |
|
||||
case .notInitialized: message += "(1)" |
|
||||
case .networkTimeout: message += "(2)" |
|
||||
case .notAvailableVersion: message += "(3)" |
|
||||
case .serviceUnderConstruction: message += "(4)" |
|
||||
case .requirePayment: message += "(5)" |
|
||||
case .accessDenied: message += "(6)" |
|
||||
case .unknown: message += "(7)" |
|
||||
@unknown default: message += "(8)" |
|
||||
|
|
||||
} |
|
||||
self?.target.alert(type: .error, message: message) |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
func openChat(animated: Bool) { |
|
||||
ChannelIO.open(animated: animated) |
|
||||
} |
|
||||
|
|
||||
@objc func touch(_ sender: UIBarButtonItem) { |
|
||||
let hotLines = HotLineService().staticHotLines |
|
||||
let nativeCountry = GMEDB.shared.user.string(.countryCode)?.lowercased() |
|
||||
let userHotLine = hotLines?.filter { $0.countryCode == nativeCountry }.first |
|
||||
|
|
||||
let alert = UIAlertController( |
|
||||
title: nil, |
|
||||
message: "help_you_text".localized(), |
|
||||
preferredStyle: .actionSheet |
|
||||
) |
|
||||
|
|
||||
let liveChat = UIAlertAction( |
|
||||
title: "live_chat_text".localized(), |
|
||||
style: .default |
|
||||
) {[weak self] _ in |
|
||||
self?.target.alertWithOkCancel( |
|
||||
message: "check_start_chat_text".localized(), |
|
||||
title: "check_start_chat_title_text".localized(), |
|
||||
okTitle: "yes_text".localized(), |
|
||||
cancelTitle: "no_text".localized(), |
|
||||
okAction: { |
|
||||
self?.setChannelIO() |
|
||||
} |
|
||||
) |
|
||||
} |
|
||||
|
|
||||
#if DEBUG |
|
||||
let debug = UIAlertAction( |
|
||||
title: "Debug", |
|
||||
style: .default |
|
||||
) { _ in |
|
||||
FLEXManager.shared()?.showExplorer() |
|
||||
} |
|
||||
|
|
||||
let changeServer = UIAlertAction( |
|
||||
title: "Change Server (\(server.rawValue))", |
|
||||
style: .destructive |
|
||||
) { _ in |
|
||||
MainWireframe.shared?.window?.rootViewController = LauncherScreenWireframe().getMainView() |
|
||||
} |
|
||||
|
|
||||
let requestHeader = UIAlertAction( |
|
||||
title: "Show Header", |
|
||||
style: .default |
|
||||
) { _ in |
|
||||
ShowAPIWireframe().open(on: self.target) |
|
||||
|
|
||||
} |
|
||||
#endif |
|
||||
|
|
||||
let contactNumber = UIAlertAction( |
|
||||
title: userHotLine?.remitPhoneNumber ?? "1588 6864", |
|
||||
style: .default |
|
||||
) { _ in |
|
||||
self.startCall(contactNumber: userHotLine?.remitPhoneNumber ?? "1588 6864") |
|
||||
} |
|
||||
|
|
||||
let facebook = UIAlertAction( |
|
||||
title: "Facebook", |
|
||||
style: .default |
|
||||
) { _ in |
|
||||
UIApplication.tryURL( |
|
||||
url: userHotLine?.remitFacebookURL ?? "https://www.facebook.com/gmenepal/" |
|
||||
) |
|
||||
} |
|
||||
|
|
||||
liveChat.setValue(UIImage(named:"chat")?.withRenderingMode(.alwaysOriginal),forKey:"image") |
|
||||
contactNumber.setValue(UIImage(named:"ic_call")?.withRenderingMode(.alwaysOriginal),forKey:"image") |
|
||||
facebook.setValue(UIImage(named:"settingsFacebook")?.withRenderingMode(.alwaysOriginal),forKey:"image") |
|
||||
|
|
||||
#if DEBUG |
|
||||
alert.addAction(changeServer) |
|
||||
alert.addAction(debug) |
|
||||
alert.addAction(requestHeader) |
|
||||
#endif |
|
||||
|
|
||||
alert.addAction(facebook) |
|
||||
alert.addAction(liveChat) |
|
||||
alert.addAction(contactNumber) |
|
||||
|
|
||||
alert.addAction(UIAlertAction( |
|
||||
title: "cancel_text".localized(), |
|
||||
style: UIAlertAction.Style.cancel, |
|
||||
handler: nil |
|
||||
) |
|
||||
) |
|
||||
alert.view.tintColor = .themeText |
|
||||
|
|
||||
if UIDevice.current.userInterfaceIdiom == .pad { |
|
||||
if let popoverController = alert.popoverPresentationController { |
|
||||
popoverController.sourceView = target.view |
|
||||
popoverController.sourceRect = CGRect( |
|
||||
x: target.view.bounds.midX, |
|
||||
y: target.view.bounds.midY, |
|
||||
width: 0, |
|
||||
height: 0 |
|
||||
) |
|
||||
|
|
||||
popoverController.permittedArrowDirections = [] |
|
||||
target.present(alert, animated: true, completion: nil) |
|
||||
} |
|
||||
} else { |
|
||||
target.present(alert, animated: true, completion: nil) |
|
||||
} |
|
||||
|
|
||||
guard |
|
||||
let label = (liveChat.value(forKey: "__representer")as? NSObject)?.value(forKey: "label") as? UILabel |
|
||||
else { return } |
|
||||
|
|
||||
var appearance = BadgeAppearance() |
|
||||
appearance.distanceFromCenterX = (label.intrinsicContentSize.width / 2) + 10 |
|
||||
appearance.distanceFromCenterY = -(label.intrinsicContentSize.height / 2) |
|
||||
|
|
||||
let message = messageCount != 0 ? "\(messageCount)" : nil |
|
||||
label.badge(text: message, appearance: appearance) |
|
||||
} |
|
||||
|
|
||||
private func startCall(contactNumber: String) { |
|
||||
if let url = URL(string: "tel://\(contactNumber.removeWhitespacesInBetween())"), |
|
||||
UIApplication.shared.canOpenURL(url) { |
|
||||
UIApplication.shared.open(url) |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// MARK: ChannelPluginDelegate |
|
||||
extension CSManagement: ChannelPluginDelegate { |
|
||||
func onChangeBadge(count: Int) { |
|
||||
messageCount = count |
|
||||
} |
|
||||
|
|
||||
func onReceivePush(event: PushEvent) { |
|
||||
//configure your view with push event data |
|
||||
//and display |
|
||||
print("event: \(event)") |
|
||||
} |
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue