Exemple #1
0
        /// <summary>
        /// Filters the list view.
        /// </summary>
        /// <param name="listView">List view.</param>
        /// <param name="filter">Filter.</param>
        /// <param name="source">Source.</param>
        protected override void FilterListView(ListView listView, string filter, IEnumerable <EntityBase> source)
        {
            listView.BeginRefresh();

            if (string.IsNullOrWhiteSpace(filter))
            {
                EntityGroup.GroupEntities <T> (EntityList.Entities, (results) => {
                    Device.BeginInvokeOnMainThread(() => {
                        listView.ItemsSource = results;
                        listView.EndRefresh();
                        IsSearching = false;
                    });
                });
            }
            else
            {
                Task.Factory.StartNew(() => {
                    EntityGroup.GroupEntities <T>(EntityList.Entities.Where(x => x.ToString().ToLower().Contains(filter.ToLower())), (results) => {
                        Device.BeginInvokeOnMainThread(() => {
                            listView.ItemsSource = results;
                            listView.EndRefresh();
                            IsSearching = false;
                        });
                    });
                });
            }
        }
Exemple #2
0
        private void AddNotificationsTab()
        {
            AddContentTab("Notifications", "icon_notifications.png");
            ListView notificationList = currentTab.AddListView(typeof(NotificationViewCell), null, (sender, e) => {
                Notification note = (Notification)e.Item;
                EntityPageBuilderFactory.ShowEntityPage <Notification>(Phoenix.Application.NotificationManager, note.Id);
            });

            notificationList.IsGroupingEnabled     = true;
            notificationList.GroupDisplayBinding   = new Binding("GroupName");
            notificationList.GroupShortNameBinding = new Binding("GroupShortName");;
            notificationList.IsRefreshing          = true;

            Phoenix.Application.NotificationManager.AllForPosition(CurrentPosition.Id, (results) => {
                if (results.Count > 0)
                {
                    UpdateNotifications(results);
                    EntityGroup.GroupEntities <Notification> (results, (groupedResults) => {
                        Device.BeginInvokeOnMainThread(() => {
                            notificationList.ItemsSource  = groupedResults;
                            notificationList.IsRefreshing = false;
                        });
                    });
                }
                else
                {
                    Device.BeginInvokeOnMainThread(() => {
                        notificationList.IsRefreshing = false;
                    });
                }
            });
        }
 /// <summary>
 /// Deletes the entity.
 /// </summary>
 /// <param name="entity">Entity.</param>
 /// <param name="callback">Callback.</param>
 protected override void DeleteEntity(EntityBase entity, Action <IEnumerable <EntityBase> > callback)
 {
     listView.IsRefreshing = true;
     Phoenix.Application.PositionManager.DeleteNote(entity.Id, (results) => {
         EntityGroup.GroupEntities <Position> (results, (groupedResults) => {
             Device.BeginInvokeOnMainThread(() => {
                 listView.ItemsSource  = groupedResults;
                 listView.IsRefreshing = false;
             });
         });
     });
 }
Exemple #4
0
 /// <summary>
 /// Deletes the entity.
 /// </summary>
 /// <param name="entity">Entity.</param>
 /// <param name="callback">Callback.</param>
 protected virtual void DeleteEntity(EntityBase entity, Action <IEnumerable <EntityBase> > callback)
 {
     listView.IsRefreshing = true;
     Manager.Delete((T)entity, (results) => {
         callback(results);
         EntityGroup.GroupEntities <T> (results, (groupedResults) => {
             Device.BeginInvokeOnMainThread(() => {
                 listView.ItemsSource  = groupedResults;
                 listView.IsRefreshing = false;
             });
         });
     });
 }
Exemple #5
0
 /// <summary>
 /// Raises the appearing event.
 /// </summary>
 protected override void OnAppearing()
 {
     if (hasDisappeared)
     {
         Phoenix.Application.PositionManager.GetPositionsWithOrders((results) => {
             EntityGroup.GroupEntities <Position> (results, (groupedResults) => {
                 Device.BeginInvokeOnMainThread(() => {
                     listView.ItemsSource  = groupedResults;
                     listView.IsRefreshing = false;
                 });
             });
         });
     }
 }
Exemple #6
0
 /// <summary>
 /// Refreshs the list.
 /// </summary>
 protected virtual void RefreshList()
 {
     Manager.Fetch((results, ex) => {
         if (ex == null)
         {
             EntityGroup.GroupEntities <T> (results, (groupedResults) => {
                 Device.BeginInvokeOnMainThread(() => {
                     listView.ItemsSource  = groupedResults;
                     listView.IsRefreshing = false;
                 });
             });
         }
         else
         {
             ShowErrorAlert(ex);
         }
     }, true);
 }
 /// <summary>
 /// Refreshs the list.
 /// </summary>
 protected override void RefreshList()
 {
     Manager.Fetch((results, ex) => {
         results = NotificationTabbedPage.FilterByPriority(results, Priority);
         if (ex == null)
         {
             EntityGroup.GroupEntities <Notification> (results, (groupedResults) => {
                 Device.BeginInvokeOnMainThread(() => {
                     listView.ItemsSource  = groupedResults;
                     listView.IsRefreshing = false;
                 });
             });
         }
         else
         {
             ShowErrorAlert(ex);
         }
     }, true);
 }
