예제 #1
0
        public static void Toast(string pstrMensagem, ToastAction pToastAction = null)
        {
            ToastConfig toastConfig = new ToastConfig(pstrMensagem)
            {
                Duration = TimeSpan.FromSeconds(6),
                Position = ToastPosition.Bottom,
                Action   = pToastAction
            };

            UserDialogs.Instance.Toast(toastConfig);
        }
        /// <summary>
        ///    Can call directly.
        /// </summary>
        /// <param name="toastStr"></param>
        /// <param name="actionText"></param>
        /// <param name="backgroundColor"></param>
        /// <param name="messageTextColor"></param>
        /// <param name="actionTextColor"></param>
        /// <param name="useTimeout"></param>
        /// <param name="toastDissolveSeconds"></param>
        /// <param name="action"></param>
        public static void ShowToastInternal
        (
            string toastStr,
            string actionText        = "OK",
            Color?backgroundColor    = default,
            Color?messageTextColor   = default,
            Color?actionTextColor    = default,
            bool useTimeout          = true,
            int toastDissolveSeconds = TOAST_DISSOLVE_SECONDS,
            Action action            = null
        )
        {
            if (toastStr.IsEmpty())
            {
                return;
            }

            var newConfig =
                new ToastConfig(toastStr).SetMessageTextColor
                (
                    messageTextColor ?? Color.White
                );

            if (backgroundColor.HasValue)
            {
                newConfig.SetBackgroundColor(backgroundColor.Value);
            }

            newConfig.SetDuration(
                TimeSpan.FromSeconds(useTimeout && (toastDissolveSeconds > 0) ? toastDissolveSeconds : WAIT_FOREVER));

            var newAction = new ToastAction();

            // Must add "SetAction"
            if ((action != null) || actionText.IsNotEmpty())
            {
                if (action != null)
                {
                    newAction.SetAction(action);
                }

                if (actionText.IsNotEmpty())
                {
                    newAction.SetText(actionText);
                    newAction.SetTextColor(actionTextColor ?? Color.White);
                }

                newConfig.SetAction(newAction);
            }
            // ELSE skip "SetAction"

            UserDialogs.Instance.Toast(newConfig);
        }
예제 #3
0
        private void SetupToast()
        {
            toastCancelationToken.Cancel();
            toastCancelationToken = new CancellationTokenSource();
            if (Device.RuntimePlatform == Device.iOS)
            {
                return;
            }

            Task.Run(async() =>
            {
                if (isToastRunning || userChoseOffline)
                {
                    return;
                }

                do
                {
                    if (CrossConnectivity.Current.IsConnected)
                    {
                        return;
                    }
                    isToastRunning        = true;
                    var toastMessage      = new ToastConfig(" No Internet Connection");
                    toastMessage.Duration = TimeSpan.FromSeconds(2);
                    var toastAction       = new ToastAction
                    {
                        Text   = "Dismiss",
                        Action = () =>
                        {
                            userChoseOffline = true;
                        }
                    };

                    toastMessage.Action = toastAction;

                    Device.BeginInvokeOnMainThread(() => UserDialogs.Instance.Toast(toastMessage));
                    await Task.Delay(TimeSpan.FromSeconds(5));
                } while (!isInternetConnected && isToastRunning && !userChoseOffline);

                isToastRunning = false;
            }, toastCancelationToken.Token);
        }
