Skip to content

Commit

Permalink
Credits cleanup/refactoring & removed warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-sarda committed Jan 14, 2022
1 parent b6e0a89 commit 0b59f03
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 49 deletions.
5 changes: 2 additions & 3 deletions ViteMaDose/Models/Credit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Foundation
// MARK: - Credit

struct Credit: Codable {
let id: String?
let nom: String?
let pseudo: String?
let photo: String?
Expand All @@ -22,11 +21,11 @@ struct Credit: Codable {
let links: [CreditLink]?

var shownName: String {
nom ?? pseudo ?? id ?? Localization.Credits.noName
nom ?? pseudo ?? Localization.Credits.noName
}

var shownRole: String {
teams?.joined(separator: ", ") ?? Localization.Credits.noRole
teams?.joined(separator: .commaWithSpace) ?? Localization.Credits.noRole
}
}

Expand Down
38 changes: 14 additions & 24 deletions ViteMaDose/ViewModels/Credit/CreditViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,19 @@ class CreditViewModel: CreditViewModelProvider {
return nil
}

let creditLink: URL? = {
if let url = URL(string: credit.site_web.emptyIfNil) {
return url
} else if let url = URL(string: (credit.links?.first?.url).emptyIfNil) {
return url
}
return nil
}()

return CreditCellViewData(
creditName: credit.shownName,
creditRole: AccessibilityString(rawValue: pretty(toDiplay: credit.shownRole), vocalizedValue: pretty(toVocalize: credit.shownRole)),
creditLink: URL(string: credit.site_web ?? credit.links?.first?.url ?? ""),
creditLink: creditLink,
creditImage: credit.photo
)
}
Expand Down Expand Up @@ -93,26 +102,6 @@ class CreditViewModel: CreditViewModelProvider {
.replacingOccurrences(of: "web", with: "application web")
}

/// Keep unique `Credit` by filtering the givene `values` by `nom` properties
/// - Parameter values: The data set to filter
/// - Returns: The filtered credits
private func keepUnique(within values: [Credit]) -> [Credit] {
var unique = [Credit]()
values.forEach { item in
let isAlradyStored = unique.contains { element in
if let itemName = item.nom?.uppercased(), let elementName = element.nom?.uppercased(), itemName == elementName {
return true
} else {
return false
}
}
if !isAlradyStored {
unique.append(item)
}
}
return unique
}

// MARK: Load of data

