public static void MakeCall(CallEntity callEntity, Activity activity) { var category = callEntity.Category; var choice = callEntity.Choice ?? ""; var detail = callEntity.Detail ?? ""; new AlertDialog.Builder(activity) .SetTitle(category + " " + choice + " " + detail) .SetMessage(Strings.CallSendMessage) .SetPositiveButton(Strings.CallSend, delegate { ThreadPool.QueueUserWorkItem(o => { activity.RunOnUiThread(() => { dialog = new ProgressDialog(activity); dialog.SetMessage(Strings.SpinnerDataSending); dialog.SetCancelable(false); dialog.Show(); }); try { ICall patientCall = new PatientCall(); // Assign the callid with the returned MongoDB id callEntity._id = patientCall.MakeCall(callEntity); activity.RunOnUiThread(() => { // Call successfull, take the user to myCalls activity.ActionBar.SelectTab(activity.ActionBar.GetTabAt(1)); SetNewCalls(callEntity); dialog.Hide(); }); } catch (Exception ex) { Console.WriteLine("ERROR making call: " + ex.Message); activity.RunOnUiThread(() => { dialog.Hide(); new AlertDialog.Builder(activity).SetTitle(Strings.Error) .SetMessage(Strings.ErrorSendingCall) .SetPositiveButton(Strings.OK, delegate { }).Show(); }); } }); }) .SetNegativeButton(Strings.Cancel, delegate {/* Do nothing */ }) .Show(); }
public static void MakeCall(CallEntity callEntity, UIViewController vc) { var category = callEntity.Category; var choice = callEntity.Choice ?? ""; var detail = callEntity.Detail ?? ""; var confirmAlertController = UIAlertController.Create(category + " " + choice + " " + detail, Strings.CallSendMessage, UIAlertControllerStyle.Alert); // When user confirms the service var okAction = UIAlertAction.Create(Strings.CallSend, UIAlertActionStyle.Destructive, action => { ShowLoadingScreen(vc, Strings.SpinnerDataSending); new System.Threading.Thread(new System.Threading.ThreadStart(() => { var callEntities = DataHandler.LoadCallsFromLocalDatabase(new LocalDB()); vc.InvokeOnMainThread(() => { if (callEntities != null && callEntities.Length > 0) { // Check if the call already has been made, then return; if (CallHasBeenMade(callEntities, callEntity)) return; } new System.Threading.Thread(new System.Threading.ThreadStart(() => { // Make the async patient call here try { ICall patientCall = new PatientCall(); // Assign the callid with the returned MongoDB id callEntity._id = patientCall.MakeCall(callEntity); vc.InvokeOnMainThread(() => { // Call successfull, take the user to myCalls passing the viewcontroller and the requested call GoToMyCalls(vc,callEntity); }); } catch (Exception ex) { // Hide the loading screen Console.WriteLine("ERROR making call: " + ex.Message); vc.InvokeOnMainThread(() => { loadingOverlay.Hide(); new UIAlertView(Strings.Error, Strings.ErrorSendingCall, null, Strings.OK, null).Show(); }); } })).Start(); }); })).Start(); new System.Threading.Thread(new System.Threading.ThreadStart(() => { })).Start(); }); // When user cancels the service var cancelAction = UIAlertAction.Create(Strings.Cancel, UIAlertActionStyle.Cancel, action => { // Do nothing. }); confirmAlertController.AddAction(okAction); confirmAlertController.AddAction(cancelAction); // Display the alert vc.PresentViewController(confirmAlertController, true, null); }
void OnListItemClick(object sender, AdapterView.ItemClickEventArgs e) { var callEntity = Call.CallEntities[e.Position]; // Do not allow user to tap on the cell if call is canceled or completed // return if so if (callEntity.Status == (int)CallUtil.StatusCode.Canceled || callEntity.Status == (int)CallUtil.StatusCode.Completed) return; new AlertDialog.Builder(this.Activity) .SetTitle(Strings.CallRegretTitle) .SetMessage(Strings.CallRegretMessage) .SetPositiveButton(Strings.CallSend, delegate { ThreadPool.QueueUserWorkItem(o => { // Update status callEntity.Status = (int)CallUtil.StatusCode.Canceled; try { // Put the async patient call here ICall patientCall = new PatientCall(); patientCall.UpdateCall(callEntity); this.Activity.RunOnUiThread(() => { new AlertDialog.Builder(this.Activity).SetTitle(Strings.CallRegretted) .SetPositiveButton("OK", delegate { }) .Show(); DataHandler.UpdateMyCallToLocalDatabase(new LocalDB(), callEntity); Call.SetNewCalls(callEntity); GenerateList(); arrayAdapter.NotifyDataSetChanged(); }); } catch (Exception ex) { } }); }) .SetNegativeButton(Strings.Cancel, delegate {/* Do nothing */ }) .Show(); }
// Fortryd kald public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { // Get the selected call var callEntity = CallEntities[indexPath.Row]; // Do not allow user to tap on the cell if call is canceled or completed // return if so if (callEntity.Status == (int)CallUtil.StatusCode.Canceled || callEntity.Status == (int)CallUtil.StatusCode.Completed) return; // Selected Call is active tableView.DeselectRow(indexPath, true); var regretAlertController = UIAlertController.Create(Strings.CallRegretTitle, Strings.CallRegretMessage, UIAlertControllerStyle.Alert); var regretAction = UIAlertAction.Create(Strings.OK, UIAlertActionStyle.Destructive, action => { new System.Threading.Thread(new System.Threading.ThreadStart(() => { // Update status callEntity.Status = (int)CallUtil.StatusCode.Canceled; // Try update the call try { // Put the async patient call here ICall patientCall = new PatientCall(); patientCall.UpdateCall(callEntity); vc.InvokeOnMainThread(() => { // (Get a confirm message that the patient call was successfull) new UIAlertView(Strings.CallRegretted, null, null, "OK", null).Show(); DataHandler.UpdateMyCallToLocalDatabase(new LocalDB(), callEntity); // Reload data SetCallEntities(callEntity); tableView.ReloadData(); }); } catch (Exception ex) { Console.WriteLine("ERROR updaing call: " + ex.Message); vc.InvokeOnMainThread(() => { new UIAlertView(Strings.Error, Strings.ErrorSendingCall, null, "OK", null).Show(); return; }); } })).Start(); }); // When user cancels the service var cancelAction = UIAlertAction.Create("Annullér", UIAlertActionStyle.Cancel, action => { // Do nothing. }); regretAlertController.AddAction(regretAction); regretAlertController.AddAction(cancelAction); // Display the alert vc.PresentViewController(regretAlertController, true, null); }