Ejemplo n.º 1
0
        private async void Register_Click(object sender, EventArgs e)
        {
            if (CheckFields())
            {
                View.EndEditing(true);

                Register.Enabled = false;
                Register.Alpha   = 0.5f;
                int locationShare = 0;
                int distanceShare = 0;

                if (UseLocationSwitch.On)
                {
                    locationShare = rc.GetLocationShareLevel();
                    distanceShare = rc.GetDistanceShareLevel();
                }

                string url = "action=register&Sex=" + (Sex.SelectedRowInComponent(0) - 1) + "&Email=" + CommonMethods.UrlEncode(Email.Text.Trim()) + "&Password="******"&Username="******"&Name=" + CommonMethods.UrlEncode(Name.Text.Trim())
                             + "&Pictures=" + CommonMethods.UrlEncode(string.Join("|", rc.uploadedImages)) + "&Description=" + CommonMethods.UrlEncode(DescriptionText.Text) + "&UseLocation=" + UseLocationSwitch.On
                             + "&LocationShare=" + locationShare + "&DistanceShare=" + distanceShare + "&regsessionid=" + regsessionid;

                string responseString = await c.MakeRequest(url);

                if (responseString.Substring(0, 2) == "OK")
                {
                    if (File.Exists(regSessionFile))
                    {
                        File.Delete(regSessionFile);
                    }
                    regsessionid = "";
                    if (File.Exists(regSaveFile))
                    {
                        File.Delete(regSaveFile);
                    }
                    registerCompleted = true; //to prevent OnPause from saving form data.

                    c.LoadCurrentUser(responseString);

                    Register.Enabled = true;
                    Register.Alpha   = 1;

                    CommonMethods.OpenPage("ListActivity", 1);
                }
                else if (responseString.Substring(0, 6) == "ERROR_")
                {
                    c.Snack(c.GetLang(responseString.Substring(6)));
                }
                else
                {
                    c.ReportError(responseString);
                }
                Register.Enabled = true;
                Register.Alpha   = 1;
            }
            else
            {
                c.Snack(checkFormMessage);
            }
        }
Ejemplo n.º 2
0
        private async void Save_Click(object sender, EventArgs e)
        {
            if (CheckFields())
            {
                Save.Enabled = false;
                Save.Alpha   = 0.5f;

                //not visible form fields do not get saved, but there is no need to reload the form, since we are exiting the activity on successful save.
                string requestStringBase = "action=profileedit&ID=" + Session.ID + "&SessionID=" + Session.SessionID;
                string requestStringAdd  = "";
                if (DescriptionText.Text != Session.Description)
                {
                    requestStringAdd += "&Description=" + CommonMethods.UrlEncode(DescriptionText.Text);
                }
                if (GetSexChoice() != Session.SexChoice)
                {
                    requestStringAdd += "&SexChoice=" + GetSexChoice();
                }
                if (AccountDataSection.Frame.Height != 0)
                {
                    if (Email.Text.Trim() != Session.Email)
                    {
                        requestStringAdd += "&Email=" + CommonMethods.UrlEncode(Email.Text.Trim());
                    }
                    if (Username.Text.Trim() != Session.Username)
                    {
                        requestStringAdd += "&Username="******"&Name=" + CommonMethods.UrlEncode(Name.Text.Trim());
                    }
                }
                if (ChangePasswordSection.Frame.Height != 0)
                {
                    requestStringAdd += "&OldPassword="******"&Password="******"&UseLocation=" + UseLocationSwitch.On;
                    }
                    int locationShare = rc.GetLocationShareLevel();
                    int distanceShare = rc.GetDistanceShareLevel();
                    if (locationShare != Session.LocationShare)
                    {
                        requestStringAdd += "&LocationShare=" + locationShare;
                    }
                    if (distanceShare != Session.DistanceShare)
                    {
                        requestStringAdd += "&DistanceShare=" + distanceShare;
                    }
                }

                if (requestStringAdd != "") //if the form was changed
                {
                    string responseString = await c.MakeRequest(requestStringBase + requestStringAdd);

                    if (responseString.Substring(0, 2) == "OK")
                    {
                        if (responseString.Length > 2) //a change happened
                        {
                            bool locationEnabled  = false;
                            bool locationDisabled = false;

                            if (!(bool)Session.UseLocation && UseLocationSwitch.On)
                            {
                                locationEnabled = true;
                            }
                            else if ((bool)Session.UseLocation && !UseLocationSwitch.On)
                            {
                                locationDisabled = true;
                            }

                            if (GetSexChoice() != Session.SexChoice)
                            {
                                ListActivity.listProfiles.Clear();
                                Session.LastDataRefresh = null;
                            }
                            c.LoadCurrentUser(responseString);

                            if (locationEnabled)
                            {
                                if (locMgr is null)
                                {
                                    locMgr = new LocationManager(this); //first location update will load the list
                                }
                                locMgr.StartLocationUpdates();
                            }
                            else if (locationDisabled)
                            {
                                if (!(locMgr is null))
                                {
                                    locMgr.StopLocationUpdates();
                                }
                                if (!string.IsNullOrEmpty(locationUpdatesTo))
                                {
                                    EndLocationShare();
                                    locationUpdatesTo = null;
                                }
                                Session.Latitude     = null;
                                Session.Longitude    = null;
                                Session.LocationTime = null;

                                if (Constants.SafeLocationMode)
                                {
                                    Session.SafeLatitude     = null;
                                    Session.SafeLongitude    = null;
                                    Session.SafeLocationTime = null;

                                    Session.LatestLatitude     = null;
                                    Session.LatestLongitude    = null;
                                    Session.LatestLocationTime = null;
                                }

                                Session.LastDataRefresh = null; //For the situation that a logged in user is filtering by current location, and now turns off uselocation. SetDistanceSourceAddress will be called in ListActivity.OnResume
                            }
                        }
                        Session.SnackMessage = LangEnglish.SettingsUpdated;

                        Save.Enabled = true;
                        Save.Alpha   = 1;
                        CommonMethods.OpenPage(null, 0);
                    }
                    else if (responseString.Substring(0, 6) == "ERROR_")
                    {
                        c.Snack(c.GetLang(responseString.Substring(6)));
                    }
                    else
                    {
                        c.ReportError(responseString);
                    }
                }
                else
                {
                    Save.Enabled = true;
                    Save.Alpha   = 1;
                    CommonMethods.OpenPage(null, 0);
                }
                Save.Enabled = true;
                Save.Alpha   = 1;
            }
            else
            {
                c.Snack(checkFormMessage);
            }
        }