Example #1
0
        private async void Tab_OnRoleSelected(Role selected)
        {
            if (!selectingrole)
            {
                selectingrole = true;
                //if its the initial connection:
                if (!dark)
                {
                    //Shoot selected = obj;
                    cancel = new CancellationTokenSource();
                    AndHUD.Shared.Show(Activity, Resources.GetString(Resource.String.connecting), -1, MaskType.Black, null, null, true, () =>
                    {
                        cancel.Cancel();
                        selectingrole = false;
                    });

                    try
                    {
                        cancel = new CancellationTokenSource();
                        await AskPermissions(Activity, CurrentEvent);

                        await Bootlegger.BootleggerClient.ConnectToEvent(CurrentEvent, false, cancel.Token);
                    }
                    catch (ServerErrorException)
                    {
                        AndHUD.Shared.Dismiss();

                        //show dialog:
                        new Android.Support.V7.App.AlertDialog.Builder(Activity).SetMessage(Resources.GetString(Resource.String.role_repeat))
                        .SetNegativeButton(Android.Resource.String.No, new EventHandler <DialogClickEventArgs>((oe, eo) =>
                        {
                        }))
                        .SetPositiveButton(Android.Resource.String.Yes, new EventHandler <DialogClickEventArgs>(async(oe, eo) =>
                        {
                            AndHUD.Shared.Show(Activity, Resources.GetString(Resource.String.connecting), -1, MaskType.Black, null, null, true, () =>
                            {
                                cancel.Cancel();
                            });
                            cancel = new CancellationTokenSource();
                            await Bootlegger.BootleggerClient.ConnectToEvent(CurrentEvent, true, cancel.Token);
                            await AskPermissions(Activity, CurrentEvent);
                            selectingrole = false;
                        }))
                        .SetTitle(Resource.String.areyousure)
                        .SetCancelable(false)
                        .Show();
                    }
                    catch (NotGivenPermissionException e)
                    {
                        AndHUD.Shared.Dismiss();
                        selectingrole = false;
                        try
                        {
                            LoginFuncs.ShowError(this.Activity, e);
                            //Toast.MakeText(Activity, Resource.String.acceptperms, ToastLength.Long).Show();
                        }
                        catch { }
                        return;
                    }
                    catch (Exception e)
                    {
                        AndHUD.Shared.Dismiss();
                        selectingrole = false;
                        try
                        {
                            //Toast.MakeText(Activity, Resource.String.problemconnecting, ToastLength.Long).Show();
                            LoginFuncs.ShowError(this.Activity, e);
                        }
                        catch { }
                        return;
                    }
                }

                //ROLE SELECTION WHEN SHOOTING:
                //AndHUD.Shared.Show(Activity, Resources.GetString(Resource.String.loading), -1, MaskType.Black, null, null, true, () =>
                //{
                //    cancel.Cancel();
                //    selectingrole = false;
                //});
                //await Task.Delay(100);
                try
                {
                    cancel = new CancellationTokenSource();
                    var res = await Bootlegger.BootleggerClient.SelectRole(selected, false, cancel.Token);

                    if (res.State == API.Model.RoleStatus.RoleState.OK)
                    {
                        OnRoleChanged?.Invoke();
                        rolelist?.Update();
                        map?.Update();
                        //AndHUD.Shared.Dismiss();
                        selectingrole = false;
                    }
                    else if (res.State == API.Model.RoleStatus.RoleState.CONFIRM)
                    {
                        new Android.Support.V7.App.AlertDialog.Builder(Activity).SetMessage(res.Message)
                        .SetNegativeButton(Android.Resource.String.No, new EventHandler <DialogClickEventArgs>(async(oe, eo) =>
                        {
                            cancel   = new CancellationTokenSource();
                            var ress = await Bootlegger.BootleggerClient.SelectRole(selected as Role, true, cancel.Token);
                            //listview.Enabled = true;

                            if (ress.State == API.Model.RoleStatus.RoleState.OK)
                            {
                                OnRoleChanged?.Invoke();
                                rolelist?.Update();
                                map?.Update();
                                //AndHUD.Shared.Dismiss();
                                selectingrole = false;
                            }
                            else
                            {
                                //you are live -- so cant do this anyway
                                //AndHUD.Shared.Dismiss();
                                selectingrole = false;
                            }
                        }))
                        .SetPositiveButton(Android.Resource.String.Yes, new EventHandler <DialogClickEventArgs>((oe, eo) =>
                        {
                            //AndHUD.Shared.Dismiss();
                            selectingrole = false;
                        }))
                        .SetTitle(Resource.String.roledescision)
                        .SetCancelable(false)
                        .Show();
                    }
                    else if (res.State == API.Model.RoleStatus.RoleState.NO)
                    {
                        //you are live and cant do it
                        //AndHUD.Shared.Dismiss();
                        selectingrole = false;
                        try
                        {
                            LoginFuncs.ShowError(this.Activity, new RoleNotSelectedException());
                        }
                        catch { }
                    }
                }
                catch (Exception e)
                {
                    //AndHUD.Shared.Dismiss();
                    selectingrole = false;
                    try
                    {
                        LoginFuncs.ShowError(this.Activity, e);
                    }
                    catch { }
                }
            }
        }
Example #2
0
 private void Myrolefrag_OnRoleChanged()
 {
     //rolechanged...
     OnRoleChanged?.Invoke();
 }