Exemplo n.º 1
0
        private void ActivitiesWeek_ItemLongClick(object sender, AdapterView.ItemLongClickEventArgs e)
        {
            try
            {
                long packedPosition = _activitiesWeek.GetExpandableListPosition(e.Position);

                if (ExpandableListView.GetPackedPositionType(packedPosition) == PackedPositionType.Child)
                {
                    // get item ID's
                    int groupPosition = ExpandableListView.GetPackedPositionGroup(packedPosition);
                    int childPosition = ExpandableListView.GetPackedPositionChild(packedPosition);

                    Activities   activity     = GlobalData.ActivitiesForWeek[groupPosition];
                    ActivityTime activityTime = activity.ActivityTimes[childPosition];

                    string startTime, endTime;

                    StringHelper.ActivityTimeBeginEndForConstant(activityTime.ActivityTime, out startTime, out endTime);

                    _timeFragment = new ActivityTimeDialogFragment(this, activity.ActivityDate, activityTime.ActivityTime, startTime, endTime, groupPosition, childPosition, "Add Activity");

                    var fragmentTransaction = FragmentManager.BeginTransaction();
                    _timeFragment.Show(fragmentTransaction, _timeFragment.Tag);

                    Log.Info(TAG, "ActivitiesWeek_ItemLongClick: groupPosition - " + groupPosition.ToString() + ", childPosition - " + childPosition.ToString());

                    e.Handled = true;
                }
            }
            catch (Exception ex)
            {
                Log.Error(TAG, "ActivitiesWeek_ItemLongClick: Exception - " + ex.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(this, ex, GetString(Resource.String.ErrorActivitySelectChildItem), "ActivitiesActivity.ActivitiesWeek_ItemLongClick");
                }
            }
        }
Exemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            expListView = FindViewById <ExpandableListView>(Resource.Id.RosterListview);

            DataAccess.Initialize();
            GetListData();

            listAdapter = new RosterDataAdapter(this, listDataHeader, listDataChild);
            expListView.SetAdapter(listAdapter);

            expListView.ExpandGroup(0);
            expListView.ExpandGroup(1);
            expListView.ExpandGroup(2);

            expListView.ChildClick += delegate(object sender, ExpandableListView.ChildClickEventArgs e)
            {
                var groupPosition = e.GroupPosition;
                var childPosition = e.ChildPosition;

                if (groupPosition == 2) //roster
                {
                    var player = listAdapter.GetChildObj(groupPosition, childPosition);

                    listAdapter.DeleteChild(groupPosition, childPosition);
                    player = listAdapter.AddChild(groupPosition - 1, player);

                    Player.UpdatePlayer(player);
                }
                else if (groupPosition == 1) //bench
                {
                    var player = listAdapter.GetChildObj(groupPosition, childPosition);

                    listAdapter.DeleteChild(groupPosition, childPosition);
                    player = listAdapter.AddChild(groupPosition - 1, player);

                    Player.UpdatePlayer(player);
                }
                else //game
                {
                    var player = listAdapter.GetChildObj(groupPosition, childPosition);

                    if (!player.isGoalkeeper)
                    {
                        listAdapter.DeleteChild(groupPosition, childPosition);
                        player = listAdapter.AddChild(groupPosition + 1, player);

                        Player.UpdatePlayer(player);
                    }
                }
                listAdapter.NotifyDataSetChanged();
            };

            expListView.ItemLongClick += delegate(object sender, AdapterView.ItemLongClickEventArgs e)
            {
                var listPosition  = expListView.GetExpandableListPosition(e.Position);
                var groupPosition = ExpandableListView.GetPackedPositionGroup(listPosition);
                var childPosition = ExpandableListView.GetPackedPositionChild(listPosition);

                if (groupPosition == 1 || groupPosition == 0)
                {
                    var player = listAdapter.GetChildObj(groupPosition, childPosition);

                    listAdapter.DeleteChild(groupPosition, childPosition);
                    player = listAdapter.AddChild(2, player);

                    Player.UpdatePlayer(player);
                }
                listAdapter.NotifyDataSetChanged();
            };

            homeScoreMinus = FindViewById <ImageButton>(Resource.Id.home_score_minus);
            homeScore      = FindViewById <TextView>(Resource.Id.home_score);
            homeScorePlus  = FindViewById <ImageButton>(Resource.Id.home_score_plus);
            matchTime      = FindViewById <TextView>(Resource.Id.match_time);
            awayScoreMinus = FindViewById <ImageButton>(Resource.Id.away_score_minus);
            awayScore      = FindViewById <TextView>(Resource.Id.away_score);
            awayScorePlus  = FindViewById <ImageButton>(Resource.Id.away_score_plus);

            if (savedInstanceState != null)
            {
                homeScoreVal = savedInstanceState.GetInt("home_score");
                awayScoreVal = savedInstanceState.GetInt("away_score");

                homeScore.Text = homeScoreVal.ToString();
                awayScore.Text = awayScoreVal.ToString();
            }

            homeScoreMinus.Click += (sender, e) => {
                if (homeScoreVal > 0)
                {
                    homeScoreVal--;
                    homeScore.Text = homeScoreVal.ToString();
                }
            };

            homeScorePlus.Click += (sender, e) =>
            {
                homeScoreVal++;
                homeScore.Text = homeScoreVal.ToString();
            };

            awayScoreMinus.Click += (sender, e) =>
            {
                if (awayScoreVal > 0)
                {
                    awayScoreVal--;
                    awayScore.Text = awayScoreVal.ToString();
                }
            };

            awayScorePlus.Click += (sender, e) =>
            {
                awayScoreVal++;
                awayScore.Text = awayScoreVal.ToString();
            };

            var bottomMenu = FindViewById <Toolbar>(Resource.Id.toolbar_bottom);

            bottomMenu.InflateMenu(Resource.Menu.Bottom_Menu);
            bottomMenu.MenuItemClick += (sender, e) =>
            {
                if (e.Item.ItemId == Resource.Id.menuAddPlayer)
                {
                    var intent = new Intent(this, typeof(AddPlayerActivity));
                    StartActivity(intent);
                    Finish();
                }
                else if (e.Item.ItemId == Resource.Id.menuResetGame)
                {
                    var builder = new AlertDialog.Builder(this);

                    builder.SetMessage(Resources.GetString(Resource.String.reset_game));
                    builder.SetNegativeButton(Resources.GetString(Resource.String.no), (s, ee) => { });
                    builder.SetPositiveButton(Resources.GetString(Resource.String.yes), (s, ee) =>
                    {
                        StopMatchClock();
                        ResetMatchClock();
                        ResetScores();
                        ResetListData();
                        listAdapter.NotifyDataSetChanged();
                    });

                    builder.Create().Show();
                }
                else if (e.Item.ItemId == Resource.Id.menuStartMatchClock)
                {
                    StartMatchClock();
                }
                else if (e.Item.ItemId == Resource.Id.menuStopMatchClock)
                {
                    StopMatchClock();
                }
                else if (e.Item.ItemId == Resource.Id.menuResetMatchClock)
                {
                    var builder = new AlertDialog.Builder(this);

                    builder.SetMessage(Resources.GetString(Resource.String.reset_match_clock));
                    builder.SetNegativeButton(Resources.GetString(Resource.String.no), (s, ee) => { });
                    builder.SetPositiveButton(Resources.GetString(Resource.String.yes), (s, ee) =>
                    {
                        ResetMatchClock();
                    });

                    builder.Create().Show();
                }
                else if (e.Item.ItemId == Resource.Id.menuResetScores)
                {
                    var builder = new AlertDialog.Builder(this);

                    builder.SetMessage(Resources.GetString(Resource.String.reset_scores));
                    builder.SetNegativeButton(Resources.GetString(Resource.String.no), (s, ee) => { });
                    builder.SetPositiveButton(Resources.GetString(Resource.String.yes), (s, ee) =>
                    {
                        ResetScores();
                    });

                    builder.Create().Show();
                }
            };
        }