/// <summary>
        /// Triggers when the chart data is fully loaded
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ChartDataRetriever_OnAgeDataComplete(object sender, ChartDataRetriever.OnAgeEventArgs e)
        {
            List <int> ageValues = new List <int>();
            List <int> ageGroups = new List <int>();

            ageGroups = e.Age;

            if (ageGroups != null)
            {
                ageValues.Add((from age in ageGroups where age < 15 select age).Count());
                ageValues.Add((from age in ageGroups where age >= 15 && age < 25 select age).Count());
                ageValues.Add((from age in ageGroups where age >= 25 && age < 55 select age).Count());
                ageValues.Add((from age in ageGroups where age >= 55 && age < 65 select age).Count());
                ageValues.Add((from age in ageGroups where age >= 65 select age).Count());
            }
            else
            {
                string error = "There was a problem retrieving the record.";
                mActivity.RunOnUiThread(() =>
                {
                    AlertGenerator.ShowError(error, mActivity);
                });
            }

            DataEntries(ageValues);
        }
Exemple #2
0
        /// <summary>
        /// Triggers when the chart data is fully loaded
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ChartDataRetriever_OnPlayTimeDataComplete(object sender, ChartDataRetriever.OnPlayTimeEventArgs e)
        {
            List <int>      playTimeValues = new List <int>();
            List <TimeSpan> playTimes      = new List <TimeSpan>();

            playTimes = e.PlayTime;

            if (playTimes != null)
            {
                playTimeValues.Add((from time in playTimes where time < new TimeSpan(1, 0, 0) select time).Count());
                playTimeValues.Add((from time in playTimes where time >= new TimeSpan(1, 0, 0) && time < new TimeSpan(5, 0, 0) select time).Count());
                playTimeValues.Add((from time in playTimes where time >= new TimeSpan(5, 0, 0) && time < new TimeSpan(20, 0, 0) select time).Count());
                playTimeValues.Add((from time in playTimes where time >= new TimeSpan(20, 0, 0) && time < new TimeSpan(100, 0, 0) select time).Count());
                playTimeValues.Add((from time in playTimes where time >= new TimeSpan(100, 0, 0) select time).Count());
            }
            else
            {
                string error = "There was a problem retrieving the record.";
                mActivity.RunOnUiThread(() =>
                {
                    AlertGenerator.ShowError(error, mActivity);
                });
            }

            DataEntries(playTimeValues);
        }
Exemple #3
0
        /// <summary>
        /// Method for loading data into the listview
        /// </summary>
        private void LoadData()
        {
            mProgressBar = FindViewById <ProgressBar>(Resource.Id.leaderboardProgressBar);

            Task.Factory.StartNew(() =>
            {
                RunOnUiThread(() => mProgressBar.Visibility = ViewStates.Visible);
                if (DbConnector.OpenSQLConnection())
                {
                    // Connection opened
                    PlayerStatsDA statsDA = new PlayerStatsDA();
                    mItems = statsDA.GetAllStats();

                    RunOnUiThread(() =>
                    {
                        // Refresh ListView
                        mAdapter          = new MyListViewAdapter(this, mItems);
                        mListView.Adapter = mAdapter;
                    });
                }
                else
                {
                    // Connection could not be opened
                    string error = "Connection to the database could not be established.";
                    RunOnUiThread(() =>
                    {
                        //Enabling the controls back
                        AlertGenerator.ShowError(error, this);
                    });
                }

                DbConnector.CloseSQLConnection(); // Close connection to the database
                RunOnUiThread(() => mProgressBar.Visibility = ViewStates.Gone);
            });
        }
