@@ -5,7 +5,7 @@ package ru.mail.data
55 import flash.geom.Point ;
66 import flash.geom.Rectangle ;
77 import flash.utils.ByteArray ;
8-
8+
99 import ru.mail.commands.DecodeBytesToBitmapCommand ;
1010 import ru.mail.commands.LoadFileCommand ;
1111 import ru.mail.commands.ResizeFileCommand ;
@@ -29,30 +29,36 @@ package ru.mail.data
2929 public class ImageFactory extends EventDispatcher implements IImageFactory
3030 {
3131 private var file: IFileVO;
32-
32+
3333 private var loadCommand: LoadFileCommand;
34-
34+
35+ private var isFileLoaded: Boolean = false ;
36+ private var isOverlayLoaded: Boolean = false ;
37+
3538 public function ImageFactory (target :IFileVO )
3639 {
3740 if (! target ) {
3841 throw new Error ("{ImageFactory} - init: target is null" );
3942 }
40-
43+
4144 file = target ;
4245 }
43-
46+
4447 public function createImage (imageTransform :ImageTransformVO ):void {
48+ isFileLoaded = false ;
49+ isOverlayLoaded = false ;
50+
4551 if (! file . fileData) {
4652 // first load file
4753 if ( file is FileVO) {
4854 var loadFileCommand: LoadFileCommand = (file as FileVO). loadCommand? (file as FileVO). loadCommand as LoadFileCommand : new LoadFileCommand(file as FileVO);
49-
55+
5056 loadFileCommand. addEventListener (ImageTransformCompleteEvent. TYPE , function (event: ImageTransformCompleteEvent): void {
5157 event. currentTarget . removeEventListener (event. type , arguments . callee );
5258 trace ("loadCommand complete" , event. isSuccess);
5359 loadCommand = null ;
5460 if (event. isSuccess) {
55- checkImageData( imageTransform);
61+ onLoadImageAndOverlay( true , imageTransform);
5662 }
5763 else {
5864 complete( false , event. data , event. error );
@@ -64,15 +70,22 @@ package ru.mail.data
6470 }
6571 }
6672 else {
67- checkImageData(imageTransform);
73+ onLoadImageAndOverlay(true , imageTransform);
74+ }
75+
76+ // check overlay
77+ if ( imageTransform. overlay ) {
78+ // todo: wait for all overlay images to load and then proceed
79+
80+ //onLoadImageAndOverlay(false, imageTransform);
6881 }
6982 }
70-
83+
7184 public function readExif ():Object {
7285 if (! file . fileData) {
7386 return null ;
7487 }
75-
88+
7689 var exif: Object = {};
7790 try {
7891 var exifReader: ExifReader2 = new ExifReader2();
@@ -81,16 +94,23 @@ package ru.mail.data
8194 // more info about orientation
8295 // http://sylvana.net/jpegcrop/exif_orientation.html
8396 var orientation : uint = uint (exifReader. getValue ("Orientation" ));
84-
97+
8598 exif[ "Orientation" ] = orientation ;
8699 }
87-
100+
88101 } catch (e: Error ) {
89102 trace ("read exif error: " + e);
90103 }
91104 return exif;
92105 }
93-
106+
107+ private function onLoadImageAndOverlay (isFile :Boolean , imageTransform :ImageTransformVO ):void
108+ {
109+ if (isFileLoaded && isOverlayLoaded) {
110+ checkImageData(imageTransform);
111+ }
112+ }
113+
94114 /**
95115 * 1/2 Check if imageData has been loaded
96116 * @param imageTransform
@@ -110,7 +130,7 @@ package ru.mail.data
110130 file . imageData. copyPixels ( event. decodedBitmap. bitmapData
111131 , new Rectangle ( 0 , 0 , event. decodedBitmap. width , event. decodedBitmap. height ), new Point ( 0 , 0 ));
112132 event. decodedBitmap. bitmapData . dispose ();
113-
133+
114134 createImageFromSource(imageTransform);
115135 }
116136 else {
@@ -123,7 +143,7 @@ package ru.mail.data
123143 createImageFromSource(imageTransform);
124144 }
125145 }
126-
146+
127147 /**
128148 * 2/2 transform original imagedata
129149 * @param imageTransform
@@ -152,7 +172,7 @@ package ru.mail.data
152172 resizeCommand. execute ();
153173 }
154174 }
155-
175+
156176 private function complete (isSuccess :Boolean , data :ByteArray , error :ErrorVO = null ):void
157177 {
158178 trace ("imageFactory complete" );
0 commit comments