示例#1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Navigation);

            // Create an instance of Preferences which will manage the shared preferences in Android.
            _Preferences = new Preferences();

            // Set up the navigation drawer.
            CreateNavigationMenu();

            if (bundle == null)
            {
                // Show the Daily Planner by default.
                // Create an instance of the fragment.
                Fragment fragment = new PlannerDailyFragment();

                // Use the FragmentManager to assign the fragment to the content layout.
                //FragmentManager fragmentManager = this.FragmentManager;
                FragmentManager.BeginTransaction()
                .Replace(Resource.Id.content, fragment)
                .Commit();
            }
        }
示例#2
0
        private void SelectItem(object sender, AdapterView.ItemClickEventArgs e)
        {
            Fragment fragment = null;

            switch (e.Position)
            {
            case 0:
                fragment = new PlannerDailyFragment();
                break;

            case 1:
                fragment = new PlannerWeeklyFragment();
                break;

            case 2:
                fragment = new SettingsFragment();
                break;

            case 3:
                //TODO logout here
                if (!_Preferences.DemoMode)
                {
                    // Make sure we're not running in demo mode, then logout and redirect to the login fragment.
                    Logout();

                    // Destroy the local cookie.
                    _Preferences.AuthenticationCookie = default(Cookie);
                    fragment = new LoginFragment();
                }
                break;
            }

            if (fragment != null)
            {
                // Load the requested fragment.
                FragmentManager.BeginTransaction()
                .Replace(Resource.Id.content, fragment)
                .AddToBackStack(null)
                .Commit();
            }
        }
示例#3
0
        private async void Save_OnClick(object sender, EventArgs e)
        {
            try
            {
                // Prepare the ActivityLog backend object.
                BackendActivityLog backend = new BackendActivityLog();

                // Get data from the UI
                TimePicker startTime = View.FindViewById <TimePicker>(Resource.Id.tpStartTime);
                TimePicker endTime   = View.FindViewById <TimePicker>(Resource.Id.tpEndTime);

                // Create timespan's that hold the updated time for this activity log.
                TimeSpan newStartTime = new TimeSpan(startTime.Hour, startTime.Minute, 0);
                TimeSpan newEndTime   = new TimeSpan(endTime.Hour, endTime.Minute, 0);

                // Update the startStart and endTimes.
                DateTime modStart = _ActivityLogs[_ActivityLogIndex].StartTime.Date + newStartTime;
                DateTime modEnd   = _ActivityLogs[_ActivityLogIndex].EndTime.Date + newEndTime;

                // Check if Demo mode is enabled, if not - update the acitivity log in the backend.
                // Otherwise, update the activity log and send it back to the Planner activity.
                if (!_Preferences.DemoMode)
                {
                    // Submit these changes to the backend.
                    await backend.Update(_ActivityLogs[_ActivityLogIndex].ActivityLogId, modStart, modEnd);
                }
                else
                {
                    // Update the activity log.
                    _ActivityLogs[_ActivityLogIndex].StartTime = modStart;
                    _ActivityLogs[_ActivityLogIndex].EndTime   = modEnd;

                    // Save the activity logs to disk so they can be view on the planner.
                    CacheActivityLogs();
                }

                // Return to the previous fragment.
                FragmentTransaction fragmentTransaction = FragmentManager.BeginTransaction();
                Fragment            fragment;

                // Create an instance of the planner fragment based on the senders view type (weekly or daily).
                if (_PlannerMode == PlannerFragment.DAILY_VIEW)
                {
                    fragment = new PlannerDailyFragment();
                }
                else
                {
                    fragment = new PlannerWeeklyFragment();
                }

                // Create a bundle that can be passed back to the planner.
                Bundle fragmentBundle = new Bundle();

                // Send the activity log's date back to the planner, so that the updated log is in the view.
                fragmentBundle.PutInt("viewDateYear", _ActivityLogs[_ActivityLogIndex].StartTime.Year);
                fragmentBundle.PutInt("viewDateMonth", _ActivityLogs[_ActivityLogIndex].StartTime.Month);
                fragmentBundle.PutInt("viewDateDay", _ActivityLogs[_ActivityLogIndex].StartTime.Day);

                // Attach the bundle to the fragment and commit it.
                fragment.Arguments = fragmentBundle;
                fragmentTransaction.Replace(Resource.Id.content, fragment).Commit();
            }
            catch (System.Net.WebException ex)
            {
                if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Unauthorized)
                {
                    // The user is not logged in. Move to the Login activity.
                    StartActivity(new Intent(this.Activity, typeof(LoginFragment)));
                }
                System.Diagnostics.Debug.WriteLine("Encountered an error while trying to connect to the server: " + ex.Message);
            }
        }
