Exemplo n.º 1
0
 public DirectoryListViewModel()
 {
     Drives = new ObservableCollection <FolderViewModel>();
     foreach (var roots in GalleryDirectory.GetRootDirectories())
     {
         var drive = new FolderViewModel(roots);
         drive.LoadSubFolders(false);
         Drives.Add(drive);
     }
 }
Exemplo n.º 2
0
        public void MoveAllImagesToFlatOrder_WhenDirectoryHasOnlyFiles_ThenNoPrefix()
        {
            string dirPath = AsCrossPlatformPath("./home/Galerie");

            string[] fileNames = CreateSomeFileNames();
            var      directory = new DirectoryNodeInfo(dirPath, null, fileNames);

            Mock <IFileSystemAccess> fileSystemAccessMock = SetupMockForFileSystemAccess();
            var galleryDirectory = new GalleryDirectory(fileSystemAccessMock.Object);

            galleryDirectory.MoveAllImagesToFlatOrder(directory);

            VerifyCallsTo(fileSystemAccessMock, dirPath, directory, $"^\\w+_\\d+\\.{_fileExt}$");
        }
Exemplo n.º 3
0
        public void MoveAllImagesToFlatOrder_WhenFilesAlongSubdirs_ThenThrow()
        {
            string dirPath = AsCrossPlatformPath("./home/Galerie");

            string[]            fileNames = CreateSomeFileNames();
            DirectoryNodeInfo[] subdirs   = { new DirectoryNodeInfo(null, null, null) };
            var directory = new DirectoryNodeInfo(dirPath, subdirs, fileNames);

            Mock <IFileSystemAccess> fileSystemAccessMock = SetupMockForFileSystemAccess();
            var galleryDirectory = new GalleryDirectory(fileSystemAccessMock.Object);

            Assert.ThrowsAny <ApplicationException>(
                () => galleryDirectory.MoveAllImagesToFlatOrder(directory)
                );
        }
Exemplo n.º 4
0
        public void MoveAllImagesToFlatOrder_WhenSubdirectoriesPresent_ThenUsePrefix()
        {
            string dirPath = AsCrossPlatformPath("./home/Galerie");

            string[] fileNames = CreateSomeFileNames();

            DirectoryNodeInfo[] subdirs =
            {
                new DirectoryNodeInfo(Path.Join(dirPath, "A"), null, fileNames),
                new DirectoryNodeInfo(Path.Join(dirPath, "B"), null, fileNames),
            };
            var directory = new DirectoryNodeInfo(dirPath, subdirs, null);

            Mock <IFileSystemAccess> fileSystemAccessMock = SetupMockForFileSystemAccess();
            var galleryDirectory = new GalleryDirectory(fileSystemAccessMock.Object);

            galleryDirectory.MoveAllImagesToFlatOrder(directory);

            VerifyCallsTo(fileSystemAccessMock, dirPath, directory, $"^\\d+_\\w+_\\d+\\.{_fileExt}$");
        }
Exemplo n.º 5
0
        private List <GalleryDirectory> FillAllPhotosFromGallery()
        {
            galleryDirectories.Clear();

            int PositionDirectory = 0;

            Android.Net.Uri uri;
            ICursor         cursor;
            int             columnPhotoIndex, columnDirectoryIndex;
            string          absolutePathOfImage = null;

            //Query photos from gallery
            uri = MediaStore.Images.Media.ExternalContentUri;
            string[] projection = { MediaStore.Images.Thumbnails.Data, MediaStore.Images.ImageColumns.BucketDisplayName };
            string   orderBy    = MediaStore.Images.ImageColumns.DateTaken;

            cursor               = ApplicationContext.ContentResolver.Query(uri, projection, null, null, orderBy + " DESC");
            columnPhotoIndex     = cursor.GetColumnIndexOrThrow(MediaStore.Images.Thumbnails.Data);
            columnDirectoryIndex = cursor.GetColumnIndexOrThrow(MediaStore.Images.ImageColumns.BucketDisplayName);

            List <GalleryDirectory> galleriesRaw = new List <GalleryDirectory>();

            //Loop to add data to collection
            while (cursor.MoveToNext())
            {
                absolutePathOfImage = cursor.GetString(columnPhotoIndex);

                for (int i = 0; i < galleriesRaw.Count; i++)
                {
                    if (galleriesRaw[i].Name.Equals(cursor.GetString(columnDirectoryIndex)))
                    {
                        FlagDirectory     = true;
                        PositionDirectory = i;
                        break;
                    }
                    else
                    {
                        FlagDirectory = false;
                    }
                }

                if (FlagDirectory)
                {
                    var imageSets = new List <GalleryImageXF>();
                    imageSets.AddRange(galleriesRaw[PositionDirectory].Images);
                    imageSets.Add(new GalleryImageXF()
                    {
                        OriginalPath = absolutePathOfImage
                    });

                    galleriesRaw[PositionDirectory].Images = (imageSets);
                }
                else
                {
                    var imageSets = new List <GalleryImageXF>();
                    imageSets.Add(new GalleryImageXF()
                    {
                        OriginalPath = absolutePathOfImage
                    });

                    var galleryDirectory = new GalleryDirectory();
                    galleryDirectory.Name   = (cursor.GetString(columnDirectoryIndex));
                    galleryDirectory.Images = (imageSets);

                    galleriesRaw.Add(galleryDirectory);
                }
            }

            galleryDirectories.AddRange(galleriesRaw.Where(obj => obj.Images.Count > 0).OrderBy(obj => obj.Name));
            galleryDirectories.ForEach(obj => obj.Images.Insert(0, new GalleryImageXF()));
            //galleryDirectoryAdapter.NotifyDataSetChanged();

            SyncGalleryItem(0);

            return(galleryDirectories);
        }
Exemplo n.º 6
0
 public FolderViewModel(GalleryDirectory model)
 {
     _model     = model;
     SubFolders = new ObservableCollection <FolderViewModel>();
     Images     = new ObservableCollection <ImageViewModel>();
 }