-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Bunn/list_gists
List gists
- Loading branch information
Showing
25 changed files
with
859 additions
and
18 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
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
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
22 changes: 22 additions & 0 deletions
22
macGist/Assets.xcassets/lock_closed.imageset/Contents.json
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,22 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "lock_closed.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "lock_closed@2x.png", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions
22
macGist/Assets.xcassets/lock_opened.imageset/Contents.json
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,22 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "lock_opened.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "lock_opened@2x.png", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,41 @@ | ||
// | ||
// Gist.swift | ||
// macGist | ||
// | ||
// Created by Fernando Bunn on 21/11/2017. | ||
// Copyright © 2017 Fernando Bunn. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Gist: Codable { | ||
let url: URL | ||
let identifier: String | ||
let publicItem: Bool | ||
let createdAt: Date | ||
let updatedAt: Date | ||
let description: String | ||
let htmlURL: URL | ||
|
||
/* | ||
GitHub API returns the files inside a dictionary with dynamic keys instead of an array | ||
the files property is a mapping one to one to the API, which is an object that contains multiple objects | ||
gistFiles is just a flatMap on files to access the files as an array. | ||
This can probably be improved at encoding time, but I decided to mantain the GitHub API structure for now. | ||
*/ | ||
private let files: GistFiles | ||
var gistFiles : [GistFile] { | ||
return files.gists.flatMap{$0} | ||
} | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case url | ||
case description | ||
case identifier = "id" | ||
case publicItem = "public" | ||
case createdAt = "created_at" | ||
case updatedAt = "updated_at" | ||
case htmlURL = "html_url" | ||
case files | ||
} | ||
} |
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,65 @@ | ||
// | ||
// GistCell.swift | ||
// macGist | ||
// | ||
// Created by Fernando Bunn on 09/01/2018. | ||
// Copyright © 2018 Fernando Bunn. All rights reserved. | ||
// | ||
// | ||
|
||
import Cocoa | ||
|
||
class GistCell: NSTableCellView { | ||
@IBOutlet private weak var titleLabel: NSTextField! | ||
@IBOutlet private weak var subtitleLabel: NSTextField! | ||
@IBOutlet private weak var lockImageView: NSImageView! | ||
|
||
static var dateFormatter: DateFormatter = { | ||
var dateFormatter = DateFormatter() | ||
dateFormatter.dateStyle = .short | ||
dateFormatter.timeStyle = .short | ||
return dateFormatter | ||
}() | ||
|
||
var selected: Bool = false { | ||
didSet { | ||
if oldValue != selected { | ||
setupColors() | ||
} | ||
} | ||
} | ||
var gist: Gist? { | ||
didSet { | ||
if let gist = gist { | ||
if gist.description.count == 0 { | ||
if let file = gist.gistFiles.first { | ||
titleLabel.stringValue = file.name | ||
} | ||
} else { | ||
titleLabel.stringValue = gist.description | ||
} | ||
|
||
subtitleLabel.stringValue = "Created at: \(GistCell.dateFormatter.string(from: gist.createdAt))" | ||
lockImageView.image = gist.publicItem ? #imageLiteral(resourceName: "lock_opened") : #imageLiteral(resourceName: "lock_closed") | ||
|
||
setupColors() | ||
} | ||
} | ||
} | ||
|
||
private func setupColors() { | ||
if selected { | ||
titleLabel.textColor = .white | ||
subtitleLabel.textColor = .white | ||
lockImageView.image = lockImageView.image?.tinting(with: .white) | ||
} else { | ||
titleLabel.textColor = .darkGray | ||
subtitleLabel.textColor = .darkGray | ||
lockImageView.image = lockImageView.image?.tinting(with: .darkGray) | ||
} | ||
} | ||
|
||
override func draw(_ dirtyRect: NSRect) { | ||
super.draw(dirtyRect) | ||
} | ||
} |
Oops, something went wrong.