public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); RetainInstance = true; ((MainActivity)Activity).SetTitle("Settings"); AccountStorage.SetContext(this.Activity); // Create your fragment here AddPreferencesFromResource(Resource.Layout.Settings); Preference pf = FindPreference("login_preference"); pf.Summary = "Logged in as : " + AccountStorage.UserId; pf.PreferenceClick += (sender, args) => { try { System.Diagnostics.Debug.WriteLine("We are about to logout"); AccountStorage.ClearStorage(); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } }; }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use this to return your custom view for this Fragment var lf = inflater.Inflate(Resource.Layout.Login, container, false); var login = lf.FindViewById <Button>(Resource.Id.login_login); var token = lf.FindViewById <TextView>(Resource.Id.login_token); var username = lf.FindViewById <TextView>(Resource.Id.login_username); var password = lf.FindViewById <TextView>(Resource.Id.login_password); //TODO: Remove b4 production AccountStorage.ClearStorage(); token.Text = "GO.YN-HK1"; username.Text = "test"; password.Text = "test"; ProgressDialog pd; login.Click += (sender, args) => { if (token.Text.Equals("") || username.Text.Equals("") || password.Text.Equals("")) { Toast.MakeText(Activity, "Please check the values you have entered", ToastLength.Short).Show(); } else { Debug.WriteLine("We are checking network connection"); if (!CrossConnectivity.Current.IsConnected) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("Unable to connect") .SetMessage("Please check your internet connection and try again") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } else { CheckCredentials(token.Text, username.Text, password.Text); } } }; return(lf); }
private async void AddData(View view) { var projectName = view.FindViewById <TextView>(Resource.Id.TaskDetails_ProjectName); var taskName = view.FindViewById <TextView>(Resource.Id.TaskDetails_TaskName); var notes = view.FindViewById <EditText>(Resource.Id.TaskDetails_Notes); var timeinfo = view.FindViewById <ListView>(Resource.Id.TaskDetails_TimeInfo); var taskComplete = view.FindViewById <CheckBox>(Resource.Id.TaskDetails_TaskComplete); if (_completionDate.HasValue) { taskComplete.Checked = true; } _play = view.FindViewById <Button>(Resource.Id.TaskDetails_Play); _pause = view.FindViewById <Button>(Resource.Id.TaskDetails_Pause); Debug.WriteLine("We are in the begining "); if (TimeLoggingController.GetInstance().IsTimerRunning() && TimeLoggingController.GetInstance().GetTimingTaskId().Equals(_taskId)) { ModifyPlayPauseState(true); } var pb = new ProgressDialog(_mActivity) { Indeterminate = true }; pb.SetTitle("Loading"); pb.SetCanceledOnTouchOutside(false); if (_taskName != null) { taskName.Text = _taskName; } if (_projectName != null) { projectName.Text = _projectName; } Debug.WriteLine(" 0 "); Entry[] output = new Entry[3]; output[0] = new Entry(); output[1] = new Entry(); output[2] = new Entry(); output[0].name = "Planned Time"; if (_estimatedTime.HasValue) { Debug.WriteLine("We have a value in estimated time"); output[0].value = "" + TimeSpan.FromMinutes(_estimatedTime.Value).ToString(@"hh\:mm"); } else { Debug.WriteLine("No value in estimated time"); output[0].value = ""; } Debug.WriteLine(" 1 "); output[1].name = "Actual Time"; if (_actualTime.HasValue) { output[1].value = "" + TimeSpan.FromMinutes(_actualTime.Value).ToString(@"hh\:mm"); } else { output[1].value = ""; } output[2].name = "Completion Date"; Debug.WriteLine(" 2 "); if (_completionDate.HasValue) { output[2].value = Util.GetInstance().GetLocalTime(_completionDate.Value).ToShortDateString(); } else { output[2].value = "-"; } var listAdapter = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem, output); Debug.WriteLine("We have reached the end "); timeinfo.Adapter = listAdapter; pb.Show(); Task taskDetail = null; try { // Get data from server taskDetail = await((MainActivity)Activity).Ctrl.GetTask(AccountStorage.DataSet, _taskId); _play.Click += (sender, args) => { Debug.WriteLine("Play Clicked"); //var timerServiceIntent = new Intent("com.tumasolutions.processdashboard.TimerService"); //var timerServiceConnection = new TimerServiceConnection((MainActivity)this.Activity); //Activity.ApplicationContext.BindService(timerServiceIntent, timerServiceConnection, Bind.AutoCreate); Intent intent = new Intent(Activity, typeof(TimerService)); intent.PutExtra("taskId", taskDetail.Id); Activity.StartService(intent); }; _pause.Click += (sender, args) => { Debug.WriteLine("Pause Clicked"); Activity.StopService(new Intent(Activity, typeof(TimerService))); Toast.MakeText(this.Activity, "Time Log Entry Saved", ToastLength.Short).Show(); }; projectName.Click += (obj, args) => { var projectId = taskDetail.Project.Id; var projectname = taskDetail.Project.Name; ((MainActivity)Activity).ListOfProjectsCallback(projectId, projectname); }; } catch (CannotReachServerException) { if (pb.IsShowing) { pb.Dismiss(); } AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("Unable to Connect") .SetMessage("Please check your network connection and try again") .SetNeutralButton("Okay", (sender, args) => { builder.Dispose(); ((MainActivity)Activity).FragmentManager.PopBackStack(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { if (pb.IsShowing) { pb.Dismiss(); } Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); AccountStorage.ClearStorage(); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (StatusNotOkayException se) { if (pb.IsShowing) { pb.Dismiss(); } AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetMessage("Error :" + se.GetMessage()) .SetNeutralButton("Okay", (sender, args) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (Exception e) { // For any other weird exceptions if (pb.IsShowing) { pb.Dismiss(); } AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetNeutralButton("Okay", (sender, args) => { builder.Dispose(); }) .SetMessage("Error :" + e.Message) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } if (taskDetail == null) { Debug.WriteLine("T is null"); } if (taskDetail != null) { projectName.Text = taskDetail.Project.Name; timeinfo.ItemClick += (sender, args) => { if (args.Position == 0) { LinearLayout ll = new LinearLayout(Activity); ll.Orientation = (Orientation.Horizontal); NumberPicker aNumberPicker = new NumberPicker(Activity); aNumberPicker.MaxValue = (100); aNumberPicker.MinValue = (0); double temp; temp = taskDetail.EstimatedTime; aNumberPicker.Value = TimeSpan.FromMinutes(temp).Hours; NumberPicker aNumberPickerA = new NumberPicker(Activity) { MaxValue = (59), MinValue = (0), Value = TimeSpan.FromMinutes(temp).Minutes }; LinearLayout.LayoutParams parameters = new LinearLayout.LayoutParams(50, 50); parameters.Gravity = GravityFlags.Center; LinearLayout.LayoutParams numPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); numPicerParams.Weight = 1; LinearLayout.LayoutParams qPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); qPicerParams.Weight = 1; ll.LayoutParameters = parameters; ll.AddView(aNumberPicker, numPicerParams); ll.AddView(aNumberPickerA, qPicerParams); //((TaskDetailsAdapter)(timeinfo.Adapter)).GetEntry() //var ts = DateTime.ParseExact("", "HH.mm", CultureInfo.InvariantCulture); AlertDialog.Builder np = new AlertDialog.Builder(Activity).SetView(ll); np.SetTitle("Update Planned Time"); np.SetNegativeButton("Cancel", (s, a) => { np.Dispose(); }); np.SetPositiveButton("Ok", (s, a) => { //Update Planned Time string number = aNumberPicker.Value.ToString("D2") + ":" + aNumberPickerA.Value.ToString("D2"); Debug.WriteLine(number); double val = Convert.ToDouble(TimeSpan.ParseExact(number, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes); Debug.WriteLine("The updated val is :" + val); try { ((MainActivity)(Activity)).Ctrl.UpdateATask(AccountStorage.DataSet, _taskId, val, null, false); } catch (CannotReachServerException) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("Unable to Connect") .SetMessage("Please check your network connection and try again") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); ((MainActivity)Activity).FragmentManager.PopBackStack(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { if (pb.IsShowing) { pb.Dismiss(); } Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); System.Diagnostics.Debug.WriteLine("We are about to logout"); AccountStorage.ClearStorage(); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (StatusNotOkayException se) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetMessage("Error :" + se.GetMessage()) .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (Exception e) { // For any other weird exceptions AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetMessage("Error :" + e.Message) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } output[0].value = TimeSpan.FromMinutes(val).ToString(@"hh\:mm"); listAdapter = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem, output); Debug.WriteLine("We have changed content "); timeinfo.Adapter = listAdapter; Toast.MakeText(_mActivity, "Planned Time Updated", ToastLength.Short).Show(); np.Dispose(); }); np.Show(); //Planned Time } else if (args.Position == 1) { //Actual Time ((MainActivity)Activity).PassTimeLogInfo(taskDetail.Id, taskDetail.Project.Name, taskDetail.FullName); } else if (args.Position == 2) { // Completion Date DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime time) { Debug.WriteLine("The received date is :" + time.ToShortDateString()); output[2].value = time.ToShortDateString(); listAdapter = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem, output); Debug.WriteLine("We have changed content "); timeinfo.Adapter = listAdapter; try { ((MainActivity)(Activity)).Ctrl.UpdateATask(AccountStorage.DataSet, _taskId, null, Util.GetInstance().GetServerTime(time), false); } catch (CannotReachServerException) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("Unable to Connect") .SetMessage("Please check your network connection and try again") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); ((MainActivity)Activity).FragmentManager.PopBackStack(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { if (pb.IsShowing) { pb.Dismiss(); } Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); System.Diagnostics.Debug.WriteLine("We are about to logout"); AccountStorage.ClearStorage(); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (StatusNotOkayException se) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetMessage("Error :" + se.GetMessage()) .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (Exception e) { // For any other weird exceptions AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetMessage("Error :" + e.Message) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } Toast.MakeText(_mActivity, "Completion Date Updated", ToastLength.Short).Show(); }); //frag.StartTime = DateTime.SpecifyKind(DateTime.Parse(""+output[2].value), DateTimeKind.Local); if (taskDetail.CompletionDate.HasValue) { frag.StartTime = Util.GetInstance().GetLocalTime(taskDetail.CompletionDate.Value); } Debug.WriteLine(frag.StartTime); frag.Show(FragmentManager, DatePickerFragment.TAG); } }; taskName.Text = taskDetail.FullName; output[0].value = TimeSpan.FromMinutes(taskDetail.EstimatedTime).ToString(@"hh\:mm"); output[1].value = TimeSpan.FromMinutes(taskDetail.ActualTime).ToString(@"hh\:mm"); output[2].value = taskDetail.CompletionDate.HasValue ? Util.GetInstance().GetLocalTime(taskDetail.CompletionDate.Value).ToShortDateString() : "-"; listAdapter = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem, output); Debug.WriteLine("We have changed content "); timeinfo.Adapter = listAdapter; if (string.IsNullOrEmpty(taskDetail.Note)) { notes.Text = "-"; notes.Gravity = GravityFlags.Center; } else { notes.Text = taskDetail.Note; } var timeLogs = view.FindViewById <Button>(Resource.Id.TaskDetails_TimeLogButton); timeLogs.Click += (sender, args) => { ((MainActivity)Activity).PassTimeLogInfo(taskDetail.Id, taskDetail.Project.Name, taskDetail.FullName); }; if (taskDetail.CompletionDate.HasValue && taskDetail.CompletionDate.Value != DateTime.MinValue) { taskComplete.Checked = true; } else { taskComplete.Checked = false; } taskComplete.CheckedChange += (sender, args) => { string text; if (args.IsChecked) { // Mark a task as complete DateTime convertedTime = Util.GetInstance().GetServerTime(DateTime.UtcNow); taskDetail.CompletionDate = convertedTime; try { ((MainActivity)(this.Activity)).Ctrl.UpdateATask(AccountStorage.DataSet, _taskId, null, convertedTime, false); output[2].value = DateTime.Now.ToShortDateString(); } catch (CannotReachServerException) { output[2].value = "-"; taskComplete.Checked = false; Toast.MakeText(Activity, "Please check your internet connection and try again.", ToastLength.Long).Show(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { if (pb.IsShowing) { pb.Dismiss(); } Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); System.Diagnostics.Debug.WriteLine("We are about to logout"); AccountStorage.ClearStorage(); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (StatusNotOkayException) { output[2].value = "-"; taskComplete.Checked = false; Toast.MakeText(Activity, "An error occured. Please try again.", ToastLength.Short).Show(); } catch (Exception) { // For any other weird exceptions taskComplete.Checked = false; output[2].value = "-"; Toast.MakeText(Activity, "Unable to make the change. Please try again.", ToastLength.Short).Show(); } text = "Task Marked Complete"; } else { var previousValue = output[2].value; // Unmark the task taskDetail.CompletionDate = null; try { ((MainActivity)(this.Activity)).Ctrl.UpdateATask(AccountStorage.DataSet, _taskId, null, null, true); output[2].value = "-"; } catch (CannotReachServerException) { taskComplete.Checked = true; output[2].value = previousValue; Toast.MakeText(Activity, "Please check your internet connection and try again.", ToastLength.Long).Show(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { if (pb.IsShowing) { pb.Dismiss(); } Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); System.Diagnostics.Debug.WriteLine("We are about to logout"); AccountStorage.ClearStorage(); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (StatusNotOkayException) { taskComplete.Checked = true; output[2].value = previousValue; Toast.MakeText(Activity, "An error has occured. Please try again.", ToastLength.Short).Show(); } catch (Exception) { // For any other weird exceptions taskComplete.Checked = true; output[2].value = previousValue; Toast.MakeText(Activity, "Unable to make the change. Please try again.", ToastLength.Short).Show(); } text = "Task Marked Incomplete"; } listAdapter = new TaskDetailsAdapter(Activity, Resource.Layout.TimeLogEntryListItem, output); Debug.WriteLine("We have changed content "); timeinfo.Adapter = listAdapter; Toast.MakeText(Activity, text, ToastLength.Short).Show(); // await (((MainActivity)(Activity)).Ctrl).UpdateTimeLog(Settings.GetInstance().Dataset,) }; } if (pb.IsShowing) { pb.Dismiss(); } // Dismiss Dialog }
public async Task <int> CheckCredentials(string datatoken, string userid, string password) { //Check username and password System.Diagnostics.Debug.WriteLine("We are inside the outer task"); ProgressDialog pd = new ProgressDialog(Activity); pd.SetMessage("Checking username and password"); pd.SetCancelable(false); pd.Show(); AlertDialog.Builder builder = new AlertDialog.Builder((Activity)); await Task.Run(() => { Debug.WriteLine("We are checking username"); HttpWebResponse resp; try { DataSetLocationResolver dslr = new DataSetLocationResolver(); dslr.ResolveFromToken(datatoken, out baseurl, out dataset); System.Diagnostics.Debug.WriteLine("Base url :" + baseurl); AccountStorage.SetContext(Activity); AccountStorage.Set(userid, password, baseurl, dataset); var req = WebRequest.CreateHttp(AccountStorage.BaseUrl + "api/v1/datasets/" + AccountStorage.DataSet + "/"); req.Method = "GET"; req.AllowAutoRedirect = false; string credential = userid + ":" + password; req.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(credential))); // req.Get resp = (HttpWebResponse)req.GetResponse(); if (resp.StatusCode == HttpStatusCode.OK) { if (resp.GetResponseStream().CanRead) { Stream data = resp.GetResponseStream(); var reader = new StreamReader(data); string responseStr = reader.ReadToEnd(); Debug.WriteLine(responseStr); if (responseStr.Contains("auth-required")) { Debug.WriteLine("Wrong credentials 2"); AccountStorage.ClearStorage(); Activity.RunOnUiThread(() => { if (pd.IsShowing) { pd.Dismiss(); } builder.SetTitle("Wrong Credentials") .SetMessage("Please check your username and password and try again.") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); Debug.WriteLine("We should have shown the dialog now"); }); } else if (responseStr.Contains("permission-denied")) { Debug.WriteLine("permission issue"); AccountStorage.ClearStorage(); Activity.RunOnUiThread(() => { if (pd.IsShowing) { pd.Dismiss(); } builder.SetTitle("Access Denied") .SetMessage("You donot have access to this dataset") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); }); } else if (responseStr.Contains("dataset")) { Debug.WriteLine("Username and password was correct"); Activity.RunOnUiThread(() => { pd.SetMessage("Getting Account Info"); pd.SetCancelable(false); if (!pd.IsShowing) { pd.Show(); } }); Task.Run(() => { //LOAD METHOD TO GET ACCOUNT INFO Debug.WriteLine("We are going to store the values"); Debug.WriteLine("We have stored the values"); Debug.WriteLine(AccountStorage.BaseUrl); Debug.WriteLine(AccountStorage.DataSet); Debug.WriteLine(AccountStorage.Password); Debug.WriteLine(AccountStorage.UserId); // Switch to next screen //HIDE PROGRESS DIALOG Activity.RunOnUiThread(() => { if (pd.IsShowing) { pd.Dismiss(); } Toast.MakeText(Activity, "Logged in", ToastLength.Short).Show(); ((MainActivity)Activity).FragmentManager.PopBackStack(); ((MainActivity)Activity).SetDrawerState(true); ((MainActivity)Activity).SwitchToFragment( MainActivity.FragmentTypes.Home); }); }); } } } } catch (WebException e) { Debug.WriteLine("We have a problem"); Activity.RunOnUiThread(() => { if (pd.IsShowing) { pd.Dismiss(); } }); using (WebResponse response = e.Response) { HttpWebResponse httpResponse = (HttpWebResponse)response; Console.WriteLine("Error code: {0}", httpResponse.StatusCode); if (httpResponse.StatusCode == HttpStatusCode.Unauthorized) { Debug.WriteLine("Wrong credentials"); AccountStorage.ClearStorage(); Activity.RunOnUiThread(() => { try { builder.SetTitle("Unauthorized") .SetMessage( "Please check your username and password and data token and try again.") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (Exception e2) { Debug.WriteLine("We have hit an error while showing the dialog :" + e2.Message); AccountStorage.ClearStorage(); } }); } } } catch (Exception e) { // Catching any generic exception Debug.WriteLine("We have hit a generic exception :" + e.Message); AccountStorage.ClearStorage(); Activity.RunOnUiThread(() => { AlertDialog.Builder builder2 = new AlertDialog.Builder(Activity); builder2.SetTitle("Error occured") .SetMessage(e.Message + ". Please report this error to the developers. We are sorry for the inconvenience.") .SetNeutralButton("Okay", (sender2, args2) => { builder2.Dispose(); }) .SetCancelable(false); AlertDialog alert2 = builder2.Create(); alert2.Show(); }); } return(true); }); // pd.Dismiss(); System.Diagnostics.Debug.WriteLine("We are done with the outer task"); return(0); }
private async Task GetData(ListView listView, Controller ctrl) { try { var output = await ctrl.GetProjects(AccountStorage.DataSet); Debug.WriteLine("We are here"); var listAdapter = new ProjectsAdapter(Activity, Android.Resource.Layout.SimpleListItem1, output.ToArray()); Debug.WriteLine("Setting the adapter"); listView.Adapter = listAdapter; Debug.WriteLine("List will be displayed"); SetListShown(true); ListView.SetSelection(listAdapter.Count - 1); } catch (CannotReachServerException) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("Unable to Connect") .SetMessage("Please check your network connection and try again") .SetNeutralButton("Okay", (sender, args) => { builder.Dispose(); ((MainActivity)Activity).FragmentManager.PopBackStack(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); System.Diagnostics.Debug.WriteLine("We are about to logout"); AccountStorage.ClearStorage(); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (StatusNotOkayException se) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetMessage("Error :" + se.GetMessage()) .SetNeutralButton("Okay", (sender, args) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (Exception e) { // For any other weird exceptions AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetNeutralButton("Okay", (sender, args) => { builder.Dispose(); }) .SetMessage("Error :" + e.Message) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } }
private async void CreateExpendableListData(View v) { var ctrl = ((MainActivity)Activity).Ctrl; try { ProgressDialog pd = new ProgressDialog(this.Activity); pd.SetMessage("Loading"); pd.Show(); var timelogEntries = await ctrl.GetTimeLogs(AccountStorage.DataSet, 0, null, null, null, null); // Debug.WriteLine("Got the values : " + timelogEntries.Count); var count = 0; foreach (var te in timelogEntries) { try { var present = true; List <TimeLogEntry> children; _headings.TryGetValue(te.StartDate.ToShortDateString(), out children); if (children == null) { // Debug.WriteLine("Children is null"); children = new List <TimeLogEntry>(); count++; present = false; } // Debug.WriteLine("Going to add children"); children.Add(te); if (present) { // Debug.WriteLine("Going to remove"); _headings.Remove(te.StartDate.Date.ToShortDateString()); } //Debug.WriteLine("Going to add to _headings"); _headings.Add(te.StartDate.Date.ToShortDateString(), children); } catch (Exception e) { Debug.WriteLine(e.Message); } } // Debug.WriteLine("Count :" + count); _timelogs = new List <string>(_headings.Keys); var ctlExListBox = v.FindViewById <ExpandableListView>(Resource.Id.myExpandableListview); ctlExListBox.SetAdapter(new GlobalTimeLogAdapter(Activity, _headings)); ctlExListBox.ChildClick += delegate(object sender, ExpandableListView.ChildClickEventArgs e) { var itmGroup = _timelogs[e.GroupPosition]; var itmChild = _headings[itmGroup][e.ChildPosition]; ((MainActivity)Activity).TimeLogEditCallBack(itmChild.Task.Project.Name, itmChild.Task.FullName, itmChild.Task.Id, itmChild); }; pd.Dismiss(); } catch (CannotReachServerException) { //TODO: Retry option ? Toast.MakeText(Activity, "Please check your internet connection and try again.", ToastLength.Long) .Show(); } catch (StatusNotOkayException) { Toast.MakeText(Activity, "An error occured. Please try again.", ToastLength.Short).Show(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); AccountStorage.ClearStorage(); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (Exception) { // For any other weird exceptions Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } }
private async void LoadData(View v, Controller ctrl) { play = v.FindViewById <Button>(Resource.Id.Home_Play); pause = v.FindViewById <Button>(Resource.Id.Home_Pause); var taskComplete = v.FindViewById <CheckBox>(Resource.Id.Home_TaskComplete); var recentTask = v.FindViewById <Button>(Resource.Id.Home_RecentTask); var recentProject = v.FindViewById <Button>(Resource.Id.Home_CurrentProject); var expandableList = v.FindViewById <ExpandableListView>(Android.Resource.Id.List); var pb = new ProgressDialog(_mActivity) { Indeterminate = true }; pb.SetTitle("Loading"); //TODO: This is under the assumption that whatever task is on the top of the recent task list // is the currently logged timer task. Check whether this assumption is valid or not. if (TimeLoggingController.GetInstance().IsTimerRunning()) { ModifyPlayPauseState(true); } play.Click += (sender, args) => { Debug.WriteLine("Play Clicked"); //var timerServiceIntent = new Intent("com.tumasolutions.processdashboard.TimerService"); //var timerServiceConnection = new TimerServiceConnection((MainActivity)this.Activity); //Activity.ApplicationContext.BindService(timerServiceIntent, timerServiceConnection, Bind.AutoCreate); if (TimeLoggingController.GetInstance().WasNetworkAvailable) { Intent intent = new Intent(Activity, typeof(TimerService)); intent.PutExtra("taskId", _currenttaskid); Activity.StartService(intent); } else { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("Previous changes not saved") .SetMessage("An earlier time log entry has not yet been synchronized with the server. Please try again later.") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } }; pause.Click += (sender, args) => { Debug.WriteLine("Pause Clicked"); Activity.StopService(new Intent(Activity, typeof(TimerService))); Toast.MakeText(this.Activity, "Time Log Entry Saved", ToastLength.Short).Show(); }; taskComplete.CheckedChange += (sender, args) => { string text = ""; if (args.IsChecked) { // Mark a task as complete DateTime convertedTime = Util.GetInstance().GetServerTime(DateTime.UtcNow); //taskDetail.CompletionDate = convertedTime; try { ((MainActivity)(Activity)).Ctrl.UpdateATask(AccountStorage.DataSet, _currenttaskid, null, convertedTime, false); text = "Task Marked Complete"; } catch (CannotReachServerException) { if (pb.IsShowing) { pb.Dismiss(); } Debug.WriteLine("We could not reach the server"); taskComplete.Checked = false; text = "Please check your internet connection and try again."; Toast.MakeText(this.Activity, text, ToastLength.Short).Show(); } catch (StatusNotOkayException) { pb.Dismiss(); taskComplete.Checked = false; //TODO: Should we report this ? text = "An error has occured. Please try again."; Toast.MakeText(this.Activity, text, ToastLength.Short).Show(); } catch (Exception e) { // For any other weird exceptions pb.Dismiss(); taskComplete.Checked = false; // Sending to HockeyApp ExceptionHandler.SaveException(Java.Lang.Throwable.FromException(e), null, null); text = "Unable to make the change. Please try again."; Toast.MakeText(this.Activity, text, ToastLength.Short).Show(); } } else { // Unmark the task try { ((MainActivity)(Activity)).Ctrl.UpdateATask(AccountStorage.DataSet, _currenttaskid, null, null, true); text = "Task Marked Incomplete"; } catch (CannotReachServerException) { if (pb.IsShowing) { pb.Dismiss(); } Debug.WriteLine("We could not reach the server"); taskComplete.Checked = true; text = "Please check your internet connection and try again."; Toast.MakeText(this.Activity, text, ToastLength.Short).Show(); } //TODO: Should we handle this ? catch (StatusNotOkayException) { pb.Dismiss(); taskComplete.Checked = true; text = "An error has occured. Please try again."; Toast.MakeText(this.Activity, text, ToastLength.Short).Show(); } catch (Exception e) { // For any other weird exceptions taskComplete.Checked = true; ExceptionHandler.SaveException(Java.Lang.Throwable.FromException(e), null, null); text = "Unable to make the change. Please try again."; Toast.MakeText(this.Activity, text, ToastLength.Short).Show(); } } Debug.WriteLine("We have changed content "); Toast.MakeText(Activity, text, ToastLength.Short).Show(); }; recentTask.Text = "Loading.."; recentProject.Text = "Loading.."; pb.SetCanceledOnTouchOutside(false); pb.Show(); try { var output = await ctrl.GetRecentTasks(AccountStorage.DataSet); pb.Dismiss(); var recent = output[0]; recentTask.Text = recent.FullName; recentProject.Text = recent.Project.Name; _currenttaskid = recent.Id; _headings.Add(recent.Project.Name, new List <Task>()); output.RemoveAt(0); foreach (Task t in output) { if (_headings.ContainsKey(t.Project.Name)) { List <Task> tt = _headings[t.Project.Name]; tt.Add(t); _headings[t.Project.Name] = tt; } else { List <Task> tt = new List <Task>(); tt.Add(t); _headings[t.Project.Name] = tt; } } //var listAdapter = new TaskAdapter(_mActivity, Android.Resource.Layout.SimpleListItem1, output.ToArray()); var listAdapter = new HomeListAdapter(this.Activity, _headings); expandableList.SetAdapter(listAdapter); //ListAdapter = listAdapter; var refresher = v.FindViewById <SwipeRefreshLayout>(Resource.Id.refresher); refresher.Refresh += async delegate { try { output = await ctrl.GetRecentTasks(AccountStorage.DataSet); recent = output[0]; _headings = new Dictionary <string, List <Task> >(); recentTask.Text = recent.FullName; recentProject.Text = recent.Project.Name; _headings.Add(recent.Project.Name, new List <Task>()); output.RemoveAt(0); foreach (Task t in output) { if (_headings.ContainsKey(t.Project.Name)) { List <Task> tt = _headings[t.Project.Name]; tt.Add(t); _headings[t.Project.Name] = tt; } else { List <Task> tt = new List <Task>(); tt.Add(t); _headings[t.Project.Name] = tt; } } listAdapter = new HomeListAdapter(this.Activity, _headings); expandableList.SetAdapter(listAdapter); refresher.Refreshing = false; } catch (CannotReachServerException) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("Unable to Connect") .SetMessage("Please check your network connection and try again") .SetNeutralButton("Okay", (sender, args) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); refresher.Refreshing = false; alert.Show(); } catch (StatusNotOkayException se) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetMessage("Error :" + se.GetMessage()) .SetNeutralButton("Okay", (sender, args) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); refresher.Refreshing = false; alert.Show(); } catch (Exception e) { // For any other weird exceptions AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetNeutralButton("Okay", (sender, args) => { builder.Dispose(); }) .SetMessage("Error :" + e.Message) .SetCancelable(false); AlertDialog alert = builder.Create(); refresher.Refreshing = false; alert.Show(); } }; recentProject.Click += (sender, args) => { ((MainActivity)Activity).ListOfProjectsCallback(recent.Project.Id, recent.Project.Name); }; recentTask.Click += (sender, args) => { ((MainActivity)Activity).PassTaskDetailsInfo(recent.Id, recent.FullName, recent.Project.Name, recent.CompletionDate, recent.EstimatedTime, recent.ActualTime); }; } catch (CannotReachServerException) { pb.Dismiss(); AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("Unable to Connect") .SetMessage("Please check your network connection and try again") .SetNeutralButton("Okay", (sender, args) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (StatusNotOkayException se) { pb.Dismiss(); AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetMessage("Error :" + se.GetMessage()) .SetNeutralButton("Okay", (sender, args) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); System.Diagnostics.Debug.WriteLine("We are about to logout"); AccountStorage.ClearStorage(); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (Exception e) { // For any other weird exceptions pb.Dismiss(); AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetNeutralButton("Okay", (sender, args) => { builder.Dispose(); }) .SetMessage("Error :" + e.Message) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } /* * private void LoadDummyData(View v) * { * * ListView lv = v.FindViewById<ListView>(Android.Resource.Id.List); * var items = new[] { "Vegetables", "Fruits", "Flower Buds", "Legumes", "Bulbs", "Tubers" }; * ArrayAdapter listAdapter = new ArrayAdapter<String>(_mActivity, Android.Resource.Layout.SimpleListItem1, items); * ListAdapter = listAdapter; * * TextView recentTask = v.FindViewById<TextView>(Resource.Id.Home_RecentTask); * recentTask.Text = "Project / Mobile App l1 / Iteration 1 / View Skeletons / Create Android Skeletons / Home Screen "; * * } */ }
public async void DeleteCurrentEntry() { ProgressDialog pd = new ProgressDialog(Activity); pd.Indeterminate = true; pd.SetCancelable(false); pd.SetMessage("Deleting"); try { await((MainActivity)Activity).Ctrl.DeleteTimeLog(AccountStorage.DataSet, "" + _timeLog.Id); pd.Dismiss(); Toast.MakeText(Activity, "Deleted the timelog entry", ToastLength.Short).Show(); Debug.WriteLine("We are going to pop backstack"); ((MainActivity)Activity).FragmentManager.PopBackStack(); } catch (CannotReachServerException) { if (pd.IsShowing) { pd.Dismiss(); } Toast.MakeText(Activity, "Please check your internet connection and try again.", ToastLength.Long).Show(); Debug.WriteLine("We are going to pop backstack"); ((MainActivity)Activity).FragmentManager.PopBackStack(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { if (pd.IsShowing) { pd.Dismiss(); } Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); System.Diagnostics.Debug.WriteLine("We are about to logout"); AccountStorage.ClearStorage(); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (StatusNotOkayException) { if (pd.IsShowing) { pd.Dismiss(); } Toast.MakeText(Activity, "An error occured. Please try again.", ToastLength.Short).Show(); Debug.WriteLine("We are going to pop backstack"); ((MainActivity)Activity).FragmentManager.PopBackStack(); } catch (Exception) { if (pd.IsShowing) { pd.Dismiss(); } // For any other weird exceptions Toast.MakeText(Activity, "Invalid operation. Please try again.", ToastLength.Short).Show(); Debug.WriteLine("We are going to pop backstack"); ((MainActivity)Activity).FragmentManager.PopBackStack(); } }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Debug.WriteLine("Time Log Detail : " + "We are in On create view"); // Use this to return your custom view for this Fragment var v = inflater.Inflate(Resource.Layout.TimeLogEntry, container, false); _tn = v.FindViewById <TextView>(Resource.Id.TimeLogEdit_TaskName); _pn = v.FindViewById <TextView>(Resource.Id.TimeLogEdit_ProjectName); _interruptTime = v.FindViewById <EditText>(Resource.Id.TimeLogEdit_InterruptTime); _comment = v.FindViewById <EditText>(Resource.Id.TimeLogEdit_Comment); _startTime = v.FindViewById <EditText>(Resource.Id.TimeLogEdit_StartTime); _deltaTime = v.FindViewById <EditText>(Resource.Id.TimeLogEdit_DeltaTime); _startTime.Focusable = false; _deltaTime.Focusable = false; _interruptTime.Focusable = false; _comment.Focusable = false; _startTime.Clickable = true; _deltaTime.Clickable = true; _interruptTime.Clickable = true; _comment.Clickable = true; if (_timeLog != null) { _oldLoggedTime = _timeLog.LoggedTime; _oldInterruptTime = _timeLog.InterruptTime; } else { _oldLoggedTime = 0; _oldInterruptTime = 0; } _deltaTime.Click += (sender, args) => { LinearLayout ll = new LinearLayout(Activity); ll.Orientation = (Orientation.Horizontal); NumberPicker aNumberPicker = new NumberPicker(Activity); // TODO: Should there be a maximum for the hour column ? aNumberPicker.MaxValue = (100); aNumberPicker.MinValue = (0); double temp = 0; if (!_deltaTime.Text.Equals("")) { temp = Convert.ToDouble(TimeSpan.ParseExact(_deltaTime.Text, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes); } //temp = Double.Parse(_deltaTime.Text); aNumberPicker.Value = TimeSpan.FromMinutes(temp).Hours; NumberPicker aNumberPickerA = new NumberPicker(Activity) { MaxValue = (59), MinValue = (0), Value = TimeSpan.FromMinutes(temp).Minutes }; LinearLayout.LayoutParams parameters = new LinearLayout.LayoutParams(50, 50); parameters.Gravity = GravityFlags.Center; LinearLayout.LayoutParams numPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); numPicerParams.Weight = 1; LinearLayout.LayoutParams qPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); qPicerParams.Weight = 1; ll.LayoutParameters = parameters; ll.AddView(aNumberPicker, numPicerParams); ll.AddView(aNumberPickerA, qPicerParams); AlertDialog.Builder np = new AlertDialog.Builder(Activity).SetView(ll); np.SetTitle("Update Delta Time"); np.SetNegativeButton("Cancel", (s, a) => { np.Dispose(); }); np.SetPositiveButton("Ok", (s, a) => { //Update Planned Time string number = aNumberPicker.Value.ToString("D2") + ":" + aNumberPickerA.Value.ToString("D2"); Debug.WriteLine(number); double val = Convert.ToDouble(TimeSpan.ParseExact(number, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes); Debug.WriteLine("The updated val is :" + val); var updatedLoggedTime = val - _oldLoggedTime; try { if (_timeLog != null) { ((MainActivity)Activity).Ctrl.UpdateTimeLog(AccountStorage.DataSet, "" + _timeLog.Id, null, null, _taskId, updatedLoggedTime, null, false); } } catch (CannotReachServerException) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("Unable to Connect") .SetMessage("Please check your network connection and try again") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); ((MainActivity)Activity).FragmentManager.PopBackStack(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); System.Diagnostics.Debug.WriteLine("We are about to logout"); AccountStorage.ClearStorage(); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (StatusNotOkayException se) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetMessage("Error :" + se.GetMessage()) .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (Exception e) { // For any other weird exceptions AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetMessage("Error :" + e.Message) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } _deltaTime.Text = "" + TimeSpan.FromMinutes(val).ToString(@"hh\:mm"); Toast.MakeText(Activity, "Delta Time Updated", ToastLength.Short).Show(); np.Dispose(); }); np.Show(); }; _startTime.Click += (sender, args) => { DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime time) { //TODO: DEBUG: Check whether this is causing any issues. _startTime.Text = time.ToString(CultureInfo.InvariantCulture); Toast.MakeText(Activity, "Start Date Updated", ToastLength.Short).Show(); TimePickerFragment frag2 = TimePickerFragment.NewInstance(delegate(int hour, int min) { Toast.MakeText(Activity, "Start Time Updated", ToastLength.Short).Show(); DateTime output = new DateTime(time.Year, time.Month, time.Day, hour, min, 0); _startTime.Text = output.ToString("g"); }); frag2.chosenDate = time; if (_timeLog != null) { frag2.StartHour = _timeLog.StartDate.Hour; frag2.StartMinute = _timeLog.StartDate.Minute; } else { frag2.StartHour = time.Hour; frag2.StartMinute = time.Minute; } frag2.Show(FragmentManager, TimePickerFragment.TAG); }); //frag.StartTime = DateTime.SpecifyKind(DateTime.Parse(""+output[2].value), DateTimeKind.Local); frag.StartTime = _timeLog != null ? _timeLog.StartDate : DateTime.Now; Debug.WriteLine(frag.StartTime); frag.Show(FragmentManager, DatePickerFragment.TAG); }; _interruptTime.Click += (sender, args) => { LinearLayout ll = new LinearLayout(Activity); ll.Orientation = (Orientation.Horizontal); NumberPicker aNumberPicker = new NumberPicker(Activity); // TODO: Should there be a maximum for the hour column ? aNumberPicker.MaxValue = (100); aNumberPicker.MinValue = (0); double temp = 0; if (!_interruptTime.Text.Equals("")) { temp = Convert.ToDouble(TimeSpan.ParseExact(_interruptTime.Text, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes); } //temp = Double.Parse(_deltaTime.Text); aNumberPicker.Value = TimeSpan.FromMinutes(temp).Hours; NumberPicker aNumberPickerA = new NumberPicker(Activity) { MaxValue = (59), MinValue = (0), Value = TimeSpan.FromMinutes(temp).Minutes }; LinearLayout.LayoutParams parameters = new LinearLayout.LayoutParams(50, 50); parameters.Gravity = GravityFlags.Center; LinearLayout.LayoutParams numPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); numPicerParams.Weight = 1; LinearLayout.LayoutParams qPicerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); qPicerParams.Weight = 1; ll.LayoutParameters = parameters; ll.AddView(aNumberPicker, numPicerParams); ll.AddView(aNumberPickerA, qPicerParams); AlertDialog.Builder np = new AlertDialog.Builder(Activity).SetView(ll); np.SetTitle("Update Interrupt Time"); np.SetNegativeButton("Cancel", (s, a) => { np.Dispose(); }); np.SetPositiveButton("Ok", (s, a) => { //Update Planned Time string number = aNumberPicker.Value.ToString("D2") + ":" + aNumberPickerA.Value.ToString("D2"); Debug.WriteLine(number); double val = Convert.ToDouble(TimeSpan.ParseExact(number, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes); Debug.WriteLine("The updated val is :" + val); var updatedInterruptTime = val - _oldInterruptTime; if (_timeLog != null) { // This is an update operation try { if (_timeLog != null) { ((MainActivity)Activity).Ctrl.UpdateTimeLog(AccountStorage.DataSet, "" + _timeLog.Id, null, null, _taskId, null, updatedInterruptTime, false); } } catch (CannotReachServerException) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("Unable to Connect") .SetMessage("Please check your network connection and try again") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); ((MainActivity)Activity).FragmentManager.PopBackStack(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); System.Diagnostics.Debug.WriteLine("We are about to logout"); AccountStorage.ClearStorage(); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager .BackStackEntryCount); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager .BackStackEntryCount); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment( MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (StatusNotOkayException se) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetMessage("Error :" + se.GetMessage()) .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (Exception e) { // For any other weird exceptions AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetMessage("Error :" + e.Message) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } } _interruptTime.Text = "" + TimeSpan.FromMinutes(val).ToString(@"hh\:mm"); Toast.MakeText(Activity, "Interrupt Time Updated", ToastLength.Short).Show(); np.Dispose(); }); np.Show(); }; _comment.Click += (sender, args) => { LinearLayout ll = new LinearLayout(Activity); ll.Orientation = (Orientation.Horizontal); EditText et = new EditText(Activity); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.WrapContent); et.LayoutParameters = lp; //et.LayoutParams = (lp); ll.AddView(et); et.Focusable = (true); if (!_comment.Text.Equals("-")) { et.Text = _comment.Text; } AlertDialog.Builder np = new AlertDialog.Builder(Activity).SetView(ll); np.SetTitle("Update Comments"); np.SetNegativeButton("Cancel", (s, a) => { np.Dispose(); }); np.SetPositiveButton("Ok", (s, a) => { //Update Comments string value = et.Text; if (_timeLog != null) { // This is an update operation try { if (_timeLog != null) { ((MainActivity)Activity).Ctrl.UpdateTimeLog(AccountStorage.DataSet, "" + _timeLog.Id, value, null, _taskId, null, null, false); } } catch (CannotReachServerException) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("Unable to Connect") .SetMessage("Please check your network connection and try again") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); ((MainActivity)Activity).FragmentManager.PopBackStack(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); AccountStorage.ClearStorage(); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment( MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (StatusNotOkayException se) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetMessage("Error :" + se.GetMessage()) .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (Exception e) { // For any other weird exceptions AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetMessage("Error :" + e.Message) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } } _comment.Text = value; Toast.MakeText(Activity, "Comment Updated", ToastLength.Short).Show(); np.Dispose(); }); np.Show(); }; if (_taskName != null && _projectName != null) { _tn.Text = _taskName; _pn.Text = _projectName; } if (_timeLog == null) { return(v); } string c = Util.GetInstance().GetLocalTime(_timeLog.StartDate).ToString("g"); _startTime.Text = (c); _interruptTime.Text = "" + TimeSpan.FromMinutes(_timeLog.InterruptTime).ToString(@"hh\:mm"); _comment.Text = _timeLog.Comment ?? "-"; _deltaTime.Text = "" + TimeSpan.FromMinutes(_timeLog.LoggedTime).ToString(@"hh\:mm"); return(v); }
public async void ProcessEntries() { ProgressDialog pd = new ProgressDialog(Activity); pd.SetMessage("Saving.."); pd.Indeterminate = true; if (_timeLog == null) { Debug.WriteLine("This is a new entry"); try { var newDate = DateTime.SpecifyKind(DateTime.Parse(_startTime.Text), DateTimeKind.Local); double val = Convert.ToDouble(TimeSpan.ParseExact(_deltaTime.Text, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes); double val2 = Convert.ToDouble(TimeSpan.ParseExact(_interruptTime.Text, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes); pd.Show(); await ((MainActivity)Activity).Ctrl.AddATimeLog(AccountStorage.DataSet, _comment.Text, newDate, _taskId, val, val2, false); pd.Dismiss(); Toast.MakeText(Activity, "Added new Timelog Entry", ToastLength.Short).Show(); Debug.WriteLine("We are going to pop backstack"); ((MainActivity)Activity).FragmentManager.PopBackStack(); } catch (CannotReachServerException) { if (pd.IsShowing) { pd.Dismiss(); } Toast.MakeText(Activity, "Please check your internet connection and try again.", ToastLength.Long).Show(); Debug.WriteLine("We are going to pop backstack"); ((MainActivity)Activity).FragmentManager.PopBackStack(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { if (pd.IsShowing) { pd.Dismiss(); } Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); AccountStorage.ClearStorage(); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (StatusNotOkayException) { if (pd.IsShowing) { pd.Dismiss(); } Toast.MakeText(Activity, "An error occured. Please try again.", ToastLength.Short).Show(); Debug.WriteLine("We are going to pop backstack"); ((MainActivity)Activity).FragmentManager.PopBackStack(); } catch (Exception ea) { if (pd.IsShowing) { pd.Dismiss(); } // For any other weird exceptions Toast.MakeText(Activity, "Invalid values. Please try again." + ea.Message, ToastLength.Short).Show(); Debug.WriteLine("We are going to pop backstack"); ((MainActivity)Activity).FragmentManager.PopBackStack(); } } else { Debug.WriteLine("This is an update operation"); try { var newDate = DateTime.SpecifyKind(DateTime.Parse(_startTime.Text), DateTimeKind.Local); double val = Convert.ToDouble(TimeSpan.ParseExact(_deltaTime.Text, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes); var updatedLoggedTime = val - _oldLoggedTime; val = Convert.ToDouble(TimeSpan.ParseExact(_interruptTime.Text, @"hh\:mm", CultureInfo.InvariantCulture).TotalMinutes); var updatedInterruptTime = val - _oldInterruptTime; pd.Show(); await ((MainActivity)Activity).Ctrl.UpdateTimeLog(AccountStorage.DataSet, "" + _timeLog.Id, _comment.Text, newDate, _taskId, updatedLoggedTime, updatedInterruptTime, false); pd.Dismiss(); Toast.MakeText(Activity, "Updated the Timelog Entry", ToastLength.Short).Show(); Debug.WriteLine("We are going to pop backstack"); ((MainActivity)Activity).FragmentManager.PopBackStack(); } catch (CannotReachServerException) { if (pd.IsShowing) { pd.Dismiss(); } Toast.MakeText(Activity, "Please check your internet connection and try again.", ToastLength.Long).Show(); Debug.WriteLine("We are going to pop backstack"); ((MainActivity)Activity).FragmentManager.PopBackStack(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { if (pd.IsShowing) { pd.Dismiss(); } Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); AccountStorage.ClearStorage(); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (StatusNotOkayException) { if (pd.IsShowing) { pd.Dismiss(); } Toast.MakeText(Activity, "An error occured. Please try again.", ToastLength.Short).Show(); Debug.WriteLine("We are going to pop backstack"); ((MainActivity)Activity).FragmentManager.PopBackStack(); } catch (Exception) { if (pd.IsShowing) { pd.Dismiss(); } // For any other weird exceptions Toast.MakeText(Activity, "Invalid values. Please try again.", ToastLength.Short).Show(); Debug.WriteLine("We are going to pop backstack"); ((MainActivity)Activity).FragmentManager.PopBackStack(); } } }
public async void GetData(View v) { var ctrl = ((MainActivity)Activity).Ctrl; var pn = v.FindViewById <TextView>(Resource.Id.TaskTimeLog_ProjectName); var tn = v.FindViewById <TextView>(Resource.Id.TaskTimeLog_TaskName); var fab = v.FindViewById <FloatingActionButton>(Resource.Id.TaskTimeLog_fab); pn.Text = ProjectName; tn.Text = TaskName; var pb = new ProgressDialog(Activity) { Indeterminate = true }; pb.SetTitle("Loading"); pb.SetCanceledOnTouchOutside(false); pb.Show(); try { var timelogs = await ctrl.GetTimeLogs(AccountStorage.DataSet, null, null, null, _id, null); Debug.WriteLine("Got data for timelogs :" + timelogs.Count); fab.Click += (sender, args) => { if (timelogs.Count > 0) { Debug.WriteLine("Project Name :" + timelogs[0].Task.Project.Name); Debug.WriteLine("Task Name :" + timelogs[0].Task.FullName); ((MainActivity)Activity).TimeLogEditCallBack(timelogs[0].Task.Project.Name, timelogs[0].Task.FullName, timelogs[0].Task.Id, null); } else { ((MainActivity)Activity).TimeLogEditCallBack(ProjectName, TaskName, _id, null); } }; fab.Show(); foreach (var timelog in timelogs) { Debug.WriteLine(timelog); } var listAdapter = new TaskTimeLogAdapter(Activity, Resource.Layout.TimeLogEntryListItem, timelogs.ToArray()); ListAdapter = listAdapter; if (timelogs.Count > 0) { pn.Text = timelogs[0].Task.Project.Name; tn.Text = timelogs[0].Task.FullName; } pb.Dismiss(); ListView.ItemClick += (sender, args) => { var i = args.Position; Debug.WriteLine("I position :" + i); ((MainActivity)Activity).TimeLogEditCallBack(timelogs[i].Task.Project.Name, timelogs[i].Task.FullName, timelogs[i].Task.Id, timelogs[i]); }; } catch (CannotReachServerException) { if (pb.IsShowing) { pb.Dismiss(); } AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("Unable to Connect") .SetMessage("Please check your network connection and try again") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); ((MainActivity)Activity).FragmentManager.PopBackStack(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (WebException we) { if (we.Status == WebExceptionStatus.ProtocolError) { var response = we.Response as HttpWebResponse; if (response != null) { Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode); if (response.StatusCode == HttpStatusCode.Forbidden) { try { if (pb.IsShowing) { pb.Dismiss(); } Toast.MakeText(this.Activity, "Username and password error.", ToastLength.Long).Show(); System.Diagnostics.Debug.WriteLine("We are about to logout"); AccountStorage.ClearStorage(); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); System.Diagnostics.Debug.WriteLine("Items in the backstack :" + Activity.FragmentManager.BackStackEntryCount); System.Diagnostics.Debug.WriteLine("Main Activity is :" + Activity == null); Activity.FragmentManager.PopBackStack(null, PopBackStackFlags.Inclusive); System.Diagnostics.Debug.WriteLine("Items in the backstack 2 :" + Activity.FragmentManager.BackStackEntryCount); ((MainActivity)(Activity)).SetDrawerState(false); ((MainActivity)(Activity)).SwitchToFragment(MainActivity.FragmentTypes.Login); } catch (System.Exception e) { System.Diagnostics.Debug.WriteLine("We encountered an error :" + e.Message); } } } else { // no http status code available Toast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } else { // no http status code availableToast.MakeText(Activity, "Unable to load the data. Please restart the application.", ToastLength.Short).Show(); } } catch (StatusNotOkayException se) { if (pb.IsShowing) { pb.Dismiss(); } AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetMessage("Error :" + se.GetMessage()) .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } catch (Exception e) { // For any other weird exceptions if (pb.IsShowing) { pb.Dismiss(); } AlertDialog.Builder builder = new AlertDialog.Builder(Activity); builder.SetTitle("An Error has occured") .SetNeutralButton("Okay", (sender2, args2) => { builder.Dispose(); }) .SetMessage("Error :" + e.Message) .SetCancelable(false); AlertDialog alert = builder.Create(); alert.Show(); } }