|
@ -26,9 +26,9 @@ class RecipientsViewController: UIViewController { |
|
|
private lazy var deleteTrigger = PublishSubject<Recipient>() |
|
|
private lazy var deleteTrigger = PublishSubject<Recipient>() |
|
|
private let impact = UISelectionFeedbackGenerator() |
|
|
private let impact = UISelectionFeedbackGenerator() |
|
|
private var model: [Recipient]? |
|
|
private var model: [Recipient]? |
|
|
var refreshControl: UIRefreshControl? |
|
|
|
|
|
var from: String? |
|
|
|
|
|
var to: String? |
|
|
|
|
|
|
|
|
private lazy var refreshControl = UIRefreshControl() |
|
|
|
|
|
var from: Date? |
|
|
|
|
|
var to: Date? |
|
|
|
|
|
|
|
|
// MARK: Computed Properties |
|
|
// MARK: Computed Properties |
|
|
|
|
|
|
|
@ -61,9 +61,9 @@ class RecipientsViewController: UIViewController { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@IBAction func cancelDate(_ sender: UIButton) { |
|
|
@IBAction func cancelDate(_ sender: UIButton) { |
|
|
from = Calendar.current.date(byAdding: .weekOfMonth, value: -1, to: Date())!.asString(style: .medium) |
|
|
|
|
|
to = Date().asString(style: .medium) |
|
|
|
|
|
self.viewModel.fetchTransaction(fromDate: from ?? "", toDate: to ?? "", pageCount: "", countryCode: "") |
|
|
|
|
|
|
|
|
self.from = Calendar.current.date(byAdding: .weekOfMonth, value: -1, to: Date()) |
|
|
|
|
|
self.to = Date() |
|
|
|
|
|
self.viewModel.fetchTransaction(fromDate: self.from?.converToString(dateFormat: "yyyy-MM-dd") ?? "", toDate: self.to?.converToString(dateFormat: "yyyy-MM-dd") ?? "", pageCount: "", countryCode: "") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@IBAction func dateTapped(_ sender: UIButton) { |
|
|
@IBAction func dateTapped(_ sender: UIButton) { |
|
@ -89,16 +89,26 @@ class RecipientsViewController: UIViewController { |
|
|
self.navigationItem.leftBarButtonItem = nil |
|
|
self.navigationItem.leftBarButtonItem = nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
refreshControl = UIRefreshControl() |
|
|
|
|
|
refreshControl?.addTarget(self, action: #selector(refresh(_:)), for: .valueChanged) |
|
|
|
|
|
scrollView.refreshControl = refreshControl |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func addRefreshControl() { |
|
|
|
|
|
let colorOption = [NSAttributedString.Key.foregroundColor : UIColor.themeWhite] |
|
|
|
|
|
|
|
|
|
|
|
let title = NSAttributedString(string: "pull to refresh", attributes: colorOption) |
|
|
|
|
|
|
|
|
|
|
|
refreshControl.attributedTitle = title |
|
|
|
|
|
refreshControl.backgroundColor = .themeBlue |
|
|
|
|
|
refreshControl.tintColor = .themeWhite |
|
|
|
|
|
refreshControl.addTarget(self, action: #selector(refresh), for: .valueChanged) |
|
|
|
|
|
|
|
|
|
|
|
self.scrollView.refreshControl = refreshControl |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@objc func refresh(_ sender: AnyObject){ |
|
|
@objc func refresh(_ sender: AnyObject){ |
|
|
refreshControl?.endRefreshing() |
|
|
|
|
|
self.viewModel.presenter?.fetchRecipients(isRefresh: true) |
|
|
|
|
|
|
|
|
refreshControl.endRefreshing() |
|
|
|
|
|
self.viewModel.fetchTransaction(fromDate: self.from?.converToString(dateFormat: "yyyy-MM-dd") ?? "", toDate: self.to?.converToString(dateFormat: "yyyy-MM-dd") ?? "", pageCount: "", countryCode: "") |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
override func viewWillLayoutSubviews() { |
|
|
override func viewWillLayoutSubviews() { |
|
|
super.viewWillLayoutSubviews() |
|
|
super.viewWillLayoutSubviews() |
|
@ -114,6 +124,15 @@ class RecipientsViewController: UIViewController { |
|
|
view.endEditing(true) |
|
|
view.endEditing(true) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func convertToDate(date: String) -> Date? { |
|
|
|
|
|
let dateFormatter = DateFormatter() |
|
|
|
|
|
dateFormatter.dateFormat = "yyyy-MM-dd" |
|
|
|
|
|
dateFormatter.timeZone = TimeZone.current |
|
|
|
|
|
dateFormatter.locale = Locale.current |
|
|
|
|
|
return dateFormatter.date(from: date) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private func getHUmanReadableDate(date: String?) -> String? { |
|
|
private func getHUmanReadableDate(date: String?) -> String? { |
|
|
if let date = DateFormatter.toDate(dateString: date ?? "", format: AppConstants.dateFormat) { |
|
|
if let date = DateFormatter.toDate(dateString: date ?? "", format: AppConstants.dateFormat) { |
|
|
let dateString = DateFormatter.toString(date: date, format: AppConstants.humanReadableDateFormat) |
|
|
let dateString = DateFormatter.toString(date: date, format: AppConstants.humanReadableDateFormat) |
|
@ -123,8 +142,8 @@ class RecipientsViewController: UIViewController { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private func selectedDate(from: String?, to: String?) { |
|
|
private func selectedDate(from: String?, to: String?) { |
|
|
self.from = from |
|
|
|
|
|
self.to = to |
|
|
|
|
|
|
|
|
self.from = convertToDate(date: from ?? "") |
|
|
|
|
|
self.to = convertToDate(date: to ?? "") |
|
|
guard let fromDate = from, let toDate = to else {return} |
|
|
guard let fromDate = from, let toDate = to else {return} |
|
|
self.viewModel.fetchTransaction(fromDate: fromDate, toDate: toDate, pageCount: "", countryCode: "") |
|
|
self.viewModel.fetchTransaction(fromDate: fromDate, toDate: toDate, pageCount: "", countryCode: "") |
|
|
} |
|
|
} |
|
@ -184,6 +203,7 @@ extension RecipientsViewController { |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
setUIBinding() |
|
|
setUIBinding() |
|
|
|
|
|
addRefreshControl() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private func setUIBinding() { |
|
|
private func setUIBinding() { |
|
@ -243,7 +263,7 @@ extension RecipientsViewController { |
|
|
onNext: {[weak self] _ in guard let `self` = self else { return } |
|
|
onNext: {[weak self] _ in guard let `self` = self else { return } |
|
|
DispatchQueue.main.async { |
|
|
DispatchQueue.main.async { |
|
|
self.viewWillLayoutSubviews() |
|
|
self.viewWillLayoutSubviews() |
|
|
guard let fromDate = self.from, let toDate = self.to else { |
|
|
|
|
|
|
|
|
guard let fromDate = self.from?.asString(style: .medium), let toDate = self.to?.asString(style: .medium) else { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
self.fromDateLabel.text = fromDate |
|
|
self.fromDateLabel.text = fromDate |
|
|