コード例 #1
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();
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
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();
            }
        }