Example #1
0
        private async void GetAndOpenActivity(string code)
        {
            ProgressDialog dialog = new ProgressDialog(this);

            dialog.SetMessage(Resources.GetString(Resource.String.PleaseWait));
            dialog.Show();

            ServerResponse <LearningActivity> result = await ServerUtils.Get <LearningActivity>("/api/LearningActivities/GetWithCode?code=" + code).ConfigureAwait(false);

            RunOnUiThread(() =>
            {
                dialog.Dismiss();
                dialog.Dispose();
            });

            if (result == null)
            {
                var suppress = AndroidUtils.ReturnToSignIn(this);
                RunOnUiThread(() => Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show());
                return;
            }

            if (result.Success)
            {
                await AndroidUtils.LaunchActivity(result.Data, this).ConfigureAwait(false);
            }
            else
            {
                // if token invalid, return to signin
                if (ServerUtils.CheckNeedsLogin(result.StatusCode))
                {
                    var suppress = AndroidUtils.ReturnToSignIn(this);
                    return;
                }
                if (result.Message.StartsWith("404"))
                {
                    RunOnUiThread(() => Toast.MakeText(this, Resource.String.searchFail, ToastLength.Long).Show());
                }
                else
                {
                    RunOnUiThread(() => Toast.MakeText(this, Resource.String.ConnectionError, ToastLength.Long).Show());
                }
            }
        }
        private async void GetAndReturnWithActivity(string code)
        {
            ProgressDialog dialog = new ProgressDialog(this);

            dialog.SetMessage(Resources.GetString(Resource.String.PleaseWait));
            dialog.Show();

            ServerResponse <LearningActivity> result =
                await ServerUtils.Get <LearningActivity>("/api/LearningActivities/GetWithCode?code=" + code).ConfigureAwait(false);

            dialog.Dismiss();

            if (result == null)
            {
                _ = AndroidUtils.ReturnToSignIn(this);
                Toast.MakeText(this, Resource.String.ForceSignOut, ToastLength.Long).Show();
                return;
            }

            if (result.Success)
            {
                ActivityChosen(result.Data);
            }
            else
            {
                // if token invalid, return to signin
                if (ServerUtils.CheckNeedsLogin(result.StatusCode))
                {
                    _ = AndroidUtils.ReturnToSignIn(this);
                    return;
                }

                if (result.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    Toast.MakeText(this, Resource.String.searchFail, ToastLength.Long).Show();
                }
                else
                {
                    Toast.MakeText(this, Resource.String.ConnectionError, ToastLength.Long).Show();
                }
            }
        }