Exemple #4
0
        /// <summary>
        /// Handles BtnSend event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSend_Click(object sender, EventArgs e)
        {
            string message = mTxtFeedback.Text.Trim();

            if (message.Length > 255)
            {
                string error = "Sorry, the feedback message is too long.";
                AlertGenerator.ShowError(error, this);
            }
            else
            {
                DisableEnableControls(false);

                Task.Factory.StartNew(() =>
                {
                    if (DbConnector.OpenSQLConnection())
                    {
                        // Connection opened
                        Feedback feedback = new Feedback()
                        {
                            Username = Intent.GetStringExtra("Username"),
                            Rating   = mRatingBar.Rating,
                            Message  = message,
                            Date     = DateTime.Now.Date
                        };

                        FeedbackDA feedbackDA = new FeedbackDA();
                        if (feedbackDA.InsertFeedback(feedback))
                        {
                            // Feedback was added successfully
                            Finish(); // Close this activity
                            OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom);
                        }
                        else
                        {
                            string error = "There was a problem saving the record.";
                            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
                });
            }
        }
        /// <summary>
        /// Method for setting the user data into the fields
        /// </summary>
        private void SetData()
        {
            mProgressBar.Visibility = ViewStates.Visible;

            Task.Factory.StartNew(() =>
            {
                if (DbConnector.OpenSQLConnection())
                {
                    // Connection opened
                    UserDA userDA   = new UserDA();
                    User resultUser = userDA.FindUser(Intent.GetStringExtra("Username"));
                    if (resultUser != null)
                    {
                        // User found
                        RunOnUiThread(() =>
                        {
                            if (resultUser.Pic != null)
                            {
                                mUserImg = BitmapFactory.DecodeByteArray(resultUser.Pic, 0, resultUser.Pic.Length);
                                mUserPic.SetImageBitmap(mUserImg);
                            }
                            else
                            {
                                mUserPic.SetImageResource(Resource.Drawable.default_pic);
                            }
                            mTxtUsername.Text       = resultUser.Username;
                            mTxtFullName.Text       = resultUser.FullName;
                            mTxtEmail.Text          = resultUser.Email;
                            mTxtDOB.Text            = resultUser.DOB.ToShortDateString();
                            mProgressBar.Visibility = ViewStates.Gone;
                        });
                    }
                    else
                    {
                        // User not found
                        string error = "There was a problem when trying to retrieve data.";
                        RunOnUiThread(() =>
                        {
                            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
            });
        }
Exemple #6
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
            });
        }
Exemple #7
0
        /// <summary>
        /// Override OnOptionsItemSelected function
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            int id = item.ItemId;

            if (id == Resource.Id.action_settings)
            {
                // Clicked on Settings
                return(true);
            }
            else if (id == Resource.Id.image_from_url)
            {
                // Clicked on ImageSearch
                using (View searchView = item.ActionView)
                {
                    using (var _searchView = searchView.JavaCast <Android.Support.V7.Widget.SearchView>())
                    {
                        _searchView.QueryHint = "Add image from url..."; // Set SearchView Hint (Placeholder) text
                        _searchView.MaxWidth  = int.MaxValue;            // Set the SearchView max width

                        // Get the value of the SearchView
                        _searchView.QueryTextSubmit += (s, e) =>
                        {
                            if (mBtnBrowse.Enabled)
                            {
                                LoadImage(null, e.Query);
                            }
                            else
                            {
                                string error = "Please pause the current puzzle before adding a new image.";
                                AlertGenerator.ShowError(error, this);
                            }
                            e.Handled = true;
                            mBtnPlay.RequestFocus(); // Change focus

                            // Close the keyboard
                            View view = CurrentFocus;
                            if (view != null)
                            {
                                KeyboardManager.CloseKeyboard(view, this); // Closing the keyboard on focus change
                            }
                        };
                    }
                }
                return(true);
            }
            return(base.OnOptionsItemSelected(item));
        }
        /// <summary>
        /// Method for loading the image asynchronously
        /// </summary>
        /// <param name="data"></param>
        /// <param name="url"></param>
        private async void LoadImage(Intent data)
        {
            try
            {
                // Call BitmapMaker to draw the selected image into a resampled bitmap
                Bitmap result = await BitmapMaker.CreateBitmapImage(240, 240, mUserPic.Width, mUserPic.Height, data, this);

                if (result != null)
                {
                    mUserImg = result;
                }
            }
            catch
            {
                string error = "There was a problem trying to load the image.";
                AlertGenerator.ShowError(error, this);
            }

            mUserPic.SetImageBitmap(mUserImg); // Set the bitmap into the userPic imageView
        }
        /// <summary>
        /// Handles BtnUpdate event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MBtnUpdate_Click(object sender, EventArgs e)
        {
            string fullname = mTxtFullName.Text.Trim();
            string email    = mTxtEmail.Text.Trim();

            #region Input validation
            if (fullname.Length < 1 || email.Length < 1 || mTxtDOB.Text.Length < 1 ||
                mTxtCurrentPwd.Text.Length < 1 || mTxtNewPwd.Text.Length < 1 || mTxtNewConfPwd.Text.Length < 1)
            {
                string error = "Please fill all the fields.";
                AlertGenerator.ShowError(error, this);
                return;
            }
            else if (mTxtNewPwd.Text.Length < 8)
            {
                string error = "Password must contain at least 8 characters.";
                AlertGenerator.ShowError(error, this);
                return;
            }
            else if (mTxtNewPwd.Text != mTxtNewConfPwd.Text)
            {
                string error = "Password and Confirm Password do not match.";
                AlertGenerator.ShowError(error, this);
                return;
            }
            #endregion

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

            Task.Factory.StartNew(() =>
            {
                if (DbConnector.OpenSQLConnection())
                {
                    // Connection opened
                    byte[] imgBytes = null;
                    if (mUserImg != null)
                    {
                        // Converting the bitmap into a byte array
                        MemoryStream memStream = new MemoryStream();
                        mUserImg.Compress(Bitmap.CompressFormat.Webp, 100, memStream);
                        imgBytes = memStream.ToArray();
                    }

                    User user = new User()
                    {
                        Username = mTxtUsername.Text.Trim(),
                        FullName = fullname,
                        Email    = email,
                        DOB      = DateTime.Parse(mTxtDOB.Text),
                        Password = CryptoHasher.Hash(mTxtNewPwd.Text),
                        Pic      = imgBytes
                    };

                    UserDA userDA = new UserDA();
                    if (userDA.UpdateUser(user, Intent.GetStringExtra("Username"), CryptoHasher.Hash(mTxtCurrentPwd.Text)))
                    {
                        // User details updated successfully
                        Intent intent = new Intent(this, typeof(LoginActivity));
                        StartActivity(intent);
                        OverridePendingTransition(Resource.Animation.slide_in_top, Resource.Animation.slide_out_bottom);
                        Finish(); // Close this activity
                    }
                    else
                    {
                        string error = "Invalid 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
            });
        }
        /// <summary>
        /// Handles BtnSignUp click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSignUp_Click(object sender, EventArgs e)
        {
            string username = mTxtUsername.Text.Trim();
            string fullname = mTxtFullName.Text.Trim();
            string email    = mTxtEmail.Text.Trim();

            #region Input validation
            if (username.Length < 1 || fullname.Length < 1 || email.Length < 1 || mTxtDOB.Text.Length < 1 ||
                mTxtPwd.Text.Length < 1 || mTxtConfPwd.Text.Length < 1)
            {
                string error = "Please fill all the fields.";
                AlertGenerator.ShowError(error, this);
                return;
            }
            else if (mTxtPwd.Text.Length < 8)
            {
                string error = "Password must contain at least 8 characters.";
                AlertGenerator.ShowError(error, this);
                return;
            }
            else if (mTxtPwd.Text != mTxtConfPwd.Text)
            {
                string error = "Password and Confirm Password do not match.";
                AlertGenerator.ShowError(error, this);
                return;
            }
            #endregion

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

            Task.Factory.StartNew(() =>
            {
                if (DbConnector.OpenSQLConnection())
                {
                    // Connection opened
                    UserDA userDA = new UserDA();
                    if (userDA.IsUsernameExists(username))
                    {
                        string error = "The Username entered already exist.";
                        RunOnUiThread(() =>
                        {
                            //Enabling the controls back
                            DisableEnableControls(true);
                            AlertGenerator.ShowError(error, this);
                        });
                    }
                    else
                    {
                        byte[] imgBytes = null;
                        if (mUserImg != null)
                        {
                            // Converting the bitmap into a byte array
                            MemoryStream memStream = new MemoryStream();
                            mUserImg.Compress(Bitmap.CompressFormat.Webp, 100, memStream);
                            imgBytes = memStream.ToArray();
                        }

                        User user = new User()
                        {
                            Username = username,
                            FullName = fullname,
                            Email    = email,
                            DOB      = DateTime.Parse(mTxtDOB.Text),
                            Password = CryptoHasher.Hash(mTxtPwd.Text),
                            Pic      = imgBytes
                        };

                        DbConnector.CloseSQLConnection(); // Close connection to the database
                        if (DbConnector.OpenSQLConnection())
                        {
                            if (userDA.InsertUser(user))
                            {
                                // User was added successfully
                                // Add a record to leaderboard
                                PlayerStats stats = new PlayerStats()
                                {
                                    Username = username,
                                    XP       = 0,
                                    SR       = 0,
                                    PlayTime = TimeSpan.FromSeconds(0),
                                    Golds    = 0,
                                    Silvers  = 0,
                                    Bronzes  = 0
                                };

                                DbConnector.CloseSQLConnection(); // Close connection to the database
                                PlayerStatsDA statsDA = new PlayerStatsDA();
                                if (DbConnector.OpenSQLConnection())
                                {
                                    if (!statsDA.InsertStats(stats))
                                    {
                                        string error = "There was a problem updating your stats.";
                                        RunOnUiThread(() =>
                                        {
                                            AlertGenerator.ShowError(error, this);
                                        });
                                    }
                                }

                                // Add achievements
                                List <AchievementsCompleted> achievementsCompleted = new List <AchievementsCompleted>();
                                for (int i = 1; i < 20; i++)
                                {
                                    achievementsCompleted.Add(new AchievementsCompleted()
                                    {
                                        Username = username,
                                        Progress = 0,
                                        Status   = false
                                    });
                                }

                                DbConnector.CloseSQLConnection(); // Close connection to the database
                                if (DbConnector.OpenSQLConnection())
                                {
                                    AchievementsDA achievementsDA = new AchievementsDA();
                                    if (!achievementsDA.InsertAchievements(achievementsCompleted))
                                    {
                                        string error = "There was a problem updating your stats.";
                                        RunOnUiThread(() =>
                                        {
                                            AlertGenerator.ShowError(error, this);
                                        });
                                    }
                                }

                                // Navigate to Login activity
                                Intent intent = new Intent(this, typeof(LoginActivity));
                                StartActivity(intent);
                                OverridePendingTransition(Resource.Animation.slide_in_left, Resource.Animation.slide_out_right);
                                Finish(); // Close this activity
                            }
                            else
                            {
                                string error = "There was a problem saving the record.";
                                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);
                            });
                        }
                    }
                }
                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
            });
        }
Exemple #11
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
            });
        }
