Esempio n. 1
0
        /// <summary>
        /// Override OnBackPressed method
        /// </summary>
        public override void OnBackPressed()
        {
            if (mBtnLogin.Enabled)
            {
                MyEventHandler.Trigger(this, "Player", "Player One", null, false);
                Finish(); // Call Finish method when back button is pressed
                OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom);
            }

            base.OnBackPressed();
        }
Esempio n. 2
0
        /// <summary>
        /// Handles deletion of the user
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DialogFrag_OnDeleteComplete(object sender, DeleteUserDialog.OnDeleteEventArgs e)
        {
            mProgressBar.Visibility = ViewStates.Visible;
            Task.Factory.StartNew(() =>
            {
                if (DbConnector.OpenSQLConnection())
                {
                    // Connection opened
                    User user = new User()
                    {
                        Username = Intent.GetStringExtra("Username"),
                        Password = CryptoHasher.Hash(e.Password)
                    };

                    UserDA userDA = new UserDA();
                    if (userDA.DeleteUser(user))
                    {
                        // User deleted
                        RunOnUiThread(() => MyEventHandler.Trigger(this));
                        Finish(); // Close the activity
                        OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom);
                    }
                    else
                    {
                        string error = "Invalid password.";
                        RunOnUiThread(() =>
                        {
                            //Enabling the controls back
                            mProgressBar.Visibility = ViewStates.Gone;
                            AlertGenerator.ShowError(error, this);
                        });
                    }
                }
                else
                {
                    // Connection could not be opened
                    string error = "Connection to the database could not be established.";
                    RunOnUiThread(() =>
                    {
                        //Enabling the controls back
                        mProgressBar.Visibility = ViewStates.Gone;
                        AlertGenerator.ShowError(error, this);
                    });
                }

                DbConnector.CloseSQLConnection(); // Close connection to the database
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Override OnOptionsItemSelected method
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            switch (item.ItemId)
            {
            case Android.Resource.Id.Home:
                if (mBtnLogin.Enabled)
                {
                    MyEventHandler.Trigger(this, "Player", "Player One", null, false);
                    Finish();     // Call Finish method when back button is pressed
                    OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom);
                }
                return(true);

            default:
                return(base.OnOptionsItemSelected(item));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Override OnCreate method
        /// </summary>
        /// <param name="savedInstanceState"></param>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_splash);

            Task.Factory.StartNew(() =>
            {
                // Load splash loading image
                ImageViewAsync splashGif = FindViewById <ImageViewAsync>(Resource.Id.splashImageView);
                ImageService.Instance.LoadCompiledResource("loading").Into(splashGif);

                // Read UserInfo for saved credentials if available
                ISharedPreferences pref = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);
                string username         = pref.GetString("Username", String.Empty);
                string password         = pref.GetString("Password", String.Empty);

                if (username == String.Empty || password == String.Empty)
                {
                    // No saved credentials, take user to the access screen
                    DbConnector.OpenSQLConnection();
                    DbConnector.CloseSQLConnection();
                    Intent intent = new Intent(this, typeof(MainActivity));
                    intent.PutExtra("LoggingStatus", false);
                    StartActivity(intent);
                    OverridePendingTransition(Resource.Animation.slide_in_left, Resource.Animation.slide_out_right);
                    Finish(); // Close this activity
                    RunOnUiThread(() => MyEventHandler.Trigger(this, "Player", "Player One", null, false));
                }
                else
                {
                    // Saved credentials found
                    // Validate credentials
                    if (DbConnector.OpenSQLConnection())
                    {
                        // Connection opened
                        User user = new User()
                        {
                            Username = username,
                            Password = password
                        };

                        UserDA userDA   = new UserDA();
                        User resultUser = userDA.LoginUser(user);
                        if (resultUser != null)
                        {
                            // User found
                            Intent resultIntent = new Intent(this, typeof(MainActivity));
                            resultIntent.PutExtra("LoggingStatus", true);
                            StartActivity(resultIntent);
                            OverridePendingTransition(Resource.Animation.slide_in_left, Resource.Animation.slide_out_right);
                            Finish(); // Close this activity
                            RunOnUiThread(() => MyEventHandler.Trigger(this, resultUser.Username, resultUser.FullName, resultUser.Pic, true));
                        }
                        else
                        {
                            // Saved credentials are incorrect, take the user to access screen
                            ISharedPreferencesEditor edit = pref.Edit();
                            edit.Remove("Username");
                            edit.Remove("Password");
                            edit.Apply();

                            Intent intent = new Intent(this, typeof(MainActivity));
                            intent.PutExtra("LoggingStatus", false);
                            StartActivity(intent);
                            OverridePendingTransition(Resource.Animation.slide_in_left, Resource.Animation.slide_out_right);
                            Finish(); // Close this activity
                            RunOnUiThread(() => MyEventHandler.Trigger(this, "Player", "Player One", null, false));
                        }
                    }
                    else
                    {
                        // Connection could not be opened, take the user to access screen
                        Intent intent = new Intent(this, typeof(MainActivity));
                        intent.PutExtra("LoggingStatus", false);
                        StartActivity(intent);
                        OverridePendingTransition(Resource.Animation.slide_in_left, Resource.Animation.slide_out_right);
                        Finish(); // Close this activity
                        RunOnUiThread(() => MyEventHandler.Trigger(this, "Player", "Player One", null, false));
                    }

                    DbConnector.CloseSQLConnection(); // Close connection to the database
                    GC.Collect();                     // Must call Garbage Collector
                }
            });
        }