示例#4
0
        private async void Delete_OnClick(object sender, EventArgs e)
        {
            // Prepare the Fragment manager.
            FragmentTransaction fragmentTransaction = FragmentManager.BeginTransaction();
            Fragment            fragment;

            // Return to the planner fragment.
            // Create an instance of the planner fragment based on the senders view type (weekly or daily).
            if (_PlannerMode == PlannerFragment.DAILY_VIEW)
            {
                fragment = new PlannerDailyFragment();
            }
            else
            {
                fragment = new PlannerWeeklyFragment();
            }

            // Create a bundle that can be passed back to the planner.
            Bundle fragmentBundle = new Bundle();

            // Send the activity log's date back to the planner.
            fragmentBundle.PutInt("viewDateYear", _ActivityLogs[_ActivityLogIndex].StartTime.Year);
            fragmentBundle.PutInt("viewDateMonth", _ActivityLogs[_ActivityLogIndex].StartTime.Month);
            fragmentBundle.PutInt("viewDateDay", _ActivityLogs[_ActivityLogIndex].StartTime.Day);

            // Attach the fragment bundle.
            fragment.Arguments = fragmentBundle;

            if (!_Preferences.DemoMode)
            {
                // Demo mode is disabled. Update the activity log in the backend.
                try
                {
                    // Prepare the ActivityLog backend object.
                    BackendActivityLog backend = new BackendActivityLog();

                    // Submit these changes to the backend.
                    await backend.Delete(_ActivityLogs[_ActivityLogIndex].ActivityLogId);

                    // Switch to the fragment.
                    fragmentTransaction.Replace(Resource.Id.content, fragment).Commit();
                }
                catch (System.Net.WebException ex)
                {
                    if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Unauthorized)
                    {
                        // The user is not logged in. Move to the Login activity.
                        StartActivity(new Intent(this.Activity, typeof(LoginFragment)));
                    }
                    System.Diagnostics.Debug.WriteLine("Encountered an error while trying to connect to the server: " + ex.Message);
                }
            }
            else
            {
                // Demo mode is enabled, delete the log from the list and write it to disk.
                _ActivityLogs.RemoveAt(_ActivityLogIndex);
                CacheActivityLogs();

                // Switch to the fragment.
                fragmentTransaction.Replace(Resource.Id.content, fragment).Commit();
            }
        }
示例#5
0
        private async void Login_OnClick(object sender, EventArgs e)
        {
            // Get the TextView's the contain the username and password.
            TextView usernameTxt = View.FindViewById <TextView>(Resource.Id.txtUsername);
            TextView passwordTxt = View.FindViewById <TextView>(Resource.Id.txtPassword);

            // Extract the text.
            string username = usernameTxt.Text.Trim();
            string password = passwordTxt.Text.Trim();

            if (username == "" || password == "")
            {
                View.FindViewById <TextView>(Resource.Id.tvErrors).Text = GetString(Resource.String.login_required_fields);
                return;
            }

            // Use a try and catch to determine if the username or password is incorrect.
            try
            {
                // Create an instance of the backend.
                BackendUser backend = new BackendUser();
                await backend.Login(username, password);

                // Switch back to the Planner fragment
                Fragment fragment = new PlannerDailyFragment();

                // Load the fragment.
                FragmentManager.BeginTransaction()
                .Replace(Resource.Id.content, fragment)
                .Commit();
            }
            catch (WebException ex)
            {
                // Use WebException to get the status code returned from the API.
                if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.Unauthorized)
                {
                    // User failed to authenticate. Tell them the username or password is incorrect.
                    View.FindViewById <TextView>(Resource.Id.tvErrors).Text = GetString(Resource.String.login_incorrect);
                }
                else
                {
                    // Some other error was thrown.
                    View.FindViewById <TextView>(Resource.Id.tvErrors).Text = GetString(Resource.String.unknown_error);
                }
            }
            catch (BackendTimeoutException)
            {
                // Display a popup.
                DisplayAlert(GetString(Resource.String.timeout), GetString(Resource.String.timeout_message));
            }
            catch (AggregateException ex)
            {
                // Catch the aggregate exception, this might be thrown by the asynchronous tasks in the backend.
                // Handle any of the types that we are aware of.
                // Managing of aggregate exceptions modified from code found here: https://msdn.microsoft.com/en-us/library/dd537614%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

                ex.Handle((x) =>
                {
                    if (x is WebException)
                    {
                        // Check for an inner exception of Socket Exception
                        if (x.InnerException is System.Net.Sockets.SocketException)
                        {
                            // There is an issue connecting to the backend.
                            DisplayAlert(GetString(Resource.String.connection_failed), GetString(Resource.String.connection_failed_message));
                        }

                        // This exception matched, return true.
                        return(true);
                    }

                    // Was not able to handle the exception.
                    return(false);
                });
            }
        }