Ejemplo n.º 1
0
        private void uploadImage()
        {
            var categoryText = categoryField.Text.Trim();

            if (imageView.Drawable == null)
            {
                Infobar.Show(this, "No image to upload", Infobar.InfoLevel.Info, GravityFlags.Top | GravityFlags.FillHorizontal);
                return;
            }
            else if (string.IsNullOrEmpty(categoryText))
            {
                categoryField.RequestFocus();
                categoryField.SetError("No category specified", null);
                return;
            }

            uploadBtn.setMode(ActionProcessButton.Mode.ENDLESS);
            uploadBtn.setProgress(1);

            var bm = (imageView.Drawable as BitmapDrawable).Bitmap;

            Task.Run(async() =>
            {
                var base64Image = string.Empty;

                using (MemoryStream memoryStream = new MemoryStream())
                {
                    await bm.CompressAsync(Bitmap.CompressFormat.Webp, 85, memoryStream);

                    base64Image = Base64.EncodeToString(memoryStream.ToArray(), Base64Flags.Default);
                }

                return(await Api.DavinciApi.UploadPost(base64Image, categoryText));
            }).ContinueWith(async t =>
            {
                var response = t.Result;

                if (t.Status == TaskStatus.Canceled)
                {
                    uploadBtn.setProgress(-1);
                    return;
                }

                if (response.OK)
                {
                    uploadBtn.setProgress(100);
                    await Task.Delay(2000);
                    this.Finish();
                }

                uploadBtn.setProgress(0);
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Ejemplo n.º 2
0
        private void authenticate()
        {
            bool isValid = validateInput();

            if (!isValid)
            {
                return;
            }

            toggleUiInput();
            loginBtn.Text = "Authenticating...";

            Task.Run(async() =>
            {
                return(await DavinciApi.Authenticate(usernameField.Text, passwordField.Text));
            }).ContinueWith(async responseTask =>
            {
                var response = responseTask.Result;

                if (responseTask.Status == TaskStatus.Canceled)
                {
                    toggleUiInput();
                    loginBtn.Text = "Login";

                    Infobar.Show(this.Context, "Connection error", Infobar.InfoLevel.Info, GravityFlags.Top | GravityFlags.FillHorizontal, false);
                }
                else if (response.OK)
                {
                    saveCredentials(rememberBox.Checked);

                    Infobar.Show(this.Context, response.message, Infobar.InfoLevel.Info, GravityFlags.Top | GravityFlags.FillHorizontal, false);

                    await Task.Delay(500);

                    showFeed();
                }
                else
                {
                    toggleUiInput();
                    loginBtn.Text = "Login";

                    Infobar.Show(this.Context, response.message, Infobar.InfoLevel.Error, GravityFlags.Top | GravityFlags.FillHorizontal, false);
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Ejemplo n.º 3
0
        private void Register()
        {
            bool isValid = validateInput();

            if (!isValid)
            {
                return;
            }

            toggleUiInput();
            registerBtn.Text = "Registering...";

            Task.Run(async() =>
            {
                return(await DavinciApi.Register(usernameField.Text, emailField.Text, passwordField.Text));
            }).ContinueWith(responseTask =>
            {
                var response = responseTask.Result;

                if (responseTask.Status == TaskStatus.Canceled)
                {
                    toggleUiInput();
                    registerBtn.Text = "Register";

                    Infobar.Show(this.Context, "Connection error", Infobar.InfoLevel.Info, GravityFlags.Top | GravityFlags.FillHorizontal, false);
                }
                else if (response.OK)
                {
                    Infobar.Show(this.Context, response.message, Infobar.InfoLevel.Info, GravityFlags.Top | GravityFlags.FillHorizontal, false);

                    ((AccountActivity)parentActivity).Login();
                }
                else
                {
                    toggleUiInput();
                    registerBtn.Text = "Register";

                    Infobar.Show(this.Context, response.message, Infobar.InfoLevel.Error, GravityFlags.Top | GravityFlags.FillHorizontal, false);
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Ejemplo n.º 4
0
        private void changeEmailAction()
        {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.SetTitle("Change email");

            View     viewInflated = LayoutInflater.From(this).Inflate(Resource.Layout.InputDialogEmail, (ViewGroup)changeEmailBtn.RootView, false);
            EditText input        = viewInflated.FindViewById <EditText>(Resource.Id.input);

            builder.SetView(viewInflated);

            // Set up the buttons
            builder.SetPositiveButton("Confirm", (s, e) =>
            {
                Task.Run(async() =>
                {
                    return(await Api.DavinciApi.ChangeAccount(null, null, input.Text));
                }).ContinueWith(t =>
                {
                    if (t.Result.OK)
                    {
                        Infobar.Show(this, t.Result.message, Infobar.InfoLevel.Info, GravityFlags.Top | GravityFlags.FillHorizontal);
                    }
                    else
                    {
                        Infobar.Show(this, t.Result.message, Infobar.InfoLevel.Error, GravityFlags.Top | GravityFlags.FillHorizontal);
                    }
                    ((AlertDialog)s).Dismiss();
                }, TaskScheduler.FromCurrentSynchronizationContext());
            });
            builder.SetNegativeButton("Cancel", (s, e) =>
            {
                ((AlertDialog)s).Dismiss();
            });

            builder.Show();
        }