Esempio n. 5
0
        /// <summary>
        /// Handles btnLogin click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            // Validation
            string username = mTxtUsername.Text.Trim();

            if (username.Length < 1 || mTxtPwd.Text.Length < 1)
            {
                string error = "Please fill all the fields.";
                AlertGenerator.ShowError(error, this);
                return;
            }

            // Disabling controls while saving the record
            DisableEnableControls(false);

            Task.Factory.StartNew(() =>
            {
                if (DbConnector.OpenSQLConnection())
                {
                    // Connection opened
                    User user = new User()
                    {
                        Username = mTxtUsername.Text,
                        Password = CryptoHasher.Hash(mTxtPwd.Text)
                    };

                    UserDA userDA   = new UserDA();
                    User resultUser = userDA.LoginUser(user);
                    if (resultUser != null)
                    {
                        // User found
                        ISharedPreferences pref       = Application.Context.GetSharedPreferences("UserInfo", FileCreationMode.Private);
                        ISharedPreferencesEditor edit = pref.Edit();
                        if (mRememberMe.Checked)
                        {
                            // Save credentials in shared preferences
                            edit.PutString("Username", resultUser.Username);
                            edit.PutString("Password", resultUser.Password);
                            edit.Apply();
                        }
                        else
                        {
                            // Remove credentials from shared preferences
                            edit.Remove("Username");
                            edit.Remove("Password");
                            edit.Apply();
                        }

                        MyEventHandler.Trigger(this, resultUser.Username, resultUser.FullName, resultUser.Pic, true);
                        Finish(); // Close the activity
                        OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom);
                    }
                    else
                    {
                        string error = "Invalid Username or Password.";
                        RunOnUiThread(() =>
                        {
                            //Enabling the controls back
                            DisableEnableControls(true);
                            AlertGenerator.ShowError(error, this);
                        });
                    }
                }
                else
                {
                    // Connection could not be opened
                    string error = "Connection to the database could not be established.";
                    RunOnUiThread(() =>
                    {
                        //Enabling the controls back
                        DisableEnableControls(true);
                        AlertGenerator.ShowError(error, this);
                    });
                }

                DbConnector.CloseSQLConnection(); // Close connection to the database
            });
        }