예제 #4
0
        //---end------------------------------------------------------------------------------------FORM VALIDATION---//

        //---start-------------------------------------------------------------------------------------SERVER COMMS---//

        private async void UserExistCheck()
        {
            UserDialogs.Instance.Loading(title: "Processing...").Show();
            var client = new HttpClient
            {
                Timeout = TimeSpan.FromSeconds(15)
            };

            JObject jsonDataObject = new JObject {
                { "email", emailForm.Text.Trim() }
            };

            JObject jsonData = new JObject {
                { "params", jsonDataObject }
            };

            var data    = jsonData.ToString();
            var content = new StringContent(data, Encoding.UTF8, "application/json");

            Console.Debug.WriteLine("REQUEST-UserExistCheck: " + data);

            try
            {
                HttpResponseMessage response = await client.PostAsync(ApiUri.BASE_URL + ApiUri.CHECK_USER, content);

                string responseContent = await response.Content.ReadAsStringAsync();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    UserDialogs.Instance.Loading().Hide();
                    Console.Debug.WriteLine("RESPONSE-UserExistCheck: " + responseContent);

                    UserExistCheckResponse userExistCheckResponse = JsonConvert.DeserializeObject <UserExistCheckResponse>(responseContent);
                    UserExistCheckResult   userExistCheckResult   = userExistCheckResponse.result;

                    if (userExistCheckResult.success)
                    {
                        if (!userExistCheckResult.user_exist)
                        {
                            User user = new User
                            {
                                email = emailForm.Text.Trim(),
                                name  = firstNameForm.Text.Trim() + " " + lastNameForm.Text.Trim()
                            };

                            user.dbID = DBLocalID.USER_TEMP_SIGN_UP;

                            var realm = Realm.GetInstance();
                            realm.Write(() =>
                            {
                                realm.Add(user, update: true);
                            });

                            await Navigation.PushAsync(new SignUpNationalityPage(this));
                        }
                        else
                        {
                            var toastAction = new ToastAction();
                            toastAction.SetText("LOG IN");
                            toastAction.SetAction(OnToastActionLogin);

                            UserDialogs.Instance.Toast(
                                new ToastConfig("User already exists")
                                .SetAction(toastAction)
                                );
                        }
                    }
                    else
                    {
                        Notifications.Internal.ServerError();
                    }
                }
                else
                {
                    UserDialogs.Instance.Loading().Hide();
                    Console.Debug.WriteLine("RESPONSE_ERROR-UserExistCheck: " + responseContent);
                    Notifications.Internal.ServerError();
                }
            }
            catch (TaskCanceledException e)
            {
                UserDialogs.Instance.Toast(new ToastConfig("Bad Connection Error"));
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
        }
        //---end------------------------------------------------------------------------------------FORM VALIDATION---//

        //---start-------------------------------------------------------------------------------------SERVER COMMS---//

        private async void UserExistCheck()
        {
            UserDialogs.Instance.Loading(title: "Finding User...").Show();

            var client = new HttpClient()
            {
                Timeout = TimeSpan.FromSeconds(20)
            };

            JObject jsonDataObject = new JObject {
                { "email", emailForm.Text.Trim() }
            };

            JObject jsonData = new JObject {
                { "params", jsonDataObject }
            };

            var data    = jsonData.ToString();
            var content = new StringContent(data, Encoding.UTF8, "application/json");

            Debug.WriteLine("REQUEST-UserExistCheck: " + data);

            try
            {
                HttpResponseMessage response = await client.PostAsync(ApiUri.BASE_URL + ApiUri.CHECK_USER, content);

                string responseContent = await response.Content.ReadAsStringAsync();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Debug.WriteLine("RESPONSE-UserExistCheck: " + responseContent);

                    UserExistCheckResponse userExistCheckResponse = JsonConvert.DeserializeObject <UserExistCheckResponse>(responseContent, App.DefaultSerializerSettings);
                    UserExistCheckResult   userExistCheckResult   = userExistCheckResponse.result;

                    if (userExistCheckResult.success)
                    {
                        if (userExistCheckResult.user_exist)
                        {
                            UserDialogs.Instance.Loading(title: "Logging in...").Show();
                            // Login sever.
                            ServerLogin();
                        }
                        else
                        {
                            UserDialogs.Instance.Loading().Hide();

                            var toastAction = new ToastAction();
                            toastAction.SetText("SIGN UP");
                            toastAction.SetAction(OnToastActionSignUp);

                            UserDialogs.Instance.Toast(
                                new ToastConfig("User doesn't exist")
                                .SetAction(toastAction)
                                );
                        }
                    }
                    else
                    {
                        Notifications.Internal.ServerError();
                    }
                }
                else
                {
                    UserDialogs.Instance.Loading().Hide();
                    Debug.WriteLine("RESPONSE_ERROR-UserExistCheck: " + responseContent);
                    Notifications.Internal.ServerError();
                }
            }
            catch (TaskCanceledException e)
            {
                UserDialogs.Instance.Loading().Hide();
                UserDialogs.Instance.Toast(new ToastConfig("Bad Connection Error. Try Again"));
                Debug.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                UserDialogs.Instance.Loading().Hide();
                Notifications.Internal.ServerError();
            }
        }
        //---end------------------------------------------------------------------------------------MODAL CALLBACKS---//

        //---start-------------------------------------------------------------------------------------SERVER COMMS---//

        private async void UpdateProfile()
        {
            UserDialogs.Instance.Loading(title: "Updating Profile...").Show();
            var client = new HttpClient
            {
                Timeout = TimeSpan.FromSeconds(20)
            };

            var AuthService = DependencyService.Get <IAuthService>();

            JObject jsonAuth = new JObject {
                { "db", ServerAuth.DB },
                { "login", AuthService.UserName },
                { "password", AuthService.Password }
            };

            JObject jsonTraveller = new JObject {
                { "name", userEditTemp.name },
                { "mobile", userEditTemp.mobile },
                { "country", userEditTemp.country },
                { "image", userEditTemp.profile_pic }
            };

            JObject jsonDataObject = new JObject {
                { "auth", jsonAuth },
                { "traveller", jsonTraveller }
            };
            JObject jsonData = new JObject {
                { "params", jsonDataObject }
            };

            var data    = jsonData.ToString();
            var content = new StringContent(data, Encoding.UTF8, "application/json");

            Debug.WriteLine("REQUEST-UpdateProfile: " + data);

            try
            {
                HttpResponseMessage response = await client.PostAsync(ApiUri.BASE_URL + ApiUri.UPDATE_TRAVELLER, content);

                string responseContent = await response.Content.ReadAsStringAsync();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    UserDialogs.Instance.Loading().Hide();
                    Debug.WriteLine("RESPONSE-UpdateProfile: " + responseContent);

                    SuccessCheckResponse successCheckResponse = JsonConvert.DeserializeObject <SuccessCheckResponse>(responseContent, App.DefaultSerializerSettings);
                    SuccessCheckResult   successCheckResult   = successCheckResponse.result;

                    if (successCheckResult.success)
                    {
                        var realm = Realm.GetInstance();
                        realm.Write(() =>
                        {
                            user.name        = userEditTemp.name;
                            user.mobile      = userEditTemp.mobile;
                            user.country     = userEditTemp.country;
                            user.profile_pic = userEditTemp.profile_pic;
                            realm.Add(user, update: true);
                        });

                        UserDialogs.Instance.Toast("Profile Updated Successfully");

                        ToggleEditState(false);
                    }
                    else
                    {
                        var toastAction = new ToastAction();
                        toastAction.SetText("RETRY");
                        toastAction.SetAction(OnToastActionUpdateProfile);

                        UserDialogs.Instance.Toast(
                            new ToastConfig("Profile Update Failed")
                            .SetAction(toastAction)
                            );
                    }
                }
                else
                {
                    UserDialogs.Instance.Loading().Hide();
                    Debug.WriteLine("RESPONSE_ERROR-UpdateProfile: " + responseContent);
                    Notifications.Internal.ServerError();
                }
            }
            catch (TaskCanceledException e)
            {
                UserDialogs.Instance.Loading().Hide();
                UserDialogs.Instance.Toast(new ToastConfig("Bad Connection Error. Try Again"));
                Debug.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                UserDialogs.Instance.Loading().Hide();
                Notifications.Internal.ServerError();
            }
        }
