Exemple #1
0
        //UI Events
        public void BtnLogin_Click(object sender, EventArgs e)
        {
            string PhoneNumber = etPhoneNumber.Text;

            //Progress bar code
            var LoadPanel = FindViewById(Resource.Id.LoginPageloadingPanel);

            LoadPanel.Visibility = Android.Views.ViewStates.Visible;
            FindViewById <ProgressBar>(Resource.Id.LoginPageSpinner).IndeterminateDrawable.SetColorFilter(new Android.Graphics.Color(255, 255, 255), Android.Graphics.PorterDuff.Mode.Multiply);


            new Thread(() =>
            {
                var Logged = RestQueries.Authenticate(PhoneNumber);
                if (Logged.Logged)
                {
                    SaveCurrentUser(PhoneNumber, Logged.Data);
                    RunOnUiThread(() =>
                    {
                        ProceedToMainActivity(PhoneNumber, Logged.Data);
                    });
                }
                else
                {
                    RunOnUiThread(() =>
                    {
                        Toast.MakeText(this, "Unrecgnized User", ToastLength.Short).Show();
                        LoadPanel.Visibility = Android.Views.ViewStates.Gone;
                        etPhoneNumber.Text   = "";
                    });
                }
            }).Start();
        }                 // Login button handler
        private void Swiperefreshview_Refresh(object sender, EventArgs e)
        {
            var swiperefresher = (Android.Support.V4.Widget.SwipeRefreshLayout)sender;

            new Thread(() =>
            {
                //Cancels the update after 12 seconds
                {
                    var timer      = new System.Timers.Timer();
                    timer.Interval = 1000;
                    int count      = 0;
                    timer.Elapsed += delegate
                    {
                        if (count++ == 12)
                        {
                            ((Activity)context).RunOnUiThread(() =>
                            {
                                if (swiperefresher.Refreshing)
                                {
                                    swiperefresher.Refreshing = false;
                                    Toast.MakeText(context, "Connection Timed Out", ToastLength.Short).Show();
                                }
                            });
                        }
                    };
                    timer.Start();
                }

                var tuple = RestQueries.Authenticate(intent.GetStringExtra("PhoneNumber"));

                if (tuple.Logged)
                {
                    if (tuple.Data != "" && tuple.Data != null)
                    {
                        var adapter = GetNicknamesList(tuple.Data);
                        ((Activity)context).RunOnUiThread(() =>
                        {
                            lview.Adapter             = adapter;
                            swiperefresher.Refreshing = false;
                        });
                    }
                    else
                    {
                        ((Activity)context).RunOnUiThread(() =>
                        {
                            swiperefresher.Refreshing = false;
                            Toast.MakeText(context, "No Connection", ToastLength.Short).Show();
                        });
                    }
                }
                else
                {
                    ((Activity)context).RunOnUiThread(() =>
                    {
                        swiperefresher.Refreshing = false;
                        Toast.MakeText(context, "No Connection", ToastLength.Short).Show();
                    });
                }
            }).Start();
        }
Exemple #3
0
        }                 // Login button handler

        public void BtnRegister_Click(object sender, EventArgs e)
        {
            //TODO: Add sms auth
            var LoadPanel = FindViewById(Resource.Id.LoginPageloadingPanel);

            LoadPanel.Visibility = Android.Views.ViewStates.Visible;
            FindViewById <ProgressBar>(Resource.Id.LoginPageSpinner).IndeterminateDrawable.SetColorFilter(new Android.Graphics.Color(255, 255, 255), Android.Graphics.PorterDuff.Mode.Multiply);
            Context context = this;
            var     t       = Task.Run(async() =>
            {
                string Phonenumber = etPhoneNumber.Text;
                if (Phonenumber == "" || !ValidateNumber(Phonenumber))
                {
                    RunOnUiThread(() =>
                    {
                        Toast.MakeText(this, "Enter A Valid Phone Number", ToastLength.Short).Show();
                        LoadPanel.Visibility = Android.Views.ViewStates.Gone;
                    });
                    return;
                }

                var content = await RestQueries.PostUser(context, Phonenumber);

                if (content == "-1")
                {
                    RunOnUiThread(() =>
                    {
                        Toast.MakeText(this, "Access Denied", ToastLength.Long).Show();
                        LoadPanel.Visibility = Android.Views.ViewStates.Gone;
                    });
                    return;
                }

                var responsedata = RestQueries.Authenticate(Phonenumber);
                if (responsedata.Logged)
                {
                    SaveCurrentUser(Phonenumber, responsedata.Data);
                    ProceedToMainActivity(Phonenumber, responsedata.Data);
                }
                else
                {
                    RunOnUiThread(() =>
                    {
                        Toast.MakeText(this, "An Error Has Accured Please Try Again Later", ToastLength.Long).Show();
                        LoadPanel.Visibility = Android.Views.ViewStates.Gone;
                    });
                }
            });
        }        // Register button handler
Exemple #4
0
        private void CheckForLoggedUser()
        {
            ISharedPreferences       prefs  = PreferenceManager.GetDefaultSharedPreferences(this);
            ISharedPreferencesEditor editor = prefs.Edit();

            string Number = prefs.GetString("PhoneNumber", null);

            if (Number != null)
            {
                var auth = RestQueries.Authenticate(Number);
                if (auth.Logged)
                {
                    ProceedToMainActivity(Number, auth.Data);
                }
            }
        }                                      // Check if a user is already logged in