Skip to content

Commit

Permalink
Basic implementation of the transcript window
Browse files Browse the repository at this point in the history
  • Loading branch information
insidegui committed Dec 20, 2015
1 parent 0ae6f70 commit 6b18c27
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 77 deletions.
46 changes: 41 additions & 5 deletions WWDC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
DDBD18661BC3227B00EF7718 /* FilterBarController.xib in Resources */ = {isa = PBXBuildFile; fileRef = DDBD18641BC3227B00EF7718 /* FilterBarController.xib */; };
DDC049D01AE564F20008D41A /* PDFWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDC049CE1AE564F20008D41A /* PDFWindowController.swift */; };
DDC049D11AE564F20008D41A /* PDFWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = DDC049CF1AE564F20008D41A /* PDFWindowController.xib */; };
DDCAB46E1C2620BE005889CB /* TranscriptViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCAB46C1C2620BE005889CB /* TranscriptViewController.swift */; };
DDCAB46F1C2620BE005889CB /* TranscriptViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = DDCAB46D1C2620BE005889CB /* TranscriptViewController.xib */; };
DDCAB48A1C263EF9005889CB /* TranscriptLineTableRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCAB4891C263EF9005889CB /* TranscriptLineTableRowView.swift */; };
DDCC5D721AF1518A00F24F55 /* Crashlytics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DDCC5D711AF1518A00F24F55 /* Crashlytics.framework */; };
DDCC5D761AF1532600F24F55 /* GRCrashlyticsHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = DDCC5D751AF1532600F24F55 /* GRCrashlyticsHelper.m */; };
DDD7A4331AE2DF14000A0102 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDD7A4321AE2DF14000A0102 /* Theme.swift */; };
Expand Down Expand Up @@ -248,6 +251,9 @@
DDBD18641BC3227B00EF7718 /* FilterBarController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FilterBarController.xib; sourceTree = "<group>"; };
DDC049CE1AE564F20008D41A /* PDFWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFWindowController.swift; sourceTree = "<group>"; };
DDC049CF1AE564F20008D41A /* PDFWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PDFWindowController.xib; sourceTree = "<group>"; };
DDCAB46C1C2620BE005889CB /* TranscriptViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TranscriptViewController.swift; sourceTree = "<group>"; };
DDCAB46D1C2620BE005889CB /* TranscriptViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TranscriptViewController.xib; sourceTree = "<group>"; };
DDCAB4891C263EF9005889CB /* TranscriptLineTableRowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TranscriptLineTableRowView.swift; sourceTree = "<group>"; };
DDCC5D711AF1518A00F24F55 /* Crashlytics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Crashlytics.framework; sourceTree = "<group>"; };
DDCC5D741AF1532600F24F55 /* GRCrashlyticsHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GRCrashlyticsHelper.h; sourceTree = "<group>"; };
DDCC5D751AF1532600F24F55 /* GRCrashlyticsHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GRCrashlyticsHelper.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -293,6 +299,7 @@
51B28F541BB62BA9001F7A6C /* VideoTableRowView.swift */,
51B28F5A1BB63F9E001F7A6C /* GridlessTableView.swift */,
DDE3A82A1BC2DD8300610FEF /* TranscriptLineTableCellView.swift */,
DDCAB4891C263EF9005889CB /* TranscriptLineTableRowView.swift */,
);
name = TableView;
sourceTree = "<group>";
Expand Down Expand Up @@ -402,6 +409,34 @@
name = Products;
sourceTree = "<group>";
};
DDCAB4641C26206D005889CB /* Transcript */ = {
isa = PBXGroup;
children = (
DD92EAAA1AE9795900D503AE /* TranscriptWindowController.swift */,
DDCAB46C1C2620BE005889CB /* TranscriptViewController.swift */,
);
name = Transcript;
sourceTree = "<group>";
};
DDCAB46A1C26207A005889CB /* Main Window */ = {
isa = PBXGroup;
children = (
DD4F6E701AE2D1C60099BEB5 /* VideoDetailsViewController.swift */,
DD4F6E531AE2D11D0099BEB5 /* VideosViewController.swift */,
);
name = "Main Window";
sourceTree = "<group>";
};
DDCAB46B1C26208D005889CB /* Playback */ = {
isa = PBXGroup;
children = (
DDC049CE1AE564F20008D41A /* PDFWindowController.swift */,
DD2016731AE411C800DD8155 /* VideoWindowController.swift */,
DDCAB4641C26206D005889CB /* Transcript */,
);
name = Playback;
sourceTree = "<group>";
};
DDCC5D731AF1530800F24F55 /* Crashlytics */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -429,11 +464,8 @@
DDD7A42E1AE2DEDD000A0102 /* Main Controllers */ = {
isa = PBXGroup;
children = (
DD4F6E701AE2D1C60099BEB5 /* VideoDetailsViewController.swift */,
DD4F6E531AE2D11D0099BEB5 /* VideosViewController.swift */,
DD2016731AE411C800DD8155 /* VideoWindowController.swift */,
DDC049CE1AE564F20008D41A /* PDFWindowController.swift */,
DD92EAAA1AE9795900D503AE /* TranscriptWindowController.swift */,
DDCAB46B1C26208D005889CB /* Playback */,
DDCAB46A1C26207A005889CB /* Main Window */,
C913E99B1AED21FB00EBC693 /* DownloadListWindowController.swift */,
DD2CC38D1AF419F500FC5F68 /* PreferencesWindowController.swift */,
);
Expand All @@ -460,6 +492,7 @@
DDD7A4301AE2DEFD000A0102 /* Resources */ = {
isa = PBXGroup;
children = (
DDCAB46D1C2620BE005889CB /* TranscriptViewController.xib */,
DDBD18641BC3227B00EF7718 /* FilterBarController.xib */,
DDE3A8221BC2DCEC00610FEF /* TranscriptSearchResultsController.xib */,
DD2CC38E1AF419F500FC5F68 /* PreferencesWindowController.xib */,
Expand Down Expand Up @@ -670,6 +703,7 @@
DD945EE01B26A72900CE7B7D /* LiveEventBannerViewController.xib in Resources */,
DDBD18661BC3227B00EF7718 /* FilterBarController.xib in Resources */,
DD92EAAD1AE9795900D503AE /* TranscriptWindowController.xib in Resources */,
DDCAB46F1C2620BE005889CB /* TranscriptViewController.xib in Resources */,
DD829F221AF271DF00B5977B /* index.json in Resources */,
DD4F6E591AE2D11D0099BEB5 /* Main.storyboard in Resources */,
DD4F6E771AE2D82A0099BEB5 /* VideosHeaderViewController.xib in Resources */,
Expand Down Expand Up @@ -720,6 +754,7 @@
DDCC5D761AF1532600F24F55 /* GRCrashlyticsHelper.m in Sources */,
DD4F6E541AE2D11D0099BEB5 /* VideosViewController.swift in Sources */,
DD2016061AE3FA6600DD8155 /* SessionProgressView.swift in Sources */,
DDCAB48A1C263EF9005889CB /* TranscriptLineTableRowView.swift in Sources */,
DDE3A82B1BC2DD8300610FEF /* TranscriptLineTableCellView.swift in Sources */,
C913E99C1AED21FB00EBC693 /* DownloadListWindowController.swift in Sources */,
DD945ED91B26A42300CE7B7D /* LiveEventBannerViewController.swift in Sources */,
Expand All @@ -739,6 +774,7 @@
1C967BAA1AE7EB27003662B2 /* NSString+QualifierSearchParser.m in Sources */,
DD2016781AE4141900DD8155 /* ArrayExtensions.swift in Sources */,
DD76C0181BBF83C10056BB20 /* SlidesDownloader.swift in Sources */,
DDCAB46E1C2620BE005889CB /* TranscriptViewController.swift in Sources */,
51B28F5B1BB63F9E001F7A6C /* GridlessTableView.swift in Sources */,
DD3081781AF3DC370009D412 /* DTFolderMonitor.m in Sources */,
DDF80A661AE88B6F004BE8E2 /* DownloadProgressViewController.swift in Sources */,
Expand Down
8 changes: 2 additions & 6 deletions WWDC/FilterBarController.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9046" systemVersion="15A284" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9046"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="FilterBarController" customModule="WWDC" customModuleProvider="target">
Expand All @@ -24,7 +24,6 @@
<subviews>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="KGp-29-lNn" customClass="GRSegmentedControl">
<rect key="frame" x="266" y="10" width="230" height="24"/>
<animations/>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectAny" id="sVr-a0-c4I" customClass="GRSegmentedCell">
<font key="font" metaFont="system"/>
<segments>
Expand All @@ -49,7 +48,6 @@
<constraints>
<constraint firstAttribute="height" constant="1" id="rkv-2a-onc"/>
</constraints>
<animations/>
</customView>
</subviews>
<constraints>
Expand All @@ -59,7 +57,6 @@
<constraint firstAttribute="trailing" secondItem="Tf8-Nm-opu" secondAttribute="trailing" id="rc2-xo-eZn"/>
<constraint firstItem="Tf8-Nm-opu" firstAttribute="leading" secondItem="c4U-fZ-wmN" secondAttribute="leading" id="teL-0U-JaF"/>
</constraints>
<animations/>
</visualEffectView>
</subviews>
<constraints>
Expand All @@ -68,7 +65,6 @@
<constraint firstAttribute="trailing" secondItem="c4U-fZ-wmN" secondAttribute="trailing" id="HeP-4w-egM"/>
<constraint firstItem="c4U-fZ-wmN" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" id="yh3-LB-oJH"/>
</constraints>
<animations/>
<point key="canvasLocation" x="302.5" y="389"/>
</customView>
<menu id="mil-Bl-w7a">
Expand Down
25 changes: 24 additions & 1 deletion WWDC/TranscriptLineTableCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ import Cocoa

class TranscriptLineTableCellView: NSTableCellView {

@IBOutlet weak private var playButton: NSButton!
@IBOutlet weak private var playButton: NSButton?
@IBOutlet weak private var summaryLabel: NSTextField!

var selected = false {
didSet {
setNeedsDisplayInRect(bounds)
}
}

var foregroundColor: NSColor?
var font: NSFont?

var playCallback: ((startTime: Double) -> Void)?

var line: TranscriptLine? {
Expand All @@ -29,6 +38,20 @@ class TranscriptLineTableCellView: NSTableCellView {
private func updateUI() {
guard let line = self.line else { return }
summaryLabel.stringValue = line.text

summaryLabel.textColor = foregroundColor
summaryLabel.font = font
summaryLabel.cell?.backgroundStyle = NSBackgroundStyle.Light
}

override func setNeedsDisplayInRect(invalidRect: NSRect) {
super.setNeedsDisplayInRect(invalidRect)

if selected {
summaryLabel.textColor = NSColor.blackColor()
} else {
summaryLabel.textColor = foregroundColor
}
}

}
32 changes: 32 additions & 0 deletions WWDC/TranscriptLineTableRowView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// TranscriptLineTableRowView.swift
// WWDC
//
// Created by Guilherme Rambo on 19/12/15.
// Copyright © 2015 Guilherme Rambo. All rights reserved.
//

import Cocoa

class TranscriptLineTableRowView: NSTableRowView {

override func drawSelectionInRect(dirtyRect: NSRect) {
NSColor.whiteColor().setFill()
NSRectFill(dirtyRect)
}

override var selected: Bool {
didSet {
updateSubviewsInterestedInSelectionState()
}
}

private func updateSubviewsInterestedInSelectionState() {
guard subviews.count > 0 else { return }

if let cell = subviews[0] as? TranscriptLineTableCellView {
cell.selected = selected
}
}

}
102 changes: 102 additions & 0 deletions WWDC/TranscriptViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// TranscriptViewController.swift
// WWDC
//
// Created by Guilherme Rambo on 19/12/15.
// Copyright © 2015 Guilherme Rambo. All rights reserved.
//

import Cocoa

class TranscriptViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource {

var session: Session!
var jumpToTimeCallback: (time: Double) -> () = { _ in }

var font: NSFont? {
didSet {
tableView.reloadData()
}
}
var textColor: NSColor? {
didSet {
tableView.reloadData()
}
}
var backgroundColor: NSColor? {
didSet {
guard let backgroundColor = backgroundColor else { return }
tableView.backgroundColor = backgroundColor
}
}

@IBOutlet weak private var tableView: NSTableView!

private struct Storyboard {
static let cellIdentifier = "transcriptCell"
static let rowIdentifier = "rowView"
}

init(session: Session) {
self.session = session
super.init(nibName: "TranscriptViewController", bundle: nil)!
}

required init?(coder: NSCoder) {
self.session = nil
super.init(coder: coder)
}

override func viewDidLoad() {
super.viewDidLoad()

tableView.setDelegate(self)
tableView.setDataSource(self)

tableView.target = self
tableView.doubleAction = Selector("doubleClickedLine:")
}

func highlightLineAt(roundedTimecode: String) {
guard let lines = session.transcript?.lines else { return }

let result = lines.filter { Transcript.roundedStringFromTimecode($0.timecode) == roundedTimecode }

guard let row = lines.indexOf(result[0]) where result.count > 0 else { return }

tableView.selectRowIndexes(NSIndexSet(index: row), byExtendingSelection: false)
tableView.scrollRowToVisible(row)
}

// MARK: - TableView

func numberOfRowsInTableView(tableView: NSTableView) -> Int {
return session.transcript!.lines.count
}

func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? {
let cell = tableView.makeViewWithIdentifier(Storyboard.cellIdentifier, owner: tableView) as! TranscriptLineTableCellView

cell.foregroundColor = textColor
cell.font = font
cell.line = session.transcript!.lines[row]

return cell
}

func tableView(tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
return tableView.makeViewWithIdentifier(Storyboard.rowIdentifier, owner: tableView) as? NSTableRowView
}

func tableView(tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
guard let font = font else { return 17.0 }

return font.pointSize * 2
}

func doubleClickedLine(sender: AnyObject?) {
let line = session.transcript!.lines[tableView.clickedRow]
jumpToTimeCallback(time: line.timecode)
}

}
Loading

0 comments on commit 6b18c27

Please sign in to comment.