Skip to content

Commit

Permalink
Sudeta data
Browse files Browse the repository at this point in the history
Idetas Movie Share
  • Loading branch information
abackys committed Oct 2, 2012
1 parent aaa5fd1 commit 2f1220f
Show file tree
Hide file tree
Showing 53 changed files with 806 additions and 109 deletions.
224 changes: 183 additions & 41 deletions scanorama.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions scanorama/Database.xcdatamodeld/Database.xcdatamodel/contents
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
<attribute name="fullImage" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="group" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="moviedescription" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="movieId" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="music" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="screenplay" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="thumbImage" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="title" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="titleEn" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="titleNative" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="videoUrl" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="schedule" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Schedule" inverseName="movie" inverseEntity="Schedule" syncable="YES"/>
</entity>
<entity name="Schedule" representedClassName="Schedule" syncable="YES">
Expand All @@ -29,7 +31,7 @@
<relationship name="movie" optional="YES" minCount="1" maxCount="1" deletionRule="Nullify" destinationEntity="Movies" inverseName="schedule" inverseEntity="Movies" syncable="YES"/>
</entity>
<elements>
<element name="Movies" positionX="160" positionY="192" width="128" height="330"/>
<element name="Schedule" positionX="-83" positionY="198" width="128" height="105"/>
<element name="Movies" positionX="160" positionY="192" width="128" height="360"/>
<element name="Schedule" positionX="-117" positionY="201" width="128" height="105"/>
</elements>
</model>
22 changes: 12 additions & 10 deletions scanorama/Movies.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Movies.h
// scanorama
//
// Created by Lion User on 18/09/2012.
// Created by Lion User on 01/10/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

Expand All @@ -13,24 +13,26 @@

@interface Movies : NSManagedObject

@property (nonatomic, retain) NSString * cast;
@property (nonatomic, retain) NSString * cinematography;
@property (nonatomic, retain) NSString * country;
@property (nonatomic, retain) NSString * createdYear;
@property (nonatomic, retain) NSString * director;
@property (nonatomic, retain) NSString * directorDescription;
@property (nonatomic, retain) NSString * directorFilms;
@property (nonatomic, retain) NSString * duration;
@property (nonatomic, retain) NSString * editing;
@property (nonatomic, retain) NSString * fullImage;
@property (nonatomic, retain) NSString * group;
@property (nonatomic, retain) NSString * moviedescription;
@property (nonatomic, retain) NSString * movieId;
@property (nonatomic, retain) NSString * music;
@property (nonatomic, retain) NSString * screenplay;
@property (nonatomic, retain) NSString * thumbImage;
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * titleEn;
@property (nonatomic, retain) NSString * titleNative;
@property (nonatomic, retain) NSString * country;
@property (nonatomic, retain) NSString * screenplay;
@property (nonatomic, retain) NSString * cinematography;
@property (nonatomic, retain) NSString * editing;
@property (nonatomic, retain) NSString * music;
@property (nonatomic, retain) NSString * cast;
@property (nonatomic, retain) NSString * moviedescription;
@property (nonatomic, retain) NSString * directorDescription;
@property (nonatomic, retain) NSString * directorFilms;
@property (nonatomic, retain) NSString * videoUrl;
@property (nonatomic, retain) NSSet *schedule;
@end

Expand Down
22 changes: 12 additions & 10 deletions scanorama/Movies.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Movies.m
// scanorama
//
// Created by Lion User on 18/09/2012.
// Created by Lion User on 01/10/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

Expand All @@ -12,24 +12,26 @@

@implementation Movies

@dynamic cast;
@dynamic cinematography;
@dynamic country;
@dynamic createdYear;
@dynamic director;
@dynamic directorDescription;
@dynamic directorFilms;
@dynamic duration;
@dynamic editing;
@dynamic fullImage;
@dynamic group;
@dynamic moviedescription;
@dynamic movieId;
@dynamic music;
@dynamic screenplay;
@dynamic thumbImage;
@dynamic title;
@dynamic titleEn;
@dynamic titleNative;
@dynamic country;
@dynamic screenplay;
@dynamic cinematography;
@dynamic editing;
@dynamic music;
@dynamic cast;
@dynamic moviedescription;
@dynamic directorDescription;
@dynamic directorFilms;
@dynamic videoUrl;
@dynamic schedule;

@end
2 changes: 2 additions & 0 deletions scanorama/SCAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>

@interface SCAppDelegate : UIResponder <UIApplicationDelegate>

Expand All @@ -15,6 +16,7 @@
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (strong, nonatomic) FBSession *sessionFb;
;

- (void)saveContext;
Expand Down
10 changes: 9 additions & 1 deletion scanorama/SCAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ @implementation SCAppDelegate
@synthesize managedObjectContext=__managedObjectContext;
@synthesize managedObjectModel=__managedObjectModel;
@synthesize persistentStoreCoordinator=__persistentStoreCoordinator;

@synthesize sessionFb = _sessionFb;

- (void)saveContext
{
Expand Down Expand Up @@ -122,6 +122,14 @@ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator
return __persistentStoreCoordinator;
}

- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [self.sessionFb handleOpenURL:url];
}

#pragma mark - Application's Documents directory

