Skip to content

Commit

Permalink
Formatting and query fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsochantaris committed May 28, 2022
1 parent fcc2598 commit 1929c01
Show file tree
Hide file tree
Showing 87 changed files with 842 additions and 871 deletions.
23 changes: 23 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
disabled_rules:
- identifier_name
- line_length
- trailing_whitespace
- force_cast
- file_length
- function_body_length
- nesting
- type_body_length
- type_name
- function_parameter_count
- unused_setter_value
- cyclomatic_complexity
- force_try
- notification_center_detachment
- large_tuple
- inclusive_language

analyzer_rules:
- explicit_self

excluded:
- Pods
2 changes: 1 addition & 1 deletion HTTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class HTTP {

let config = URLSessionConfiguration.default
config.httpShouldUsePipelining = true
config.httpAdditionalHeaders = ["User-Agent" : userAgent]
config.httpAdditionalHeaders = ["User-Agent": userAgent]
config.urlCache = URLCache(memoryCapacity: 32 * 1024 * 1024, diskCapacity: 1024 * 1024 * 1024, diskPath: API.cacheDirectory)
return config
}
Expand Down
5 changes: 2 additions & 3 deletions PocketTrailer WatchKit Extension/CommentRow.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import WatchKit

final class CommentRow: NSObject {
Expand All @@ -9,13 +8,13 @@ final class CommentRow: NSObject {
@IBOutlet private var margin: WKInterfaceGroup!
var commentId: String?

func set(comment: [AnyHashable : Any], unreadCount: Int, unreadIndex: inout Int) {
func set(comment: [AnyHashable: Any], unreadCount: Int, unreadIndex: inout Int) {

let username = S(comment["user"] as? String)
usernameL.setText("@\(username)")
dateL.setText(shortDateFormatter.string(from: comment["date"] as! Date))
commentL.setText(comment["text"] as? String)
if(comment["mine"] as! Bool) {
if comment["mine"] as? Bool == true {
usernameBackground.setBackgroundColor(.gray)
commentL.setTextColor(.lightGray)
margin.setBackgroundColor(.darkGray)
Expand Down
10 changes: 5 additions & 5 deletions PocketTrailer WatchKit Extension/CommonController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CommonController: WKInterfaceController {
}

private var loading = 0
func send(request: [String : Any]) {
func send(request: [String: Any]) {
if loading == 0 {
if showLoadingFeedback {
show(status: "Loading…", hideTable: false)
Expand All @@ -49,11 +49,11 @@ class CommonController: WKInterfaceController {
}
}

private func attempt(request: [String : Any]) {
private func attempt(request: [String: Any]) {

loading += 1

WCSession.default.sendMessage(request, replyHandler: { [weak self] response in
WCSession.default.sendMessage(request) { [weak self] response in
guard let S = self else { return }
if let errorIndicator = response["error"] as? Bool, errorIndicator == true {
DispatchQueue.main.async {
Expand All @@ -66,7 +66,7 @@ class CommonController: WKInterfaceController {
}
S.update(from: response)
}
}) { error in
} errorHandler: { error in
DispatchQueue.main.async { [weak self] in
guard let S = self else { return }
if S.loading==5 {
Expand All @@ -89,7 +89,7 @@ class CommonController: WKInterfaceController {
}
}

func update(from response: [AnyHashable : Any]) {
func update(from response: [AnyHashable: Any]) {
// for subclassing
}

Expand Down
68 changes: 34 additions & 34 deletions PocketTrailer WatchKit Extension/ComplicationDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ final class ComplicationDataSource: NSObject, CLKComplicationDataSource {
}
}

private func processOverview(for complication: CLKComplication, _ overview: [AnyHashable : Any], _ handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
private func processOverview(for complication: CLKComplication, _ overview: [AnyHashable: Any], _ handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {

let showIssues = overview["preferIssues"] as! Bool

var prCount = 0
var issueCount = 0
var commentCount = 0
for r in overview["views"] as? [[AnyHashable : Any]] ?? [] {
if let v = r["prs"] as? [AnyHashable : Any] {
for r in overview["views"] as? [[AnyHashable: Any]] ?? [] {
if let v = r["prs"] as? [AnyHashable: Any] {
prCount += v["total_open"] as? Int ?? 0
commentCount += v["unread"] as? Int ?? 0
}
if let v = r["issues"] as? [AnyHashable : Any] {
if let v = r["issues"] as? [AnyHashable: Any] {
issueCount += v["total_open"] as? Int ?? 0
commentCount += v["unread"] as? Int ?? 0
}
Expand Down Expand Up @@ -73,22 +73,22 @@ final class ComplicationDataSource: NSObject, CLKComplicationDataSource {
}
}
}
private func constructTemplate(for complication: CLKComplication, issues: Bool, prCount: Int?, issueCount: Int?, commentCount: Int) -> CLKComplicationTemplate {

switch complication.family {
case .modularSmall:
return CLKComplicationTemplateModularSmallStackImage(
private func constructTemplate(for complication: CLKComplication, issues: Bool, prCount: Int?, issueCount: Int?, commentCount: Int) -> CLKComplicationTemplate {
switch complication.family {
case .modularSmall:
return CLKComplicationTemplateModularSmallStackImage(
line1ImageProvider: CLKImageProvider(onePieceImage: UIImage(named: issues ? "ComplicationIssues" : "ComplicationPrs")!),
line2TextProvider: CLKSimpleTextProvider(text: count(issues ? issueCount : prCount, unit: nil)))

case .modularLarge:
return CLKComplicationTemplateModularLargeStandardBody(
case .modularLarge:
return CLKComplicationTemplateModularLargeStandardBody(
headerImageProvider: CLKImageProvider(onePieceImage: UIImage(named: "ComplicationPrs")!),
headerTextProvider: CLKSimpleTextProvider(text: count(commentCount, unit: "Comment")),
body1TextProvider: CLKSimpleTextProvider(text: count(prCount, unit: "Pull Request")),
body2TextProvider: CLKSimpleTextProvider(text: count(issueCount, unit: "Issue")))

case .extraLarge:
let t = CLKComplicationTemplateExtraLargeColumnsText(
row1Column1TextProvider: CLKSimpleTextProvider(text: issues ? "Iss" : "PRs"),
Expand All @@ -99,21 +99,21 @@ final class ComplicationDataSource: NSObject, CLKComplicationDataSource {
t.highlightColumn2 = commentCount > 0
return t

case .utilitarianSmallFlat, .utilitarianSmall:
return CLKComplicationTemplateUtilitarianSmallFlat(
case .utilitarianSmallFlat, .utilitarianSmall:
return CLKComplicationTemplateUtilitarianSmallFlat(
textProvider: CLKSimpleTextProvider(text: count(issues ? issueCount : prCount, unit: nil)),
imageProvider: CLKImageProvider(onePieceImage: UIImage(named: issues ? "ComplicationIssues" : "ComplicationPrs")!))

case .utilitarianLarge:
if commentCount > 0 {
case .utilitarianLarge:
if commentCount > 0 {
return CLKComplicationTemplateUtilitarianLargeFlat(textProvider: CLKSimpleTextProvider(text: count(commentCount, unit: "New Comment")))
} else if issues {
} else if issues {
return CLKComplicationTemplateUtilitarianLargeFlat(textProvider: CLKSimpleTextProvider(text: count(issueCount, unit: "Issue")))
} else {
} else {
return CLKComplicationTemplateUtilitarianLargeFlat(textProvider: CLKSimpleTextProvider(text: count(prCount, unit: "Pull Request")))
}

case .circularSmall:
}
case .circularSmall:
return CLKComplicationTemplateCircularSmallStackImage(
line1ImageProvider: CLKImageProvider(onePieceImage: UIImage(named: issues ? "ComplicationIssues" : "ComplicationPrs")!),
line2TextProvider: CLKSimpleTextProvider(text: count(issues ? issueCount : prCount, unit: nil)))
Expand All @@ -134,8 +134,8 @@ final class ComplicationDataSource: NSObject, CLKComplicationDataSource {
textProvider: CLKSimpleTextProvider(text: count(prCount, unit: "PR")),
imageProvider: CLKFullColorImageProvider(fullColorImage: UIImage(named: issues ? "IssuesCorner" : "PrsCorner")!))
}

case .graphicBezel:
case .graphicBezel:
let textProvider: CLKSimpleTextProvider
if commentCount > 0 {
textProvider = CLKSimpleTextProvider(text: count(commentCount, unit: "New Comment"))
Expand All @@ -148,8 +148,8 @@ final class ComplicationDataSource: NSObject, CLKComplicationDataSource {
imageProvider: CLKFullColorImageProvider(fullColorImage: UIImage(named: issues ? "ComplicationIssues" : "ComplicationPrs")!)
)
return CLKComplicationTemplateGraphicBezelCircularText(circularTemplate: img, textProvider: textProvider)

case .graphicCircular:
case .graphicCircular:
let gaugeProvider: CLKSimpleGaugeProvider
let centerTextProvider: CLKSimpleTextProvider
if commentCount > 0 {
Expand All @@ -164,23 +164,23 @@ final class ComplicationDataSource: NSObject, CLKComplicationDataSource {
gaugeProvider = CLKSimpleGaugeProvider(style: .fill, gaugeColor: .white, fillFraction: 0)
}
return CLKComplicationTemplateGraphicCircularClosedGaugeText(gaugeProvider: gaugeProvider, centerTextProvider: centerTextProvider)

case .graphicRectangular:
case .graphicRectangular:
let headerTextProvider = CLKSimpleTextProvider(text: count(commentCount, unit: "Comment"))
headerTextProvider.tintColor = commentCount > 0 ? .red : .white
headerTextProvider.tintColor = commentCount > 0 ? .red : .white
return CLKComplicationTemplateGraphicRectangularStandardBody(
headerImageProvider: CLKFullColorImageProvider(fullColorImage: UIImage(named: "ComplicationPrs")!),
headerTextProvider: headerTextProvider,
body1TextProvider: CLKSimpleTextProvider(text: count(prCount, unit: "Pull Request")),
body2TextProvider: CLKSimpleTextProvider(text: count(issueCount, unit: "Issue")))

case .graphicExtraLarge:
return CLKComplicationTemplateGraphicExtraLargeCircularStackText(
line1TextProvider: CLKSimpleTextProvider(text: "\(issues ? (issueCount ?? 0) : (prCount ?? 0)) \(issues ? "Iss" : "PRs")"),
line2TextProvider: CLKSimpleTextProvider(text: commentCount == 0 ? "- Com" : "\(commentCount) Com"))

@unknown default:
abort()
}
abort()
}
}
}
3 changes: 1 addition & 2 deletions PocketTrailer WatchKit Extension/ExtensionDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

let SECTION_KEY = "INDEX_KEY"
let ITEM_KEY = "ITEM_KEY"
let TYPE_KEY = "TYPE_KEY"
Expand Down Expand Up @@ -35,7 +34,7 @@ final class ExtensionDelegate: NSObject, WKExtensionDelegate, WCSessionDelegate

func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {}

func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
func session(_ session: WCSession, didReceiveMessage message: [String: Any]) {
if message["newInfoAvailable"] as? Bool == true {
potentialUpdate()
}
Expand Down
1 change: 0 additions & 1 deletion PocketTrailer WatchKit Extension/LabelRow.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import WatchKit

final class LabelRow: NSObject {
Expand Down
11 changes: 5 additions & 6 deletions PocketTrailer WatchKit Extension/PRDetailController.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import WatchKit
import Foundation

Expand All @@ -18,7 +17,7 @@ final class PRDetailController: CommonController {
_statusLabel = statusLabel
_table = table

let c = context as! [AnyHashable : Any]
let c = context as! [AnyHashable: Any]
itemId = (c[ITEM_KEY] as! String)

super.awake(withContext: context)
Expand Down Expand Up @@ -48,7 +47,7 @@ final class PRDetailController: CommonController {
requestData(command: "openItem")
}

override func update(from response: [AnyHashable : Any]) {
override func update(from response: [AnyHashable: Any]) {
guard let compressedData = response["result"] as? Data,
let uncompressedData = compressedData.data(operation: .decompress),
let itemInfo = try? NSKeyedUnarchiver.unarchivedObject(ofClass: NSDictionary.self, from: uncompressedData)
Expand All @@ -67,15 +66,15 @@ final class PRDetailController: CommonController {
super.show(status: status, hideTable: hideTable)
}

private func completeUpdate(from itemInfo: [AnyHashable : Any]) {
private func completeUpdate(from itemInfo: [AnyHashable: Any]) {

loading = false

rowControllers.removeAll(keepingCapacity: false)

var rowCount = 0

if let statuses = itemInfo["statuses"] as? [[AnyHashable : Any]] {
if let statuses = itemInfo["statuses"] as? [[AnyHashable: Any]] {
for status in statuses {
if !(table.rowController(at: rowCount) is StatusRow) {
table.insertRows(at: IndexSet(integer: rowCount), withRowType: "StatusRow")
Expand Down Expand Up @@ -103,7 +102,7 @@ final class PRDetailController: CommonController {
rowCount += 1
}

if let comments = itemInfo["comments"] as? [[AnyHashable : Any]] {
if let comments = itemInfo["comments"] as? [[AnyHashable: Any]] {
if comments.isEmpty {
setTitle("\(comments.count) Comments")
} else {
Expand Down
11 changes: 5 additions & 6 deletions PocketTrailer WatchKit Extension/PRListController.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import WatchKit
import WatchConnectivity

Expand All @@ -20,13 +19,13 @@ final class PRListController: CommonController {
private var apiServerUri: String?

private var onlyUnread = false
private var loadingBuffer = [[AnyHashable : Any]]()
private var loadingBuffer = [[AnyHashable: Any]]()
private var loading = false
private var sleeping = false

override func awake(withContext context: Any?) {

let c = context as! [AnyHashable : Any]
let c = context as! [AnyHashable: Any]
sectionIndex = (c[SECTION_KEY] as! Int64)
type = (c[TYPE_KEY] as! String)
onlyUnread = (c[UNREAD_KEY] as! Bool)
Expand Down Expand Up @@ -112,17 +111,17 @@ final class PRListController: CommonController {
loadingBuffer.removeAll(keepingCapacity: false)
}

override func update(from response: [AnyHashable : Any]) {
override func update(from response: [AnyHashable: Any]) {
guard let compressedData = response["result"] as? Data,
let uncompressedData = compressedData.data(operation: .decompress),
let page = NSKeyedUnarchiver.unarchiveObject(with: uncompressedData) as? [[AnyHashable : Any]]
let page = NSKeyedUnarchiver.unarchiveObject(with: uncompressedData) as? [[AnyHashable: Any]]
else { return }
DispatchQueue.main.async { [weak self] in
self?.completeUpdate(from: page)
}
}

private func completeUpdate(from page: [[AnyHashable : Any]]) {
private func completeUpdate(from page: [[AnyHashable: Any]]) {

loadingBuffer.append(contentsOf: page)

Expand Down
3 changes: 1 addition & 2 deletions PocketTrailer WatchKit Extension/PRRow.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import WatchKit

final class PRRow: NSObject {
Expand All @@ -17,7 +16,7 @@ final class PRRow: NSObject {
var itemId: String?
var hasUnread: Bool!

func populate(from itemData: [AnyHashable : Any]) {
func populate(from itemData: [AnyHashable: Any]) {

let title = itemData["title"] as! NSAttributedString
titleL.setAttributedText(title)
Expand Down
Loading

0 comments on commit 1929c01

Please sign in to comment.