예제 #7
0
        /// <summary>
        /// Callback method for starting connection
        /// </summary>
        async void OnConnectionStarted()
        {
            // Bail if the user has already started a connection
            if (IsAttemptingConnection())
            {
                return;
            }

            try
            {
                // Connect to IP
                bool success = connection.Connect(IPAddress);

                if (!success)
                {
                    if (!QTMNetworkConnection.QTMVersionSupported)
                    {
                        // QTM is not supported
                        userDialogs.Alert("Please make sure that you are connecting to a Windows PC with " +
                                          "a Qualisys Track Manager software version of at least 2.16", "Attention", "Dismiss");
                    }
                    else
                    {
                        // There was an error with the connection
                        notificationService.Show("Attention", "There was a connection error, please check IP address");
                    }

                    return;
                }
                else if (connection.HasPassword())
                {
                    // NOTE: A new propmt configuration has to be created everytime we run it
                    // if we do not do this the acr library will add an action to it and since
                    // it is async it does not expect that and will thus throw an error
                    PromptResult result = await userDialogs
                                          .PromptAsync(
                        new PromptConfig()
                        .SetTitle("Please enter password (blank for slave mode)")
                        .SetOkText("Connect"));

                    if (!result.Ok)
                    {
                        return;
                    }

                    // Connect to host
                    connection.Connect(IPAddress, result.Text);

                    if (!connection.TakeControl() && result.Text != "")
                    {
                        ToastAction toastAction = new ToastAction().SetText("Retry").SetAction(() => OnConnectionStarted());
                        ToastConfig toastConfig = new ToastConfig("Incorrect Password")
                                                  .SetAction(toastAction);

                        userDialogs.Toast(toastConfig);
                        return;
                    }
                }

                // Send connection instance to settings service
                if (!SettingsService.Initialize())
                {
                    // There was a problem when attempting to establish the connection
                    userDialogs.Alert("There was a communication mismatch with QTM, please make sure you are running the" +
                                      " latest version of this application and that you have the QTM version specified in" +
                                      " the requirements", "Error", "Dismiss");

                    connection.Disconnect();
                    return;
                }

                // Show loading screen whilst connecting
                // This loading screen is disabled in the CameraPageViewModel constructor
                Task.Run(() => userDialogs.ShowLoading("Establishing connection..."));

                // Fetch information from system and fill structures accordingly
                CameraManager.GenerateCameras();

                // Connection was successfull
                // Navigate to camera page
                NavigationParameters navigationParams = new NavigationParameters();
                navigationParams.Add(Helpers.Constants.NAVIGATION_DEMO_MODE_STRING, false);
                Device.BeginInvokeOnMainThread(() => navigationService.NavigateAsync("CameraPage", navigationParams));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                notificationService.Show("Attention", "Please make sure that QTM is up and running and that the cameras are plugged in");

                Task.Run(() => userDialogs.HideLoading());

                return;
            }
        }
 public ToastActionViewModel(ToastAction inAction)
 {
     _toastAction = inAction;
     wordPointer  = _toastAction;
 }
 public ToastActionViewModel()
 {
     _toastAction = new ToastAction();
     wordPointer  = _toastAction;
 }