Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
merge status, fixes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Nystrom committed Jun 29, 2017
1 parent c081818 commit 1de117b
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 22 deletions.
3 changes: 1 addition & 2 deletions Classes/Issues/Closed/IssueClosedCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ final class IssueClosedCell: UICollectionViewCell {
]
label.attributedText = NSAttributedString(string: model.actor, attributes: actorAttributes)

button.setStatusIcon(pullRequest: model.pullRequest, closed: model.closed)
button.setBackgroundColor(closed: model.closed)
button.config(pullRequest: model.pullRequest, status: model.closed ? .closed : .open)
button.setTitle(model.closed ? Strings.closed : Strings.reopened, for: .normal)

dateLabel.setText(date: model.date)
Expand Down
4 changes: 4 additions & 0 deletions Classes/Issues/Issue+IssueType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ extension IssueOrPullRequestQuery.Data.Repository.IssueOrPullRequest.AsIssue: Is
return fragments.closableFields
}

var merged: Bool {
return false
}

func timelineViewModels(width: CGFloat) -> [ListDiffable] {
var results = [ListDiffable]()

Expand Down
15 changes: 15 additions & 0 deletions Classes/Issues/IssueStatus.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// IssueStatus.swift
// Freetime
//
// Created by Ryan Nystrom on 6/28/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//

import Foundation

enum IssueStatus: Int {
case closed
case open
case merged
}
1 change: 1 addition & 0 deletions Classes/Issues/IssueType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protocol IssueType {
var commentFields: CommentFields { get }
var reactionFields: ReactionFields { get }
var closableFields: ClosableFields { get }
var merged: Bool { get }

func timelineViewModels(width: CGFloat) -> [ListDiffable]
}
3 changes: 2 additions & 1 deletion Classes/Issues/IssueViewModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ func createViewModels(

var result = [ListDiffable]()

result.append(IssueStatusModel(closed: issue.closableFields.closed, pullRequest: issue.pullRequest))
let status: IssueStatus = issue.merged ? .merged : issue.closableFields.closed ? .closed : .open
result.append(IssueStatusModel(status: status, pullRequest: issue.pullRequest))
result.append(titleStringSizing(title: issue.title, width: width))
result.append(IssueLabelsModel(labels: issue.labelableFields.issueLabelModels))

Expand Down
12 changes: 9 additions & 3 deletions Classes/Issues/Status/IssueStatusCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ final class IssueStatusCell: UICollectionViewCell, ListBindable {
func bindViewModel(_ viewModel: Any) {
guard let viewModel = viewModel as? IssueStatusModel else { return }

button.setBackgroundColor(closed: viewModel.closed)
button.setStatusIcon(pullRequest: viewModel.pullRequest, closed: viewModel.closed)
button.setTitle(viewModel.closed ? Strings.closed : Strings.open, for: .normal)
button.config(pullRequest: viewModel.pullRequest, status: viewModel.status)

let title: String
switch viewModel.status {
case .closed: title = Strings.closed
case .open: title = Strings.open
case .merged: title = Strings.merged
}
button.setTitle(title, for: .normal)
}

}
8 changes: 4 additions & 4 deletions Classes/Issues/Status/IssueStatusModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import IGListKit

final class IssueStatusModel: ListDiffable {

let closed: Bool
let status: IssueStatus
let pullRequest: Bool

init(closed: Bool, pullRequest: Bool) {
self.closed = closed
init(status: IssueStatus, pullRequest: Bool) {
self.status = status
self.pullRequest = pullRequest
}

Expand All @@ -28,7 +28,7 @@ final class IssueStatusModel: ListDiffable {
func isEqual(toDiffableObject object: ListDiffable?) -> Bool {
if self === object { return true }
guard let object = object as? IssueStatusModel else { return false }
return closed == object.closed && pullRequest == object.pullRequest
return status == object.status && pullRequest == object.pullRequest
}

}
1 change: 1 addition & 0 deletions Classes/Views/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ struct Strings {
static let closed = NSLocalizedString("Closed", comment: "")
static let reopened = NSLocalizedString("Reopened", comment: "")
static let unknown = NSLocalizedString("Unknown", comment: "")
static let merged = NSLocalizedString("Merged", comment: "")

}
1 change: 1 addition & 0 deletions Classes/Views/Styles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct Styles {
static let green = "28a745"
static let red = "cb2431"
static let background = "ffffff"
static let purple = "6f42c1"

struct Blue {
static let medium = "0366d6"
Expand Down
28 changes: 17 additions & 11 deletions Classes/Views/UIButton+Label.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@ extension UIButton {
contentEdgeInsets = UIEdgeInsets(top: 2, left: Styles.Sizes.columnSpacing + 2, bottom: 2, right: 4)
}

func setStatusIcon(pullRequest: Bool, closed: Bool) {
func config(pullRequest: Bool, status: IssueStatus) {

let prName = "git-pull-request-small"
let iconName: String
if closed {
iconName = !pullRequest ? "issue-closed-small" : prName
} else {
iconName = !pullRequest ? "issue-opened-small" : prName
}
setImage(UIImage(named: iconName)?.withRenderingMode(.alwaysTemplate), for: .normal)
}

func setBackgroundColor(closed: Bool) {
backgroundColor = closed ? Styles.Colors.red.color : Styles.Colors.green.color
let icon: String
let color: UIColor
switch status {
case .closed:
icon = pullRequest ? prName : "issue-closed-small"
color = Styles.Colors.red.color
case .open:
icon = pullRequest ? prName : "issue-opened-small"
color = Styles.Colors.green.color
case .merged:
icon = "git-merge-small"
color = Styles.Colors.purple.color
}
setImage(UIImage(named: icon)?.withRenderingMode(.alwaysTemplate), for: .normal)
backgroundColor = color
}

}
4 changes: 4 additions & 0 deletions Freetime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
290D2A3D1F044CB20082E6CC /* UIViewController+SmartDeselection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290D2A3C1F044CB20082E6CC /* UIViewController+SmartDeselection.swift */; };
290D2A3F1F0466820082E6CC /* NotificationNavigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290D2A3E1F0466820082E6CC /* NotificationNavigation.swift */; };
290D2A421F04D3470082E6CC /* IssueStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290D2A411F04D3470082E6CC /* IssueStatus.swift */; };
291F99D71EFFFA2600CFBF78 /* SettingsReportSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291F99D61EFFFA2600CFBF78 /* SettingsReportSectionController.swift */; };
292484B81F01CB5C0054FE20 /* SwipeCellKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 292484B71F01CB5C0054FE20 /* SwipeCellKit.framework */; };
292484B91F01CB5C0054FE20 /* SwipeCellKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 292484B71F01CB5C0054FE20 /* SwipeCellKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -461,6 +462,7 @@
2161D42FE580EF8B85D6834C /* Pods-Freetime.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Freetime.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Freetime/Pods-Freetime.debug.xcconfig"; sourceTree = "<group>"; };
290D2A3C1F044CB20082E6CC /* UIViewController+SmartDeselection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+SmartDeselection.swift"; sourceTree = "<group>"; };
290D2A3E1F0466820082E6CC /* NotificationNavigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationNavigation.swift; sourceTree = "<group>"; };
290D2A411F04D3470082E6CC /* IssueStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueStatus.swift; sourceTree = "<group>"; };
291F99D61EFFFA2600CFBF78 /* SettingsReportSectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsReportSectionController.swift; sourceTree = "<group>"; };
292484B71F01CB5C0054FE20 /* SwipeCellKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwipeCellKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
292FCACA1EDFCC510026635E /* IssueCommentCodeBlockCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueCommentCodeBlockCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -665,6 +667,7 @@
292FCAE81EDFCC510026635E /* IssueState.swift */,
292FCAE91EDFCC510026635E /* IssuesViewController.swift */,
294563EF1EE5036A00DBCD35 /* IssueType.swift */,
290D2A411F04D3470082E6CC /* IssueStatus.swift */,
292FCAEA1EDFCC510026635E /* IssueViewModels.swift */,
29FB942A1EE750720016E6D4 /* Labeled */,
292FCAEC1EDFCC510026635E /* Labels */,
Expand Down Expand Up @@ -1697,6 +1700,7 @@
2949674E1EF9719300B1CF1A /* IssueCommentHrCell.swift in Sources */,
2963A9321EE1EBE20066509C /* UIMenuController+Reactions.swift in Sources */,
29A1950C1EC7901400C3E289 /* NotificationType.swift in Sources */,
290D2A421F04D3470082E6CC /* IssueStatus.swift in Sources */,
29A195041EC74C4800C3E289 /* Date+Display.swift in Sources */,
295840DA1EEA07E4007723C6 /* IssueCommentQuoteCell.swift in Sources */,
29A195131EC7AD2D00C3E289 /* RepoNotificationsSectionController.swift in Sources */,
Expand Down
22 changes: 22 additions & 0 deletions Resources/Assets.xcassets/git-merge-small.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "git-merge-small@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "git-merge-small@3x.png",
"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.
2 changes: 1 addition & 1 deletion Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>126</string>
<string>127</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>org-appextension-feature-password-management</string>
Expand Down
4 changes: 4 additions & 0 deletions gql/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ public final class IssueOrPullRequestQuery: GraphQLQuery {
" ...nodeFields" +
" number" +
" title" +
" merged" +
" }" +
" }" +
" }" +
Expand Down Expand Up @@ -729,6 +730,8 @@ public final class IssueOrPullRequestQuery: GraphQLQuery {
public let number: Int
/// Identifies the pull request title.
public let title: String
/// Whether or not the pull request was merged.
public let merged: Bool

public let fragments: Fragments

Expand All @@ -737,6 +740,7 @@ public final class IssueOrPullRequestQuery: GraphQLQuery {
timeline = try reader.value(for: Field(responseName: "timeline", arguments: ["first": reader.variables["page_size"]]))
number = try reader.value(for: Field(responseName: "number"))
title = try reader.value(for: Field(responseName: "title"))
merged = try reader.value(for: Field(responseName: "merged"))

let reactionFields = try ReactionFields(reader: reader)
let commentFields = try CommentFields(reader: reader)
Expand Down
1 change: 1 addition & 0 deletions gql/IssueOrPullRequest.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ query IssueOrPullRequest($owner: String!, $repo: String!, $number: Int!, $page_s
...nodeFields
number
title
merged
}
}
}
Expand Down

0 comments on commit 1de117b

Please sign in to comment.