Example #1
0
        public async void StartDialog()
        {
            PermissionManager permissions = new PermissionManager();
            var taskPermissionRead        = await permissions.CheckAndRequestStorageReadPermission();

            if (taskPermissionRead.HasFlag(Xamarin.Essentials.PermissionStatus.Granted))
            {
                ImagesCacheDbManager imagesCache      = new ImagesCacheDbManager(new ImageManager(), DateTime.Now.AddDays(90), DateTime.Now);
                ParameterManager     parameterManager = new ParameterManager();
                _initDCIMDirectory = string.Empty;
                if (!parameterManager.Get("CameraDirectoryFullPath", out _initDCIMDirectory))
                {
                    //параметр заполняется при старте индексации, уже должен быть заполнен
                    _initDCIMDirectory = imagesCache.GetPublicDirectoryDcim();
                }

                PathToDefaultDCIM = imagesCache.GetPublicDirectoryDcim();
                PathToCustomDCIM  = _initDCIMDirectory;
                IsUsageMainMemory = _initDCIMDirectory.Equals(PathToDefaultDCIM);

                await Task.Run(() =>
                {
                    MediaFileManager mediaFileManager = new MediaFileManager();
                    CountOfPhotoDefaultDCIM           = mediaFileManager.GetMediaFilesFromDirectory(new DirectoryInfo(PathToDefaultDCIM)).Count();
                    _pathToImagesDir       = _initDCIMDirectory;
                    CountOfPhotoCustomDCIM = mediaFileManager.GetMediaFilesFromDirectory(new DirectoryInfo(_initDCIMDirectory)).Count();
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CountOfPhotoDefaultDCIM"));
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("CountOfPhotoCustomDCIM"));
                    updateDirContent(new DirectoryInfo(_pathToImagesDir));
                });
            }
        }
Example #2
0
        private (ObservableCollection <string>, ObservableCollection <string>, bool userHaveAccess) getDirContent(DirectoryInfo currentDirectory)
        {
            ObservableCollection <string> files = new ObservableCollection <string>();
            ObservableCollection <string> dirs  = new ObservableCollection <string>();
            bool userHaveAccess = false;

            try
            {
                if (currentDirectory.FullName.Equals("/storage"))
                {
                    dirs = currentDirectory.GetDirectories().Where(d => !d.Name.Equals("emulated")).OrderBy(d => d.Name).Select(d => d.Name)
                           .ToObservableCollection();
                    dirs.Add("/storage/emulated/0");
                }
                else
                {
                    dirs = currentDirectory.GetDirectories().OrderBy(d => d.Name).Select(d => d.Name)
                           .ToObservableCollection();
                }

                MediaFileManager mediaFileManager = new MediaFileManager();
                files = mediaFileManager.GetMediaFilesFromDirectory(currentDirectory).OrderByDescending(f => f.CreationTime)
                        .Select(f => f.FullName).ToArray().ToObservableCollection();;
                userHaveAccess = true;
            }
            catch (IOException ioException)
            {
                HandleError.Process("Settings", "getDirContent", ioException, false, currentDirectory.FullName);
            }
            catch (UnauthorizedAccessException e)
            {
                HandleError.Process("Settings", "getDirContent", e, false, currentDirectory.FullName);
            }
            return(files, dirs, userHaveAccess);
        }