func load() {
Expand All @@ -133,9 +122,10 @@ class CreditViewModel: CreditViewModelProvider {
}

private func handleLoad(with credits: [Credit]) {
let uniqueCredits = keepUnique(within: credits)
self.allCredits = uniqueCredits.sorted(by: { $0.shownName < $1.shownName })
delegate?.reloadTableView(with: uniqueCredits)
self.allCredits = credits
.unique(by: \.pseudo)
.sorted(by: { $0.shownName < $1.shownName })
delegate?.reloadTableView(with: self.allCredits)
}

private func handleError(_ error: Error) {
Expand Down
8 changes: 4 additions & 4 deletions ViteMaDose/Views/CentresList/Cells/CentreActionCell.xib
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="3ej-ox-E3h" userLabel="Filter Button">
<rect key="frame" x="309" y="0.0" width="45" height="78"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" image="line.3.horizontal.decrease.circle.fill" catalog="system" title=""/>
<rect key="frame" x="334.5" y="0.0" width="19.5" height="78"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" title="" image="ellipsis" catalog="system"/>
</button>
</subviews>
</stackView>
Expand All @@ -58,7 +58,7 @@
</tableViewCell>
</objects>
<resources>
<image name="line.3.horizontal.decrease.circle.fill" catalog="system" width="128" height="121"/>
<image name="ellipsis" catalog="system" width="128" height="37"/>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
Expand Down
6 changes: 4 additions & 2 deletions ViteMaDose/Views/Credits/Cells/CreditCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class CreditCell: UITableViewCell {
creditImageView.setCornerRadius(Constant.viewsCornerRadius)
creditContainerView.setCornerRadius(Constant.viewsCornerRadius)

creditImageView.kf.setImage(with: URL(string: viewData.creditImage ?? ""))
if let imageURL = URL(string: viewData.creditImage.emptyIfNil) {
creditImageView.kf.setImage(with: imageURL)
}
creditNameLabel.text = viewData.creditName

// Need to be refactored: if too big a11y sizes, diplay is dirty (sometimes role or name)
Expand All @@ -76,7 +78,7 @@ class CreditCell: UITableViewCell {
creditRoleLabel.accessibilityLabel = viewData.creditRole.vocalizedValue
}

if let url = buttonURL, UIApplication.shared.canOpenURL(url) {
if let url = buttonURL, url.isValid {
creditLinkButton.isHidden = false
creditLinkButton.accessibilityLabel = Localization.A11y.VoiceOver.Credits.credit_button_label
creditLinkButton.accessibilityHint = Localization.A11y.VoiceOver.Credits.credit_button_hint
Expand Down
14 changes: 7 additions & 7 deletions ViteMaDose/Views/Credits/Cells/CreditCell.xib
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,30 @@
</constraints>
</view>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="ZXs-sh-754">
<rect key="frame" x="55" y="0.0" width="288" height="80.5"/>
<rect key="frame" x="55" y="0.0" width="223" height="80.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="Name" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" minimumFontSize="12" translatesAutoresizingMaskIntoConstraints="NO" id="Arf-tf-NyD">
<rect key="frame" x="0.0" y="0.0" width="288" height="60"/>
<rect key="frame" x="0.0" y="0.0" width="223" height="60"/>
<fontDescription key="fontDescription" type="system" pointSize="24"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Role" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3zb-J9-cLa">
<rect key="frame" x="0.0" y="60" width="288" height="20.5"/>
<rect key="frame" x="0.0" y="60" width="223" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="right" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="SpD-fC-YN7">
<rect key="frame" x="343" y="0.0" width="25" height="80.5"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="right" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="SpD-fC-YN7">
<rect key="frame" x="293" y="0.0" width="50" height="80.5"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="25" id="8fD-T2-b4K"/>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="50" id="FcV-4K-0xg"/>
</constraints>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" image="person.text.rectangle" catalog="system"/>
<state key="normal" image="arrow.up.right" catalog="system"/>
<connections>
<action selector="creditLinkButtonClicked:" destination="6oK-Dz-Q8T" eventType="touchUpInside" id="V6C-rI-0TD"/>
</connections>
Expand Down Expand Up @@ -102,7 +102,7 @@
</tableViewCell>
</objects>
<resources>
<image name="person.text.rectangle" catalog="system" width="128" height="93"/>
<image name="arrow.up.right" catalog="system" width="128" height="112"/>
<systemColor name="secondarySystemBackgroundColor">
<color red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
Expand Down
17 changes: 8 additions & 9 deletions ViteMaDose/Views/Settings/Cells/SettingsCell.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -26,14 +26,14 @@
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="yMG-HU-3lW">
<rect key="frame" x="0.0" y="0.0" width="245" height="116"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="Titre d'un élément des settings" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" minimumFontSize="10" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9VB-T9-xhP">
<rect key="frame" x="0.0" y="0.0" width="245" height="73"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="Titre d'un élément des settings" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="9VB-T9-xhP">
<rect key="frame" x="0.0" y="0.0" width="245" height="80.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle2"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Information complémentaire sur l'élément de settings" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumFontSize="8" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Jil-go-r7k">
<rect key="frame" x="0.0" y="78" width="245" height="38"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Information complémentaire sur l'élément de settings" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Jil-go-r7k">
<rect key="frame" x="0.0" y="85.5" width="245" height="30.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleSubhead"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
Expand All @@ -46,8 +46,8 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Qfk-IG-jfH">
<rect key="frame" x="0.0" y="35.5" width="45" height="45"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="cursorarrow.square" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="1SE-Ue-LxH">
<rect key="frame" x="10" y="8.5" width="25" height="27.5"/>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="1SE-Ue-LxH">
<rect key="frame" x="10" y="7.5" width="25" height="30"/>
<color key="tintColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="width" constant="25" id="XlY-kX-hcd"/>
Expand Down Expand Up @@ -102,7 +102,6 @@
</tableViewCell>
</objects>
<resources>
<image name="cursorarrow.square" catalog="system" width="128" height="114"/>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
Expand Down

0 comments on commit 0b59f03

Please sign in to comment.