Add sections for history list
This commit is contained in:
parent
efafeb6cb0
commit
47801fa56d
@ -40,6 +40,7 @@
|
||||
7A530B87240180CC00CBFE6E /* Reactive+RxRealmDataSources.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A530B83240180CC00CBFE6E /* Reactive+RxRealmDataSources.swift */; };
|
||||
7A530B88240180CC00CBFE6E /* RxTableViewRealmDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A530B84240180CC00CBFE6E /* RxTableViewRealmDataSource.swift */; };
|
||||
7A530B8B240181F500CBFE6E /* RxRealm in Frameworks */ = {isa = PBXBuildFile; productRef = 7A530B8A240181F500CBFE6E /* RxRealm */; };
|
||||
7A6DD903242BF4A5009DE740 /* PlateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A6DD902242BF4A5009DE740 /* PlateView.swift */; };
|
||||
7A7547DD2403180A004E8406 /* SectionHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A7547DB2403180A004E8406 /* SectionHeader.swift */; };
|
||||
7A7547DE2403180A004E8406 /* SectionHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7A7547DC2403180A004E8406 /* SectionHeader.xib */; };
|
||||
7A7547E024032CB6004E8406 /* VehiclePhotoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A7547DF24032CB6004E8406 /* VehiclePhotoCell.swift */; };
|
||||
@ -75,6 +76,7 @@
|
||||
7A530B82240180CC00CBFE6E /* RealmBindObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealmBindObserver.swift; sourceTree = "<group>"; };
|
||||
7A530B83240180CC00CBFE6E /* Reactive+RxRealmDataSources.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Reactive+RxRealmDataSources.swift"; sourceTree = "<group>"; };
|
||||
7A530B84240180CC00CBFE6E /* RxTableViewRealmDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxTableViewRealmDataSource.swift; sourceTree = "<group>"; };
|
||||
7A6DD902242BF4A5009DE740 /* PlateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlateView.swift; sourceTree = "<group>"; };
|
||||
7A7547DB2403180A004E8406 /* SectionHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionHeader.swift; sourceTree = "<group>"; };
|
||||
7A7547DC2403180A004E8406 /* SectionHeader.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SectionHeader.xib; sourceTree = "<group>"; };
|
||||
7A7547DF24032CB6004E8406 /* VehiclePhotoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VehiclePhotoCell.swift; sourceTree = "<group>"; };
|
||||
@ -131,6 +133,7 @@
|
||||
7A1146FF23FDE7E500B424AF /* AutoCat */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7A6DD901242BF48D009DE740 /* Views */,
|
||||
7A530B7C24017FBE00CBFE6E /* Cells */,
|
||||
7A11474523FF2A9000B424AF /* Models */,
|
||||
7A11474223FF06B600B424AF /* Utils */,
|
||||
@ -219,6 +222,14 @@
|
||||
path = Cells;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7A6DD901242BF48D009DE740 /* Views */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7A6DD902242BF4A5009DE740 /* PlateView.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
@ -355,6 +366,7 @@
|
||||
7A530B88240180CC00CBFE6E /* RxTableViewRealmDataSource.swift in Sources */,
|
||||
7A11471623FDEB2A00B424AF /* MainSplitController.swift in Sources */,
|
||||
7AF58D3124029E1000CE01A0 /* VehicleHeaderCell.swift in Sources */,
|
||||
7A6DD903242BF4A5009DE740 /* PlateView.swift in Sources */,
|
||||
7A530B85240180CC00CBFE6E /* RxCollectionViewRealmDataSource.swift in Sources */,
|
||||
7A11470323FDE7E500B424AF /* SceneDelegate.swift in Sources */,
|
||||
7A530B7E24017FEE00CBFE6E /* VehicleCell.swift in Sources */,
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="pme-aR-UNJ">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="pme-aR-UNJ">
|
||||
<device id="retina4_7" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16086"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="collection view cell content view" minToolsVersion="11.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
@ -239,15 +239,15 @@
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="Peq-Zq-kNT">
|
||||
<rect key="frame" x="62.5" y="68" width="250" height="104"/>
|
||||
<rect key="frame" x="62.5" y="68" width="250" height="105.5"/>
|
||||
<subviews>
|
||||
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="A001AA 777" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="8FU-Gy-4MU">
|
||||
<rect key="frame" x="0.0" y="0.0" width="250" height="49"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="250" height="50.5"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle0"/>
|
||||
<textInputTraits key="textInputTraits" returnKeyType="done"/>
|
||||
</textField>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ync-fd-xQI">
|
||||
<rect key="frame" x="0.0" y="65" width="250" height="39"/>
|
||||
<rect key="frame" x="0.0" y="66.5" width="250" height="39"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle2"/>
|
||||
<state key="normal" title="Check"/>
|
||||
<connections>
|
||||
@ -260,31 +260,32 @@
|
||||
</constraints>
|
||||
</stackView>
|
||||
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="JKr-UE-x8f">
|
||||
<rect key="frame" x="0.0" y="196" width="375" height="422"/>
|
||||
<rect key="frame" x="0.0" y="197.5" width="375" height="420.5"/>
|
||||
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
|
||||
<prototypes>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="VehicleCell" id="3ON-lr-UlV" customClass="VehicleCell" customModule="AutoCat" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="28" width="375" height="70.5"/>
|
||||
<rect key="frame" x="0.0" y="28" width="375" height="95"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="3ON-lr-UlV" id="IGw-UK-ebp">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="70.5"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="95"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="prz-7c-HiS">
|
||||
<rect key="frame" x="8" y="8" width="359" height="54.5"/>
|
||||
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="prz-7c-HiS">
|
||||
<rect key="frame" x="8" y="8" width="359" height="79"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Kia (JF) Optima" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h3N-1o-J20">
|
||||
<rect key="frame" x="0.0" y="0.0" width="359" height="20.5"/>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Kia (JF) Optima" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h3N-1o-J20">
|
||||
<rect key="frame" x="0.0" y="0.0" width="359" height="21"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="A001AA 777" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tnO-FL-oTE">
|
||||
<rect key="frame" x="0.0" y="20.5" width="359" height="34"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle1"/>
|
||||
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="VHX-o0-3BP" customClass="PlateView" customModule="AutoCat" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="29" width="359" height="50"/>
|
||||
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="50" id="vzo-oF-mWb"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</subviews>
|
||||
</stackView>
|
||||
</subviews>
|
||||
@ -298,7 +299,7 @@
|
||||
<inset key="separatorInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
|
||||
<connections>
|
||||
<outlet property="name" destination="h3N-1o-J20" id="jcM-B4-bEJ"/>
|
||||
<outlet property="number" destination="tnO-FL-oTE" id="klG-fF-iiQ"/>
|
||||
<outlet property="plate" destination="VHX-o0-3BP" id="D8N-L7-O8b"/>
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
</prototypes>
|
||||
@ -451,9 +452,9 @@
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
<image name="eye" catalog="system" width="64" height="40"/>
|
||||
<image name="eye.fill" catalog="system" width="64" height="38"/>
|
||||
<image name="gear" catalog="system" width="64" height="58"/>
|
||||
<image name="magnifyingglass" catalog="system" width="64" height="56"/>
|
||||
<image name="eye" catalog="system" width="128" height="81"/>
|
||||
<image name="eye.fill" catalog="system" width="128" height="78"/>
|
||||
<image name="gear" catalog="system" width="128" height="119"/>
|
||||
<image name="magnifyingglass" catalog="system" width="128" height="115"/>
|
||||
</resources>
|
||||
</document>
|
||||
|
||||
@ -3,16 +3,16 @@ import UIKit
|
||||
class VehicleCell: UITableViewCell {
|
||||
|
||||
@IBOutlet weak var name: UILabel!
|
||||
@IBOutlet weak var number: UILabel!
|
||||
@IBOutlet weak var plate: PlateView!
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
// Initialization code
|
||||
|
||||
}
|
||||
|
||||
func configure(with vehicle: Vehicle) {
|
||||
self.name.text = vehicle.brand?.name?.original
|
||||
self.number.text = vehicle.number
|
||||
self.plate.number = vehicle.number
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -51,12 +51,26 @@ class CheckController: UIViewController, MaskedTextFieldDelegateListener {
|
||||
.subscribe(onNext: self.updateDetailController(with:))
|
||||
.disposed(by: self.bag)
|
||||
|
||||
let now = Date()
|
||||
let monthStart = now.dateAtStartOf(.month)
|
||||
let weekStart = now.dateAtStartOf(.weekOfMonth)
|
||||
|
||||
print("==================================")
|
||||
print("now: \(now)")
|
||||
print("week start: \(weekStart)")
|
||||
print("month start: \(monthStart)")
|
||||
print("==================================")
|
||||
|
||||
Observable.collection(from: realm.objects(Vehicle.self).sorted(byKeyPath: "addedDate", ascending: false)).map { (vehicles: Results<Vehicle>) -> [DateSection<Vehicle>] in
|
||||
var sections: [TimeInterval: [Vehicle]] = [:]
|
||||
for vehicle in vehicles {
|
||||
let date = Date(timeIntervalSince1970: vehicle.addedDate)
|
||||
let key = date.dateAtStartOf(.weekday).timeIntervalSince1970
|
||||
print("==== Key: \(key)")
|
||||
let date = Date(timeIntervalSince1970: vehicle.addedDate/1000)
|
||||
|
||||
var key = date.dateAtStartOf(.day).timeIntervalSince1970
|
||||
if date.isBeforeDate(monthStart, orEqual: false, granularity: .day) {
|
||||
key = date.dateAtStartOf(.month).timeIntervalSince1970
|
||||
}
|
||||
|
||||
if sections[key] == nil {
|
||||
sections[key] = [vehicle]
|
||||
} else {
|
||||
@ -64,21 +78,12 @@ class CheckController: UIViewController, MaskedTextFieldDelegateListener {
|
||||
}
|
||||
}
|
||||
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .medium
|
||||
formatter.timeStyle = .medium
|
||||
var sectionsArray: [DateSection<Vehicle>] = []
|
||||
for (timestamp, vehicles) in sections {
|
||||
let dateStr = formatter.string(from: Date(timeIntervalSince1970: timestamp/1000))
|
||||
sectionsArray.append(DateSection<Vehicle>(header: dateStr, items: vehicles))
|
||||
sectionsArray.append(DateSection<Vehicle>(timestamp: timestamp, items: vehicles))
|
||||
}
|
||||
|
||||
print("==========================")
|
||||
for s in sectionsArray {
|
||||
print(s.header)
|
||||
}
|
||||
|
||||
return sectionsArray
|
||||
return sectionsArray.sorted { $0.timestamp > $1.timestamp }
|
||||
}
|
||||
.bind(to: self.history.rx.items(dataSource: ds))
|
||||
.disposed(by: self.bag)
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import Foundation
|
||||
import RxDataSources
|
||||
import SwiftDate
|
||||
|
||||
struct DateSection<T>: AnimatableSectionModelType where T: IdentifiableType, T: Equatable {
|
||||
|
||||
var timestamp: Double = 0
|
||||
var header: String
|
||||
var items: [T]
|
||||
|
||||
@ -15,8 +17,35 @@ struct DateSection<T>: AnimatableSectionModelType where T: IdentifiableType, T:
|
||||
self.items = items
|
||||
}
|
||||
|
||||
init(header: String, items: [T]) {
|
||||
self.header = header
|
||||
init(timestamp: Double, items: [T]) {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .medium
|
||||
formatter.timeStyle = .medium
|
||||
|
||||
let now = Date()
|
||||
let monthStart = now.dateAtStartOf(.month)
|
||||
let weekStart = now.dateAtStartOf(.weekOfMonth)
|
||||
|
||||
let date = Date(timeIntervalSince1970: timestamp)
|
||||
print("Date: \(date)")
|
||||
if date.isToday {
|
||||
self.header = "Today"
|
||||
}
|
||||
else if date.isYesterday {
|
||||
self.header = "Yesterday"
|
||||
} else if date.isAfterDate(weekStart, granularity: .day) {
|
||||
formatter.dateFormat = "EEEE"
|
||||
self.header = formatter.string(from: date)
|
||||
} else if date.isAfterDate(monthStart, orEqual: false, granularity: .day) {
|
||||
formatter.dateStyle = .medium
|
||||
formatter.timeStyle = .none
|
||||
self.header = formatter.string(from: date)
|
||||
} else {
|
||||
formatter.dateFormat = "MMMM yyyy"
|
||||
self.header = formatter.string(from: date)
|
||||
}
|
||||
|
||||
self.timestamp = timestamp
|
||||
self.items = items
|
||||
}
|
||||
}
|
||||
|
||||
18
AutoCat/Views/PlateView.swift
Normal file
18
AutoCat/Views/PlateView.swift
Normal file
@ -0,0 +1,18 @@
|
||||
import UIKit
|
||||
|
||||
class PlateView: UIView {
|
||||
private var bgLayer = CAShapeLayer()
|
||||
private var mainBgLayer = CAShapeLayer()
|
||||
private var regionBgLayer = CAShapeLayer()
|
||||
|
||||
var number: String {
|
||||
didSet {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
self.number = ""
|
||||
super.init(coder: coder)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user