Ejemplo n.º 1
0
        public override void OnBackPressed()
        {
            //List<Team> teams = new List<Team>();
            //try
            //{
            //    teams = AWSDataAccess.GetBetTeam(0);
            //}
            //catch (Exception exp)
            //{

            //    teams.Add(new Team()
            //    {
            //        Name = exp.Message,
            //        Bet = exp.Message
            //    });
            //}
            AddBetFragment addBetFragment = FragmentManager.FindFragmentByTag("AddBet") as AddBetFragment;

            if (addBetFragment != null && addBetFragment.IsVisible)
            {
                FragmentTransaction ft = FragmentManager.BeginTransaction();
                ft.Replace(Resource.Id.frameLayout1, new HomeFragment());
                ft.Commit();
                return;
            }

            ModifyBetFragment modBetFragment = FragmentManager.FindFragmentByTag("ModifyBet") as ModifyBetFragment;

            if (modBetFragment != null && modBetFragment.IsVisible)
            {
                FragmentTransaction ft = FragmentManager.BeginTransaction();
                ft.Replace(Resource.Id.frameLayout1, new HomeFragment());
                ft.Commit();
                return;
            }

            CalculateBetFragment fragment = FragmentManager.FindFragmentByTag("CALCULATE") as CalculateBetFragment;

            if (fragment != null && fragment.IsVisible)
            {
                FragmentTransaction ft = FragmentManager.BeginTransaction();
                ft.Replace(Resource.Id.frameLayout1, new ActiveBetFragment());
                ft.Commit();
                return;
            }

            Finish();
            Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
        }
