diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 406a87d..1c4894c 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -93,6 +93,20 @@ 7AE24C5F251F1B4E00758E39 /* Buttons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE24C5E251F1B4E00758E39 /* Buttons.swift */; }; 7AE26A3324EEF9EC00625033 /* UIViewControllerExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE26A3224EEF9EC00625033 /* UIViewControllerExt.swift */; }; 7AE26A3524F31B0700625033 /* EventsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE26A3424F31B0700625033 /* EventsController.swift */; }; + 7AE492922591FF5100322D2E /* RxSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 7A11471C23FEA18700B424AF /* RxSwift */; }; + 7AE492932591FF5100322D2E /* RxRelay in Frameworks */ = {isa = PBXBuildFile; productRef = 7A11471E23FEA18700B424AF /* RxRelay */; }; + 7AE492942591FF5100322D2E /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 7A11472023FEA18700B424AF /* RxCocoa */; }; + 7AE492952591FF5100322D2E /* RxBlocking in Frameworks */ = {isa = PBXBuildFile; productRef = 7A11472223FEA18700B424AF /* RxBlocking */; }; + 7AE492962591FF5100322D2E /* Realm in Frameworks */ = {isa = PBXBuildFile; productRef = 7A11472523FEA1F400B424AF /* Realm */; }; + 7AE492972591FF5100322D2E /* RealmSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 7A11472723FEA1F400B424AF /* RealmSwift */; }; + 7AE492982591FF5100322D2E /* RxRealm in Frameworks */ = {isa = PBXBuildFile; productRef = 7A530B8A240181F500CBFE6E /* RxRealm */; }; + 7AE492992591FF5100322D2E /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = 7AF58D332402A91C00CE01A0 /* Kingfisher */; }; + 7AE4929A2591FF5100322D2E /* SwiftDate in Frameworks */ = {isa = PBXBuildFile; productRef = 7A051610241412CA00FC55AC /* SwiftDate */; }; + 7AE4929B2591FF5100322D2E /* ExceptionCatcher in Frameworks */ = {isa = PBXBuildFile; productRef = 7A813DC02508C4D900CC93B9 /* ExceptionCatcher */; }; + 7AE4929C2591FF5100322D2E /* PKHUD in Frameworks */ = {isa = PBXBuildFile; productRef = 7AABDE1C2532F3EB0041AFC6 /* PKHUD */; }; + 7AE4929D2591FF5100322D2E /* DifferenceKit in Frameworks */ = {isa = PBXBuildFile; productRef = 7AABDE22253327F10041AFC6 /* DifferenceKit */; }; + 7AE4929E2591FF5100322D2E /* Eureka in Frameworks */ = {isa = PBXBuildFile; productRef = 7AEF47A3253DC4D2001D6238 /* Eureka */; }; + 7AE492A1259232F000322D2E /* MultilineLinkRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AE492A0259232F000322D2E /* MultilineLinkRow.swift */; }; 7AEFC3BE2529D3CC00BADFB2 /* ConfigurableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AEFC3BD2529D3CC00BADFB2 /* ConfigurableCell.swift */; }; 7AEFE728240455E200910EB7 /* SettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AEFE727240455E200910EB7 /* SettingsController.swift */; }; 7AF12B1D258C9CFF0090F8B8 /* Cloneable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AF12B1C258C9CFF0090F8B8 /* Cloneable.swift */; }; @@ -196,6 +210,7 @@ 7AE24C5E251F1B4E00758E39 /* Buttons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Buttons.swift; sourceTree = ""; }; 7AE26A3224EEF9EC00625033 /* UIViewControllerExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewControllerExt.swift; sourceTree = ""; }; 7AE26A3424F31B0700625033 /* EventsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventsController.swift; sourceTree = ""; }; + 7AE492A0259232F000322D2E /* MultilineLinkRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultilineLinkRow.swift; sourceTree = ""; }; 7AEFC3BD2529D3CC00BADFB2 /* ConfigurableCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurableCell.swift; sourceTree = ""; }; 7AEFE727240455E200910EB7 /* SettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsController.swift; sourceTree = ""; }; 7AF12B1C258C9CFF0090F8B8 /* Cloneable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cloneable.swift; sourceTree = ""; }; @@ -206,7 +221,20 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 7AE492972591FF5100322D2E /* RealmSwift in Frameworks */, + 7AE4929B2591FF5100322D2E /* ExceptionCatcher in Frameworks */, + 7AE492962591FF5100322D2E /* Realm in Frameworks */, + 7AE492922591FF5100322D2E /* RxSwift in Frameworks */, + 7AE492952591FF5100322D2E /* RxBlocking in Frameworks */, + 7AE4929E2591FF5100322D2E /* Eureka in Frameworks */, + 7AE492992591FF5100322D2E /* Kingfisher in Frameworks */, 7A813DBE2506A57100CC93B9 /* AuthenticationServices.framework in Frameworks */, + 7AE4929C2591FF5100322D2E /* PKHUD in Frameworks */, + 7AE492942591FF5100322D2E /* RxCocoa in Frameworks */, + 7AE4929A2591FF5100322D2E /* SwiftDate in Frameworks */, + 7AE4929D2591FF5100322D2E /* DifferenceKit in Frameworks */, + 7AE492982591FF5100322D2E /* RxRealm in Frameworks */, + 7AE492932591FF5100322D2E /* RxRelay in Frameworks */, 7A96AE2F246B2BCD00297C33 /* WebKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -237,6 +265,7 @@ children = ( 7A0B969F257D6D4B000B39AD /* MultilineLabelRow.swift */, 7A2DE69D2589606A00A113FC /* ImageGridRow.swift */, + 7AE492A0259232F000322D2E /* MultilineLinkRow.swift */, ); path = eureka; sourceTree = ""; @@ -459,19 +488,19 @@ ); name = AutoCat; packageProductDependencies = ( - 7A11471C23FEA18700B424AF, - 7A11471E23FEA18700B424AF, - 7A11472023FEA18700B424AF, - 7A11472223FEA18700B424AF, - 7A11472523FEA1F400B424AF, - 7A11472723FEA1F400B424AF, - 7A530B8A240181F500CBFE6E, - 7AF58D332402A91C00CE01A0, - 7A051610241412CA00FC55AC, - 7A813DC02508C4D900CC93B9, - 7AABDE1C2532F3EB0041AFC6, - 7AABDE22253327F10041AFC6, - 7AEF47A3253DC4D2001D6238, + 7A11471C23FEA18700B424AF /* RxSwift */, + 7A11471E23FEA18700B424AF /* RxRelay */, + 7A11472023FEA18700B424AF /* RxCocoa */, + 7A11472223FEA18700B424AF /* RxBlocking */, + 7A11472523FEA1F400B424AF /* Realm */, + 7A11472723FEA1F400B424AF /* RealmSwift */, + 7A530B8A240181F500CBFE6E /* RxRealm */, + 7AF58D332402A91C00CE01A0 /* Kingfisher */, + 7A051610241412CA00FC55AC /* SwiftDate */, + 7A813DC02508C4D900CC93B9 /* ExceptionCatcher */, + 7AABDE1C2532F3EB0041AFC6 /* PKHUD */, + 7AABDE22253327F10041AFC6 /* DifferenceKit */, + 7AEF47A3253DC4D2001D6238 /* Eureka */, ); productName = AutoCat; productReference = 7A1146FD23FDE7E500B424AF /* AutoCat.app */; @@ -503,15 +532,15 @@ ); mainGroup = 7A1146F423FDE7E500B424AF; packageReferences = ( - 7A11471B23FEA18700B424AF, - 7A11472423FEA1F400B424AF, - 7A530B89240181F500CBFE6E, - 7AF58D322402A91C00CE01A0, - 7A05160F241412CA00FC55AC, - 7A813DBF2508C4D900CC93B9, - 7AABDE1B2532F3EB0041AFC6, - 7AABDE21253327F10041AFC6, - 7AEF47A2253DC4D2001D6238, + 7A11471B23FEA18700B424AF /* XCRemoteSwiftPackageReference "RxSwift" */, + 7A11472423FEA1F400B424AF /* XCRemoteSwiftPackageReference "realm-cocoa" */, + 7A530B89240181F500CBFE6E /* XCRemoteSwiftPackageReference "RxRealm" */, + 7AF58D322402A91C00CE01A0 /* XCRemoteSwiftPackageReference "Kingfisher" */, + 7A05160F241412CA00FC55AC /* XCRemoteSwiftPackageReference "SwiftDate" */, + 7A813DBF2508C4D900CC93B9 /* XCRemoteSwiftPackageReference "ExceptionCatcher" */, + 7AABDE1B2532F3EB0041AFC6 /* XCRemoteSwiftPackageReference "PKHUD" */, + 7AABDE21253327F10041AFC6 /* XCRemoteSwiftPackageReference "DifferenceKit" */, + 7AEF47A2253DC4D2001D6238 /* XCRemoteSwiftPackageReference "Eureka" */, ); productRefGroup = 7A1146FE23FDE7E500B424AF /* Products */; projectDirPath = ""; @@ -615,6 +644,7 @@ 7ADF6C95250D037700F237B2 /* ShowEventController.swift in Sources */, 7A27ADC7249D43210035F39E /* RegionsController.swift in Sources */, 7A05161A2414FF0900FC55AC /* DateSection.swift in Sources */, + 7AE492A1259232F000322D2E /* MultilineLinkRow.swift in Sources */, 7A333814249A532400D878F1 /* Filter.swift in Sources */, 7A11474B23FF368B00B424AF /* Settings.swift in Sources */, 7ADF6C93250B954900F237B2 /* Navigation.swift in Sources */, @@ -865,7 +895,7 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - 7A05160F241412CA00FC55AC = { + 7A05160F241412CA00FC55AC /* XCRemoteSwiftPackageReference "SwiftDate" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/malcommac/SwiftDate.git"; requirement = { @@ -873,7 +903,7 @@ minimumVersion = 6.1.0; }; }; - 7A11471B23FEA18700B424AF = { + 7A11471B23FEA18700B424AF /* XCRemoteSwiftPackageReference "RxSwift" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/ReactiveX/RxSwift.git"; requirement = { @@ -881,7 +911,7 @@ minimumVersion = 5.0.1; }; }; - 7A11472423FEA1F400B424AF = { + 7A11472423FEA1F400B424AF /* XCRemoteSwiftPackageReference "realm-cocoa" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/realm/realm-cocoa"; requirement = { @@ -889,7 +919,7 @@ minimumVersion = 5.0.0; }; }; - 7A530B89240181F500CBFE6E = { + 7A530B89240181F500CBFE6E /* XCRemoteSwiftPackageReference "RxRealm" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/RxSwiftCommunity/RxRealm"; requirement = { @@ -897,7 +927,7 @@ minimumVersion = 3.0.0; }; }; - 7A813DBF2508C4D900CC93B9 = { + 7A813DBF2508C4D900CC93B9 /* XCRemoteSwiftPackageReference "ExceptionCatcher" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/sindresorhus/ExceptionCatcher"; requirement = { @@ -905,7 +935,7 @@ minimumVersion = 1.1.0; }; }; - 7AABDE1B2532F3EB0041AFC6 = { + 7AABDE1B2532F3EB0041AFC6 /* XCRemoteSwiftPackageReference "PKHUD" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/pkluz/PKHUD.git"; requirement = { @@ -913,7 +943,7 @@ minimumVersion = 5.4.0; }; }; - 7AABDE21253327F10041AFC6 = { + 7AABDE21253327F10041AFC6 /* XCRemoteSwiftPackageReference "DifferenceKit" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/ra1028/DifferenceKit.git"; requirement = { @@ -921,7 +951,7 @@ minimumVersion = 1.1.5; }; }; - 7AEF47A2253DC4D2001D6238 = { + 7AEF47A2253DC4D2001D6238 /* XCRemoteSwiftPackageReference "Eureka" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/selim-mustafaev/Eureka"; requirement = { @@ -929,7 +959,7 @@ kind = branch; }; }; - 7AF58D322402A91C00CE01A0 = { + 7AF58D322402A91C00CE01A0 /* XCRemoteSwiftPackageReference "Kingfisher" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/onevcat/Kingfisher"; requirement = { @@ -940,69 +970,69 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - 7A051610241412CA00FC55AC = { + 7A051610241412CA00FC55AC /* SwiftDate */ = { isa = XCSwiftPackageProductDependency; - package = 7A05160F241412CA00FC55AC; + package = 7A05160F241412CA00FC55AC /* XCRemoteSwiftPackageReference "SwiftDate" */; productName = SwiftDate; }; - 7A11471C23FEA18700B424AF = { + 7A11471C23FEA18700B424AF /* RxSwift */ = { isa = XCSwiftPackageProductDependency; - package = 7A11471B23FEA18700B424AF; + package = 7A11471B23FEA18700B424AF /* XCRemoteSwiftPackageReference "RxSwift" */; productName = RxSwift; }; - 7A11471E23FEA18700B424AF = { + 7A11471E23FEA18700B424AF /* RxRelay */ = { isa = XCSwiftPackageProductDependency; - package = 7A11471B23FEA18700B424AF; + package = 7A11471B23FEA18700B424AF /* XCRemoteSwiftPackageReference "RxSwift" */; productName = RxRelay; }; - 7A11472023FEA18700B424AF = { + 7A11472023FEA18700B424AF /* RxCocoa */ = { isa = XCSwiftPackageProductDependency; - package = 7A11471B23FEA18700B424AF; + package = 7A11471B23FEA18700B424AF /* XCRemoteSwiftPackageReference "RxSwift" */; productName = RxCocoa; }; - 7A11472223FEA18700B424AF = { + 7A11472223FEA18700B424AF /* RxBlocking */ = { isa = XCSwiftPackageProductDependency; - package = 7A11471B23FEA18700B424AF; + package = 7A11471B23FEA18700B424AF /* XCRemoteSwiftPackageReference "RxSwift" */; productName = RxBlocking; }; - 7A11472523FEA1F400B424AF = { + 7A11472523FEA1F400B424AF /* Realm */ = { isa = XCSwiftPackageProductDependency; - package = 7A11472423FEA1F400B424AF; + package = 7A11472423FEA1F400B424AF /* XCRemoteSwiftPackageReference "realm-cocoa" */; productName = Realm; }; - 7A11472723FEA1F400B424AF = { + 7A11472723FEA1F400B424AF /* RealmSwift */ = { isa = XCSwiftPackageProductDependency; - package = 7A11472423FEA1F400B424AF; + package = 7A11472423FEA1F400B424AF /* XCRemoteSwiftPackageReference "realm-cocoa" */; productName = RealmSwift; }; - 7A530B8A240181F500CBFE6E = { + 7A530B8A240181F500CBFE6E /* RxRealm */ = { isa = XCSwiftPackageProductDependency; - package = 7A530B89240181F500CBFE6E; + package = 7A530B89240181F500CBFE6E /* XCRemoteSwiftPackageReference "RxRealm" */; productName = RxRealm; }; - 7A813DC02508C4D900CC93B9 = { + 7A813DC02508C4D900CC93B9 /* ExceptionCatcher */ = { isa = XCSwiftPackageProductDependency; - package = 7A813DBF2508C4D900CC93B9; + package = 7A813DBF2508C4D900CC93B9 /* XCRemoteSwiftPackageReference "ExceptionCatcher" */; productName = ExceptionCatcher; }; - 7AABDE1C2532F3EB0041AFC6 = { + 7AABDE1C2532F3EB0041AFC6 /* PKHUD */ = { isa = XCSwiftPackageProductDependency; - package = 7AABDE1B2532F3EB0041AFC6; + package = 7AABDE1B2532F3EB0041AFC6 /* XCRemoteSwiftPackageReference "PKHUD" */; productName = PKHUD; }; - 7AABDE22253327F10041AFC6 = { + 7AABDE22253327F10041AFC6 /* DifferenceKit */ = { isa = XCSwiftPackageProductDependency; - package = 7AABDE21253327F10041AFC6; + package = 7AABDE21253327F10041AFC6 /* XCRemoteSwiftPackageReference "DifferenceKit" */; productName = DifferenceKit; }; - 7AEF47A3253DC4D2001D6238 = { + 7AEF47A3253DC4D2001D6238 /* Eureka */ = { isa = XCSwiftPackageProductDependency; - package = 7AEF47A2253DC4D2001D6238; + package = 7AEF47A2253DC4D2001D6238 /* XCRemoteSwiftPackageReference "Eureka" */; productName = Eureka; }; - 7AF58D332402A91C00CE01A0 = { + 7AF58D332402A91C00CE01A0 /* Kingfisher */ = { isa = XCSwiftPackageProductDependency; - package = 7AF58D322402A91C00CE01A0; + package = 7AF58D322402A91C00CE01A0 /* XCRemoteSwiftPackageReference "Kingfisher" */; productName = Kingfisher; }; /* End XCSwiftPackageProductDependency section */ diff --git a/AutoCat/Controllers/AdsController.swift b/AutoCat/Controllers/AdsController.swift index 2e9a6d4..274618a 100644 --- a/AutoCat/Controllers/AdsController.swift +++ b/AutoCat/Controllers/AdsController.swift @@ -1,9 +1,12 @@ import UIKit import Eureka +import Kingfisher +import SafariServices -class AdsController: FormViewController { +class AdsController: FormViewController, MediaBrowserViewControllerDataSource { var ads: [VehicleAd] = [] + private var currentAd: VehicleAd? override func viewDidLoad() { super.viewDidLoad() @@ -53,17 +56,52 @@ class AdsController: FormViewController { } } -// if let url = URL(string: ad.url) { -// section <<< URLRow() { row in -// row.title = NSLocalizedString("Link", comment: "") -// row.value = url -// } -// } + if let urlStr = ad.url, let url = URL(string: urlStr) { + section <<< MultilineLinkRow() { row in + row.title = NSLocalizedString("Link", comment: "") + row.value = urlStr + } + .onCellSelection { _, _ in + let safari = SFSafariViewController(url: url) + self.present(safari, animated: true) + } + } if !ad.photos.isEmpty { section <<< ImageGridRow() { row in row.value = ad.photos.toArray() } + .onDidSelected { index in + self.currentAd = ad + let mediaBrowser = MediaBrowserViewController(index: index, dataSource: self, delegate: nil) + mediaBrowser.shouldShowTitle = false + self.present(mediaBrowser, animated: true, completion: nil) + } + } + } + } + + // MARK: - MediaBrowserViewControllerDataSource + + func numberOfItems(in mediaBrowser: MediaBrowserViewController) -> Int { + guard let images = self.currentAd?.photos else { return 0 } + return images.count + } + + func mediaBrowser(_ mediaBrowser: MediaBrowserViewController, imageAt index: Int, completion: @escaping MediaBrowserViewControllerDataSource.CompletionBlock) { + guard let images = self.currentAd?.photos, let url = URL(string: images[index]) else { + completion(index, nil, ZoomScale.default, NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Image not found"])) + return + } + + KingfisherManager.shared.retrieveImage(with: url) { result in + switch result { + case .success(let res): + completion(index, res.image, ZoomScale.default, nil) + break + case .failure(let error): + completion(index, nil, ZoomScale.default, error) + break } } } diff --git a/AutoCat/Views/ImageGrid.swift b/AutoCat/Views/ImageGrid.swift index 4e37821..ee45c69 100644 --- a/AutoCat/Views/ImageGrid.swift +++ b/AutoCat/Views/ImageGrid.swift @@ -30,6 +30,7 @@ class ImageCell: UICollectionViewCell { func configure(with image: String) { guard let url = URL(string: image) else { return } + print("=== Configure cell with url: \(image)") self.imgView.kf.setImage(with: url, options: [ .processor(DownsamplingImageProcessor(size: self.imgView.frame.size)), .scaleFactor(UIScreen.main.scale), @@ -42,6 +43,8 @@ class ImageGrid: UICollectionView, UICollectionViewDataSource, UICollectionViewD private var images: [String] = [] private var columnsCount: Int = 1 private var spacing: CGFloat = 0 + + var selectionChanged: ((Int) -> Void)? required init?(coder: NSCoder) { super.init(coder: coder) @@ -101,4 +104,9 @@ class ImageGrid: UICollectionView, UICollectionViewDataSource, UICollectionViewD let cellSize = (self.bounds.size.width - self.spacing*(CGFloat(self.columnsCount) - 1))/CGFloat(self.columnsCount) return CGSize(width: cellSize, height: cellSize) } + + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + collectionView.deselectItem(at: indexPath, animated: false) + self.selectionChanged?(indexPath.row) + } } diff --git a/AutoCat/Views/eureka/ImageGridRow.swift b/AutoCat/Views/eureka/ImageGridRow.swift index 141eba9..88ce880 100644 --- a/AutoCat/Views/eureka/ImageGridRow.swift +++ b/AutoCat/Views/eureka/ImageGridRow.swift @@ -6,15 +6,7 @@ final class ImageGridCell: Cell<[String]>, CellType { required init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) - } - - required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - } - - override func setup() { - super.setup() - + self.grid = ImageGrid(columns: 3, spacing: 2) self.grid.translatesAutoresizingMaskIntoConstraints = false self.contentView.addSubview(self.grid) @@ -26,6 +18,20 @@ final class ImageGridCell: Cell<[String]>, CellType { ]) } + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + override func setup() { + super.setup() + + self.grid.selectionChanged = { index in + if let row = self.row as? ImageGridRow { + row.select(at: index) + } + } + } + override func update() { super.update() self.textLabel?.text = nil @@ -35,8 +41,20 @@ final class ImageGridCell: Cell<[String]>, CellType { } final class ImageGridRow: Row, RowType { + private var selectionCallback: ((Int) -> Void)? + required init(tag: String?) { super.init(tag: tag) cellProvider = CellProvider() } + + fileprivate func select(at index: Int) { + self.selectionCallback?(index) + } + + @discardableResult + func onDidSelected(_ callback: @escaping (Int) -> Void) -> ImageGridRow { + self.selectionCallback = callback + return self + } } diff --git a/AutoCat/Views/eureka/MultilineLabelRow.swift b/AutoCat/Views/eureka/MultilineLabelRow.swift index b6bdfd3..e8c0af8 100644 --- a/AutoCat/Views/eureka/MultilineLabelRow.swift +++ b/AutoCat/Views/eureka/MultilineLabelRow.swift @@ -1,9 +1,9 @@ import UIKit import Eureka -final class MultilineLabelCell: Cell, CellType { - private var title: UILabel! - private var value: UILabel! +class MultilineLabelCell: Cell, CellType { + private(set) var title: UILabel! + private(set) var value: UILabel! required init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) @@ -16,6 +16,8 @@ final class MultilineLabelCell: Cell, CellType { override func setup() { super.setup() + self.selectionStyle = .none + self.title = UILabel() self.contentView.addSubview(self.title) self.title.translatesAutoresizingMaskIntoConstraints = false diff --git a/AutoCat/Views/eureka/MultilineLinkRow.swift b/AutoCat/Views/eureka/MultilineLinkRow.swift new file mode 100644 index 0000000..438cf59 --- /dev/null +++ b/AutoCat/Views/eureka/MultilineLinkRow.swift @@ -0,0 +1,36 @@ +import UIKit +import Eureka + +class MultilineLinkCell: MultilineLabelCell { + required init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + } + + override func update() { + super.update() + + self.textLabel?.text = nil + self.detailTextLabel?.text = nil + + self.title.text = row.title + + if let url = row.value { + self.value.attributedText = NSAttributedString(string: url, attributes: [ + .link: url + ]) + } else { + self.title.attributedText = NSAttributedString(string: "") + } + } +} + +final class MultilineLinkRow: Row, RowType { + required init(tag: String?) { + super.init(tag: tag) + cellProvider = CellProvider() + } +}