Skip to content

Commit

Permalink
Merge pull request #2 from GusGA/develop
Browse files Browse the repository at this point in the history
Primera versión estable
  • Loading branch information
GusGA committed Jul 28, 2014
2 parents 1e7b921 + 9de278e commit 1665269
Show file tree
Hide file tree
Showing 17 changed files with 1,377 additions and 518 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/Pods
Podfile.lock
3 changes: 3 additions & 0 deletions Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
platform :osx, '10.9'

pod 'AFNetworking', '~> 2.0'
1,606 changes: 1,124 additions & 482 deletions lechuga-status-bar.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lechuga-status-bar.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "0"
version = "2.0">
</Bucket>
26 changes: 13 additions & 13 deletions lechuga-status-bar/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5023" systemVersion="13A603" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5023"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand All @@ -13,7 +13,7 @@
<customObject id="-3" userLabel="Application"/>
<customObject id="Voe-Tx-rLC" customClass="GGLAppDelegate">
<connections>
<outlet property="window" destination="QvC-M9-y7g" id="gIp-Ho-8D9"/>
<outlet property="statusMenu" destination="m6K-4F-ijn" id="SLx-1s-78g"/>
</connections>
</customObject>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
Expand Down Expand Up @@ -666,15 +666,15 @@
</menuItem>
</items>
</menu>
<window title="lechuga-status-bar" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="335" y="390" width="480" height="360"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1028"/>
<view key="contentView" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
<autoresizingMask key="autoresizingMask"/>
</view>
</window>
<menu id="m6K-4F-ijn">
<items>
<menuItem title="Actualizar Precios" id="niu-KD-eku">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="jsonConsola:" target="Voe-Tx-rLC" id="G2c-b7-vao"/>
</connections>
</menuItem>
</items>
</menu>
</objects>
</document>
5 changes: 4 additions & 1 deletion lechuga-status-bar/GGLAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

@interface GGLAppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;
@property (readwrite, retain) IBOutlet NSMenu *statusMenu;
@property (readwrite, retain) NSStatusItem *statusItem;


- (IBAction)jsonConsola:(id)sender;
@end
106 changes: 105 additions & 1 deletion lechuga-status-bar/GGLAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,116 @@
//

#import "GGLAppDelegate.h"
#import "GGLechuga.h"

@interface GGLAppDelegate ()

@property (nonatomic, strong)GGLechuga *lechuga;

@end

@implementation GGLAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application


self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength ];

GGLechuga *lechuga = [[GGLechuga alloc] init];
self.lechuga = lechuga;

NSMenuItem *quit = [[NSMenuItem alloc] initWithTitle:@"Salir"
action:@selector(terminate:)
keyEquivalent:@""];

[self setIconImages];

[[self statusItem] setMenu:[self statusMenu]];
[[self statusItem] setHighlightMode:YES];
[self performSelector:@selector(addItems) withObject:nil afterDelay:2];
[[self statusMenu] performSelector:@selector(addItem:) withObject:quit afterDelay:2.1];


}

- (IBAction)jsonConsola:(id)sender{
[self.lechuga updateRates];
[self performSelector:@selector(updateItems) withObject:nil afterDelay:2.0];
}

- (void) updateItems {
for (NSMenuItem *item in [self.statusMenu itemArray]) {
if ([item.title isEqualToString:@"BS/USD"]){
[self updateItemsPrice:[item.submenu itemArray] WithPrices:self.lechuga.usdData];
}else if ([item.title isEqualToString:@"BS/EURO"]){
[self updateItemsPrice:[item.submenu itemArray] WithPrices:self.lechuga.euroData];
}
}
}

- (void)setIconImages{
NSImage *dollarIcon = [NSImage imageNamed:@"dollar"];
NSImage *dollarIconHighLigth = [NSImage imageNamed:@"dollar_highligth"];
[dollarIconHighLigth setTemplate:YES];
[[self statusItem] setImage:dollarIcon];
[[self statusItem] setAlternateImage:dollarIconHighLigth];
}

- (void)addItems{

NSMenuItem *bsf_usd = [[NSMenuItem alloc] init];
[bsf_usd setEnabled:YES];
[bsf_usd setTitle:@"BS/USD"];
[bsf_usd setSubmenu:[self addSubMenuWith:self.lechuga.usdData]];

NSMenuItem *bsf_euro = [[NSMenuItem alloc] init];
[bsf_euro setEnabled:YES];
[bsf_euro setTitle:@"BS/EURO"];
[bsf_euro setSubmenu:[self addSubMenuWith:self.lechuga.euroData]];

[[self statusMenu] addItem:bsf_usd];
[[self statusMenu] addItem:bsf_euro];

}

