Skip to content

Commit

Permalink
refatorando #3
Browse files Browse the repository at this point in the history
  • Loading branch information
renanvs committed Mar 4, 2014
1 parent a79c2d5 commit e57d585
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 25 deletions.
12 changes: 12 additions & 0 deletions PaleoProject/PaleoProject.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
1E157B0C18C050AC00E0BC61 /* Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E157AC818C050AC00E0BC61 /* Utils.m */; };
1E56B1EF18B43DEB004E8523 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1E56B1EE18B43DEB004E8523 /* CoreData.framework */; };
1E56B20018B443E1004E8523 /* libsqlite3.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1E56B1FF18B443E1004E8523 /* libsqlite3.0.dylib */; settings = {ATTRIBUTES = (Weak, ); }; };
1E92781118C3CEBE0056B4FB /* foodItemTopCellBorder1.png in Resources */ = {isa = PBXBuildFile; fileRef = 1E92780E18C3CEBE0056B4FB /* foodItemTopCellBorder1.png */; };
1E92781218C3CEBE0056B4FB /* foodItemTopCellBorder2.png in Resources */ = {isa = PBXBuildFile; fileRef = 1E92780F18C3CEBE0056B4FB /* foodItemTopCellBorder2.png */; };
1E92781318C3CEBE0056B4FB /* foodItemTopCellBorder3.png in Resources */ = {isa = PBXBuildFile; fileRef = 1E92781018C3CEBE0056B4FB /* foodItemTopCellBorder3.png */; };
1E9DD70518B931260076F3DC /* MessageUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1E9DD70318B930790076F3DC /* MessageUI.framework */; };
1ECCC4CA18B06B7F0073992A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1ECCC4C918B06B7F0073992A /* Foundation.framework */; };
1ECCC4CC18B06B7F0073992A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1ECCC4CB18B06B7F0073992A /* CoreGraphics.framework */; };
Expand Down Expand Up @@ -253,6 +256,9 @@
1E157AC818C050AC00E0BC61 /* Utils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Utils.m; sourceTree = "<group>"; };
1E56B1EE18B43DEB004E8523 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
1E56B1FF18B443E1004E8523 /* libsqlite3.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.0.dylib; path = usr/lib/libsqlite3.0.dylib; sourceTree = SDKROOT; };
1E92780E18C3CEBE0056B4FB /* foodItemTopCellBorder1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = foodItemTopCellBorder1.png; sourceTree = "<group>"; };
1E92780F18C3CEBE0056B4FB /* foodItemTopCellBorder2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = foodItemTopCellBorder2.png; sourceTree = "<group>"; };
1E92781018C3CEBE0056B4FB /* foodItemTopCellBorder3.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = foodItemTopCellBorder3.png; sourceTree = "<group>"; };
1E9DD70318B930790076F3DC /* MessageUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MessageUI.framework; path = System/Library/Frameworks/MessageUI.framework; sourceTree = SDKROOT; };
1ECCC4C618B06B7F0073992A /* PaleoProject.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PaleoProject.app; sourceTree = BUILT_PRODUCTS_DIR; };
1ECCC4C918B06B7F0073992A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -656,6 +662,9 @@
1E157A9418C050AC00E0BC61 /* ImagesTest */ = {
isa = PBXGroup;
children = (
1E92780E18C3CEBE0056B4FB /* foodItemTopCellBorder1.png */,
1E92780F18C3CEBE0056B4FB /* foodItemTopCellBorder2.png */,
1E92781018C3CEBE0056B4FB /* foodItemTopCellBorder3.png */,
1E157A9518C050AC00E0BC61 /* categoryCellBorder.png */,
1E157A9618C050AC00E0BC61 /* defaultImage.png */,
1E157A9718C050AC00E0BC61 /* defaultMoreCellButton.png */,
Expand Down Expand Up @@ -877,6 +886,7 @@
1E157AEB18C050AC00E0BC61 /* default in Resources */,
1E157AFC18C050AC00E0BC61 /* [email protected] in Resources */,
1E157AF518C050AC00E0BC61 /* maca.jpg in Resources */,
1E92781118C3CEBE0056B4FB /* foodItemTopCellBorder1.png in Resources */,
1E157AED18C050AC00E0BC61 /* defaultImage.png in Resources */,
1E157AD018C050AC00E0BC61 /* FoodCategoryViewController.xib in Resources */,
1E157AF418C050AC00E0BC61 /* foodItemTopCellBorder.png in Resources */,
Expand Down Expand Up @@ -906,6 +916,7 @@
1E157AEE18C050AC00E0BC61 /* defaultMoreCellButton.png in Resources */,
1E157AEC18C050AC00E0BC61 /* categoryCellBorder.png in Resources */,
1E157ADD18C050AC00E0BC61 /* FoodSubcategoryHeadView.xib in Resources */,
1E92781218C3CEBE0056B4FB /* foodItemTopCellBorder2.png in Resources */,
1E157AE518C050AC00E0BC61 /* test.png in Resources */,
1E157AD418C050AC00E0BC61 /* AboutAppView.xib in Resources */,
1E157AE818C050AC00E0BC61 /* bolo1.png in Resources */,
Expand All @@ -914,6 +925,7 @@
1E157AFF18C050AC00E0BC61 /* tabBarItemSettings.png in Resources */,
1E157ACC18C050AC00E0BC61 /* FoodItemViewController.xib in Resources */,
1E157ACE18C050AC00E0BC61 /* FoodSubcategoriesViewController.xib in Resources */,
1E92781318C3CEBE0056B4FB /* foodItemTopCellBorder3.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
IBOutlet UIImageView *foodImage;
IBOutlet UILabel *foodLabel;
IBOutlet UITextView *foodAbout;
IBOutlet UIImageView *typeImageView;
FoodItemModel *foodModel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ -(void)viewWillAppear:(BOOL)animated{
foodLabel.text = foodModel.name;
foodAbout.text = foodModel.about;
[self setFavoriteImage];
[self setFoodTypeImage];
}

-(void)viewDidLoad{
Expand All @@ -53,4 +54,16 @@ -(void)setFavoriteImage{
[favoriteButton setImage:[UIImage imageNamed:favoriteImageName] forState:UIControlStateNormal];
}

-(void)setFoodTypeImage{
NSString *type = foodModel.type.name;

if ([type isEqualToString:@"Paleo"]) {
typeImageView.image = [UIImage imageNamed:@"foodItemTopCellBorder1.png"];
}else if ([type isEqualToString:@"Low-Carb"]) {
typeImageView.image = [UIImage imageNamed:@"foodItemTopCellBorder2.png"];
}else if ([type isEqualToString:@"Não LowCarb"]) {
typeImageView.image = [UIImage imageNamed:@"foodItemTopCellBorder3.png"];
}
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<outlet property="foodAbout" destination="gKN-Hg-xVa" id="SO8-YD-1Uo"/>
<outlet property="foodImage" destination="sby-cB-eEN" id="LAt-gg-xPV"/>
<outlet property="foodLabel" destination="m9C-0u-dot" id="hMe-HW-TGs"/>
<outlet property="typeImageView" destination="4Nb-gH-w7g" id="nqH-mg-tv4"/>
<outlet property="typeLabel" destination="9ia-dq-eWq" id="Fjp-DL-1Pq"/>
<outlet property="view" destination="1" id="3"/>
</connections>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ - (void)dealloc {
}

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
foodItemList = [[PaleoFoodManager sharedInstance] getFoodWithSearchQuery:searchText];
foodItemList = [[NSArray alloc ]initWithArray: [[PaleoFoodManager sharedInstance] getFoodWithSearchQuery:searchText]];
[tableView reloadData];
}

Expand Down Expand Up @@ -108,17 +108,4 @@ -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[self removeKeyboard];
}

//-(NSUInteger)supportedInterfaceOrientations{
//
// return UIInterfaceOrientationMaskPortraitUpsideDown;
//}
//
//-(BOOL)shouldAutorotate{
// return NO;
//}
//
//-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
// return UIInterfaceOrientationPortrait;
//}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

@interface FoodSubcategoryHeadView : UIView{
IBOutlet UILabel *typeLabel;
UIImageView *headBackgroundImageView;
}

@property (retain, nonatomic) IBOutlet UIImageView *headBackgroundImageView;

-(void)setTypeName:(NSString*)typeName;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
#import "FoodSubcategoryHeadView.h"

@implementation FoodSubcategoryHeadView
@synthesize headBackgroundImageView;

-(void)setTypeName:(NSString*)typeName{
typeLabel.text = typeName;
}


- (void)dealloc {
[headBackgroundImageView release];
[super dealloc];
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="1" customClass="FoodSubcategoryHeadView">
<rect key="frame" x="0.0" y="0.0" width="320" height="40"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="60"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="foodItemTopCellBorder.png" id="hFd-qn-6Zn">
<rect key="frame" x="0.0" y="0.0" width="320" height="40"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<rect key="frame" x="0.0" y="20" width="320" height="40"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
</imageView>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="CNS-aD-51j">
<rect key="frame" x="20" y="5" width="280" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" heightSizable="YES"/>
<rect key="frame" x="20" y="25" width="280" height="30"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<connections>
<outlet property="headBackgroundImageView" destination="hFd-qn-6Zn" id="wyy-We-Bnm"/>
<outlet property="typeLabel" destination="CNS-aD-51j" id="VFY-dm-P8U"/>
</connections>
</view>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
-(NSArray *)getFoodListByCategory:(FoodCategoryModel*)categoryModel;
-(NSArray*)getFoodTypeListWithFoodList:(NSArray*)list;
-(NSDictionary*)getDictionaryWithFoodTypeList:(NSArray*)typeList_ AndFoodList:(NSArray*)foodList;
-(FoodItemModel*)findFoodItemByIndex:(NSIndexPath*)index AtList:(NSArray*)list;

@end
31 changes: 25 additions & 6 deletions PaleoProject/PaleoProject/PaleoFoodManager/PaleoFoodManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ -(NSArray *)getFavoriteFoodList{
}

-(NSArray *)getFoodWithSearchQuery:(NSString*)query{
if ([query isEqualToString:@"*"]) {
return [self getAllFoodItens];
}

query = [[Utils sharedInstance] getSafeLiteralString:query];
NSEntityDescription *entity = [NSEntityDescription entityForName:EntityFood inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = entity;
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
request.sortDescriptors = [NSArray arrayWithObject:descriptor];
NSArray *list = [context executeFetchRequest:request error:nil];

NSMutableArray *foundedItens = [[NSMutableArray alloc] init];
NSRange range;

NSArray *list = [self getAllFoodItens];

for (FoodItemModel *foodItem in list) {
NSString *foodName = [[Utils sharedInstance] getSafeLiteralString:foodItem.name];
range = [foodName rangeOfString:query];
Expand All @@ -95,6 +95,16 @@ -(NSArray *)getFoodWithSearchQuery:(NSString*)query{
return foundedItens;
}

-(NSArray *)getAllFoodItens{
NSEntityDescription *entity = [NSEntityDescription entityForName:EntityFood inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = entity;
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
request.sortDescriptors = [NSArray arrayWithObject:descriptor];
NSArray *list = [context executeFetchRequest:request error:nil];
return list;
}

-(NSArray *)getTypeList{
NSEntityDescription *entity = [NSEntityDescription entityForName:EntityType inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
Expand Down Expand Up @@ -144,4 +154,13 @@ -(NSArray *)favoriteFoodList{
return [self getFavoriteFoodList];
}

-(FoodItemModel*)findFoodItemByIndex:(NSIndexPath*)index AtList:(NSArray*)list{
NSArray *type = [self getFoodTypeListWithFoodList:list];
NSDictionary *dic = [self getDictionaryWithFoodTypeList:type AndFoodList:list];
NSString *keyDesire = [[dic allKeys] objectAtIndex:index.section];
FoodItemModel *currentFood = [[dic objectForKey:keyDesire] lastObject];

return currentFood;
}

@end
5 changes: 5 additions & 0 deletions PaleoProject/PaleoProject/Utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#import <Foundation/Foundation.h>

#define debugAlert(message) \
[Utils debugAlert:(message)]

@interface Utils : NSObject

+ (Utils *) sharedInstance;
Expand All @@ -18,6 +21,8 @@

+(UIInterfaceOrientation)getDeviceOrientation;

+(void)debugAlert:(NSString*)message;

@end

@interface NSString (custom)
Expand Down
4 changes: 4 additions & 0 deletions PaleoProject/PaleoProject/Utils/Utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ +(UIInterfaceOrientation)getDeviceOrientation{
return interfaceOrientation;
}

+(void)debugAlert:(NSString*)message{
[[[[UIAlertView alloc] initWithTitle:@"Debbug" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil] autorelease]show];
}

@end

@implementation UIView (Additions)
Expand Down
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e57d585

Please sign in to comment.