Skip to content

Commit

Permalink
Mano Programa patvarkyta kad favorite tarp visur butu deliojamas ns N…
Browse files Browse the repository at this point in the history
…Snotification
  • Loading branch information
abackys committed Sep 16, 2012
1 parent fbcd519 commit 11d944c
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 37 deletions.
6 changes: 6 additions & 0 deletions scanorama.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
CEB8107915FA57C300956FF7 /* SCTabBarViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CEB8107815FA57C200956FF7 /* SCTabBarViewController.m */; };
CEB8108115FA738900956FF7 /* SCMovieCell.m in Sources */ = {isa = PBXBuildFile; fileRef = CEB8108015FA738900956FF7 /* SCMovieCell.m */; };
CEBA611E15FF56090047DA80 /* Database.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = CEBA611C15FF56090047DA80 /* Database.xcdatamodeld */; };
CEBDF43B1605EEAB00571282 /* FavoriteButtonDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = CEBDF43A1605EEAB00571282 /* FavoriteButtonDelegate.m */; };
CECEA45B15FB67D500365ED3 /* Star-256.png in Resources */ = {isa = PBXBuildFile; fileRef = CECEA45915FB67D500365ED3 /* Star-256.png */; };
CECEA45C15FB67D500365ED3 /* Star-empty-256.png in Resources */ = {isa = PBXBuildFile; fileRef = CECEA45A15FB67D500365ED3 /* Star-empty-256.png */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -92,6 +93,8 @@
CEB8107F15FA738900956FF7 /* SCMovieCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SCMovieCell.h; sourceTree = "<group>"; };
CEB8108015FA738900956FF7 /* SCMovieCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SCMovieCell.m; sourceTree = "<group>"; };
CEBA611D15FF56090047DA80 /* Database.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Database.xcdatamodel; sourceTree = "<group>"; };
CEBDF4391605EEAB00571282 /* FavoriteButtonDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FavoriteButtonDelegate.h; sourceTree = "<group>"; };
CEBDF43A1605EEAB00571282 /* FavoriteButtonDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FavoriteButtonDelegate.m; sourceTree = "<group>"; };
CECEA45915FB67D500365ED3 /* Star-256.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Star-256.png"; path = "assets/icons/Star-256.png"; sourceTree = "<group>"; };
CECEA45A15FB67D500365ED3 /* Star-empty-256.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Star-empty-256.png"; path = "assets/icons/Star-empty-256.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -218,6 +221,8 @@
CE71A52015F75CF300FE4DC3 /* Supporting Files */,
CEB8107715FA57C200956FF7 /* SCTabBarViewController.h */,
CEB8107815FA57C200956FF7 /* SCTabBarViewController.m */,
CEBDF4391605EEAB00571282 /* FavoriteButtonDelegate.h */,
CEBDF43A1605EEAB00571282 /* FavoriteButtonDelegate.m */,
);
path = scanorama;
sourceTree = "<group>";
Expand Down Expand Up @@ -370,6 +375,7 @@
CE6C2C62160103B80087CED3 /* SCDateNavigator.m in Sources */,
CE6D312A1601EC3E00511AF1 /* Schedule.m in Sources */,
CE6D312F1601F24C00511AF1 /* SCConfig.m in Sources */,
CEBDF43B1605EEAB00571282 /* FavoriteButtonDelegate.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
13 changes: 13 additions & 0 deletions scanorama/FavoriteButtonDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// FavoriteButtonDelegate.h
// scanorama
//
// Created by Lion User on 16/09/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface FavoriteButtonDelegate : NSObject

@end
21 changes: 21 additions & 0 deletions scanorama/FavoriteButtonDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// FavoriteButtonDelegate.m
// scanorama
//
// Created by Lion User on 16/09/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "FavoriteButtonDelegate.h"
#import "SCMovieCell.h"
@protocol FavoriteButtonDelegate


-(void)movieCell:(SCMovieCell *)cell favoriteButtonClicked:(UIButton *)button;

@end


@implementation FavoriteButtonDelegate

@end
6 changes: 5 additions & 1 deletion scanorama/SCMovieCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <UIKit/UIKit.h>


@protocol FavoriteButtonDelegate


Expand All @@ -18,6 +19,7 @@
@interface SCMovieCell : UITableViewCell



@property (assign) id<FavoriteButtonDelegate> delegate;


Expand All @@ -26,7 +28,9 @@
@property (weak, nonatomic) IBOutlet UILabel *movieEnLabel;
@property (weak, nonatomic) IBOutlet UIButton *favoriteButton;
@property (weak, nonatomic) IBOutlet UIImageView *thumbImage;
@property (weak, nonatomic) NSString *cinema;
@property (strong, nonatomic) NSString *cinema;
@property (strong, nonatomic) NSDate *date;
@property (strong, nonatomic) NSString *city;
-(IBAction)favoriteButtonClicked:(id)sender;


Expand Down
2 changes: 2 additions & 0 deletions scanorama/SCMovieCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ @implementation SCMovieCell
@synthesize favoriteButton = _favoriteButton;
@synthesize thumbImage = _thumbImage;
@synthesize cinema = _cinema;
@synthesize city = _city;
@synthesize date = _date;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
Expand Down
5 changes: 5 additions & 0 deletions scanorama/SCMyProgramViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#import "Movies.h"
#import "SCConfig.h"
#import "SCMovieCell.h"
#import "SCScheduleViewController.h"


@interface SCMyProgramViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate, FavoriteButtonDelegate>

Expand All @@ -19,6 +21,9 @@
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
@property (strong, nonatomic) NSMutableArray *favoriteMovieArray;
@property (strong, nonatomic) SCScheduleViewController *scheduleView;
@property (strong, nonatomic) IBOutlet UITableView *myProgramTableView;




Expand Down
92 changes: 66 additions & 26 deletions scanorama/SCMyProgramViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "SCMyProgramViewController.h"
#import "SCAppDelegate.h"
#import "SCDateString.h"

@interface SCMyProgramViewController ()

Expand All @@ -19,6 +20,10 @@ @implementation SCMyProgramViewController
@synthesize config = _config;
@synthesize fetchedResultsController = _fetchedResultsController;
@synthesize favoriteMovieArray = _favoriteMovieArray;
@synthesize scheduleView = _scheduleView;
@synthesize myProgramTableView = _myProgramTableView;




- (void)viewDidLoad
Expand All @@ -37,7 +42,9 @@ - (void)viewDidLoad

- (void)viewDidUnload
{

_scheduleView = [[SCScheduleViewController alloc] init];


[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
Expand All @@ -48,14 +55,12 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void) textFieldDidBeginEditing:(UITextField *)textField {
NSLog(@"Bujawawa");
}

- (void)viewWillAppear:(BOOL)animated
{
_favoriteMovieArray = [[NSMutableArray alloc] init];
_favoriteMovieArray = [[NSMutableArray alloc] init];
[self getFavoriteMoviesArray];
[_myProgramTableView reloadData];
NSLog(@"MyProgramView");

[super viewWillAppear:animated];
Expand Down Expand Up @@ -120,56 +125,61 @@ -(void) addMoviesArrayToSectionsArrays:(NSArray *)moviesArray{
Schedule *tempSchedule = (Schedule *) [moviesArray objectAtIndex:0];
NSDate *lastDate = tempSchedule.date;
for (Schedule *scheduleData in moviesArray) {

// [_favoriteMovieArray addObject:model];


// Preparing dates for comparing YY-MM-DD only
// NSDateComponents *lastDateComp = [calendar components:flags fromDate:lastDate];
// NSDate lastDate = [calendar dateFromComponents:lastDateComp];

lastDateInt = [calendar ordinalityOfUnit:NSDayCalendarUnit inUnit:NSEraCalendarUnit forDate:lastDate];
currentDateInt = [calendar ordinalityOfUnit:NSDayCalendarUnit inUnit:NSEraCalendarUnit forDate:scheduleData.date];

// NSLog(@"%i currentDate: %i",lastDateInt, currentDateInt);
if(currentDateInt != lastDateInt){
NSLog(@"Last date %@ , CurrentDate: %@", lastDate, scheduleData.date);
NSLog(@"%i", sectionArray.count);

[_favoriteMovieArray addObject: [sectionArray copy]];
NSLog(@"SectionArray %i", [sectionArray count]);
// NSLog(@"SectionArray %i", [sectionArray count]);
[sectionArray removeAllObjects];
}
[sectionArray addObject:scheduleData];
lastDate = scheduleData.date;

}
NSLog(@"SectionArray %i", [sectionArray count]);

[_favoriteMovieArray addObject:[sectionArray copy] ];

for(NSMutableArray *array in _favoriteMovieArray){
NSLog(@"QQQQQ%i", [array count]);
}
NSLog(@"Favorite Array : %i", _favoriteMovieArray.count);


}

-(void)movieCell:(UITableViewCell *)cell favoriteButtonClicked:(UIButton *)button {
SCMovieCell *movieCell = (SCMovieCell *)cell;

NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:!button.selected] forKey:@"favoriteButton"];

[[NSNotificationCenter defaultCenter] postNotificationName:@"changeFavoriteValue" object:movieCell userInfo:dict];


// NSLog(@"%@", movieCell.timeLabel.text);
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
Schedule * scheduleData = [[_favoriteMovieArray objectAtIndex:section ] firstObject ];
SCDateString *dateString = [[SCDateString alloc] initWithPredefinedData];

return [dateString getDateStringsByDate:scheduleData.date].dateStringLt;

}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

NSLog(@"EWEWEWEWEWEWE: %i", _favoriteMovieArray.count);
// Return the number of sections.
return _favoriteMovieArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

// Return the number of rows in the section.
// NSLog(@"WEWEWE: %@", [_favoriteMovieArray lastObject]);
for(NSMutableArray *array in _favoriteMovieArray){
NSLog(@"%i", [array count]);
}

NSArray *sectionData = (NSArray *) [_favoriteMovieArray objectAtIndex:section ];
NSLog(@"NumberOFrow: %i at section: %i", sectionData.count, section);
Expand All @@ -178,14 +188,44 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// NSLog(@"%@", [indexPath ]);
NSLog(@"MyPqqqrogramView");
NSDateFormatter * hours_minutes = [[NSDateFormatter alloc ] init ];
[hours_minutes setDateFormat:@"HH:mm"];

NSArray *sectionArray = [_favoriteMovieArray objectAtIndex:indexPath.section];
Schedule * schedule = [sectionArray objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"MovieCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
SCMovieCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

cell.delegate = self;
cell.movieLabel.text = schedule.movie.title;
cell.movieEnLabel.text = schedule.movie.titleEn;
cell.favoriteButton.selected = [schedule.favorite boolValue];
cell.timeLabel.text = [ hours_minutes stringFromDate:schedule.date];
cell.thumbImage.image = [UIImage imageNamed:schedule.movie.thumbImage];
cell.cinema = schedule.cinema;
cell.city = schedule.city;
cell.date = schedule.date;


// Configure the cell...

return cell;
}

-(IBAction)toggleFavorite:(UIButton *)sender {
// NSLog(@"%@",[sender parentViewController]);
if(sender.selected){
sender.selected = NO;
}
else {
sender.selected = YES;
}
}



/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
Expand Down
3 changes: 2 additions & 1 deletion scanorama/SCScheduleViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ NSFetchedResultsControllerDelegate, FavoriteButtonDelegate>
- (IBAction)nextDay:(id)sender;
- (IBAction)previousDay:(id)sender;
-(void) disableDateNavigationButtons;

-(NSDate *) combineDateWithTime:(NSDate *)selectedDate movieTime:(NSString *)movieTime;
-(void) insertFavoriteToDatabase:(NSDate *)date byCity:(NSString *)city byCinema:(NSString *)cinema favoriteState:(NSNumber *)favorite;

@property (weak, nonatomic) IBOutlet UITableView *scheduleTableView;

Expand Down
29 changes: 22 additions & 7 deletions scanorama/SCScheduleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ - (void)viewDidLoad
{

// [self configureView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeFavoriteNotification:) name:@"changeFavoriteValue" object:nil];

_dateString = [[SCDateString alloc] initWithPredefinedData];

Expand Down Expand Up @@ -238,16 +239,15 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
-(void)movieCell:(UITableViewCell *)cell favoriteButtonClicked:(UIButton *)button {
SCMovieCell *movieCell = (SCMovieCell *)cell;
// NSLog(@"selected: %@", [NSNumber numberWithBool:button.selected]);
NSDate * movieDate = [self combineDateWithTime: _dateString.getCurrentDate.date movieTime:movieCell.timeLabel.text];
NSDate * movieDate = [self combineDateWithTime: movieCell.date movieTime:movieCell.timeLabel.text];

[self insertFavoriteToDatabase:movieDate byCity:[_config getCityName] byCinema:movieCell.cinema favoriteState:[NSNumber numberWithBool:!button.selected]];
[self insertFavoriteToDatabase:movieDate byCity:movieCell.city byCinema:movieCell.cinema favoriteState:[NSNumber numberWithBool:!button.selected]];


NSLog(@"%@", movieDate);

}

-(void) insertFavoriteToDatabase:(NSDate *)date byCity:(NSString *)city byCinema:(NSString *)cinema favoriteState:(NSNumber *)favorite{

NSLog(@"Favorite: BUJAKAKAKAK");
NSError *error;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

Expand All @@ -262,7 +262,7 @@ -(void) insertFavoriteToDatabase:(NSDate *)date byCity:(NSString *)city byCinema


Schedule *scheduleRow = [[context executeFetchRequest:fetchRequest error:&error] lastObject];
NSLog(@"%@", scheduleRow.favorite);
NSLog(@"Favorite: %@", scheduleRow.favorite);
scheduleRow.favorite = favorite;

error = nil;
Expand All @@ -275,6 +275,16 @@ -(void) insertFavoriteToDatabase:(NSDate *)date byCity:(NSString *)city byCinema

}

-(void)changeFavoriteNotification:(NSNotification *)pNotification {
SCMovieCell *movieCell = [pNotification object];

NSNumber *favorite = [[pNotification userInfo] valueForKey:@"favoriteButton"];
[self insertFavoriteToDatabase:movieCell.date byCity:movieCell.city byCinema:movieCell.cinema favoriteState:favorite];
NSLog(@"%@", favorite);
// NSLog(@"wwew %@", (NSString*) [pNotification object]);

}


-(NSDate *) combineDateWithTime:(NSDate *)selectedDate movieTime:(NSString *)movieTime{

Expand Down Expand Up @@ -315,6 +325,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.timeLabel.text = [ hours_minutes stringFromDate:schedule.date];
cell.thumbImage.image = [UIImage imageNamed:schedule.movie.thumbImage];
cell.cinema = schedule.cinema;
cell.city = schedule.city;

cell.date = schedule.date;

//cell.favoriteButton.selected = [movieData.inFavorite boolValue];

Expand All @@ -332,6 +345,7 @@ -(IBAction)toggleFavorite:(UIButton *)sender {
else {
sender.selected = YES;
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeFavoriteValue" object:nil];
}


Expand Down Expand Up @@ -362,7 +376,8 @@ -(NSMutableArray *) getMoviesByDateAndCity:(NSDate *)startDate endDate:(NSDate *
[_ScheduleArray addObject:model];

}

Schedule *schedule = [_ScheduleArray lastObject];
NSLog(@"%@",schedule.date);
return [NSMutableArray arrayWithArray:fetchedObjects];
}

Expand Down
Loading

0 comments on commit 11d944c

Please sign in to comment.