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

Twitter handler #51

Merged
merged 4 commits into from
Mar 3, 2018
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
12 changes: 12 additions & 0 deletions trySwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
499CCFF21CC2E0F4007A5BBB /* UIViewControllerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 499CCFF11CC2E0F4007A5BBB /* UIViewControllerExtension.swift */; };
49F7B2811E8475F900F09768 /* SplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49F7B2801E8475F900F09768 /* SplitViewController.swift */; };
4D498DB1B98D4B496FDBB7AA /* Pods_try__Extension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD2E9D5733A6E1B6E10AFEEF /* Pods_try__Extension.framework */; };
5CDB20792048952A00C3E0D3 /* TwitterFollowDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */; };
7AD1E19C80B78BB08E3DF079 /* Pods_trySwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 620220ABCCCDF47FDAF48B67 /* Pods_trySwift.framework */; };
EAFE1C26E49EFABF83487BDC /* Pods_try__Today.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24718BF11477753FCD47A7A8 /* Pods_try__Today.framework */; };
FA0E2B4F1E63B90400B40814 /* SessionDetailInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA0E2B4E1E63B90400B40814 /* SessionDetailInterfaceController.swift */; };
Expand Down Expand Up @@ -193,6 +194,7 @@
499CCFF11CC2E0F4007A5BBB /* UIViewControllerExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewControllerExtension.swift; sourceTree = "<group>"; };
49F7B2801E8475F900F09768 /* SplitViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SplitViewController.swift; sourceTree = "<group>"; };
58F81AD508535BD405F98215 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwitterFollowDelegate.swift; sourceTree = "<group>"; };
5FA07FBC036240AEF8B7C739 /* Pods-trySwift.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-trySwift.release.xcconfig"; path = "Pods/Target Support Files/Pods-trySwift/Pods-trySwift.release.xcconfig"; sourceTree = "<group>"; };
620220ABCCCDF47FDAF48B67 /* Pods_trySwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_trySwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6C1F9C27BCD8099DCA758F7A /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -381,6 +383,14 @@
name = Frameworks;
sourceTree = "<group>";
};
5CDB20772048951F00C3E0D3 /* Twitter */ = {
isa = PBXGroup;
children = (
5CDB20782048952A00C3E0D3 /* TwitterFollowDelegate.swift */,
);
path = Twitter;
sourceTree = "<group>";
};
F413680C9BA29129B4319377 /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -449,6 +459,7 @@
FA39E8CB1C6AF89D0074B6BE /* Utilities */ = {
isa = PBXGroup;
children = (
5CDB20772048951F00C3E0D3 /* Twitter */,
FA39E8ED1C6C034B0074B6BE /* UIColorExtension.swift */,
499CCFF11CC2E0F4007A5BBB /* UIViewControllerExtension.swift */,
FA3A1CB51D68E1950042F8DD /* WatchSessionManager.swift */,
Expand Down Expand Up @@ -1123,6 +1134,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5CDB20792048952A00C3E0D3 /* TwitterFollowDelegate.swift in Sources */,
499BD62A1D05910200E74061 /* Twitter.swift in Sources */,
FA39E90F1C6C81870074B6BE /* SponsorsViewController.swift in Sources */,
FA36B7071E5DA3970022E6A9 /* DateFormatterExtension.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion trySwift/OfficeHoursDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension OfficeHoursDetailViewController {
return cell
case .speakerInfo:
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as SpeakerTableViewCell
cell.configure(withSpeaker: speaker, selectionEnabled: false, accessoryEnabled: false)
cell.configure(withSpeaker: speaker, selectionEnabled: false, accessoryEnabled: false, delegate: self)
return cell
case .bio:
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TextTableViewCell
Expand Down
2 changes: 1 addition & 1 deletion trySwift/SessionDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension SessionDetailsViewController {
return cell
case .speakerInfo:
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as SpeakerTableViewCell
cell.configure(withSpeaker: presentation.speaker!, selectionEnabled: false, accessoryEnabled: false)
cell.configure(withSpeaker: presentation.speaker!, selectionEnabled: false, accessoryEnabled: false, delegate: self)
return cell
case .summary:
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TextTableViewCell
Expand Down
2 changes: 1 addition & 1 deletion trySwift/SpeakerDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension SpeakerDetailViewController {
switch SpeakerDetail(rawValue: indexPath.row)! {
case .header:
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as SpeakerTableViewCell
cell.configure(withSpeaker: speaker, selectionEnabled: false, accessoryEnabled: false)
cell.configure(withSpeaker: speaker, selectionEnabled: false, accessoryEnabled: false, delegate: self)
return cell
case .bio:
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TextTableViewCell
Expand Down
26 changes: 19 additions & 7 deletions trySwift/SpeakerTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,31 @@ class SpeakerTableViewCell: UITableViewCell {

@IBOutlet weak var speakerImageView: UIImageView!
@IBOutlet weak var speakerNameLabel: UILabel!
@IBOutlet weak var speakerTwitterLabel: UILabel!

@IBOutlet weak var speakerTwitterButton: UIButton!

fileprivate var speaker: Speaker?
fileprivate weak var delegate: TwitterFollowDelegate?

override func awakeFromNib() {
super.awakeFromNib()

speakerTwitterLabel.textColor = .trySwiftAccentColor()
speakerTwitterButton.setTitleColor(.trySwiftAccentColor(), for: .normal)
}

func configure(withSpeaker speaker: Speaker, selectionEnabled: Bool = true, accessoryEnabled: Bool = true) {

@IBAction func speakerTwitterButtonDidTap(_ sender: Any) {
guard let speaker = speaker else {
assertionFailure("Speaker is not set")
return
}
self.delegate?.followUser(speaker.twitter)
}

func configure(withSpeaker speaker: Speaker, selectionEnabled: Bool = true, accessoryEnabled: Bool = true, delegate: TwitterFollowDelegate) {
let scale = UIScreen.main.scale
let processor = RoundCornerImageProcessor(cornerRadius: 34, targetSize: CGSize(width: 67, height: 67))
speakerImageView.kf.setImage(with: speaker.imageURL, placeholder: nil, options: [.processor(processor), .scaleFactor(scale)])
speakerNameLabel.text = speaker.localizedName
speakerTwitterLabel.text = "@\(speaker.twitter)"

speakerTwitterButton.setTitle("@\(speaker.twitter)", for: .normal)
if !selectionEnabled {
selectionStyle = .none
}
Expand All @@ -40,5 +49,8 @@ class SpeakerTableViewCell: UITableViewCell {

setNeedsUpdateConstraints()
layoutIfNeeded()

self.speaker = speaker
self.delegate = delegate
}
}
35 changes: 17 additions & 18 deletions trySwift/SpeakerTableViewCell.xib
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -16,46 +15,46 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="82"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="287" height="81.5"/>
<rect key="frame" x="0.0" y="0.0" width="286" height="81.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="GJ0-wN-VIc">
<rect key="frame" x="8" y="8" width="67" height="67"/>
<rect key="frame" x="16" y="11" width="67" height="67"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" constant="67" id="CSc-Fq-CFF"/>
<constraint firstAttribute="height" constant="67" id="G3p-Xx-UFN"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Speaker Name" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ir9-dv-8TT">
<rect key="frame" x="90" y="21.5" width="112" height="20.5"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="749" text="Speaker Name" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ir9-dv-8TT">
<rect key="frame" x="98" y="24.5" width="112" height="15"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="@twitter" textAlignment="natural" lineBreakMode="characterWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="980-ih-bht">
<rect key="frame" x="90" y="44" width="57" height="18"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<fontDescription key="fontDescription" type="system" weight="light" pointSize="15"/>
<color key="textColor" red="0.33333333333333331" green="0.33333333333333331" blue="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="f5Z-lq-2Xw">
<rect key="frame" x="98" y="35" width="58" height="30"/>
<state key="normal" title="@twitter"/>
<connections>
<action selector="speakerTwitterButtonDidTap:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="TQ8-gr-bc9"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="ir9-dv-8TT" firstAttribute="leading" secondItem="GJ0-wN-VIc" secondAttribute="trailing" constant="15" id="14W-um-tOD"/>
<constraint firstAttribute="bottom" secondItem="f5Z-lq-2Xw" secondAttribute="bottom" constant="16.5" id="5XV-yg-wdC"/>
<constraint firstItem="GJ0-wN-VIc" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leadingMargin" id="6Mk-ta-AhD"/>
<constraint firstItem="980-ih-bht" firstAttribute="top" secondItem="ir9-dv-8TT" secondAttribute="bottom" constant="2" id="9kl-XZ-6MT"/>
<constraint firstItem="ir9-dv-8TT" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="topMargin" constant="13.5" id="Gd8-aC-ye0"/>
<constraint firstItem="GJ0-wN-VIc" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="topMargin" id="Kp2-Vu-vZw"/>
<constraint firstAttribute="bottomMargin" secondItem="980-ih-bht" secondAttribute="bottom" constant="11.5" id="NDV-bw-ILg"/>
<constraint firstItem="980-ih-bht" firstAttribute="leading" secondItem="ir9-dv-8TT" secondAttribute="leading" id="Yzq-oB-Hza"/>
<constraint firstItem="f5Z-lq-2Xw" firstAttribute="leading" secondItem="ir9-dv-8TT" secondAttribute="leading" id="S1y-Og-m7A"/>
<constraint firstItem="f5Z-lq-2Xw" firstAttribute="top" secondItem="ir9-dv-8TT" secondAttribute="bottom" constant="-4.5" id="SbS-Eh-s8L"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="speakerImageView" destination="GJ0-wN-VIc" id="pub-eH-fa9"/>
<outlet property="speakerNameLabel" destination="ir9-dv-8TT" id="ELP-of-NZX"/>
<outlet property="speakerTwitterLabel" destination="980-ih-bht" id="Jxc-OH-eH3"/>
<outlet property="speakerTwitterButton" destination="f5Z-lq-2Xw" id="Euk-CM-I8n"/>
</connections>
<point key="canvasLocation" x="243" y="307"/>
</tableViewCell>
Expand Down
2 changes: 1 addition & 1 deletion trySwift/SpeakersViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extension SpeakersViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as SpeakerTableViewCell

cell.configure(withSpeaker: speakers[indexPath.row])
cell.configure(withSpeaker: speakers[indexPath.row], delegate: self)

return cell
}
Expand Down
35 changes: 35 additions & 0 deletions trySwift/Twitter/TwitterFollowDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// TwitterFollowDelegate.swift
// trySwift
//
// Created by Sash Zats on 3/2/18.
// Copyright © 2018 NatashaTheRobot. All rights reserved.
//

import UIKit

protocol TwitterFollowDelegate: class {
func followUser(_ username: String)
}

extension UIViewController: TwitterFollowDelegate {

func followUser(_ username: String) {
var applicationOpened = false
let application = UIApplication.shared
for twitterURL in Twitter.urls(forUsername: username) {
if let url = URL(string: twitterURL) , application.canOpenURL(url) && !applicationOpened {
application.open(url, options: [String:Any](), completionHandler: nil)
applicationOpened = true
break
}
}

if !applicationOpened {
if let twitterURL = URL(string: "https://twitter.com/\(username)") {
openSafariViewController(withURL: twitterURL)
}
}
}
}

4 changes: 0 additions & 4 deletions trySwift/TwitterFollowTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

import UIKit

protocol TwitterFollowDelegate: class {
func followUser(_ username: String)
}

class TwitterFollowTableViewCell: UITableViewCell {

@IBOutlet weak var followButton: UIButton!
Expand Down
21 changes: 0 additions & 21 deletions trySwift/UIViewControllerExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,6 @@ extension UIViewController: SFSafariViewControllerDelegate {
}
}

extension UIViewController: TwitterFollowDelegate {

func followUser(_ username: String) {
var applicationOpened = false
let application = UIApplication.shared
for twitterURL in Twitter.urls(forUsername: username) {
if let url = URL(string: twitterURL) , application.canOpenURL(url) && !applicationOpened {
application.open(url, options: [String:Any](), completionHandler: nil)
applicationOpened = true
break
}
}

if !applicationOpened {
if let twitterURL = URL(string: "http://twitter.com/\(username)") {
openSafariViewController(withURL: twitterURL)
}
}
}
}

extension UIViewController: MFMailComposeViewControllerDelegate {

func sendMail(withConfiguration configuration: MailConfiguration) {
Expand Down
2 changes: 1 addition & 1 deletion trySwift/WorkshopDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension WorkshopDetailViewController {
return cell
case .speakerInfo:
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as SpeakerTableViewCell
cell.configure(withSpeaker: presentation.speaker!, selectionEnabled: false, accessoryEnabled: false)
cell.configure(withSpeaker: presentation.speaker!, selectionEnabled: false, accessoryEnabled: false, delegate: self)
return cell
case .summary:
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TextTableViewCell
Expand Down