コード例 #1
0
        public EditableProfilePageViewModel(
            INavigationService navigationService,
            IUserDialogs dialogService,
            IProjectDataStore projectDataStore,
            IPermissionsService permissionsService) : base(navigationService)
        {
            Title = "Edit Profile";

            AddValidationRules();

            NavigatedTo
            .Take(1)
            .Select(args => args["user"] as Account)
            .Subscribe(user =>
            {
                // TODO: Handle null user, handle editing...
            });

            ChangePhoto = ReactiveCommand.CreateFromTask(async() =>
            {
                try
                {
                    // check if permission has been granted to the photos
                    var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Photos);
                    if (status != PermissionStatus.Granted)
                    {
                        status = await permissionsService.CheckPermissionsAsync(Permission.Photos, dialogService);
                    }

                    // if permission was granted, open the photo picker
                    if (status == PermissionStatus.Granted)
                    {
                        using (var file = await CrossMedia.Current.PickPhotoAsync(_pickOptions))
                        {
                            if (file != null)
                            {
                                Photo = file.GetStream();
                            }
                        }
                    }
                    else
                    {
                        // permission was not granted. Let the user know they can't pick a photo
                        // without permissions
                        await dialogService.AlertAsync(
                            new AlertConfig
                        {
                            Title   = "Photos Not Supported",
                            Message = ":( Permission not granted to photos.",
                            OkText  = "OK"
                        }).ConfigureAwait(false);

                        return;
                    }
                }
                catch (MediaPermissionException mediaException)
                {
                    await dialogService.AlertAsync(
                        new AlertConfig
                    {
                        Title   = "Permission Error",
                        Message = $"Permissions not granted: {string.Join(", ", mediaException.Permissions)}",
                        OkText  = "OK"
                    }).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    // TODO: log the exception...
                    await dialogService.AlertAsync(
                        new AlertConfig
                    {
                        Title   = "Error",
                        Message = "An error has occurred.",
                        OkText  = "OK"
                    }).ConfigureAwait(false);
                }
            });

            Save = ReactiveCommand.CreateFromTask(async() =>
            {
                // TODO:...
            });

            Cancel = ReactiveCommand.CreateFromTask(async() =>
            {
                await NavigationService.GoBackAsync(useModalNavigation: true).ConfigureAwait(false);
            });

            SelectCommunities = ReactiveCommand.CreateFromTask(async() =>
            {
                var args = new NavigationParameters();
                args.Add(
                    "items",
                    (await projectDataStore.GetTradesAsync()).Select(specialty => new SelectionViewModel <Trade>(specialty)
                {
                    DisplayValue = specialty.Name
                }));

                await NavigationService.NavigateAsync(nameof(MultiSelectListViewPage), args).ConfigureAwait(false);
            });
        }
コード例 #2
0
 /// <inheritdoc />
 public Task <PermissionStatus> CheckAsync <T>()
     where T : BasePermission, new()
 {
     return(_permissionsService.CheckPermissionsAsync <T>());
 }