You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

279 lines
11 KiB

//
// SideMenuViewController.swift
// GMERemittance
//
// Created by Sujal on 2/22/18.
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import UIKit
import SDWebImage
import LGSideMenuController
import Localize_Swift
struct SideMenuNavigationNotifications {
static let aboutGme = "aboutGme"
static let support = "support"
static let setting = "setting"
static let availableBalance = "Available_Balance"
static let withdraw = "withdraw"
static let KftcAccountList = "KftcAccountList"
static let transactionHistory = "transaction_History_from_sidemenu"
}
class SideMenuViewController: UIViewController {
struct StringConstants {
let logoutTitleText = "logout_text".localized()
let logoutConfirmationText = "logout_confirmation_text".localized()
let noText = "no_text".localized()
let yesText = "yes_text".localized()
let autoDebitMenuText = "auto_debit_account_text".localized()
let aboutGmeMenuText = "about_gme_text".localized()
let settingMenuText = "settings_text".localized()
let availableBalanceTitleLabelText = "available_balance_text".localized()
let withdrawButtonText = "withdraw_text".localized()
let gmeWalletNoTitleText = "gme_wallet_no_text".localized()
}
// @IBOutlets
@IBOutlet weak var imageViewProfileSetting: UIImageView!
@IBOutlet weak var labelProfileName: UILabel!
@IBOutlet weak var labelPhone: UILabel!
@IBOutlet weak var labelEmail: UILabel!
@IBOutlet weak var roundedBgView: UIView!
@IBOutlet weak var labelBalance: UILabel!
@IBOutlet weak var labelWalletNumber: UILabel!
@IBOutlet weak var labelBank: UILabel!
@IBOutlet weak var labelUserNameInitial: UILabel!
@IBOutlet weak var settingButton: UIButton!
@IBOutlet weak var aboutGmeButton: UIButton!
@IBOutlet weak var autoDebitAccountButton: UIButton!
@IBOutlet weak var logoutButton: UIButton!
@IBOutlet weak var aboutIconImageView: UIImageView!
@IBOutlet weak var settingIconImageView: UIImageView!
@IBOutlet weak var logoutIconImageView: UIImageView!
@IBOutlet weak var withdrawButton: UIButton!
@IBOutlet weak var manageAccountStackView: UIStackView!
@IBOutlet weak var availableBalanceTitleLabel: UILabel!
@IBOutlet weak var gmeWalletNoTitleLabel: UILabel!
@IBOutlet weak var transactionHistryButton: UIButton!
// Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
setUpSettingsScreen()
setup()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.setUpSettingsScreen()
NotificationCenter.default.addObserver(self, selector: #selector(configureText), name: NSNotification.Name(LCLLanguageChangeNotification), object: nil)
}
// Other Functions
private func addShadow(view: UIView) {
view.layer.shadowColor = UIColor.darkGray.cgColor
view.layer.shadowOpacity = 0.5
view.layer.shadowRadius = 2
let offset = CGSize(width: 1, height: 1)
view.layer.shadowOffset = offset
}
private func setup() {
configureText()
let shouldShowWithdrawButton = Utility.pennyTestVerified() && Utility.isVerifiedUser()
self.withdrawButton.isHidden = !shouldShowWithdrawButton
self.manageAccountStackView.isHidden = !shouldShowWithdrawButton
// self.manageAccountStackView.isHidden = true
self.view.backgroundColor = AppConstants.themeRedColor
self.roundedBgView.layer.cornerRadius = 20
self.labelBalance.text = "0"
NotificationCenter.default.addObserver(self, selector: #selector(self.updateBalance(sender:)), name: self.getAvailableBalanceNotificationName(), object: nil)
self.addShadow(view: withdrawButton)
}
@objc private func configureText() {
autoDebitAccountButton.setTitle(StringConstants().autoDebitMenuText, for: UIControlState.normal)
aboutGmeButton.setTitle(StringConstants().aboutGmeMenuText, for: UIControlState.normal)
settingButton.setTitle(StringConstants().settingMenuText, for: UIControlState.normal)
logoutButton.setTitle(StringConstants().logoutTitleText, for: UIControlState.normal)
self.availableBalanceTitleLabel.text = StringConstants().availableBalanceTitleLabelText
self.gmeWalletNoTitleLabel.text = StringConstants().gmeWalletNoTitleText
self.withdrawButton.setTitle(StringConstants().withdrawButtonText, for: UIControlState.normal)
self.transactionHistryButton.setTitle("transaction_report_text".localized(), for: UIControlState.normal)
}
@objc private func updateBalance(sender: Notification) {
let balance = sender.userInfo?[SideMenuNavigationNotifications.availableBalance] as? String
self.labelBalance.text = balance
let shouldShowWithdrawButton = Utility.pennyTestVerified() && Utility.isVerifiedUser()
self.withdrawButton.isHidden = !shouldShowWithdrawButton
self.manageAccountStackView.isHidden = !shouldShowWithdrawButton
// self.manageAccountStackView.isHidden = true
}
private func setupBlueBackGroundTheme() {
self.roundedBgView.backgroundColor = AppConstants.themeBlueColor
[ labelPhone, labelEmail, labelBalance, labelWalletNumber, labelBank, labelUserNameInitial].forEach({
$0?.textColor = AppConstants.themWhiteColor
})
[aboutGmeButton, settingButton, logoutButton].forEach({
$0?.setTitleColor(AppConstants.themWhiteColor, for: UIControlState.normal)
})
aboutIconImageView.tintColor = AppConstants.themWhiteColor
}
@IBAction func withdraw(_ sender: UIButton) {
self.sideMenuController?.hideLeftView()
NotificationCenter.default.post(name: self.getWithdrawNotificationName(), object: nil, userInfo: nil)
}
@IBAction func openTransactionHistory(_ sender: Any) {
self.sideMenuController?.hideLeftView()
NotificationCenter.default.post(name: self.getTransactionHistoryNotificationName(), object: nil, userInfo: nil)
}
@IBAction func openKftcAccountList(_ sender: UIButton) {
self.sideMenuController?.hideLeftView()
NotificationCenter.default.post(name: self.getKftcAccountListNotificationName(), object: nil, userInfo: nil)
}
@IBAction func aboutGme(_ sender: UIButton) {
self.sideMenuController?.hideLeftView()
NotificationCenter.default.post(name: self.getAboutGmeNotificationName(), object: nil, userInfo: nil)
}
@IBAction func support(_ sender: UIButton) {
self.sideMenuController?.hideLeftView()
NotificationCenter.default.post(name: self.getSupportNotificationName(), object: nil, userInfo: nil)
}
@IBAction func setting(_ sender: UIButton) {
self.sideMenuController?.hideLeftView()
NotificationCenter.default.post(name: self.getSettingNotificationName(), object: nil, userInfo: nil)
}
@IBAction func logout(_ sender: Any) {
// let alert = UIAlertController(title: StringConstants().logoutTitleText, message: StringConstants().logoutConfirmationText, preferredStyle: .alert)
//
// let yesAction = UIAlertAction(title: StringConstants().yesText, style: .default,handler: {
// (action : UIAlertAction!) -> Void in
// MainWireframe.logout()
// })
// let noAction = UIAlertAction(title: StringConstants().noText, style: .default, handler: nil)
// noAction.setValue(UIColor.black, forKey: "titleTextColor")
// yesAction.setValue(UIColor(hex:0xEC1C24), forKey: "titleTextColor")
//
// alert.addAction(noAction)
// alert.addAction(yesAction)
// self.present(alert, animated: true, completion: nil)
alertWithOkCancel(
type: .normal,
message: StringConstants().logoutConfirmationText,
title: StringConstants().logoutTitleText,
okTitle: "Yes",
style: .alert,
cancelTitle: "No",
okAction: { MainWireframe.logout() }
)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func setUpSettingsScreen() {
let store = UserDefaults.standard
//PHONE
labelPhone.text = store.string(forKey: UserKeys.mobileNumber)
//EMAIL
labelEmail.text = store.string(forKey: UserKeys.email)
//NAME
labelProfileName.text = store.string(forKey: UserKeys.firstName)?.capitalized
//WALLET NUMBER
labelWalletNumber.text = store.string(forKey: UserKeys.walletNumber)
//BALANCE
let balance = store.string(forKey: UserKeys.availableBalance)
labelBalance.text = Utility.getCommaSeperatedString(numberString: balance ?? "")
//BANK NAME
labelBank.text = store.string(forKey: UserKeys.primaryBankName)
//IMAGE
let userDpString = store.string(forKey: UserKeys.dpUrl)
if let userDpUrl = URL(string: userDpString!) {
SDImageCache.shared().clearMemory()
SDImageCache.shared().clearDisk()
self.imageViewProfileSetting.sd_setImage(with: userDpUrl, completed: nil)
labelUserNameInitial.isHidden = true
imageViewProfileSetting.isHidden = false
imageViewProfileSetting.contentMode = .scaleAspectFill
} else {
labelUserNameInitial.layer.backgroundColor = UIColor(hex: 0x2e3192).cgColor
labelUserNameInitial.layer.cornerRadius = labelUserNameInitial.frame.height / 2
labelUserNameInitial.text = labelProfileName.text?.prefix(1).uppercased()
labelUserNameInitial.isHidden = false
imageViewProfileSetting.isHidden = true
}
imageViewProfileSetting.layer.cornerRadius = imageViewProfileSetting.frame.height / 2
}
// Notification Names
func getAboutGmeNotificationName() -> Notification.Name {
return Notification.Name.init(SideMenuNavigationNotifications.aboutGme)
}
func getSupportNotificationName() -> Notification.Name {
return Notification.Name.init(SideMenuNavigationNotifications.support)
}
func getSettingNotificationName() -> Notification.Name {
return Notification.Name.init(SideMenuNavigationNotifications.setting)
}
func getAvailableBalanceNotificationName() -> Notification.Name {
return Notification.Name.init(SideMenuNavigationNotifications.availableBalance)
}
func getWithdrawNotificationName() -> Notification.Name {
return Notification.Name.init(SideMenuNavigationNotifications.withdraw)
}
func getTransactionHistoryNotificationName() -> Notification.Name {
return Notification.Name.init(SideMenuNavigationNotifications.transactionHistory)
}
func getKftcAccountListNotificationName() -> Notification.Name {
return Notification.Name.init(SideMenuNavigationNotifications.KftcAccountList)
}
}