Kaydet (Commit) 1c8ad3b4 authored tarafından siqi's avatar siqi

asynchronsly load image into slideshow

üst 98ae2b23
......@@ -51,7 +51,7 @@
[[NSNotificationCenter defaultCenter] postNotificationName:MSG_SLIDE_CHANGED object:[NSNumber numberWithUnsignedInt:currentSlide]];
} else if ([instruction isEqualToString:@"slideshow_finished"]){
NSLog(@"Interpreter: slideshow_started");
NSLog(@"Interpreter: slideshow_finished");
self.slideShow = [[SlideShow alloc] init];
[[NSNotificationCenter defaultCenter] postNotificationName:STATUS_CONNECTED_NOSLIDESHOW object:nil];
} else {
......
......@@ -12,6 +12,7 @@
@class Client;
@class Server;
@class CommandInterpreter;
@class CommandTransmitter;
@class SlideShow;
#define MSG_SLIDESHOW_STARTED @"SLIDESHOW_STARTED"
......@@ -57,5 +58,8 @@ enum ConnectionState : NSInteger {
@property ConnectionState state;
@property (nonatomic, strong) id delegate;
@property (nonatomic, strong) CommandInterpreter* interpreter;
@property (nonatomic, strong) CommandTransmitter* transmitter;
+ (CommunicationManager *)sharedComManager;
@end
......@@ -19,7 +19,6 @@
@interface CommunicationManager()
@property (nonatomic, strong) Client* client;
@property (nonatomic, strong) CommandTransmitter* transmitter;
@property (atomic, strong) NSMutableSet* servers;
@property (nonatomic, strong) id connectionConnectedObserver;
@property (nonatomic, strong) id connectionDisconnectedObserver;
......
......@@ -15,7 +15,7 @@
@property uint size;
@property uint currentSlide;
@property (nonatomic, strong) id delegate;
@property (nonatomic, strong) slideShowViewController* delegate;
- (void) putImage: (NSString *)img AtIndex: (uint) index;
- (void) putNotes: (NSString *)notes AtIndex: (uint) index;
......
......@@ -14,8 +14,12 @@
@interface SlideShow()
@property (nonatomic, strong) NSMutableArray* imagesArray;
@property (nonatomic, strong) NSMutableArray* notesArray;
@property (nonatomic, strong) NSMutableDictionary* imagesDictionary;
@property (nonatomic, strong) NSMutableDictionary* notesDictionary;
@property int lastRequestedImage, lastRequestedNote;
@property (nonatomic, strong) id slideShowImageReadyObserver;
@property (nonatomic, strong) id slideShowNoteReadyObserver;
@end
......@@ -29,37 +33,80 @@ dispatch_queue_t backgroundQueue;
- (SlideShow *) init{
self = [super init];
self.imagesArray = [[NSMutableArray alloc] init];
self.notesArray = [[NSMutableArray alloc] init];
self.imagesDictionary = [[NSMutableDictionary alloc] init];
self.notesDictionary = [[NSMutableDictionary alloc] init];
_size = 0;
_currentSlide = 0;
backgroundQueue = dispatch_queue_create("org.libreoffice.iosremote.bgqueue", NULL);
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
self.slideShowImageReadyObserver =[[NSNotificationCenter defaultCenter]
addObserverForName:@"storage_update_image_ready"
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
if ([[[note userInfo] objectForKey:@"index"] intValue] == self.lastRequestedImage) {
[self.delegate.image setImage:[self getImageAtIndex:self.lastRequestedImage]];
self.lastRequestedImage = -1;
}
}];
self.slideShowNoteReadyObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"storage_update_note_ready"
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
if ([[[note userInfo] objectForKey:@"index"] intValue] == self.lastRequestedNote) {
[self.delegate.lecturer_notes loadHTMLString:[self getNotesAtIndex:self.lastRequestedNote] baseURL:nil];
self.lastRequestedNote = -1;
}
}];
return self;
}
- (void) putImage: (NSString *)img AtIndex: (uint) index{
NSData* data = [NSData dataWithBase64String:img];
UIImage* image = [UIImage imageWithData:data];
[self.imagesArray insertObject:image atIndex:index];
[[NSNotificationCenter defaultCenter] postNotificationName:@"IMAGE_READY" object:nil];
// NSLog(@"Put Image into %u", index);
dispatch_async(backgroundQueue, ^(void) {
NSData* data = [NSData dataWithBase64String:img];
UIImage* image = [UIImage imageWithData:data];
[self.imagesDictionary setObject:image forKey:[NSNumber numberWithUnsignedInt:index]];
[[NSNotificationCenter defaultCenter] postNotificationName:@"storage_update_image_ready"
object:nil
userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:index] forKey:@"index"]];
});
}
- (void) putNotes: (NSString *)notes AtIndex: (uint) index{
[self.notesArray insertObject:notes atIndex:index];
[[NSNotificationCenter defaultCenter] postNotificationName:@"NOTE_READY" object:nil];
// NSLog(@"Put note into %u", index);
[self.notesDictionary setObject:notes forKey:[NSNumber numberWithUnsignedInt:index]];
[[NSNotificationCenter defaultCenter] postNotificationName:@"storage_update_note_ready"
object:nil
userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:index] forKey:@"index"]];
}
- (UIImage *) getImageAtIndex: (uint) index
{
return [self.imagesArray objectAtIndex:index];
if (![self.imagesDictionary objectForKey:[NSNumber numberWithUnsignedInt:index]]) {
self.lastRequestedImage = index;
return nil;
}
else{
self.lastRequestedImage = -1;
return [self.imagesDictionary objectForKey:[NSNumber numberWithUnsignedInt:index]];
}
}
- (NSString *) getNotesAtIndex: (uint) index
{
return [self.notesArray objectAtIndex:index];
if (![self.notesDictionary objectForKey:[NSNumber numberWithUnsignedInt:index]]) {
self.lastRequestedNote = index;
return nil;
}
else {
self.lastRequestedNote = -1;
return [self.notesDictionary objectForKey:[NSNumber numberWithUnsignedInt:index]];
}
}
......
......@@ -9,7 +9,7 @@
<objects>
<viewController id="2" customClass="libreoffice_sdremoteViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="5">
<rect key="frame" x="0.0" y="64" width="768" height="960"/>
<rect key="frame" x="0.0" y="64" width="768" height="916"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="192.168.0.22" borderStyle="roundedRect" minimumFontSize="17" id="9w1-Ym-HcF">
......@@ -28,6 +28,13 @@
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<toolbarItems>
<barButtonItem title="Start Presentation" id="R1W-H8-kVN">
<connections>
<action selector="startPresentation:" destination="2" id="D8F-FY-mIu"/>
</connections>
</barButtonItem>
</toolbarItems>
<navigationItem key="navigationItem" id="7ye-Vv-ZD0">
<barButtonItem key="rightBarButtonItem" title="Connect" id="ZJB-Ei-Sa9">
<connections>
......@@ -35,6 +42,7 @@
</connections>
</barButtonItem>
</navigationItem>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="ipAddressTextEdit" destination="9w1-Ym-HcF" id="hab-JH-3Lf"/>
<outlet property="pinLabel" destination="Cg3-f5-zuM" id="HaU-jr-8oJ"/>
......@@ -126,22 +134,36 @@
<objects>
<viewController id="zdX-BL-bmY" customClass="slideShowViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Tkv-NW-1bl">
<rect key="frame" x="0.0" y="64" width="768" height="960"/>
<rect key="frame" x="0.0" y="64" width="768" height="916"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" id="T6z-xu-j8h">
<rect key="frame" x="14" y="20" width="741" height="442"/>
<rect key="frame" x="14" y="20" width="741" height="398"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</imageView>
<webView contentMode="scaleToFill" id="y0E-Wp-yUc">
<rect key="frame" x="20" y="513" width="728" height="378"/>
<rect key="frame" x="20" y="487.5" width="728" height="359.5"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</webView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" id="uc0-p3-wnG"/>
<toolbarItems>
<barButtonItem title="Previous" id="fEE-h8-5be">
<connections>
<action selector="previousSlide:" destination="zdX-BL-bmY" id="DMr-Rh-WfD"/>
</connections>
</barButtonItem>
</toolbarItems>
<navigationItem key="navigationItem" id="uc0-p3-wnG">
<barButtonItem key="rightBarButtonItem" title="Next" id="502-Fp-Hjs">
<connections>
<action selector="nextSlide:" destination="zdX-BL-bmY" id="YU1-0k-qPi"/>
</connections>
</barButtonItem>
</navigationItem>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="image" destination="T6z-xu-j8h" id="o1L-LM-TbP"/>
<outlet property="lecturer_notes" destination="y0E-Wp-yUc" id="qNC-Bc-jAZ"/>
......
......@@ -11,6 +11,7 @@
#import "Server.h"
#import "slideShowViewController.h"
#import "CommunicationManager.h"
#import "CommandTransmitter.h"
#import "CommandInterpreter.h"
@interface libreoffice_sdremoteViewController ()
......@@ -39,12 +40,12 @@
self.slideShowPreviewStartObserver = [self.center addObserverForName:STATUS_CONNECTED_SLIDESHOW_RUNNING object:nil
queue:mainQueue usingBlock:^(NSNotification *note) {
NSLog(@"Received performSegue!");
[self performSegueWithIdentifier:@"slidesPreviewSegue" sender:self];
[self performSegueWithIdentifier:@"slidesPreviewSegue" sender:self ];
}];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"slidesPreviewSegue"]) {
slideShowViewController *destViewController = segue.destinationViewController;
destViewController.slideshow = [self.comManager.interpreter slideShow];
......@@ -67,6 +68,11 @@
[self.comManager connectToServer:self.server];
}
- (IBAction)startPresentation:(id)sender {
[self.comManager.transmitter startPresentation];
}
- (void)viewDidUnload {
[self setIpAddressTextEdit:nil];
[self setPinLabel:nil];
......
......@@ -8,9 +8,13 @@
#import "slideShowViewController.h"
#import "SlideShow.h"
#import "CommandTransmitter.h"
#import "CommunicationManager.h"
@interface slideShowViewController ()
@property (nonatomic, strong) CommunicationManager* comManager;
@end
@implementation slideShowViewController
......@@ -18,6 +22,7 @@
@synthesize slideshow = _slideshow;
@synthesize slideShowImageReadyObserver = _slideShowImageReadyObserver;
@synthesize slideShowNoteReadyObserver = _slideShowNoteReadyObserver;
@synthesize comManager = _comManager;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
......@@ -34,23 +39,34 @@
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
// [self.image setImage:[self.slideshow getImageAtIndex:0]];
// [self.lecturer_notes loadHTMLString: [self.slideshow getNotesAtIndex:0]baseURL:nil];
self.slideShowImageReadyObserver = [center addObserverForName:@"IMAGE_READY" object:nil
queue:mainQueue usingBlock:^(NSNotification *note) {
if ([self.slideshow size] == 0)
NSLog(@"Oups");
NSLog(@"Getting image to display: %@", [self.slideshow getImageAtIndex:0]);
[self.image setImage:[self.slideshow getImageAtIndex:0]];
self.slideShowImageReadyObserver =[center addObserverForName:MSG_SLIDE_CHANGED
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
NSLog(@"Getting slide: %u image to display: %@", self.slideshow.currentSlide, [self.slideshow getImageAtIndex:self.slideshow.currentSlide]);
[self.image setImage:[self.slideshow getImageAtIndex:self.slideshow.currentSlide]];
[self.lecturer_notes loadHTMLString: [self.slideshow getNotesAtIndex:self.slideshow.currentSlide]baseURL:nil];
}];
self.slideShowNoteReadyObserver = [center addObserverForName:@"NOTE_READY" object:nil
queue:mainQueue usingBlock:^(NSNotification *note) {
NSLog(@"Getting note to display: %@", [self.slideshow getNotesAtIndex:0]);
[self.lecturer_notes loadHTMLString: [self.slideshow getNotesAtIndex:0]baseURL:nil];
self.slideShowNoteReadyObserver = [center addObserverForName:STATUS_CONNECTED_NOSLIDESHOW
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
[self.navigationController popViewControllerAnimated:YES];
}];
self.comManager = [CommunicationManager sharedComManager];
}
- (IBAction)nextSlide:(id)sender {
[self.comManager.transmitter nextTransition];
}
- (IBAction)previousSlide:(id)sender {
[self.comManager.transmitter previousTransition];
}
- (void)didReceiveMemoryWarning
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment