Esempio n. 1
0
            protected override async Task <Java.Lang.Void> RunInBackground(params Java.Lang.Void[] @params)
            {
                ISharedPreferences info = Application.Context.GetSharedPreferences(context.GetString(Resource.String.ApplicationInfo), FileCreationMode.Private);
                bool LoggedIn           = info.GetBoolean(context.GetString(Resource.String.LogIn), false);

                MeritMoneyBrain.CurrentAccessToken = info.GetString(context.GetString(Resource.String.CurrentAccessToken), String.Empty);

                if (context.NetworkStatus.State != NetworkState.Disconnected)
                {
                    if (LoggedIn)
                    {
                        Profile p = await MeritMoneyBrain.GetProfile();

                        p.AvatarIsDefault = OperationWithBitmap.isDefault(p.imageUri);
                        ProfileDatabase db = new ProfileDatabase();
                        db.Update(p);
                    }
                    context.StartActivity(new Intent(Application.Context, typeof(MainActivity)));
                }
                else
                {
                    await Task.Delay(500);

                    context.StartActivity(new Intent(Application.Context, typeof(NoInternetActivity)));
                }

                return(null);
            }
Esempio n. 2
0
        protected override Android.Graphics.Bitmap RunInBackground(params Profile[] @params)
        {
            String imageUrl        = @params[0].imageUri;
            String userId          = @params[0].ID;
            Bitmap image           = null;
            bool   AvatarIsDefault = @params[0].AvatarIsDefault;

            if (imageUrl == null)
            {
                return(null);
            }

            try
            {
                byte[] data = OperationWithBitmap.Retrieve(context, userId);

                if (data == null)
                {
                    image = OperationWithBitmap.GetFromUrl(imageUrl);
                    var bitmapData = OperationWithBitmap.ConvertToByteArray(image);
                    OperationWithBitmap.Cache(context, bitmapData, userId);
                }
                else
                {
                    image = OperationWithBitmap.ConvertFromByteArray(data);
                }
            }
            catch (Exception e) { Console.Out.WriteLine(e.Message); }

            return(image);
        }
Esempio n. 3
0
            protected override void OnPostExecute(Task <Bitmap> result)
            {
                byte[] bitmapData = OperationWithBitmap.ConvertToByteArray(result.Result);
                db.UpdateAvatarUrl(New: url, at: UserId);
                OperationWithBitmap.Cache(Application.Context, bitmapData, UserId);

                base.OnPostExecute(result);
            }
Esempio n. 4
0
        public static async Task <String> UploadImage(Bitmap image)
        {
            string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(await GetUploadUrl());

            request.ContentType = "multipart/form-data; boundary=" +
                                  boundary;
            request.Method    = "POST";
            request.KeepAlive = true;
            request.Headers.Add("Access-Token", CurrentAccessToken);

            Stream memStream = new System.IO.MemoryStream();

            var boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" +
                                                                    boundary + "\r\n");
            var endBoundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" +
                                                                       boundary + "--");

            string formdataTemplate = "\r\n--" + boundary +
                                      "\r\nContent-Disposition: form-data; name=\"{0}\";\r\n\r\n{1}";

            string headerTemplate =
                "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" +
                "Content-Type: application/octet-stream\r\n\r\n";

            byte[] file = OperationWithBitmap.ConvertToByteArray(image);

            memStream.Write(boundarybytes, 0, boundarybytes.Length);
            var header      = string.Format(headerTemplate, "uplTheFile", file);
            var headerbytes = System.Text.Encoding.UTF8.GetBytes(header);

            memStream.Write(headerbytes, 0, headerbytes.Length);
            memStream.Write(file, 0, file.Length);
            memStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);

            request.ContentLength = memStream.Length;

            using (Stream requestStream = request.GetRequestStream())
            {
                memStream.Position = 0;
                byte[] tempBuffer = new byte[memStream.Length];
                memStream.Read(tempBuffer, 0, tempBuffer.Length);
                memStream.Close();
                requestStream.Write(tempBuffer, 0, tempBuffer.Length);
            }

            JsonValue jsonDoc;

            using (var response = request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    jsonDoc = await Task.Run(() => JsonValue.Load(stream));
                }
            }
            return(jsonDoc["imageUrl"]);
        }
Esempio n. 5
0
        private async Task HandleResult()
        {
            if (EditName.Text != String.Empty)
            {
                UserName.Text = EditName.Text;
                EditName.Text = String.Empty;
            }

            if (SaveSwitchState != NotificationSwitch.Checked)
            {
                SwitchWasChanged = true;
            }
            else
            {
                SwitchWasChanged = false;
            }

            if (SaveName != UserName.Text)
            {
                nameWasChanged = true;
            }
            else
            {
                nameWasChanged = false;
            }

            if (AvatarWasChanged)
            {
                new UploadAvatarOnServer(UserAvatar).Execute().Get();
                AvatarWasChanged = false;
            }

            if (SwitchWasChanged && !nameWasChanged)
            {
                Profile p = await MeritMoneyBrain.updateProfile(String.Empty, SwitchWasChanged, NotificationSwitch.Checked);

                p.AvatarIsDefault = OperationWithBitmap.isDefault(p.imageUri);
                ProfileDatabase db = new ProfileDatabase();
                db.Update(p);
            }
            if (nameWasChanged)
            {
                Profile p = await MeritMoneyBrain.updateProfile(UserName.Text, SwitchWasChanged, NotificationSwitch.Checked);

                ProfileDatabase db = new ProfileDatabase();
                db.Update(p);
            }
        }
