Esempio n. 1
0
        //================Public methods=============//

        public void FetchDetailedImageInfoAsync(ImageInfo imageInfo)
        {
            ThreadPool.QueueUserWorkItem(
                (args) =>
            {
                lock (mLockObj)
                {
                    mImageFile  = Path.Combine(mImagesPath, imageInfo.ImageName);
                    mDbImgRowId = imageInfo.DbRowId;

                    DbDao dbDao = DbDao.GetInstance();

                    mPhotoCaptureLocation = dbDao.GetPhotoCaptureLocation(
                        mContext,
                        mDbImgRowId);

                    mComments = dbDao.GetComments(mContext, mDbImgRowId);

                    RaiseModelChanged(
                        DetailedImageModelEvents.DETAILED_IMAGE_INFO_FETCHED,
                        new FetchedDetailedImageInfo {
                        ImageFilePath   = mImageFile,
                        Comments        = mComments,
                        CaptureLocation = mPhotoCaptureLocation
                    }
                        );
                }
            });
        }
        public void ImportImageFromCameraAsync(String cameraImgFileName)
        {
            ThreadPool.QueueUserWorkItem(
                (args) =>
            {
                lock (lockObj)
                {
                    DbDao dbDao = DbDao.GetInstance();

                    long dbImgRowId = dbDao.InsertImageInfo(mContext, cameraImgFileName);

                    // Fetching photo capture location.
                    Location location =
                        LocationManagerUtils.getLastKnownLocationFromBestAvailableProvider(mContext);

                    if (location != null)
                    {
                        dbDao.InsertPhotoCaptureLocation(mContext, dbImgRowId, location);
                    }

                    ImageInfo imageInfo = new ImageInfo
                    {
                        DbRowId   = dbImgRowId,
                        ImageName = cameraImgFileName
                    };

                    mImageInfoList.Add(imageInfo);

                    RaiseModelChanged(OverviewImageGalleryModelEvents.IMAGES_COLLECTION_CHANGED, null);
                }
            });
        }
        //================Private methods=============//

        /*return copied image info or null if image copy was not successful;*/
        private ImageInfo TryImportImageFromGallery(Stream imageInputStream)
        {
            if (ExtStorageUtils.IsExtStorageWritable())
            {
                string imgName    = Guid.NewGuid().ToString();
                string newImgFile = Path.Combine(mImagesPath, imgName);

                using (imageInputStream)
                    using (var outputStream = new FileStream(newImgFile, FileMode.CreateNew))
                    {
                        try
                        {
                            imageInputStream.CopyTo(outputStream);
                            // Saving copied image info to the database.
                            long dbRowId = DbDao.GetInstance().InsertImageInfo(mContext, imgName);

                            return(new ImageInfo {
                                DbRowId = dbRowId,
                                ImageName = imgName
                            });
                        }
                        catch (Exception) {     }
                    }
            }

            return(new ImageInfo {
                DbRowId = -1,
                ImageName = null
            });
        }
Esempio n. 4
0
        public void AddNewCommentAsync(string comment)
        {
            ThreadPool.QueueUserWorkItem(
                (args) =>
            {
                lock (mLockObj)
                {
                    DbDao.GetInstance().InsertComment(mContext, mDbImgRowId, comment);
                    mComments.Add(comment);

                    RaiseModelChanged(DetailedImageModelEvents.COMMENTS_UPDATED, null);
                }
            });
        }
        public void RemoveImageAsync(int position)
        {
            ThreadPool.QueueUserWorkItem(
                (args) =>
            {
                lock (lockObj)
                {
                    ImageInfo imageInfo = mImageInfoList[position];

                    DbDao.GetInstance().DeleteImageInfoEntry(mContext, imageInfo.DbRowId);

                    File.Delete(Path.Combine(mImagesPath, imageInfo.ImageName));

                    mImageInfoList.RemoveAt(position);

                    RaiseModelChanged(OverviewImageGalleryModelEvents.IMAGES_COLLECTION_CHANGED, null);
                }
            });
        }
        public void FetchImagesInfoAsync()
        {
            ThreadPool.QueueUserWorkItem(
                (args) =>
            {
                lock (lockObj)
                {
                    List <ImageInfo> imgInfoList = DbDao.GetInstance().GetAllImagesInfo(mContext);

                    mImageInfoList = imgInfoList;

                    RaiseModelChanged(
                        OverviewImageGalleryModelEvents.IMAGES_INFO_FETCHED,
                        new FetchedImagesInfo
                    {
                        ImagesPath     = mImagesPath,
                        ImagesInfoList = mImageInfoList
                    });
                }
            });
        }