예제 #1
0
        private void expandableListView_ChildClick(object sender, ExpandableListView.ChildClickEventArgs e)
        {
            InstructionNotificationDialog.Hide();

            var childSelected = (InstructionGroupedListObject)e.Parent.ExpandableListAdapter.GetChild(e.GroupPosition, e.ChildPosition);

            childSelected.Instructions[e.ChildPosition].OpenMessageModal((result) =>
            {
                if (result)
                {
                    var childList = (InstructionGroupedListObject)e.Parent.ExpandableListAdapter.GetChild(e.GroupPosition, e.ChildPosition);
                    var child     = childList.Instructions[e.ChildPosition];
                    child.MobileData.ProgressState = InstructionProgress.Complete;

                    CurrentPopInstructions.Remove(child);
                }

                InstructionNotificationDialog.Show();
            });
        }
예제 #2
0
        /// <summary>
        /// This method is called when new instructions that have been polled were added, updated or deleted.
        /// It causes a modal pop up to appear showing the new instructions and what action was taken to them.
        /// </summary>
        /// <param name="alteredInstructions">The list of instructions to display</param>
        /// <param name="done">The action that is taken when the postive button is pressed</param>
        /// <param name="title">Title of the modal</param>
        /// <param name="okButton">The text of the positive button</param>
        public void PopUpInstructionNotification(List <ManifestInstructionViewModel> alteredInstructions, Action <List <ManifestInstructionViewModel> > done = null, string title = "", string okButton = "OK")
        {
            Application.SynchronizationContext.Post(ignored =>
            {
                if (CurrentActivity == null)
                {
                    return;
                }

                //This closes the pop if its showing so it can reopen another, else it will play sound and vibrate first time.
                if (InstructionNotificationDialog != null && InstructionNotificationDialog.IsShowing)
                {
                    try
                    {
                        InstructionNotificationDialog.Dismiss();
                        InstructionNotificationDialog = null;
                    } catch (Exception ex)
                    {
                        throw;
                    }
                }
                else
                {
                    Vibrate.VibrateDevice();
                    Sound.Play();
                }

                var customView = CurrentActivity.LayoutInflater.Inflate(Resource.Layout.PopUp_InstructionNotification, null);

                InstructionGroupedListObject addInstructions    = new InstructionGroupedListObject();
                InstructionGroupedListObject updateInstructions = new InstructionGroupedListObject();
                InstructionGroupedListObject deleteInstructions = new InstructionGroupedListObject();
                InstructionGroupedListObject messages           = new InstructionGroupedListObject();
                InstructionGroupedListObject messagesWithPoints = new InstructionGroupedListObject();

                CurrentPopInstructions.AddRange(alteredInstructions);

                //Filter the instructions into SyncStates (Added, Updated, Deleted)
                foreach (var instruction in CurrentPopInstructions)
                {
                    if (instruction.InstructionType == InstructionType.OrderMessage)
                    {
                        if (instruction.MobileData.Order.Addresses == null)
                        {
                            messages.Instructions.Add(instruction);
                        }
                        else
                        {
                            messagesWithPoints.Instructions.Add(instruction);
                        }
                    }
                    else
                    {
                        switch (instruction.MobileData.SyncState)
                        {
                        case SyncState.Add:
                            addInstructions.Instructions.Add(instruction);
                            break;

                        case SyncState.Update:
                            updateInstructions.Instructions.Add(instruction);
                            break;

                        case SyncState.Delete:
                            deleteInstructions.Instructions.Add(instruction);
                            break;
                        }
                    }
                }

                var inoList = new List <InstructionGroupedListObject>();
                var headers = new List <string>();

                if (addInstructions.Instructions.Count > 0)
                {
                    inoList.Add(addInstructions);
                    headers.Add("Instructions added (" + addInstructions.Instructions.Count + ")");
                }

                if (updateInstructions.Instructions.Count > 0)
                {
                    inoList.Add(updateInstructions);
                    headers.Add(" Instructions updated (" + updateInstructions.Instructions.Count + ")");
                }

                if (deleteInstructions.Instructions.Count > 0)
                {
                    inoList.Add(deleteInstructions);
                    headers.Add("Instructions deleted (" + deleteInstructions.Instructions.Count + ")");
                }
                if (messages.Instructions.Count > 0)
                {
                    inoList.Add(messages);
                    headers.Add("Messages added (" + messages.Instructions.Count + ")");
                }

                if (messagesWithPoints.Instructions.Count > 0)
                {
                    inoList.Add(messagesWithPoints);
                    headers.Add("Messages with points added (" + messagesWithPoints.Instructions.Count + ")");
                }

                if (inoList.Count > 0)
                {
                    //Create the expandableListView to be displayed
                    var expandableListView = (ExpandableListView)customView.FindViewById(Resource.Id.instuctionList);

                    expandableListView.ChildClick += expandableListView_ChildClick;

                    var expandableListAdapter = new ExpandableListAdapter(CurrentActivity, headers, inoList);

                    expandableListView.SetAdapter(expandableListAdapter);

                    //Expand all the sections from the start.
                    for (int i = 0; i < expandableListAdapter.GroupCount; i++)
                    {
                        expandableListView.ExpandGroup(i);
                    }

                    //Create the dialog popup
                    var notificationDialog = new AlertDialog.Builder(CurrentActivity)
                                             .SetView(customView)
                                             .SetTitle(title)

                                             //Prevent the user from closing the pop up by clicking on the sides.
                                             .SetCancelable(false)

                                             .SetPositiveButton(okButton, (s, e) =>
                    {
                        if (done != null)
                        {
                            done(CurrentPopInstructions);
                            CurrentPopInstructions.Clear();
                        }
                    });

                    InstructionNotificationDialog = notificationDialog.Create();
                    InstructionNotificationDialog.Show();
                }
            }, null);
        }