Esempio n. 6
0
            protected override Java.Lang.Void RunInBackground(params Profile[] @params)
            {
                Profile                  profile = @params[0];
                ISharedPreferences       info    = Application.Context.GetSharedPreferences(Application.Context.GetString(Resource.String.ApplicationInfo), FileCreationMode.Private);
                ISharedPreferencesEditor edit    = info.Edit();

                edit.PutString(Application.Context.GetString(Resource.String.CurrentAccessToken), MeritMoneyBrain.CurrentAccessToken);
                edit.Apply();

                profile.AvatarIsDefault = OperationWithBitmap.isDefault(profile.imageUri);

                ProfileDatabase db = new ProfileDatabase();

                db.CreateDatabase();
                db.Insert(profile);

                return(null);
            }
Esempio n. 7
0
        public async void OnClick(IDialogInterface dialog, int which)
        {
            switch (which)
            {
            case (int)DialogButtonType.Neutral:
                dialog.Dismiss();
                NumberOfPoints.Text      = String.Empty;
                SendPointsButton.Enabled = false;
                break;

            case (int)DialogButtonType.Positive:
                try
                {
                    ProfileDatabase pdb = new ProfileDatabase();
                    if (Convert.ToInt64(NumberOfPoints.Text) > pdb.GetProfile().distribute)
                    {
                        Toast.MakeText(this, "Unavailible points amount.", ToastLength.Short).Show();
                        break;
                    }
                }
                catch (Exception) { Toast.MakeText(this, "Too many points to send.", ToastLength.Short).Show(); break; }

                ProgressDialog progressDialog = ProgressDialog.Show(this, "", "Sending points...", true);

                String name = userNameToDistribute.Text;
                userNameToDistribute.Text = String.Empty;
                String number = NumberOfPoints.Text;
                NumberOfPoints.Text = String.Empty;
                String notes = Notes.Text;

                Profile p = await MeritMoneyBrain.DistributePoints(number, userIDtoDistribute, notes);

                p.AvatarIsDefault = OperationWithBitmap.isDefault(p.imageUri);
                ProfileDatabase db = new ProfileDatabase();
                db.Update(p);

                new UpdateProfileData(this, progressDialog, number, name).Execute(p);
                break;
            }
        }
Esempio n. 8
0
        protected override Java.Lang.Void RunInBackground(params object[] @params)
        {
            if (@params[0].GetType() == typeof(HistoryListItem))
            {
                HistoryListItem historyItem = @params[0] as HistoryListItem;
                UsersDatabase   db          = new UsersDatabase();
                UserListItem    user        = db.GetUserByID(historyItem.fromUserID);

                try
                {
                    byte[] data = OperationWithBitmap.Retrieve(context, user.ID);

                    if (data == null)
                    {
                        Bitmap curImage = OperationWithBitmap.GetFromUrl(user.url);
                        //user.AvatarIsDefault = OperationWithBitmap.isDefault(curImage);
                        //if (!user.AvatarIsDefault)
                        //{
                        historyItem.image = curImage;
                        //}
                        var bitmapData = OperationWithBitmap.ConvertToByteArray(historyItem.image);
                        OperationWithBitmap.Cache(context, bitmapData, historyItem.ID);
                    }
                    else
                    {
                        //if (!user.AvatarIsDefault)
                        historyItem.image = OperationWithBitmap.ConvertFromByteArray(data);
                    }
                }
                catch (Exception e) { Console.Out.WriteLine(e.Message); }
            }
            else if (@params[0].GetType() == typeof(UserListItem))
            {
                UserListItem user            = @params[0] as UserListItem;
                bool         AvatarIsDefault = user.AvatarIsDefault;
                try
                {
                    byte[] data = OperationWithBitmap.Retrieve(context, user.ID);

                    if (data == null)
                    {
                        Bitmap curImage = OperationWithBitmap.GetFromUrl(user.url);
                        //user.AvatarIsDefault = OperationWithBitmap.isDefault(curImage);
                        //if (!user.AvatarIsDefault)
                        //{
                        user.image = curImage;
                        //    UsersDatabase db = new UsersDatabase();
                        //    db.UpdateAvatarState(user);
                        //}
                        var bitmapData = OperationWithBitmap.ConvertToByteArray(user.image);
                        OperationWithBitmap.Cache(context, bitmapData, user.ID);
                    }
                    else
                    {
                        //if (!user.AvatarIsDefault)
                        user.image = OperationWithBitmap.ConvertFromByteArray(data);
                    }
                }
                catch (Exception e) { Console.Out.WriteLine(e.Message); }
            }
            else
            {
                throw new Exception("Wrong ItemList type.");
            }
            return(null);
        }
Esempio n. 9
0
 protected override void OnPreExecute()
 {
     base.OnPreExecute();
     OperationWithBitmap.Delete(Application.Context, UserId);
 }
Esempio n. 10
0
            protected override Java.Lang.Void RunInBackground(params Java.Lang.Void[] @params)
            {
                profile.AvatarIsDefault = OperationWithBitmap.isDefault(profile.imageUri);

                return(null);
            }