-(NSMenu *)addSubMenuWith:(NSDictionary *)dictionary {

NSMenuItem *efectivo = [[NSMenuItem alloc] init];
NSMenuItem *transferencia = [[NSMenuItem alloc] init];
NSMenuItem *sicadDos = [[NSMenuItem alloc] init];

[efectivo setEnabled:YES];
[transferencia setEnabled:YES];
[sicadDos setEnabled:YES];

NSMenu *returnMenu = [[NSMenu alloc] init];
[returnMenu addItem:efectivo];
[returnMenu addItem:transferencia];
[returnMenu addItem:sicadDos];
[self updateItemsPrice:[returnMenu itemArray] WithPrices:dictionary];
return returnMenu;

}


- (void)updateItemsPrice:(NSArray *)inArray WithPrices:(NSDictionary *)prices {
NSMutableArray *titles = [NSMutableArray arrayWithObjects:
[NSMutableString stringWithFormat:@"Efectivo Bs.F. %@",[prices objectForKey:@"efectivo"]],
[NSMutableString stringWithFormat:@"Transferencia Bs.F. %@",[prices objectForKey:@"transferencia"]],
[NSMutableString stringWithFormat:@"Sicad 2 Bs.F. %@", [prices objectForKey:@"sicad2"]], nil];
for (int i = 0; i < titles.count; i++) {
if ([titles[i] rangeOfString:@"(null)"].location != NSNotFound){
[titles[i] performSelector:@selector(stringByReplacingOccurrencesOfString:withString:)
withObject:@"(null)"
withObject:@"-"];
}

[[inArray objectAtIndex:i] performSelector:@selector(setTitle:)
withObject:[NSString stringWithString:titles[i]]];
}
}



@end
19 changes: 19 additions & 0 deletions lechuga-status-bar/GGLechuga.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// GGLechuga.h
// lechuga-status-bar
//
// Created by Gustavo Gimenez on 7/25/14.
// Copyright (c) 2014 Gustavo Gimenez. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AFHTTPSessionManager.h"

@interface GGLechuga : NSObject

@property (nonatomic, strong) NSDictionary *usdData;
@property (nonatomic, strong) NSDictionary *euroData;

- (void) jsonRequest;
- (void) updateRates;
@end
61 changes: 61 additions & 0 deletions lechuga-status-bar/GGLechuga.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// GGLechuga.m
// lechuga-status-bar
//
// Created by Gustavo Gimenez on 7/25/14.
// Copyright (c) 2014 Gustavo Gimenez. All rights reserved.
//

#import "GGLechuga.h"
#import "AFHTTPRequestOperation.h"

@interface GGLechuga ()

@property (nonatomic, strong) NSMutableDictionary *fullData;

@end

@implementation GGLechuga

#pragma mark - init

- (id) init {
self = [super init];
if (self){
[self updateRates];
}
return self;
}



- (void) updateRates {
[self jsonRequest];
[self performSelector:@selector(setCurrenciesDictionaries) withObject:nil afterDelay:2.0];
}
- (void) jsonRequest {
NSURL *url = [NSURL URLWithString:@"https://lechuga.herokuapp.com/"];
AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc]initWithRequest:[NSURLRequest
requestWithURL:url]];

[requestOperation setResponseSerializer:[AFHTTPResponseSerializer serializer]];

[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSError *err;
self.fullData = [[NSMutableDictionary alloc] initWithDictionary:[NSJSONSerialization JSONObjectWithData:responseObject options:0 error:&err]];

} failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"Oops, something went wrong: %@", [error localizedDescription]);
}];

[requestOperation start];
}


- (void)setCurrenciesDictionaries {

self.usdData = [NSDictionary dictionaryWithDictionary:[self.fullData objectForKey:@"USD"]];
self.euroData = [NSDictionary dictionaryWithDictionary:[self.fullData objectForKey:@"EUR"]];
}

@end
13 changes: 13 additions & 0 deletions lechuga-status-bar/Images.xcassets/dollar.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "dollar@2x.png"
}
],
"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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "dollar_highligth@2x.png"
}
],
"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.
28 changes: 7 additions & 21 deletions lechuga-status-bar/en.lproj/Credits.rtf
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
{\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;}
{\rtf1\ansi\ansicpg1252\cocoartf1265\cocoasubrtf210
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\paperw9840\paperh8400
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
\vieww9600\viewh8400\viewkind0
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720

\f0\b\fs24 \cf0 Engineering:
\b0 \
Some people\
\

\b Human Interface Design:
\b0 \
Some other people\
\

\b Testing:
\b0 \
Hopefully not nobody\
\

\b Documentation:
\b0 \
Whoever\
Gustavo Gim\'e9nez\
\

\b With special thanks to:
\b0 \
Mom\
}
Dolar Today\
}
2 changes: 2 additions & 0 deletions lechuga-status-bar/lechuga-status-bar-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<string>public.app-category.finance</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>LSUIElement</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2014 Gustavo Gimenez. All rights reserved.</string>
<key>NSMainNibFile</key>
Expand Down
1 change: 1 addition & 0 deletions lechuga-status-bar/main.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

//
// main.m
// lechuga-status-bar
Expand Down

0 comments on commit 1665269

Please sign in to comment.