Exemple #12
0
        /// <summary>
        /// Method for updating player stats and achievements once a puzzle is fixed
        /// </summary>
        /// <param name="scores"></param>
        private void UpdatePlayerStats(PlayerStats scores)
        {
            if (mUsername != String.Empty)
            {
                Task.Factory.StartNew(() =>
                {
                    PlayerStats stats = new PlayerStats();

                    #region Update Player Stats
                    if (DbConnector.OpenSQLConnection())
                    {
                        // Connection opened
                        PlayerStatsDA statsDA = new PlayerStatsDA();
                        if (statsDA.IsStatsExist(mUsername))
                        {
                            // Stats exist, therefore update
                            stats           = statsDA.FindStats(mUsername);
                            stats.XP       += scores.XP;
                            stats.SR       += scores.SR;
                            stats.PlayTime += TimeSpan.FromSeconds(mTimeInSeconds);
                            stats.Golds    += scores.Golds;
                            stats.Silvers  += scores.Silvers;
                            stats.Bronzes  += scores.Bronzes;

                            DbConnector.CloseSQLConnection(); // Close connection to the database
                            if (DbConnector.OpenSQLConnection())
                            {
                                if (!statsDA.UpdateStats(stats))
                                {
                                    string error = "There was a problem updating your stats.";
                                    RunOnUiThread(() =>
                                    {
                                        AlertGenerator.ShowError(error, this);
                                    });
                                }
                            }
                            else
                            {
                                // Connection could not be opened
                                string error = "Connection to the database could not be established.";
                                RunOnUiThread(() =>
                                {
                                    AlertGenerator.ShowError(error, this);
                                });
                            }
                        }
                        else
                        {
                            // Stats does not exist, therefore insert
                            stats.Username = mUsername;
                            stats.XP       = scores.XP;
                            stats.SR       = scores.SR;
                            stats.PlayTime = TimeSpan.FromSeconds(mTimeInSeconds);
                            stats.Golds    = scores.Golds;
                            stats.Silvers  = scores.Silvers;
                            stats.Bronzes  = scores.Bronzes;

                            if (!statsDA.InsertStats(stats))
                            {
                                string error = "There was a problem updating your stats.";
                                RunOnUiThread(() =>
                                {
                                    AlertGenerator.ShowError(error, this);
                                });
                            }
                        }
                    }
                    else
                    {
                        // Connection could not be opened
                        string error = "Connection to the database could not be established.";
                        RunOnUiThread(() =>
                        {
                            AlertGenerator.ShowError(error, this);
                        });
                    }

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

                    #region Update Achievements
                    if (DbConnector.OpenSQLConnection())
                    {
                        // Connection opened
                        AchievementsDA achievementsDA = new AchievementsDA();
                        List <AchievementsCompleted> achievementsCompleted = new List <AchievementsCompleted>();
                        achievementsCompleted = achievementsDA.GetAllAchievements(mUsername);
                        DbConnector.CloseSQLConnection(); // Close connection to the database

                        if (achievementsCompleted != null)
                        {
                            // Achievements exist, therefore update
                            achievementsCompleted = AchievementsTracker.UpdateAchievements(achievementsCompleted, mUsername, stats, mCurrentMode, sCurrentLvl);
                            for (int i = 0; i < 19; i++)
                            {
                                if (achievementsCompleted[i].Title != String.Empty)
                                {
                                    string title       = achievementsCompleted[i].Title;
                                    string description = achievementsCompleted[i].Description;
                                    string image       = achievementsCompleted[i].Image;

                                    // Pull up Achievement dialog
                                    FragmentTransaction transaction = FragmentManager.BeginTransaction();
                                    AchDialog dialogFrag            = new AchDialog(title, description, image);
                                    dialogFrag.Show(transaction, "dialog fragment");
                                }
                            }
                            if (DbConnector.OpenSQLConnection())
                            {
                                if (!achievementsDA.UpdateAchievements(achievementsCompleted))
                                {
                                    string error = "There was a problem updating your stats.";
                                    RunOnUiThread(() =>
                                    {
                                        AlertGenerator.ShowError(error, this);
                                    });
                                }
                            }
                            else
                            {
                                // Connection could not be opened
                                string error = "Connection to the database could not be established.";
                                RunOnUiThread(() =>
                                {
                                    AlertGenerator.ShowError(error, this);
                                });
                            }
                        }
                        else
                        {
                            // Achievements do not exist, therefore insert
                            achievementsCompleted = AchievementsTracker.InsertAchievements(achievementsCompleted, mUsername, mCurrentMode);

                            if (DbConnector.OpenSQLConnection())
                            {
                                if (!achievementsDA.InsertAchievements(achievementsCompleted))
                                {
                                    string error = "There was a problem updating your stats.";
                                    RunOnUiThread(() =>
                                    {
                                        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
                            AlertGenerator.ShowError(error, this);
                        });
                    }

                    DbConnector.CloseSQLConnection(); // Close connection to the database
                    #endregion
                });
            }
        }
Exemple #13
0
        /// <summary>
        /// Method for loading the image asynchronously
        /// </summary>
        /// <param name="data"></param>
        /// <param name="url"></param>
        private async void LoadImage(Intent data, string url)
        {
            mPuzzlePanel.RemoveView(mPicBoxWhole);
            mLayoutMessage.Visibility  = ViewStates.Gone;
            mLayoutProgress.Visibility = ViewStates.Visible;
            sTvProgress.Text           = "0%";
            GC.Collect(); // Must call Garbage Collector

            try
            {
                // Call BitmapMaker to draw the selected image into a resampled bitmap
                if (url == null)
                {
                    mImage = await BitmapMaker.CreateBitmapImage(640, 360, mPuzzlePanel.Width, mPuzzlePanel.Height - 2, data, this);

                    sCurrentLvl   = LVL_1_NUM;
                    mBtnPlay.Text = "Play";
                    Drawable img = ContextCompat.GetDrawable(this, Resource.Drawable.ic_play_white);
                    mBtnPlay.SetCompoundDrawablesWithIntrinsicBounds(img, null, null, null); // Set button icon
                }
                else
                {
                    // Check for network availability
                    if (ConnectionChecker.IsNetworkAvailable(this))
                    {
                        Bitmap result = await BitmapMaker.CreateBitmapImage(640, 360, mPuzzlePanel.Width, mPuzzlePanel.Height - 2, url, sTvProgress, this);

                        if (result != null)
                        {
                            mImage        = result;
                            sCurrentLvl   = LVL_1_NUM;
                            mBtnPlay.Text = "Play";
                            Drawable img = ContextCompat.GetDrawable(this, Resource.Drawable.ic_play_white);
                            mBtnPlay.SetCompoundDrawablesWithIntrinsicBounds(img, null, null, null); // Set button icon
                        }
                        else
                        {
                            string error = "Couldn't load the image. Please check the URL.";
                            AlertGenerator.ShowError(error, this);
                        }
                    }
                    else
                    {
                        string error = "Device is not connected to a network.";
                        AlertGenerator.ShowError(error, this);
                    }
                }
            }
            catch
            {
                string error = "There was a problem trying to load the image.";
                AlertGenerator.ShowError(error, this);
            }

            mPuzzlePanel.AddView(mPicBoxWhole);  // Add picBoxWhole to puzzlePanel
            mPicBoxWhole.SetImageBitmap(mImage); // Set the bitmap into the picBoxWhole imageView

            mLayoutProgress.Visibility = ViewStates.Gone;
            mLayoutMessage.Visibility  = ViewStates.Visible;

            if (mImage != null)
            {
                // Make btnPlay clickable
                mBtnPlay.Enabled = true;
                mBtnPlay.SetBackgroundResource(Resource.Drawable.btn_accent_style);
            }
        }