Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added subredditname #62

Merged
merged 1 commit into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Area51/Resources/UI/TableviewCells/ListingTableViewCell.xib
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</constraints>
</imageView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" alignment="top" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="Cc5-63-XHE">
<rect key="frame" x="88" y="0.0" width="200" height="39"/>
<rect key="frame" x="88" y="0.0" width="200" height="57.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wgH-vm-i9o">
<rect key="frame" x="0.0" y="0.0" width="33.5" height="20.5"/>
Expand All @@ -43,6 +43,12 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="bottomRight" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Subreddit" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="82B-DU-pKc">
<rect key="frame" x="0.0" y="43" width="55.5" height="14.5"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
Expand All @@ -58,6 +64,7 @@
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
<connections>
<outlet property="bodyLabel" destination="ZIu-c8-W5l" id="hE4-te-3NQ"/>
<outlet property="subredditLabel" destination="82B-DU-pKc" id="Qch-qY-SBh"/>
<outlet property="thumbnailImageView" destination="WYq-7j-qxI" id="WAm-2v-xpP"/>
<outlet property="titleLabel" destination="wgH-vm-i9o" id="SHY-7p-Cvx"/>
</connections>
Expand Down
12 changes: 12 additions & 0 deletions Area51/Sources/TableViewCells/ListingTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ListingService
class ListingTableViewCell: UITableViewCell {
@IBOutlet private var titleLabel: UILabel!
@IBOutlet private var bodyLabel: UILabel!
@IBOutlet private var subredditLabel: UILabel!
@IBOutlet private var thumbnailImageView: NetworkImageView!

static var reuseIdentifier: String {
Expand All @@ -20,6 +21,7 @@ extension ListingTableViewCell: ListingDisplayable {
func display(_ listing: Listing) {
configureTitleText(with: listing)
configureThumbnailImageView(with: listing)
configureSubredditLabel(with: listing)
configureBodyText(with: listing)
}
}
Expand All @@ -34,6 +36,16 @@ private extension ListingTableViewCell {
thumbnailImageView.url = listing.thumbnailURL
}

func configureSubredditLabel(with listing: Listing) {
guard let subredditName = listing.subredditName else {
subredditLabel.isHidden = true
return
}

subredditLabel.isHidden = subredditName.isEmpty
subredditLabel.text = subredditName.strippedHtml
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to FeedViewModel.swift removeHtmlFromListings

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually nvm, I will be refactoring that area soon.

}

func configureBodyText(with listing: Listing) {
guard let selfText = listing.selfText else {
bodyLabel.isHidden = true
Expand Down
3 changes: 3 additions & 0 deletions ListingService/Sources/Models/Listing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Listing: Decodable {
public let url: URL
public let thumbnailURL: URL?
public var selfText: String?
public let subredditName: String?
public var displayName: String?
let fullServerID: String

Expand All @@ -23,6 +24,7 @@ public class Listing: Decodable {
case fullServerID = "name"
case thumbnailURL = "thumbnail"
case displayName = "display_name"
case subredditName = "subreddit"
}

public required init(from decoder: Decoder) throws {
Expand All @@ -32,6 +34,7 @@ public class Listing: Decodable {
title = try innerData.decode(String.self, forKey: .title)
fullServerID = try innerData.decode(String.self, forKey: .fullServerID)
displayName = try? innerData.decode(String.self, forKey: .displayName)
subredditName = try? innerData.decode(String.self, forKey: .subredditName)
selfText = try? innerData.decode(String.self, forKey: .selfText)

let urlString = try innerData.decode(String.self, forKey: .url)
Expand Down