/**
Expand Down
16 changes: 16 additions & 0 deletions scanorama/SCDirectorViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// SCDirectorViewController.h
// scanorama
//
// Created by Lion User on 01/10/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "Movies.h"

@interface SCDirectorViewController : UIViewController

@property (strong, nonatomic) Movies *movieData;

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

#import "SCDirectorViewController.h"

@interface SCDirectorViewController ()

@end

@implementation SCDirectorViewController
@synthesize movieData = _movieData;


-(void) viewWillAppear:(BOOL)animated {
NSLog(@"%@", _movieData.director);
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

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

#import <UIKit/UIKit.h>
#import "Movies.h"
#import "Schedule.h"

@interface SCJsonDatabase : NSObject <NSFetchedResultsControllerDelegate>


@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;

- (void) insertMoviesJsonToDatabase;
-(void) insertScheduleJsonToDatabase;

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

#import "SCJsonDatabase.h"
#import "SCAppDelegate.h"

@implementation SCJsonDatabase


@synthesize managedObjectContext = _managedObjectContext;
@synthesize fetchedResultsController = _fetchedResultsController;

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

SCAppDelegate *app = [UIApplication sharedApplication].delegate;
_managedObjectContext = app.managedObjectContext;
}
return self;
}



-(void) insertScheduleJsonToDatabase {

NSManagedObjectContext *context = _managedObjectContext;
NSError *error;

NSString* dataPath = [[NSBundle mainBundle] pathForResource:@"schedule" ofType:@"json"];
NSArray* ScheduleArray = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:dataPath]
options:kNilOptions
error:&error];
NSLog(@"%i", [ScheduleArray count]);

[ScheduleArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSError *err;
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];


Schedule *scheduleDb = [NSEntityDescription insertNewObjectForEntityForName:@"Schedule" inManagedObjectContext:context];


// NSLog(@"%@", [obj objectForKey:@"movie"]);
NSFetchRequest *fetchMovieRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entityMovie = [NSEntityDescription
entityForName:@"Movies" inManagedObjectContext:context];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"movieId=%@", [obj objectForKey:@"movie"]];
[fetchMovieRequest setPredicate:predicate];
[fetchMovieRequest setEntity:entityMovie];

NSArray *fetchedMovie = [context executeFetchRequest:fetchMovieRequest error:&err];

if([fetchedMovie count]){
Movies *movieQuery = [fetchedMovie objectAtIndex:0];
scheduleDb.date = [df dateFromString:[obj objectForKey:@"date"]];
scheduleDb.city = [obj objectForKey:@"city"];
scheduleDb.cinema = [obj objectForKey:@"cinema"];
scheduleDb.favorite = 0;
scheduleDb.movie = movieQuery;
/*
NSMutableSet *scheduleSet = [NSMutableSet setWithSet:moviesInsert.schedule];
[scheduleSet addObject:scheduleDb];
moviesInsert.schedule = (NSSet *) [scheduleSet copy];
*/

// NSLog(@"%@",scheduleDb.movie);
}

// Movies *movieDB = [fetchedMovie objectAtIndex:0];

// NSLog(@"%@", movieDB);








// NSLog(@"%@", scheduleDb);
// failedBankInfo.word = [obj objectForKey:@"word"];
// failedBankInfo.translations = [obj objectForKey:@"trans"];

NSError *error;
if (![context save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}



}];
// NSLog(@"%@,", ScheduleArray);

}


- (void) insertMoviesJsonToDatabase{

NSManagedObjectContext *context = _managedObjectContext;

NSError* err = nil;
NSString* dataPath = [[NSBundle mainBundle] pathForResource:@"movies" ofType:@"json"];
NSArray* MoviesArray = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:dataPath]
options:kNilOptions
error:&err];

[MoviesArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
Movies *moviesDB = [NSEntityDescription insertNewObjectForEntityForName:@"Movies" inManagedObjectContext:context];

moviesDB.movieId = [obj objectForKey:@"movieId"];
moviesDB.title = [obj objectForKey:@"title"];
moviesDB.titleEn = [obj objectForKey:@"titleEn"];
moviesDB.titleNative = [obj objectForKey:@"titleNative"];
moviesDB.createdYear = [obj objectForKey:@"createdYear"];
moviesDB.director = [obj objectForKey:@"director"];
moviesDB.duration = [obj objectForKey:@"duration"];
moviesDB.fullImage = [obj objectForKey:@"fullImage"];
moviesDB.thumbImage = [obj objectForKey:@"thumbImage"];
moviesDB.country = [obj objectForKey:@"country"];
moviesDB.screenplay = [obj objectForKey:@"screenplay"];
moviesDB.cinematography = [obj objectForKey:@"cinematography"];
moviesDB.editing = [obj objectForKey:@"editing"];
moviesDB.music = [obj objectForKey:@"music"];
moviesDB.group = [obj objectForKey:@"group"];
moviesDB.cast = [obj objectForKey:@"cast"];
moviesDB.moviedescription = [obj objectForKey:@"moviedescription"];
moviesDB.directorDescription = [obj objectForKey:@"directorDescription"];
moviesDB.directorFilms = [obj objectForKey:@"directorFilms"];
moviesDB.videoUrl = @"http://www.youtube.com/embed/oHg5SJYRHA0";



NSLog(@"%i", 1);
// failedBankInfo.word = [obj objectForKey:@"word"];
// failedBankInfo.translations = [obj objectForKey:@"trans"];

NSError *error;
if (![context save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}


}];


}

@end
Loading

0 comments on commit 2f1220f

Please sign in to comment.