-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afd779d
commit 5753fab
Showing
300 changed files
with
8,307 additions
and
21,788 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// AppDelegate.swift | ||
// HN | ||
// | ||
// Created by Ben Gordon on 9/8/14. | ||
// Copyright (c) 2014 bennyguitar. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import Accelerate | ||
|
||
@UIApplicationMain | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
var window: UIWindow? | ||
|
||
|
||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { | ||
// Start Loading Data | ||
HNManager.sharedManager().startSession() | ||
|
||
// Create VCs | ||
var postsVC = HNPostsViewController(nibName: BGUtils.className(HNPostsViewController.self), bundle: nil, postType: PostFilterType.Top) | ||
var postsNavVC = UINavigationController(navigationBarClass: BMYScrollableNavigationBar.self, toolbarClass: nil) | ||
postsNavVC.viewControllers = [postsVC] | ||
var navVC = HNNavigationViewController(nibName: BGUtils.className(HNNavigationViewController.self), bundle: nil) | ||
|
||
// Create MMDrawerController | ||
var drawer = MMDrawerController(centerViewController: postsNavVC, rightDrawerViewController: navVC) | ||
drawer.setMaximumRightDrawerWidth(258, animated: false, completion: nil) | ||
drawer.openDrawerGestureModeMask = MMOpenDrawerGestureMode.All | ||
drawer.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.All | ||
drawer.centerHiddenInteractionMode = MMDrawerOpenCenterInteractionMode.None | ||
|
||
|
||
// Launch | ||
window = UIWindow(frame: UIScreen.mainScreen().bounds) | ||
window!.rootViewController = drawer | ||
window!.makeKeyAndVisible() | ||
return true | ||
} | ||
|
||
func applicationWillResignActive(application: UIApplication) { | ||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | ||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. | ||
} | ||
|
||
func applicationDidEnterBackground(application: UIApplication) { | ||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. | ||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. | ||
} | ||
|
||
func applicationWillEnterForeground(application: UIApplication) { | ||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. | ||
} | ||
|
||
func applicationDidBecomeActive(application: UIApplication) { | ||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. | ||
} | ||
|
||
func applicationWillTerminate(application: UIApplication) { | ||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. | ||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
// | ||
// HNCommentsViewController.swift | ||
// HN | ||
// | ||
// Created by Ben Gordon on 9/17/14. | ||
// Copyright (c) 2014 bennyguitar. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class HNCommentsViewController: HNViewController, UITableViewDelegate, UITableViewDataSource, HNCommentsCellDelegate { | ||
@IBOutlet weak var commentsTableView: UITableView! | ||
var currentPost: HNPost? = nil | ||
var allComments: [HNComment]? = [] | ||
var topLevelHiddenIndexPaths: NSMutableIndexSet? = NSMutableIndexSet() | ||
var hiddenCommentMap: [String:Int] = Dictionary() | ||
var visibleIndexPath: NSIndexPath? = nil | ||
var didSelectIndex: Int? = 0 | ||
|
||
// MARK: - Init | ||
init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?, post: HNPost?) { | ||
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) | ||
currentPost = post! | ||
} | ||
|
||
required init(coder aDecoder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
|
||
// MARK: - VC Lifecycle | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
// UI | ||
buildUI() | ||
resetUI() | ||
menuType = .AllComments | ||
|
||
// Data | ||
loadComments() | ||
} | ||
|
||
override func viewDidAppear(animated: Bool) { | ||
super.viewDidAppear(animated) | ||
bindNavigationBarToScrollView(commentsTableView) | ||
} | ||
|
||
override func viewDidLayoutSubviews() { | ||
super.viewDidLayoutSubviews() | ||
} | ||
|
||
override func didReceiveMemoryWarning() { | ||
super.didReceiveMemoryWarning() | ||
} | ||
|
||
override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) { | ||
super.didRotateFromInterfaceOrientation(fromInterfaceOrientation) | ||
commentsTableView.reloadData() | ||
if (visibleIndexPath != nil) { | ||
commentsTableView.scrollToRowAtIndexPath(visibleIndexPath!, atScrollPosition: UITableViewScrollPosition.Top, animated: true) | ||
} | ||
} | ||
|
||
override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) { | ||
super.willRotateToInterfaceOrientation(toInterfaceOrientation, duration: duration) | ||
visibleIndexPath = commentsTableView.indexPathsForVisibleRows()!.first as? NSIndexPath | ||
} | ||
|
||
|
||
// MARK: - UI | ||
func buildUI() { | ||
commentsTableView.registerNib(UINib(nibName: BGUtils.className(HNCommentCell), bundle: nil), forCellReuseIdentifier: HNPostsCollectionCellIdentifier) | ||
commentsTableView.rowHeight = UITableViewAutomaticDimension | ||
commentsTableView.estimatedRowHeight = 72.0 | ||
commentsTableView.separatorInset = UIEdgeInsetsZero | ||
if (commentsTableView.respondsToSelector("layoutMargins")) { | ||
commentsTableView.layoutMargins = UIEdgeInsetsZero | ||
} | ||
} | ||
|
||
override func resetUI() { | ||
super.resetUI() | ||
|
||
// Table | ||
commentsTableView.separatorColor = HNTheme.currentTheme().colorForUIElement(HNTheme.ThemeUIElement.CellSeparator) | ||
commentsTableView.backgroundColor = HNTheme.currentTheme().colorForUIElement(HNTheme.ThemeUIElement.BackgroundColor) | ||
commentsTableView.reloadData() | ||
} | ||
|
||
|
||
// MARK: - Load Data | ||
func loadComments() { | ||
if (currentPost != nil) { | ||
HNManager.sharedManager().loadCommentsFromPost(currentPost, completion: {[weak self](comments) -> Void in | ||
if (comments != nil && self != nil) { | ||
var s = self! | ||
s.allComments = comments as? [HNComment] | ||
s.commentsTableView.reloadData() | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// MARK: - Table View | ||
func numberOfSectionsInTableView(tableView: UITableView) -> Int { | ||
return 1 | ||
} | ||
|
||
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return allComments!.count | ||
} | ||
|
||
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | ||
// Create Cell | ||
var cell: HNCommentCell = tableView.dequeueReusableCellWithIdentifier(HNPostsCollectionCellIdentifier, forIndexPath: indexPath) as HNCommentCell | ||
|
||
// Get Visibility | ||
let comment = allComments![indexPath.row] | ||
let v = topLevelHiddenIndexPaths!.containsIndex(indexPath.row) ? HNCommentCellVisibility.Closed : (hiddenCommentMap[comment.CommentId] != nil ? HNCommentCellVisibility.Hidden : HNCommentCellVisibility.Visible) | ||
|
||
// Return it | ||
cell.setContentWithComment(allComments![indexPath.row], indexPath: indexPath, delegate: self, visibility: v) | ||
cell.setNeedsUpdateConstraints() | ||
return cell | ||
} | ||
|
||
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { | ||
//singleCommentMenuView?.launchInView(view, launch: true) | ||
didSelectIndex = indexPath.row | ||
var options = HNManager.sharedManager().SessionUser != nil ? ["Reply", "Share", "Upvote", "Downvote"] : ["Share"] | ||
HNGridMenuView.showMenuViewWithType(.OneComment, vc: self, _delegate: self, options: options) | ||
} | ||
|
||
|
||
// MARK: - Comments Delegate | ||
func didSelectHideNested(index: Int, level: Int) { | ||
// Add or Remove from Top Level Hidden Indexes | ||
var isHiding = true | ||
if (topLevelHiddenIndexPaths!.containsIndex(index)) { | ||
isHiding = false | ||
topLevelHiddenIndexPaths!.removeIndex(index) | ||
} | ||
else { | ||
topLevelHiddenIndexPaths!.addIndex(index) | ||
} | ||
|
||
// Add or Remove from all hidden comments | ||
for (var i = index + 1; i < allComments!.count - index; i++) { | ||
// If level is the same or less, get out of this loop | ||
let comment = allComments![i] | ||
if (Int(comment.Level) <= level) { | ||
hiddenCommentMap[comment.CommentId] = nil | ||
break; | ||
} | ||
else { | ||
hiddenCommentMap[comment.CommentId] = isHiding ? 1 : nil | ||
} | ||
|
||
// Set Comment Map up | ||
//hiddenCommentMap[comment.CommentId] = isHiding ? 1 : nil | ||
} | ||
|
||
// Reload | ||
commentsTableView.reloadData() | ||
} | ||
|
||
// Grid Menu | ||
override func didSelectGridMenuOption(name: String, idx: Int, type: HNMenuType) { | ||
if (type == HNMenuType.AllComments) { | ||
if (name == "Link") { | ||
HNNavigationBrain.navigateToWebViewController(currentPost!) | ||
} | ||
else if (name == "Reply") { | ||
HNNavigationBrain.navigateToReply(currentPost, navController: navigationController!) | ||
} | ||
else if (name == "Share") { | ||
BGUtils.shareObject("https://news.ycombinator.com/item?id=\(currentPost!.PostId)", fromViewController: self) | ||
} | ||
else if (name == "Upvote Post") { | ||
BGUtils.vote(true, object: currentPost!) | ||
} | ||
} | ||
else if (type == HNMenuType.OneComment) { | ||
let comment = allComments![didSelectIndex!] as HNComment | ||
if (name == "Share") { | ||
BGUtils.shareObject(comment, fromViewController: self) | ||
} | ||
else if (name == "Upvote") { | ||
BGUtils.vote(true, object: comment) | ||
} | ||
else if (name == "Downvote") { | ||
BGUtils.vote(false, object: comment) | ||
} | ||
else if (name == "Reply") { | ||
HNNavigationBrain.navigateToReply(comment, navController: navigationController!) | ||
} | ||
} | ||
} | ||
|
||
override func didToggleActionsButton() { | ||
var options = HNManager.sharedManager().SessionUser != nil ? ["Link","Reply", "Share","Upvote Post"] : ["Link", "Share"] | ||
HNGridMenuView.showMenuViewWithType(menuType, vc: self, _delegate: self, options: options) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6245" systemVersion="14A329f" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6238"/> | ||
</dependencies> | ||
<objects> | ||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="HNCommentsViewController" customModule="HN" customModuleProvider="target"> | ||
<connections> | ||
<outlet property="commentsTableView" destination="LWr-q5-o1R" id="LvZ-ID-h5L"/> | ||
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> | ||
</connections> | ||
</placeholder> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> | ||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<subviews> | ||
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="none" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="LWr-q5-o1R"> | ||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/> | ||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> | ||
<inset key="separatorInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/> | ||
<connections> | ||
<outlet property="dataSource" destination="-1" id="LCi-N5-txl"/> | ||
<outlet property="delegate" destination="-1" id="4oF-M8-ZBy"/> | ||
</connections> | ||
</tableView> | ||
</subviews> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> | ||
<constraints> | ||
<constraint firstItem="LWr-q5-o1R" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="LLX-bM-WPk"/> | ||
<constraint firstItem="LWr-q5-o1R" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" id="ME6-ym-CCX"/> | ||
<constraint firstAttribute="trailing" secondItem="LWr-q5-o1R" secondAttribute="trailing" id="hjH-eE-VWD"/> | ||
<constraint firstAttribute="bottom" secondItem="LWr-q5-o1R" secondAttribute="bottom" id="hkK-ln-TYS"/> | ||
</constraints> | ||
</view> | ||
</objects> | ||
</document> |
Oops, something went wrong.