Ejemplo n.º 2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var progressDialog = ProgressDialog.Show(Activity, "", "Creating plot", true);

            progressDialog.SetProgressStyle(ProgressDialogStyle.Spinner);

            progressDialog.Show();

            // Use this to return your custom view for this Fragment
            View view = inflater.Inflate(Resource.Layout.Home, container, false);
            //Button newBetBtn = view.FindViewById<Button>(Resource.Id.newBetBtn);
            //Button closeBetBtn = view.FindViewById<Button>(Resource.Id.closeBetBtn);
            //Button modifyBetBtn = view.FindViewById<Button>(Resource.Id.modifyBetBtn);



            //betProviders.Visibility = ViewStates.Visible;
            //var providers = new List<BetProvider>() { BetProvider.PaddyPower, BetProvider.Bet365 };
            //betProviders.Adapter = new ArrayAdapter<BetProvider>(Activity,
            //    Android.Resource.Layout.SimpleDropDownItem1Line, providers);
            string model = Build.Model;

            //betProviders.Visibility = ViewStates.Visible;
            //var providers = new List<BetProvider>() { BetProvider.PaddyPower, BetProvider.Bet365 };
            //betProviders.Adapter = new ArrayAdapter<BetProvider>(Activity,
            //    Android.Resource.Layout.SimpleDropDownItem1Line, providers);

            //betProviders.ItemSelected += delegate
            //{
            //    ApplicationState.ActiveProvider = providers[betProviders.SelectedItemPosition];

            //};
            if (model.StartsWith("frd", StringComparison.CurrentCultureIgnoreCase))
            {
                ApplicationState.ActiveProvider = BetProvider.Bet365;
            }



            #region button click
            //newBetBtn.Click += delegate
            //{
            //    var addBetFragment = new AddBetFragment() { Arguments = new Bundle() };
            //    //calculateBetFragment.Arguments.PutString("PID", teams[e.Position - 1].Id.ToString());
            //    FragmentTransaction ft = this.Activity.FragmentManager.BeginTransaction();
            //    ft.Replace(Resource.Id.frameLayout1, addBetFragment, "AddBet");
            //    ft.Commit();

            //};


            //modifyBetBtn.Click += delegate
            //{
            //    var modBetFragment = new ModifyBetFragment() { Arguments = new Bundle() };
            //    //calculateBetFragment.Arguments.PutString("PID", teams[e.Position - 1].Id.ToString());
            //    FragmentTransaction ft = this.Activity.FragmentManager.BeginTransaction();
            //    ft.Replace(Resource.Id.frameLayout1, modBetFragment, "ModifyBet");
            //    ft.Commit();

            //};


            //closeBetBtn.Click += delegate
            // {
            //     FragmentTransaction ft = FragmentManager.BeginTransaction();
            //     //Remove fragment else it will crash as it is already added to backstack
            //     Fragment prev = FragmentManager.FindFragmentByTag("closeBetDialog");
            //     if (prev != null)
            //     {
            //         ft.Remove(prev);
            //     }

            //     ft.AddToBackStack(null);

            //     // Create and show the dialog.
            //     CloseBetDialogFragment newFragment = CloseBetDialogFragment.NewInstance(null);
            //     //newFragment.Arguments.PutString("TEAMID",)

            //     //Add fragment
            //     newFragment.Show(ft, "closeBetDialog");
            // };
            #endregion


            new Thread(new ThreadStart(delegate
            {
                #region Calculation
                List <Team> activeTeam = AWSDataAccess.GetBetTeam(0);
                List <Team> closedTeam = AWSDataAccess.GetBetTeam(1);
                decimal spentMoney     = 100;
                foreach (var t in activeTeam)
                {
                    List <BetDetails> details =
                        AWSDataAccess.GetBetDetailsByTeamId(t.Id);

                    foreach (var d in details)
                    {
                        spentMoney += d.Quantity;
                    }
                }
                decimal winnedMoney = 0;
                foreach (var ti in closedTeam)
                {
                    List <BetDetails> details =
                        AWSDataAccess.GetBetDetailsByTeamId(ti.Id);
                    winnedMoney += ti.Win;
                    foreach (var de in details)
                    {
                        spentMoney += de.Quantity;
                    }
                }
                #endregion

                Activity.RunOnUiThread(() => { PlotView plotView = view.FindViewById <PlotView>(Resource.Id.plot_view);
                                               plotView.Model    = CreatePlotModel(winnedMoney, spentMoney); });
                Thread.Sleep(10);
                progressDialog.Dismiss();
            })).Start();



            //float percentComplete = (float)Math.Round((100 * winnedMoney) / spentMoney);


            //LinearLayout balanceLayout = (LinearLayout)view.FindViewById(Resource.Id.balanceLayout);
            //balanceLayout.AddView(new Rectangle(Activity, percentComplete, winnedMoney));



            var editToolbar = view.FindViewById <Toolbar>(Resource.Id.edit_toolbar);
            editToolbar.Title = "Editing";
            editToolbar.InflateMenu(Resource.Menu.edit_menus);


            if (model.StartsWith("frd", StringComparison.CurrentCultureIgnoreCase))
            {
                editToolbar.Menu.FindItem(Resource.Id.menu_preferences).SetVisible(true);
                //ApplicationState.ActiveProvider = BetProvider.Bet365;
            }
            else
            {
                editToolbar.Menu.FindItem(Resource.Id.menu_preferences).SetVisible(false);
            }



            editToolbar.MenuItemClick += (sender, e) =>
            {
                FragmentTransaction ft;
                switch (e.Item.ItemId)
                {
                case Resource.Id.menu_create:
                    var addBetFragment = new AddBetFragment()
                    {
                        Arguments = new Bundle()
                    };
                    //calculateBetFragment.Arguments.PutString("PID", teams[e.Position - 1].Id.ToString());
                    ft = this.Activity.FragmentManager.BeginTransaction();
                    ft.Replace(Resource.Id.frameLayout1, addBetFragment, "AddBet");
                    ft.Commit();
                    break;

                case Resource.Id.menu_edit:
                    var modBetFragment = new ModifyBetFragment()
                    {
                        Arguments = new Bundle()
                    };
                    //calculateBetFragment.Arguments.PutString("PID", teams[e.Position - 1].Id.ToString());
                    ft = this.Activity.FragmentManager.BeginTransaction();
                    ft.Replace(Resource.Id.frameLayout1, modBetFragment, "ModifyBet");
                    ft.Commit();
                    break;

                case Resource.Id.menu_close:
                    ft = FragmentManager.BeginTransaction();
                    //Remove fragment else it will crash as it is already added to backstack
                    Fragment prev = FragmentManager.FindFragmentByTag("closeBetDialog");
                    if (prev != null)
                    {
                        ft.Remove(prev);
                    }

                    ft.AddToBackStack(null);

                    // Create and show the dialog.
                    CloseBetDialogFragment newFragment = CloseBetDialogFragment.NewInstance(null);
                    //newFragment.Arguments.PutString("TEAMID",)

                    //Add fragment
                    newFragment.Show(ft, "closeBetDialog");
                    break;

                case Resource.Id.menu_preferences:
                    ft = FragmentManager.BeginTransaction();
                    Fragment p = FragmentManager.FindFragmentByTag("providerChoiceDialog");
                    if (p != null)
                    {
                        ft.Remove(p);
                    }
                    ft.AddToBackStack(null);
                    ProviderChoiceFragment pcFragment = ProviderChoiceFragment.NewInstance(null);
                    pcFragment.Show(ft, "providerChoiceDialog");
                    break;

                default:
                    break;
                }
            };
            return(view);
        }