コード例 #1
0
ファイル: SmsGroupFragment.cs プロジェクト: jheerman/Prattle
        public override bool OnContextItemSelected(IMenuItem item)
        {
            if (_position < 0) return false;

            switch (item.ItemId)
            {
                case Resource.Id.editSMS:
                    using (var editSmsIntent = new Intent())
                    {
                        editSmsIntent.PutExtra ("groupId", _smsGroups[_position].Id);
                        editSmsIntent.SetClass (Activity, typeof(EditSmsGroupActivity));
                        StartActivity (editSmsIntent);
                    }
                    break;
                case Resource.Id.sendSMS:
                    using (var sendMessage = new Intent())
                    {
                        sendMessage.PutExtra ("groupId", _smsGroups[_position].Id);
                        sendMessage.SetClass (Activity, typeof(SendMessageActivity));
                        StartActivity (sendMessage);
                    }
                    break;
                case Resource.Id.deleteSMS:
                    new AlertDialog.Builder(Activity)
                        .SetTitle ("Delete SMS Group")
                        .SetMessage (string.Format ("Are you sure you want to delete the following group: {0}",
                                                    _smsGroups[_position]))
                        .SetPositiveButton ("Ok", (o, e) => {
                            _progressDialog = new ProgressDialog(Activity);
                            _progressDialog.SetTitle ("Delete SMS Group");
                            _progressDialog.SetMessage ("Please wait.  Deleting SMS Group...");
                            _progressDialog.Show ();

                            Task.Factory
                                .StartNew(() => {
                                    var smsGroup = _smsGroups[_position];

                                    //Delete all messages, group memebers, and then delete sms group
                                    var messageRepo = new SmsMessageRepository();
                                    var messages = messageRepo.GetAllForGroup (smsGroup.Id);
                                    messages.ForEach (messageRepo.Delete);

                                    _contactRepo = new ContactRepository(Activity);
                                    var contacts = _contactRepo.GetMembersForSmsGroup(smsGroup.Id);
                                    contacts.ForEach (c => _contactRepo.Delete (c));

                                    _smsGroupRepo.Delete (smsGroup);
                                })
                                .ContinueWith(task =>
                                    Activity.RunOnUiThread(() => {
                                        _smsGroups.RemoveAt (_position);
                                        ListAdapter = new GroupListAdapter(Activity, _smsGroups);
                                        ((BaseAdapter)ListAdapter).NotifyDataSetChanged ();
                                        _progressDialog.Dismiss ();
                                    }));
                        })
                        .SetNegativeButton ("Cancel", (o, e) => { })
                        .Show ();
                    break;
            }

            return base.OnContextItemSelected (item);
        }
コード例 #2
0
ファイル: SmsGroupFragment.cs プロジェクト: jheerman/Prattle
        public override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);
            _smsGroupRepo = new Repository<SmsGroup>();
            _smsGroups = _smsGroupRepo.GetAll ().ToList ();

            ListAdapter = new GroupListAdapter(Activity, _smsGroups);
        }