Exemple #8
0
 /// <summary>
 /// Groups the entities.
 /// </summary>
 /// <param name="entities">Entities.</param>
 /// <param name="callback">Callback.</param>
 /// <typeparam name="T">The 1st type parameter.</typeparam>
 public static void GroupEntities <T>(IEnumerable <EntityBase> entities, Action <IEnumerable <EntityGroup> > callback)  where T :   EntityBase, new()
 {
     Task.Factory.StartNew(() => {
         Dictionary <string, EntityGroup> mapping = new Dictionary <string, EntityGroup> ();
         foreach (T item in entities)
         {
             EntityGroup group;
             if (item.Group == null)
             {
                 if (mapping.ContainsKey(""))
                 {
                     group = mapping [""];
                 }
                 else
                 {
                     group = new EntityGroup("", "*");
                     mapping.Add("", group);
                 }
             }
             else if (mapping.ContainsKey(item.Group))
             {
                 group = mapping [item.Group];
             }
             else
             {
                 group = new EntityGroup(item.Group, item.GroupShortName);
                 mapping.Add(item.Group, group);
             }
             group.Add(item);
         }
         IEnumerable <EntityGroup> grouped = from element in mapping.Values
                                             orderby element.GroupName
                                             select element;
         callback(grouped);
     });
 }
Exemple #9
0
        private void SubmitOrders()
        {
            Insights.Track("Submit Orders");
            submitButton.IsEnabled = false;
            submitButton.IsVisible = false;
            helpLabel.IsVisible    = false;

            Log.WriteLine(Log.Layer.UI, GetType(), "Submitting Orders for " + positionsWithOrders.Count);
            if (positionsWithOrders.Count < 1)
            {
                return;
            }
            ProgressBar progressBar = new ProgressBar {
                Progress = 0f
            };

            PageLayout.Children.Add(progressBar);

            float progressPerPosition = 1.0f / (float)positionsWithOrders.Count;

            int totalPositions  = positionsWithOrders.Count;
            int positionsSent   = 0;
            int positionsFailed = 0;

            Device.BeginInvokeOnMainThread(() => {
                listView.IsRefreshing = true;
            });

            foreach (Position position in positionsWithOrders)
            {
                Phoenix.Application.OrderManager.SubmitOrdersForPosition(position.Id, (count, e) => {
                    if (e == null)
                    {
                        Log.WriteLine(Log.Layer.UI, GetType(), "Successfuly uploaded " + count + " orders for " + position);
                        positionsSent += 1;
                        positionsWithOrders.Remove(position);
                        EntityGroup.GroupEntities <Position>(positionsWithOrders, (results) => {
                            Device.BeginInvokeOnMainThread(() => {
                                listView.ItemsSource = results;
                            });
                        });
                    }
                    else
                    {
                        positionsFailed += 1;
                    }
                    UpdateProgressBar(progressBar, (float)(progressBar.Progress + progressPerPosition));

                    if ((positionsFailed + positionsSent) >= totalPositions)
                    {
                        string message = "Submitted orders for positions.";
                        if (positionsSent > 0)
                        {
                            message = message + " " + positionsSent + " succeeded.";
                        }
                        if (positionsFailed > 0)
                        {
                            message = message + " " + positionsFailed + " failed.";
                        }
                        Device.BeginInvokeOnMainThread(() => {
                            listView.IsRefreshing  = false;
                            submitButton.IsVisible = true;
                            submitButton.IsEnabled = true;
                            helpLabel.IsVisible    = true;
                            ShowInfoAlert("Orders Submitted", message);
                        });
                    }
                });
            }
        }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PhoenixImperator.Pages.Entities.EntityListPage`1"/> class.
        /// </summary>
        /// <param name="title">Title.</param>
        /// <param name="manager">Manager.</param>
        /// <param name="entities">Entities.</param>
        /// <param name="entityHasDetail">If set to <c>true</c> entity has detail.</param>
        /// <param name="pullToRefresh">If set to <c>true</c> pull to refresh.</param>
        /// <param name="swipeLeftToDelete">If set to <c>true</c> swipe left to delete.</param>
        public EntityListPage(string title, NexusManager <T> manager, IEnumerable <T> entities, bool entityHasDetail = true, bool pullToRefresh = true, bool swipeLeftToDelete = true) : base(title)
        {
            Manager = manager;
            EntityList.UpdateEntities(entities);
            EntityList.DeleteEntityCallback = DeleteEntity;

            EntityHasDetail = entityHasDetail;
            PullToRefresh   = pullToRefresh;

            Type cellType;

            if (swipeLeftToDelete)
            {
                cellType = typeof(EntityViewCell);
            }
            else
            {
                cellType = typeof(TextCell);
            }
            BeforeList();
            listView = AddListViewWithSearchBar(cellType, null, (sender, e) => {
                EntitySelected(manager, (T)e.Item);
            });
            AfterList();

            listView.IsGroupingEnabled     = true;
            listView.GroupDisplayBinding   = new Binding("GroupName");
            listView.GroupShortNameBinding = new Binding("GroupShortName");

            listView.IsRefreshing = true;
            EntityGroup.GroupEntities <T> (entities, (results) => {
                Device.BeginInvokeOnMainThread(() => {
                    listView.ItemsSource  = results;
                    listView.IsRefreshing = false;
                });
            });


            if (pullToRefresh)
            {
                listView.IsPullToRefreshEnabled = true;
                listView.RefreshCommand         = new Command((e) => {
                    if (!IsSearching)
                    {
                        RefreshList();
                    }
                });
            }

            if (PullToRefresh)
            {
                if (swipeLeftToDelete)
                {
                    helpLabel = AddHelpLabel("Pull down to refresh. Swipe left to delete an entry.");
                }
                else
                {
                    helpLabel = AddHelpLabel("Pull down to refresh.");
                }
            }
            else if (swipeLeftToDelete)
            {
                helpLabel = AddHelpLabel("Swipe left to delete an entry.");
            }
        }