Skip to content

Commit

Permalink
Patvarkyti share my program ir movie,
Browse files Browse the repository at this point in the history
  • Loading branch information
abackys committed Oct 2, 2012
1 parent 2f1220f commit 7658a7c
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 98 deletions.
18 changes: 18 additions & 0 deletions SCErrors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// SCErrors.h
// scanorama
//
// Created by Lion User on 02/10/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface SCErrors : NSObject

- (void)showAlert:(NSString *)message
result:(id)result
error:(NSError *)error;


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

#import "SCErrors.h"

@implementation SCErrors


- (void)showAlert:(NSString *)message
result:(id)result
error:(NSError *)error {

NSString *alertMsg;
NSString *alertTitle;
if (error) {
alertMsg = error.localizedDescription;
alertTitle = @"Klaida";
} else {

alertMsg = message;
alertTitle = @"Pasidalinta";
}

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:alertTitle
message:alertMsg
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}


@end
6 changes: 6 additions & 0 deletions scanorama.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
CE00F36B1600D6A30084C702 /* SCDate.m in Sources */ = {isa = PBXBuildFile; fileRef = CE00F36A1600D6A30084C702 /* SCDate.m */; };
CE683449161B48B300F8F0E7 /* SCErrors.m in Sources */ = {isa = PBXBuildFile; fileRef = CE683448161B48B300F8F0E7 /* SCErrors.m */; };
CE69AE21161A167A00C07A37 /* FacebookSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE69AE20161A167A00C07A37 /* FacebookSDK.framework */; };
CE69AE24161A168D00C07A37 /* FacebookSDKResources.bundle in Resources */ = {isa = PBXBuildFile; fileRef = CE69AE23161A168D00C07A37 /* FacebookSDKResources.bundle */; };
CE69AE26161A169C00C07A37 /* Accounts.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE69AE25161A169C00C07A37 /* Accounts.framework */; };
Expand Down Expand Up @@ -80,6 +81,8 @@
/* Begin PBXFileReference section */
CE00F3691600D6A30084C702 /* SCDate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SCDate.h; sourceTree = "<group>"; };
CE00F36A1600D6A30084C702 /* SCDate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SCDate.m; sourceTree = "<group>"; };
CE683447161B48B300F8F0E7 /* SCErrors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SCErrors.h; path = ../SCErrors.h; sourceTree = "<group>"; };
CE683448161B48B300F8F0E7 /* SCErrors.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SCErrors.m; path = ../SCErrors.m; sourceTree = "<group>"; };
CE69AE20161A167A00C07A37 /* FacebookSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FacebookSDK.framework; path = ../../../Documents/FacebookSDK/FacebookSDK.framework; sourceTree = "<group>"; };
CE69AE23161A168D00C07A37 /* FacebookSDKResources.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; name = FacebookSDKResources.bundle; path = ../../../Documents/FacebookSDK/FacebookSDK.framework/Versions/A/Resources/FacebookSDKResources.bundle; sourceTree = "<group>"; };
CE69AE25161A169C00C07A37 /* Accounts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accounts.framework; path = System/Library/Frameworks/Accounts.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -294,6 +297,8 @@
CE71A51F15F75CF300FE4DC3 /* scanorama */ = {
isa = PBXGroup;
children = (
CE683447161B48B300F8F0E7 /* SCErrors.h */,
CE683448161B48B300F8F0E7 /* SCErrors.m */,
CE6D312C1601F22C00511AF1 /* Utility */,
CE6C9F8215FF43C400BEE44A /* CoreData.framework */,
CE6C9F4715FF3C2400BEE44A /* CoreData */,
Expand Down Expand Up @@ -514,6 +519,7 @@
CEC3166B160B50AD001DD984 /* SCJsonDatabase.m in Sources */,
CE6C40821619B2DC005FB90E /* Movies.m in Sources */,
CE6C40C51619C198005FB90E /* SCDirectorViewController.m in Sources */,
CE683449161B48B300F8F0E7 /* SCErrors.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
3 changes: 3 additions & 0 deletions scanorama/SCAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>


@interface SCAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
Expand All @@ -22,4 +23,6 @@
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;



@end
4 changes: 2 additions & 2 deletions scanorama/SCAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ - (BOOL)application:(UIApplication *)application
return [self.sessionFb handleOpenURL:url];
}



#pragma mark - Application's Documents directory

/**
Expand All @@ -142,8 +144,6 @@ - (NSURL *)applicationDocumentsDirectory





- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

Expand Down
1 change: 1 addition & 0 deletions scanorama/SCMovieDescriptionViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
@property (weak, nonatomic) IBOutlet UITextView *scheduleTextView;
- (void)shareMovie;
- (IBAction)shareMovieButtonClicked:(id)sender;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *shareMovieButton;

@end
25 changes: 12 additions & 13 deletions scanorama/SCMovieDescriptionViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
#import "SCMovieDescriptionViewController.h"
#import "SCDirectorViewController.h"
#import "SCAppDelegate.h"
#import "SCErrors.h"


@implementation SCMovieDescriptionViewController
@synthesize shareMovieButton = _shareMovieButton;

@synthesize movieData = _movieData;

Expand All @@ -27,7 +29,7 @@ @implementation SCMovieDescriptionViewController
- (void)viewWillAppear:(BOOL)animated {

UIImage *promoImg = [UIImage imageNamed:_movieData.fullImage];

_shareMovieButton.enabled = TRUE;
CGRect rect = _scheduleTextView.frame;
CGRect descriptionRect = _movieDescriptionTextView.frame;
CGRect bottomRect = _bottomView.frame;
Expand Down Expand Up @@ -174,6 +176,7 @@ - (void)viewDidUnload
[self setMovieMetaTextView:nil];
[self setHeaderImage:nil];
[self setScheduleTextView:nil];
[self setShareMovieButton:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
Expand All @@ -194,12 +197,15 @@ - (void)shareMovie {

NSString *message = [NSString stringWithFormat:@"Scanorama Europos šalių kino forumas\n %@(%@)\n %@\n", _movieData.title, _movieData.titleNative, _movieData.moviedescription];
NSLog(@"%@", message);

_shareMovieButton.enabled = FALSE;
[FBRequestConnection startForPostStatusUpdate:message
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

SCErrors *showError = [[SCErrors alloc] init];
[showError showAlert:[NSString stringWithFormat:@"Jūs pasidalinote \"%@\" su savo draugais", _movieData.title ] result:result error:error];

NSLog(@"%@", error);
}];

}];
}

- (IBAction)shareMovieButtonClicked:(id)sender {
Expand All @@ -209,11 +215,7 @@ - (IBAction)shareMovieButtonClicked:(id)sender {
if(!appDelegate.sessionFb.isOpen){

NSLog(@"Viduj");
// NSLog(@"%@", [[FBSession activeSession] accessToken]);
// appDelegate.sessionFb = [[FBSession alloc] init];

// if([FBSession activeSession].state != FBSessionStateCreated){


appDelegate.sessionFb = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObject:@"status_update"]];
// NSLog(@"viduj vidujss");

Expand All @@ -222,10 +224,7 @@ - (IBAction)shareMovieButtonClicked:(id)sender {
NSLog(@"Open WIth CompletionnHeader%@", [session accessToken]);
[self shareMovie];
} ];
// }
// else { [self shareMovie]; }
// [FBSession setActiveSession:appDelegate.sessionFb];
//

}
else {
[self shareMovie];
Expand Down
2 changes: 2 additions & 0 deletions scanorama/SCMyProgramViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "SCConfig.h"
#import "SCMovieCell.h"
#import "SCScheduleViewController.h"
#import "SCErrors.h"


@interface SCMyProgramViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate, FavoriteButtonDelegate>
Expand All @@ -25,6 +26,7 @@
@property (strong, nonatomic) IBOutlet UITableView *myProgramTableView;
- (IBAction)shareMyProgramCliked:(id)sender;

@property (weak, nonatomic) IBOutlet UIBarButtonItem *shareProgramButton;



Expand Down
69 changes: 61 additions & 8 deletions scanorama/SCMyProgramViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ @interface SCMyProgramViewController ()
@end

@implementation SCMyProgramViewController
@synthesize shareProgramButton = _shareProgramButton;

@synthesize managedObjectContext = _managedObjectContext;
@synthesize config = _config;
Expand Down Expand Up @@ -46,6 +47,7 @@ - (void)viewDidUnload
_scheduleView = [[SCScheduleViewController alloc] init];


[self setShareProgramButton:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
Expand All @@ -62,7 +64,9 @@ - (void)viewWillAppear:(BOOL)animated
self.tabBarController.title = @"Mano Programa";

_favoriteMovieArray = [[NSMutableArray alloc] init];
[self getFavoriteMoviesArray];
NSArray *fetchedFavoriteArray = [self getFavoriteMoviesArray];
if([fetchedFavoriteArray count])
[self addMoviesArrayToSectionsArrays:fetchedFavoriteArray];
[_myProgramTableView reloadData];


Expand All @@ -85,18 +89,13 @@ - (void)viewDidDisappear:(BOOL)animated
}


-(void) getFavoriteMoviesArray{
-(NSArray *) getFavoriteMoviesArray{


NSError *error;

NSManagedObjectContext *context = _managedObjectContext;


NSSortDescriptor *sortByDate = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:TRUE];



NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription
Expand All @@ -110,6 +109,10 @@ -(void) getFavoriteMoviesArray{
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
// NSLog(@"fetched: %i",[fetchedObjects count ]);
if([fetchedObjects count])
return fetchedObjects;
else {
return nil;
}
[self addMoviesArrayToSectionsArrays:fetchedObjects];


Expand Down Expand Up @@ -176,7 +179,12 @@ -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteg

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

if(_favoriteMovieArray.count)
_shareProgramButton.enabled = TRUE;
else {
_shareProgramButton.enabled = FALSE;
}

// Return the number of sections.
return _favoriteMovieArray.count;
}
Expand Down Expand Up @@ -289,6 +297,51 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*/
}


-(void) shareMyProgram{
NSString *message = @"Filmus kuriuos noriu pamatyti per Europos šalių kino forumą - Scanorama:\n";
NSArray *fetchedFavoriteArray = [self getFavoriteMoviesArray];
for (Schedule *scheduleData in fetchedFavoriteArray) {
message = [message stringByAppendingFormat:@"%@ (%@)\n", scheduleData.movie.title, scheduleData.movie.titleNative];

NSLog(@"%@", scheduleData.movie.title);
}

NSLog(@"%@", message);
_shareProgramButton.enabled = FALSE;
[FBRequestConnection startForPostStatusUpdate:message
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

SCErrors *errorAlert = [[SCErrors alloc] init];
[errorAlert showAlert:@"Jūs pasidalinote repertuaru su draugais" result:result error:error];
}];

}


- (IBAction)shareMyProgramCliked:(id)sender {


SCAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSLog(@"qqqq%@", [NSNumber numberWithBool:appDelegate.sessionFb.isOpen]);
if(!appDelegate.sessionFb.isOpen){

NSLog(@"Viduj");

appDelegate.sessionFb = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObject:@"status_update"]];
// NSLog(@"viduj vidujss");

[appDelegate.sessionFb openWithCompletionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[FBSession setActiveSession:appDelegate.sessionFb];
NSLog(@"Open WIth CompletionnHeader%@", [session accessToken]);
[self shareMyProgram];
} ];

}
else {
[self shareMyProgram];
}


}
@end
Binary file removed scanorama/assets/icons/Star-256.png
Binary file not shown.
Binary file removed scanorama/assets/icons/Star-empty-256.png
Binary file not shown.
Binary file removed scanorama/assets/icons/tabbar/46-movie.png
Binary file not shown.
Binary file removed scanorama/assets/icons/tabbar/light_list.png
Binary file not shown.
Loading

0 comments on commit 7658a7c

Please sign in to comment.