Skip to content

Commit

Permalink
ADD: New models indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Christos Kasketis committed Nov 27, 2015
1 parent 61f3525 commit 2a9d4dc
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Very useful and handy for network related issues and bugs

Implemented in Swift 2.1 - bridged also for Objective-C

Current version: 1.2.1
Current version: 1.3

Feel free to contribute :)

Expand Down
4 changes: 2 additions & 2 deletions netfox.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "netfox"
s.version = "1.2.1"
s.version = "1.3"
s.summary = "A lightweight, one line setup, iOS network debugging library!"

s.description = <<-DESC
Expand All @@ -11,7 +11,7 @@ DESC
s.screenshots = "https://raw.githubusercontent.com/kasketis/netfox/master/assets/overview0_2.gif"
s.license = 'MIT'
s.author = "Christos Kasketis"
s.source = { :git => "https://github.com/kasketis/netfox.git", :tag => '1.2.1' }
s.source = { :git => "https://github.com/kasketis/netfox.git", :tag => '1.3' }

s.platform = :ios, '8.0'
s.requires_arc = true
Expand Down
16 changes: 15 additions & 1 deletion netfox/NFX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import UIKit

let nfxVersion = "1.2.2"
let nfxVersion = "1.3"

@objc
public class NFX: NSObject
Expand Down Expand Up @@ -49,6 +49,7 @@ public class NFX: NSObject
private var selectedGesture: ENFXGesture = .shake
private var ignoredURLs = [String]()
private var filters = [Bool]()
private var newModels: Int = 0

@objc public func start()
{
Expand Down Expand Up @@ -168,13 +169,26 @@ public class NFX: NSObject
return
}

self.newModels = 0

presentingViewController?.dismissViewControllerAnimated(true, completion: { () -> Void in
self.presented = false
})
}

internal func newModelAdded()
{
self.newModels++
}

internal func numberOfNewModels() -> Int
{
return self.newModels
}

internal func clearOldData()
{
self.newModels = 0
NFXHTTPModelManager.sharedInstance.clear()
do {
let documentsPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true).first!
Expand Down
1 change: 1 addition & 0 deletions netfox/NFXHTTPModelManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class NFXHTTPModelManager: NSObject

func add(obj: NFXHTTPModel)
{
NFX.sharedInstance().newModelAdded()
self.models.insert(obj, atIndex: 0)
}

Expand Down
34 changes: 29 additions & 5 deletions netfox/NFXListCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class NFXListCell: UITableViewCell
var methodLabel: UILabel!
var leftSeparator: UIView!
var rightSeparator: UIView!
var circleView: UIView!


override init(style: UITableViewCellStyle, reuseIdentifier: String?)
Expand All @@ -31,7 +32,7 @@ class NFXListCell: UITableViewCell


self.statusView = UIView(frame: CGRectZero)
contentView.addSubview(statusView)
contentView.addSubview(self.statusView)

self.requestTimeLabel = UILabel(frame: CGRectZero)
self.requestTimeLabel.textAlignment = .Center
Expand Down Expand Up @@ -61,6 +62,10 @@ class NFXListCell: UITableViewCell
self.typeLabel.font = UIFont.NFXFont(11)
contentView.addSubview(self.typeLabel)

self.circleView = UIView(frame: CGRectZero)
self.circleView.backgroundColor = UIColor.NFXGray44Color()
contentView.addSubview(self.circleView)

self.leftSeparator = UIView(frame: CGRectZero)
self.leftSeparator.backgroundColor = UIColor.whiteColor()
contentView.addSubview(self.leftSeparator)
Expand All @@ -80,30 +85,49 @@ class NFXListCell: UITableViewCell

self.statusView.frame = CGRectMake(0, 0, 50, frame.height - 1)

self.requestTimeLabel.frame = CGRectMake(0, 15, CGRectGetWidth(statusView.frame), 14)
self.requestTimeLabel.frame = CGRectMake(0, 13, CGRectGetWidth(statusView.frame), 14)

self.timeIntervalLabel.frame = CGRectMake(0, CGRectGetMaxY(requestTimeLabel.frame) + 5, CGRectGetWidth(statusView.frame), 14)

self.URLLabel.frame = CGRectMake(CGRectGetMaxX(statusView.frame) + padding, 0, frame.width - CGRectGetMinX(URLLabel.frame) - padding, 40)
self.URLLabel.frame = CGRectMake(CGRectGetMaxX(statusView.frame) + padding, 0, frame.width - CGRectGetMinX(URLLabel.frame) - 25 - padding, 40)
self.URLLabel.autoresizingMask = .FlexibleWidth

self.methodLabel.frame = CGRectMake(CGRectGetMaxX(statusView.frame) + padding, CGRectGetMaxY(URLLabel.frame), 40, frame.height - CGRectGetMaxY(URLLabel.frame) - padding)

self.typeLabel.frame = CGRectMake(CGRectGetMaxX(methodLabel.frame) + padding, CGRectGetMaxY(URLLabel.frame), 180, frame.height - CGRectGetMaxY(URLLabel.frame) - padding)

self.circleView.frame = CGRectMake(CGRectGetMaxX(self.URLLabel.frame) + 5, 17, 8, 8)
self.circleView.layer.cornerRadius = 4
self.circleView.alpha = 0.2

self.leftSeparator.frame = CGRectMake(0, frame.height - 1, CGRectGetWidth(self.statusView.frame), 1)
self.rightSeparator.frame = CGRectMake(CGRectGetMaxX(self.leftSeparator.frame), frame.height - 1, frame.width - CGRectGetMaxX(self.leftSeparator.frame), 1)


}

func isNew()
{
self.circleView.hidden = false
}

func isOld()
{
self.circleView.hidden = true
}

func configForObject(obj : NFXHTTPModel)
func configForObject(obj: NFXHTTPModel, new: Bool)
{
setURL(obj.requestURL ?? "-")
setStatus(obj.responseStatus ?? 999)
setTimeInterval(obj.timeInterval ?? "-")
setRequestTime(obj.requestTime ?? "-")
setType(obj.responseType ?? "-")
setMethod(obj.requestMethod ?? "-")
if new {
isNew()
} else {
isOld()
}
}

func setURL(url : String)
Expand Down
6 changes: 4 additions & 2 deletions netfox/NFXListController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ class NFXListController: UIViewController, UITableViewDelegate, UITableViewDataS
{
let cell = self.tableView.dequeueReusableCellWithIdentifier( NSStringFromClass(NFXListCell), forIndexPath: indexPath) as! NFXListCell


if (self.searchController.active) {
let obj = self.filteredTableData[indexPath.row]
cell.configForObject(obj)
let realIndex = NFXHTTPModelManager.sharedInstance.getModels().indexOf(obj)
cell.configForObject(obj, new: realIndex < NFX.sharedInstance().numberOfNewModels())
} else {
let obj = NFXHTTPModelManager.sharedInstance.getModels()[indexPath.row]
cell.configForObject(obj)
cell.configForObject(obj, new: indexPath.row < NFX.sharedInstance().numberOfNewModels())
}

return cell
Expand Down

0 comments on commit 2a9d4dc

Please sign in to comment.