Beispiel #1
0
        async void ShowGroupsList()
        {
            var token = _prefs.GetString("token", null);

            if (token != null && CheckConnection())
            {
                var dialog = new Android.App.AlertDialog.Builder(this);

                try
                {
                    var permissions = await _manager.GetUserPostPermissions(token);

                    if (permissions != null && permissions.Count > 0)
                    {
                        dialog.SetTitle("Выберите группу");
                        ArrayAdapter <Model.Group> arrayAdapter = new ArrayAdapter <Model.Group>(this, Android.Resource.Layout.SelectDialogSingleChoice);
                        permissions.ForEach(p => arrayAdapter.Add(p));
                        dialog.SetAdapter(arrayAdapter, (o, e) =>
                        {
                            var selectedGroup = arrayAdapter.GetItem(e.Which);
                            OpenMesageInputWindow(token, selectedGroup);
                        });
                        dialog.SetNegativeButton("Отмена", delegate { });
                        dialog.Show();
                    }
                    else
                    {
                        string message = "К сожаелнию, на данный момент нет ни одной группы, куда вы могли бы сделать объявление";
                        dialog.SetMessage(message);
                        dialog.SetPositiveButton("Ок", delegate { });
                        dialog.Show();
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    string message = "Ваши параметры авторизации устарели." +
                                     "\nВы будете возвращены на страницу авторизации, чтобы пройти процедуру авторизации заново";
                    dialog.SetMessage(message);
                    dialog.SetCancelable(false);
                    dialog.SetPositiveButton("Ок", delegate
                    {
                        LogOut();
                    });
                    dialog.Show();
                }
                catch (System.Exception ex)
                {
                    string message = ex.Message;
                    dialog.SetMessage(message);
                    dialog.SetPositiveButton("Ок", delegate { });
                    dialog.Show();
                }
            }
        }
Beispiel #2
0
        public virtual void OnFilePrompt(GeckoSession session, string title, int type, string[] mimeTypes, GeckoSession.PromptDelegateClassFileCallback callback)
        {
            var currentActivity = BlazorWebViewService.GetCurrentActivity();

            AlertDialog _futureDialog = null; //Workaround dismiss method not available on AlertDialog.Builder before Show();

            bool shouldDismiss = true;

            var dialogBuilder = new Android.App.AlertDialog.Builder(_renderer.Context);
            BlazorFileDialogDismissListener onDismissEvent = new BlazorFileDialogDismissListener();

            onDismissEvent.SetDismissHandler(() =>
            {
                if (shouldDismiss)
                {
                    callback.Dismiss();
                }

                dialogBuilder.Dispose();
            });

            dialogBuilder.SetOnDismissListener(onDismissEvent);

            GetContentCompatibleIntents(type, out List <IntentMetadata> intentList, out List <ResolveInfo> activitiesInfo);
            dialogBuilder.SetAdapter(BuilderAdapter(currentActivity, activitiesInfo),
                                     (sender, e) =>
            {
                //On Intent click

                shouldDismiss = false;
                IntentMetadata selectedIntent = intentList.ElementAt(e.Which);

                //Check for Android permissions for intents
                RequestPermissionHelper.CheckForPermission(selectedIntent.RequiredPermissions, () =>
                {
                    //On Intent permission availables

                    //We must manage multiple file selection too

                    //TODO: Even by adding this intent
                    //this seem to not working yet. Not sure if possible through launching external intents
                    if (type == FilePromptType.MULTIPLE)
                    {
                        selectedIntent.Intent.PutExtra(Intent.ExtraAllowMultiple, true);
                    }

                    currentActivity.StartActivityForResult(selectedIntent.Intent, 1, (int requestCode, Result resultCode, Intent data) =>
                    {
                        if (resultCode != Result.Ok)
                        {
                            //Do nothing as the user is still now on the Intent dialog box chooser

                            //As on Permission not granted, see comment below =>
                            //We should reset this value to true if denied, as the user may don't click on Cancel but use a back button instead
                            //As the back button will call the Dialog dismiss internally, we should emulate the cancel behavior (see SetNeutralButton code)
                            shouldDismiss = true;
                        }
                        else
                        {
                            try
                            {
                                callback.Confirm(currentActivity, GetFileForBrowser(data.Data));
                            }
                            catch (System.Exception e)
                            {
                                ConsoleHelper.WriteException(e);
                                callback.Dismiss();
                            }

                            _futureDialog.Dismiss();
                        }
                    });
                }, () =>
                {
                    //On Intent permission unavailable

                    //We should reset this value to true if denied, as the user may don't click on Cancel but use a back button instead
                    //As the back button will call the Dialog dismiss internally, we should emulate the cancel behavior (see SetNeutralButton code)
                    shouldDismiss = true;
                });
            });


            dialogBuilder.SetNeutralButton(currentActivity.Resources.GetString(Android.Resource.String.Cancel),
                                           (sender, e) =>
            {
                shouldDismiss = true;
                _futureDialog.Dismiss();
            });
            shouldDismiss = true;
            _futureDialog = dialogBuilder.Show();
        }