Inheritance: Prattle.Android.Core.PrattleBase, ISmsGroup
Example #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            BindService ();

            SetContentView(Resource.Layout.SendMessage);
            ActionBar.SetDisplayHomeAsUpEnabled (true);

            var groupId = Intent.GetIntExtra("groupId", 0);
            _smsGroupRepo = new SmsGroupRepository();
            _smsGroup = _smsGroupRepo.Get (groupId);

            _contactRepo = new ContactRepository(this);
            _recipients = _contactRepo.GetMembersForSmsGroup (groupId);

            FindViewById <TextView>(Resource.Id.recipientGroup).Text = _smsGroup.Name;
            FindViewById <TextView>(Resource.Id.recipients).Text = string.Join (", ", _recipients.Select (c => c.Name));
            FindViewById <ImageButton>(Resource.Id.cmdSend).Click += (sender, e) =>
                {
                    _progressDialog = new ProgressDialog(this);
                    _progressDialog.SetTitle ("Sending Messages");
                    _progressDialog.SetMessage ("Please wait.  Sending message to recipients in group...");

                    Task.Factory
                        .StartNew(() =>
                            QueueMessage ())
                        .ContinueWith(task =>
                            RunOnUiThread(() => {
                                if (task.Result)
                                {
                                    new AlertDialog.Builder(this)
                                        .SetTitle ("Messages Queued")
                                        .SetMessage (string.Format ("Your message was queued to be sent to each recipient of the '{0}' group",
                                                                    _smsGroup.Name))
                                        .SetPositiveButton ("Ok", (o, args) => {
                                                    var homeIntent = new Intent();
                                                    homeIntent.PutExtra ("defaultTab", 0);
                                                    homeIntent.AddFlags (ActivityFlags.ClearTop);
                                                    homeIntent.SetClass (this, typeof(MainActivity));
                                                    StartActivity(homeIntent);
                                                })
                                        .Show ();
                                }
                                else
                                {
                                    new AlertDialog.Builder(this)
                                        .SetTitle ("Message Error")
                                        .SetMessage (string.Format ("Doh!  Your message could not be sent to the '{0}' group.",
                                                                    _smsGroup.Name))
                                        .Show ();
                                }
                                _progressDialog.Dismiss ();
                            }));
                };
        }
Example #2
0
        public bool SendMessage(string messageText, SmsGroup smsGroup, List<Contact> recipients)
        {
            var dateSent = DateTime.Now;
            recipients.ForEach (recipient => {
                var messageIntent = new Intent("SMS_SENT");
                messageIntent.PutExtra ("messageText", messageText);
                messageIntent.PutExtra ("smsGroupId", smsGroup.Id);
                messageIntent.PutExtra ("addressBookId", recipient.AddressBookId);
                messageIntent.PutExtra ("contactName", recipient.Name);
                messageIntent.PutExtra ("dateSent", dateSent.ToString ("M/d/yyyy hh:mm:ss tt"));

                var random = new Random();
                var requestCode = random.Next (Int32.MinValue, Int32.MaxValue);
                var _sentIntent = PendingIntent.GetBroadcast (ApplicationContext, requestCode, messageIntent, PendingIntentFlags.UpdateCurrent);
                T.SmsManager.Default.SendTextMessage (recipient.MobilePhone, null, messageText, _sentIntent, null);
            });
            return true;
        }
Example #3
0
        private void SaveGroup()
        {
            SmsGroup smsGroup;

            //get the selected contacts
            var selectedContacts = _contacts.Where (c => c.Selected);

            _smsRepo = new SmsGroupRepository();
            _contactRepo = new ContactRepository(this);

            var enumerable = selectedContacts as IList<Contact> ?? selectedContacts.ToList();
            if (string.IsNullOrEmpty (GroupName))  //if updating an existing group
            {
                smsGroup = _smsRepo.Get (GroupId);
                smsGroup.MemberCount = enumerable.Count();
                smsGroup.ModifiedDate = DateTime.Now;
                _smsRepo.Save (smsGroup);

                //reset previously selected contacts
                _contactRepo.GetMembersForSmsGroup (GroupId).ForEach (c => {
                    c.Selected = false;
                    c.ModifiedDate = DateTime.Now;
                    _contactRepo.Save (c);
                });
            }
            else  //if new group
            {
                smsGroup = new SmsGroup
                {
                    Name = GroupName,
                    CreatedDate = DateTime.Now,
                    UUID = Guid.NewGuid().ToString(),
                    MemberCount = enumerable.Count()
                };
                _smsRepo.Save (smsGroup);
            }

            foreach (var contact in enumerable)
            {
                if (contact.Id == 0)  //if new contact
                {
                    contact.Selected = true;
                    contact.CreatedDate = DateTime.Now;
                    contact.UUID = Guid.NewGuid ().ToString ();
                    contact.SmsGroupId = smsGroup.Id;
                    _contactRepo.Save(contact);
                }
                else  //if update existing
                {
                    contact.Selected = true;
                    contact.SmsGroupId = smsGroup.Id;
                    contact.ModifiedDate = DateTime.Now;
                    _contactRepo.Save (contact);
                }
            }
        }
Example #4
0
        protected override void OnDestroy()
        {
            base.OnDestroy ();
            UnbindService ();

            _recipients = null;
            _smsGroup = null;
            _smsGroupRepo = null;
            _contactRepo = null;
        }