Example #1
0
        public async Task <bool> PickAndShowFile()
        {
            FilePicker _FilePicker = FilePicker.GetInstance();
            string     thumbnail   = null;
            string     CheckType   = null;

            if (!await _FilePicker.CheckPermission())
            {
                return(false);
            }

            var pickedFile = await _FilePicker.PickAndShowFile();

            if (pickedFile == null)
            {
                return(false);
            }
            else
            {
                CheckType = _FilePicker.IsSupportedType(pickedFile.FileName);

                if (CheckType == null)
                {
                    await App.Current.MainPage.DisplayAlert("Something happen....", "Selected file format not supported", "Ok");

                    return(false);
                }

                switch (CheckType)
                {
                case "Img":
                    thumbnail = pickedFile.FilePath;
                    break;

                case "Video":
                    thumbnail = "round_movie_black_48.png";
                    break;

                case "PDF":
                    thumbnail = "round_insert_drive_file_black_48.png";
                    break;
                }
                Attachment.FileName  = pickedFile.FileName;
                Attachment.Thumbnail = thumbnail;
                Attachment._FileData = pickedFile;
                OnPropertyChanged("Attachment");
                return(true);
            }
        }
Example #2
0
        public async Task AddAttachment()
        {
            FilePicker _FilePicker = FilePicker.GetInstance();
            string     Thumbnail   = "";

            if (!await _FilePicker.CheckPermission())
            {
                return;
            }

            var pickedFile = await _FilePicker.PickAndShowFile();

            if (pickedFile != null)
            {
                string CheckType = _FilePicker.IsSupportedType(pickedFile.FileName);
                if (CheckType == null)
                {
                    await App.Current.MainPage.DisplayAlert("Something happen....", "Selected file format not supported", "Ok");

                    return;
                }

                switch (CheckType)
                {
                case "Img":
                    Thumbnail = pickedFile.FilePath;
                    break;

                case "Video":
                    Thumbnail = "round_movie_black_48.png";
                    break;

                case "PDF":
                    Thumbnail = "round_insert_drive_file_black_48.png";
                    break;
                }
                BoardMessageAttachment = new Attachment(pickedFile.FileName, Thumbnail, pickedFile);
                Debug.Write(BoardMessageAttachment.Thumbnail);
                IsAttach = true;

                OnPropertyChanged("IsAttach");
                OnPropertyChanged("BoardMessageAttachment");
            }
        }
Example #3
0
        public SocialViewModel()
        {
            OnAddMoments = new Command(async() => {
                await App.Current.MainPage.Navigation.PushAsync(new AddMoments());
            });

            OnPickFileCommand = new Command(async() => {
                FilePicker filePicker = FilePicker.GetInstance();
                string CheckType      = null;
                string thumbnail      = null;

                if (!await filePicker.CheckPermission())
                {
                    return;
                }

                var pickedFile = await filePicker.PickAndShowFile();
                if (pickedFile == null)
                {
                    return;
                }
                else
                {
                    CheckType = filePicker.IsSupportedMomentType(pickedFile.FileName);
                    if (CheckType == null)
                    {
                        await App.Current.MainPage.DisplayAlert("Something wrong....",
                                                                "File format not supported.\nSupport format: \n*.MP4 \n*.jpg*\n*.png",
                                                                "Ok");
                        return;
                    }

                    switch (CheckType)
                    {
                    case "Img":
                        thumbnail = pickedFile.FilePath;
                        break;

                    case "Video":
                        thumbnail = "round_movie_black_48.png";
                        break;
                    }
                }
                IsOnAttachmentSection = true;
                _Attachment.FileName  = pickedFile.FileName;
                _Attachment._FileData = pickedFile;
                _Attachment.Thumbnail = thumbnail;
                OnPropertyChanged("IsOnAttachmentSection");
                OnPropertyChanged("_Attachment");
            });

            OnSendToCommand = new Command(async() => {
                try
                {
                    if (string.IsNullOrWhiteSpace(Description) && string.IsNullOrEmpty(_Attachment.FileName))
                    {
                        await App.Current.MainPage.DisplayAlert("Something wrong...", "Must write something or attach some photo/video.", "Ok");
                        return;
                    }
                }
                catch (NullReferenceException) {
                }
                Moment _Moment = new Moment(UserSetting.UserEmail, UserSetting.UserName, Description, _Attachment);
                await App.Current.MainPage.Navigation.PushAsync(new MomentSendTo(_Moment));
            });

            OnDeleteCommand = new Command(() =>
            {
                _Attachment           = null;
                IsOnAttachmentSection = false;
                OnPropertyChanged("IsOnAttachmentSection");
            });

            OnClickAttachment = new Command <string>(async(string uri) => {
                await App.Current.MainPage.Navigation.PushAsync(new WebViewAttachment(uri));
            });
        }