예제 #1
0
파일: Call.cs 프로젝트: dsb92/patientcare
	    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();
	    }
예제 #2
0
        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);
        }