Browse Source

shown date label in human readable format

pull/1/head
gme_2 6 years ago
parent
commit
57a0a9651f
  1. 1
      GMERemittance/Module/TransactionHistory/Application Logic/Interactor/TransactionHistoryInteractor.swift
  2. 3
      GMERemittance/Module/TransactionHistory/User Interface/Presenter/TransactionHistoryPresenter.swift
  3. 14
      GMERemittance/Module/TransactionHistory/User Interface/View/DatePickerViewController.swift
  4. 40
      GMERemittance/Module/TransactionHistory/User Interface/View/TransactionHistory.storyboard
  5. 11
      GMERemittance/Module/TransactionHistory/User Interface/View/TransactionHistoryDatePicker.storyboard
  6. 49
      GMERemittance/Module/TransactionHistory/User Interface/View/TransactionHistoryViewController.swift
  7. 1
      GMERemittance/Utility/AppConstants.swift

1
GMERemittance/Module/TransactionHistory/Application Logic/Interactor/TransactionHistoryInteractor.swift

@ -42,7 +42,6 @@ extension TransactionHistoryInteractor: TransactionHistoryInteractorInput {
}
let parameters = (param.isEmpty ?? true) ? nil : param
self.service.fetchTransactionHistories(user: userName, param: parameters, success: { (model) in
self.output?.show(models: model)
}) { (error) in

3
GMERemittance/Module/TransactionHistory/User Interface/Presenter/TransactionHistoryPresenter.swift

@ -30,11 +30,11 @@ class TransactionHistoryPresenter {
extension TransactionHistoryPresenter: TransactionHistoryModuleInterface {
func fetchTransactionHistories(fromDate: String?, toDate: String?) {
self.view?.showLoading()
interactor?.fetchTransactionHistories(fromDate: fromDate, toDate: toDate)
}
func viewIsReady() {
self.view?.showLoading()
self.fetchTransactionHistories(fromDate: nil, toDate: nil)
}
@ -80,7 +80,6 @@ extension TransactionHistoryPresenter: TransactionHistoryInteractorOutput {
func show(models: [TransactionModel]) {
self.view?.hideLoading()
self.view?.show(models: models)
self.models = models
self.filteredModels = self.models
}

14
GMERemittance/Module/TransactionHistory/User Interface/View/DatePickerViewController.swift

@ -17,6 +17,14 @@ class DatePickerViewController: UIViewController {
var fromDate: String?
var toDate: String?
var _fromDate: Date? {
didSet {
self.toDatePicker.minimumDate = _fromDate
self.toDatePicker.maximumDate = Date()
}
}
var _toDate: Date?
let fromDatePicker = UIDatePicker()
let toDatePicker = UIDatePicker()
@ -24,6 +32,8 @@ class DatePickerViewController: UIViewController {
super.viewDidLoad()
self.setupToDatePicker()
self.setupFromDatePicker()
self.fromDatePicker.date = Date()
self.handleFromDatePicker(sender: fromDatePicker)
// Do any additional setup after loading the view.
}
@ -52,6 +62,7 @@ class DatePickerViewController: UIViewController {
}
@objc private func handleFromDatePicker(sender: UIDatePicker) {
self._fromDate = sender.date
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = AppConstants.dateFormat
let date = dateFormatter.string(from: sender.date)
@ -62,11 +73,12 @@ class DatePickerViewController: UIViewController {
private func setupToDatePicker() {
self.toDatePicker.datePickerMode = .date
self.toTextfield.inputView = toDatePicker
toDatePicker.maximumDate = Date()
toDatePicker.maximumDate = self._fromDate
self.toDatePicker.addTarget(self, action: #selector(handleToDatePicker(sender:)), for: .valueChanged)
}
@objc private func handleToDatePicker(sender: UIDatePicker) {
self._toDate = sender.date
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = AppConstants.dateFormat
let date = dateFormatter.string(from: sender.date)

40
GMERemittance/Module/TransactionHistory/User Interface/View/TransactionHistory.storyboard

@ -79,7 +79,7 @@
</connections>
</segmentedControl>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="V5c-xg-UKz">
<rect key="frame" x="10" y="53" width="355" height="546"/>
<rect key="frame" x="10" y="83" width="355" height="516"/>
<color key="backgroundColor" red="0.90588235289999997" green="0.92941176469999998" blue="0.94901960780000005" alpha="1" colorSpace="calibratedRGB"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="TransactionHistoryTableViewCell" rowHeight="86" id="Atv-Nn-ubf" customClass="TransactionHistoryTableViewCell" customModule="GMERemittance" customModuleProvider="target">
@ -173,14 +173,47 @@
</tableViewCell>
</prototypes>
</tableView>
<stackView opaque="NO" contentMode="scaleToFill" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="Rah-XK-yIo">
<rect key="frame" x="16" y="43" width="343" height="35"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="W5a-gp-mdv">
<rect key="frame" x="0.0" y="0.0" width="164" height="35"/>
<fontDescription key="fontDescription" name="SanFranciscoDisplay-Medium" family="San Francisco Display" pointSize="16"/>
<color key="textColor" red="0.2901960784" green="0.2901960784" blue="0.2901960784" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="-" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eFC-pC-p6h">
<rect key="frame" x="169" y="0.0" width="5.5" height="35"/>
<constraints>
<constraint firstAttribute="width" constant="5.5" id="AYn-tF-Ijc"/>
</constraints>
<fontDescription key="fontDescription" name="SanFranciscoDisplay-Medium" family="San Francisco Display" pointSize="14"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AHn-8d-aGF">
<rect key="frame" x="179.5" y="0.0" width="163.5" height="35"/>
<fontDescription key="fontDescription" name="SanFranciscoDisplay-Medium" family="San Francisco Display" pointSize="16"/>
<color key="textColor" red="0.2901960784" green="0.2901960784" blue="0.2901960784" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="35" id="hJN-CB-9IL"/>
<constraint firstItem="W5a-gp-mdv" firstAttribute="width" secondItem="AHn-8d-aGF" secondAttribute="width" id="oUq-E2-hOL"/>
</constraints>
</stackView>
</subviews>
<color key="backgroundColor" red="0.90588235289999997" green="0.92941176469999998" blue="0.94901960780000005" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="V5c-xg-UKz" firstAttribute="leading" secondItem="Lab-Ej-i1M" secondAttribute="leading" constant="10" id="19B-2c-AKi"/>
<constraint firstItem="V5c-xg-UKz" firstAttribute="top" secondItem="Nqp-Xe-KAa" secondAttribute="bottom" constant="10" id="2zl-gn-cRq"/>
<constraint firstItem="Rah-XK-yIo" firstAttribute="top" secondItem="Nqp-Xe-KAa" secondAttribute="bottom" id="Fi6-rY-lgc"/>
<constraint firstItem="Rah-XK-yIo" firstAttribute="trailing" secondItem="Nqp-Xe-KAa" secondAttribute="trailing" id="L6M-Gp-g7g"/>
<constraint firstAttribute="bottom" secondItem="V5c-xg-UKz" secondAttribute="bottom" id="bgE-O3-gDE"/>
<constraint firstAttribute="trailing" secondItem="Nqp-Xe-KAa" secondAttribute="trailing" constant="16" id="dJJ-PA-IBF"/>
<constraint firstItem="Rah-XK-yIo" firstAttribute="leading" secondItem="Nqp-Xe-KAa" secondAttribute="leading" id="meW-v8-DAo"/>
<constraint firstItem="Nqp-Xe-KAa" firstAttribute="top" secondItem="Lab-Ej-i1M" secondAttribute="top" constant="14" id="pRo-d7-cki"/>
<constraint firstItem="V5c-xg-UKz" firstAttribute="top" secondItem="Rah-XK-yIo" secondAttribute="bottom" constant="5" id="q7k-Xg-mTd"/>
<constraint firstAttribute="trailing" secondItem="V5c-xg-UKz" secondAttribute="trailing" constant="10" id="rnJ-w4-OL3"/>
<constraint firstItem="Nqp-Xe-KAa" firstAttribute="leading" secondItem="Lab-Ej-i1M" secondAttribute="leading" constant="16" id="voS-P3-7PY"/>
</constraints>
@ -208,9 +241,12 @@
<viewLayoutGuide key="safeArea" id="p2D-KN-s9L"/>
</view>
<connections>
<outlet property="dateRangeLabelHeightConstraint" destination="hJN-CB-9IL" id="whx-Hw-6dG"/>
<outlet property="fromDateLabel" destination="W5a-gp-mdv" id="3j3-id-7Zc"/>
<outlet property="searchTextField" destination="Y2X-bs-0NT" id="Q9B-ie-seX"/>
<outlet property="segmentedControl" destination="Nqp-Xe-KAa" id="xLd-qf-mMh"/>
<outlet property="tableView" destination="V5c-xg-UKz" id="FbE-4L-pJk"/>
<outlet property="toDateLabel" destination="AHn-8d-aGF" id="J3c-pf-B14"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="pCp-ps-wXp" userLabel="First Responder" sceneMemberID="firstResponder"/>

11
GMERemittance/Module/TransactionHistory/User Interface/View/TransactionHistoryDatePicker.storyboard

@ -10,6 +10,9 @@
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
<array key="SanFranciscoDisplay-Regular.otf">
<string>SanFranciscoDisplay-Regular</string>
</array>
<array key="SanFranciscoText-Regular.otf">
<string>SanFranciscoText-Regular</string>
</array>
@ -37,8 +40,8 @@
<constraints>
<constraint firstAttribute="height" constant="43" id="Dk4-ZC-Ey4"/>
</constraints>
<color key="textColor" white="0.75" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" red="0.29019607843137252" green="0.29019607843137252" blue="0.29019607843137252" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" name="SanFranciscoDisplay-Regular" family="San Francisco Display" pointSize="17"/>
<textInputTraits key="textInputTraits"/>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="To" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8R4-ao-hRh">
@ -52,8 +55,8 @@
<constraints>
<constraint firstAttribute="height" constant="43" id="3EU-b3-51N"/>
</constraints>
<color key="textColor" white="0.75" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" red="0.29019607843137252" green="0.29019607843137252" blue="0.29019607843137252" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" name="SanFranciscoDisplay-Regular" family="San Francisco Display" pointSize="17"/>
<textInputTraits key="textInputTraits"/>
</textField>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="nPo-RO-gkQ">

49
GMERemittance/Module/TransactionHistory/User Interface/View/TransactionHistoryViewController.swift

@ -21,19 +21,38 @@ class TransactionHistoryViewController: UIViewController {
case sent
case delivered
}
struct Constant {
static let heightOfDateRangeLabel: CGFloat = 35
}
@IBOutlet weak var fromDateLabel: UILabel!
@IBOutlet weak var toDateLabel: UILabel!
// MARK: IBOutlets
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var segmentedControl: UISegmentedControl!
@IBOutlet weak var dateRangeLabelHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var searchTextField: UITextField!
// MARK: Properties
var from: String?
var to: String?
var transactions: [TransactionModel] = [] {
didSet {
self.tableView.reloadData()
guard let fromDate = from, let toDate = to else {
self.dateRangeLabelHeightConstraint.constant = 0
return
}
self.fromDateLabel.text = self.getHUmanReadableDate(date: fromDate)
self.toDateLabel.text = self.getHUmanReadableDate(date: toDate)
UIView.animate(withDuration: 0.33, animations: {
self.dateRangeLabelHeightConstraint.constant = Constant.heightOfDateRangeLabel
})
}
}
@ -92,16 +111,26 @@ class TransactionHistoryViewController: UIViewController {
// MARK: Other Functions
private func selectedDate(from: String?, to: String?) {
self.from = from
self.to = to
guard let fromDate = from, let toDate = to else {return}
// self.presenter.
self.presenter?.fetchTransactionHistories(fromDate: fromDate, toDate: toDate)
}
private func getHUmanReadableDate(date: String?) -> String? {
if let date = DateFormatter.toDate(dateString: date ?? "", format: AppConstants.dateFormat) {
let dateString = DateFormatter.toString(date: date, format: AppConstants.humanReadableDateFormat)
return dateString
}
return nil
}
private func setup() {
// all setup should be done here
setupSearchTextField()
setupDelegates()
self.transactionType = .all
self.dateRangeLabelHeightConstraint.constant = 0
}
private func setupSearchTextField() {
@ -170,4 +199,20 @@ extension TransactionHistoryViewController: UITableViewDataSource {
}
}
extension DateFormatter {
static func toDate(dateString: String, format: String = AppConstants.dateFormat) -> Date? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = format
// dateFormatter.locale = Locale(identifier: "en_Us")
return dateFormatter.date(from: dateString)
}
static func toString(date: Date, format: String = AppConstants.humanReadableDateFormat) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = format
// dateFormatter.locale = Locale(identifier: "en_US")
return dateFormatter.string(from: date)
}
}

1
GMERemittance/Utility/AppConstants.swift

@ -12,6 +12,7 @@ import Foundation
class AppConstants {
static let uuid = "uuid"
static let dateFormat = "yyyy-MM-dd"
static let humanReadableDateFormat = "MMM d, yyyy"
static let errorBorderWidth: CGFloat = 0.1
}

Loading…
Cancel
Save