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.
194 lines
6.1 KiB
194 lines
6.1 KiB
//
|
|
// AllRecipientsViewController.swift
|
|
// GME Remit
|
|
//
|
|
// Created by IME iMac on 5/10/23.
|
|
//Copyright © 2023 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class AllRecipientsViewController: UIViewController {
|
|
|
|
// MARK: Properties
|
|
var presenter: AllRecipientsModuleInterface?
|
|
var beneficaiaryModel: [Recipient]?
|
|
var searchBarValue: String?
|
|
var filteredData: [Recipient]?
|
|
|
|
// MARK: IBOutlets
|
|
|
|
@IBOutlet weak var tableView: UITableView!
|
|
@IBOutlet weak var searchBar: UISearchBar!
|
|
|
|
// MARK: VC's Life cycle
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
self.setup()
|
|
}
|
|
|
|
// MARK: IBActions
|
|
|
|
// MARK: Other Functions
|
|
|
|
private func setup() {
|
|
self.tableView.delegate = self
|
|
self.tableView.dataSource = self
|
|
self.searchBar.delegate = self
|
|
self.title = "all_beneficiaries".localized()
|
|
self.searchBar.placeholder = "search_beneficiary_text".localized()
|
|
self.presenter?.makeApiRequest()
|
|
|
|
}
|
|
|
|
|
|
}
|
|
/*
|
|
extension AllRecipientsViewController {
|
|
private func addDimView() {
|
|
self.bgView.tag = 999
|
|
self.tabBarController?.view.addSubview(self.bgView)
|
|
self.bgView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
|
|
self.bgView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
|
|
self.bgView.topAnchor.constraint(equalTo: self.messageView.bottomAnchor).isActive = true
|
|
self.bgView.heightAnchor.constraint(equalToConstant: UIScreen.main.bounds.size.height).isActive = true
|
|
if #available(iOS 10.0, *) {
|
|
bgView.refreshControl = getRefreshControl()
|
|
} else {
|
|
bgView.addSubview(getRefreshControl())
|
|
}
|
|
}
|
|
|
|
private func removeDimView() {
|
|
if let views = self.tabBarController?.view.subviews{
|
|
for each in views {
|
|
if each.tag == 999 {
|
|
each.removeFromSuperview()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func getRefreshControl() -> UIRefreshControl{
|
|
let colorOption = [NSAttributedString.Key.foregroundColor : UIColor.themeWhite]
|
|
|
|
let title = NSAttributedString(string: "pull to refresh", attributes: colorOption)
|
|
let refreshControl = UIRefreshControl()
|
|
refreshControl.attributedTitle = title
|
|
refreshControl.backgroundColor = .themeBlue
|
|
refreshControl.tintColor = .themeWhite
|
|
refreshControl.addTarget(self, action: #selector(self.refresh), for: .valueChanged)
|
|
return refreshControl
|
|
}
|
|
|
|
@objc private func refresh() {
|
|
presenter?.refreshData()
|
|
}
|
|
|
|
private func addRefreshControlTableView() {
|
|
let colorOption = [NSAttributedString.Key.foregroundColor : UIColor.themeWhite]
|
|
|
|
let title = NSAttributedString(string: "pull to refresh", attributes: colorOption)
|
|
let refreshControl = UIRefreshControl()
|
|
refreshControl.attributedTitle = title
|
|
refreshControl.backgroundColor = .themeBlue
|
|
refreshControl.tintColor = .themeWhite
|
|
refreshControl.addTarget(self, action: #selector(self.refresh), for: .valueChanged)
|
|
self.refreshControl = refreshControl
|
|
if #available(iOS 10.0, *) {
|
|
scrollView.refreshControl = self.refreshControl
|
|
} else {
|
|
if let control = self.refreshControl {
|
|
scrollView.addSubview(control)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
extension AllRecipientsViewController: UITableViewDelegate, UITableViewDataSource {
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
return self.filteredData?.count ?? 0
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
if let cell = tableView.dequeueReusableCell(withIdentifier: "seeAll", for: indexPath) as? AllRecipientTableViewCell {
|
|
cell.setUp(model: self.filteredData?[indexPath.row])
|
|
cell.selectionStyle = .none
|
|
return cell
|
|
}
|
|
return UITableViewCell()
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
if let navVC = self.navigationController {
|
|
let wireframe = BeneficiaryDetailWireframe()
|
|
wireframe.recipient = self.filteredData?[indexPath.row]
|
|
navVC.push(wireframe.getMainView(), animated: true)
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: AllRecipientsViewInterface
|
|
extension AllRecipientsViewController: AllRecipientsViewInterface {
|
|
func setRecipients(using model: FetchBeneficiariesModel?) {
|
|
self.beneficaiaryModel = model?.beneficiaries
|
|
filteredData = self.beneficaiaryModel
|
|
self.tableView.reloadData()
|
|
}
|
|
|
|
func showLoading() {
|
|
self.showProgressHud()
|
|
}
|
|
|
|
func hideLoading() {
|
|
self.hideProgressHud()
|
|
}
|
|
|
|
func show(error: String) {
|
|
self.alert(type: .error, message: error)
|
|
}
|
|
|
|
func show(message: String) {
|
|
self.alertWithOk(
|
|
type: .success,
|
|
message: message,
|
|
title: "Success",
|
|
okTitle: "Ok"
|
|
) {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
extension AllRecipientsViewController: UISearchBarDelegate {
|
|
|
|
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
|
|
searchBar.text = nil
|
|
searchBar.resignFirstResponder()
|
|
tableView.resignFirstResponder()
|
|
self.tableView.reloadData()
|
|
}
|
|
|
|
func searchBarShouldEndEditing(_ searchBar: UISearchBar) -> Bool {
|
|
return true
|
|
}
|
|
|
|
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
|
|
if searchText != "" {
|
|
self.filteredData = self.beneficaiaryModel?.filter({
|
|
$0.fullName?.lowercased().contains(searchText.lowercased()) ?? false
|
|
})
|
|
self.tableView.reloadData()
|
|
} else {
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
searchBar.resignFirstResponder()
|
|
}
|
|
self.filteredData = self.beneficaiaryModel
|
|
self.tableView.reloadData()
|
|
}
|
|
}
|
|
|
|
}
|