Exemple #1
0
        void HandleItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            var item = adapter [e.Position];

            var alert = new AlertDialog.Builder(this);

            alert.SetIcon(Resource.Drawable.ic_launcher);
            alert.SetTitle(Resource.String.steps_cap);
            var view      = LayoutInflater.Inflate(Resource.Layout.step_entry, null);
            var stepsEdit = view.FindViewById <EditText> (Resource.Id.step_count);

            stepsEdit.Text = item.Steps.ToString();
            alert.SetView(view);

            alert.SetPositiveButton(Resource.String.ok, (object sender2, DialogClickEventArgs e2) => {
                //so now we want to see where we were previously, and where they
                //want to set it. We will update the database entry,
                //update total steps in settings, and action bar title
                //which will also invalidate our share options!
                //if they set it to a negative number do not allow it.

                var newCount = -1;
                if (!Int32.TryParse(stepsEdit.Text, out newCount))
                {
                    return;
                }

                if (newCount < 0)
                {
                    return;
                }

                var diff = newCount - item.Steps;

                //update total steps even if negative as it will never go to 0
                //also update steps before today so home screen is correct and doesn't change
                Settings.TotalSteps       += diff;
                Settings.StepsBeforeToday += diff;

                if (spinnerAdapter != null)
                {
                    var last7  = DateTime.Today.AddDays(-6);
                    var last30 = DateTime.Today.AddDays(-30);
                    if (item.Date >= last7)
                    {
                        weekSteps  += diff;
                        monthSteps += diff;
                    }
                    else if (item.Date >= last30)
                    {
                        monthSteps += diff;
                    }
                }

                item.Steps = newCount;

                Database.StepEntryManager.SaveStepEntry(item);

                //update UI
                RunOnUiThread(() => {
                    adapter.NotifyDataSetChanged();
                    SetActionBar();
                });
            });

            //we are lucky here as cancel is translated by android :)
            alert.SetNegativeButton(Android.Resource.String.Cancel, delegate {
                //do nothing here.
            });

            alert.Show();
        }
 public override void OnResume()
 {
     base.OnResume();
     adapter.NotifyDataSetChanged();
     ViewModel.ResumeCommand.Execute();
 }