示例#1
0
        private void AddToSection(List <CustomerItem> customerItems, int statusId, int color)
        {
            if (customerItems == null || customerItems.Count == 0)
            {
                return;
            }
            string statusString = GetString(statusId);


            CustomerItemListAdapter itemListAdapter = new CustomerItemListAdapter
                                                      (
                this
                , customerItems
                                                      );

            Logger.Debug("Adding item to adapter in section ~".GetFormated(statusString));
            PersonSectionAdapter.AddSection(statusString, itemListAdapter, color);
        }
示例#2
0
        private void UpdateDataSet(bool isOnUiThread = false)
        {
            if (!isOnUiThread)
            {
                RunOnUiThread
                (
                    () =>
                {
                    UpdateDataSet(true);
                }
                );
                return;
            }
            PersonSectionAdapter.ClearSections();
            SetNewAdapter <CustomerItem>(new CustomerListAdapter(this));

            List <CustomerSearchResult> customerSearch = SearchResults as List <CustomerSearchResult>;;


            if (customerSearch == null)
            {
                customerSearch = new List <CustomerSearchResult>();
            }
            customerItems = new List <CustomerItem>();


            // check if there are customers before search filter
            bool noCustomers = customerSearch.Count == 0;

            customerSearch = customerSearch
                             .OrderByDescending(cust => cust.DateCreated).ToList();

            Logger.Debug("Refreshing list before doing the task run");


            foreach (var customer in customerSearch)
            {
                Logger.Debug("Adding new item to adapter");


                CustomerItem customerItem = new CustomerItem(customer);

                customerItems.Add(customerItem);
            }

            Logger.Debug("Adding stuff to sections: " + customerItems.Count);

            AddToSection(customerItems.Where(item => !item.SearchResult.ProductIsActive).ToList(),
                         Resource.String.customer_list_title_in_progress,
                         Resource.Color.red);

            AddToSection(customerItems.Where(item => item.SearchResult.ProductIsActive).ToList(),
                         Resource.String.customer_list_title_active,
                         Resource.Color.green);

            AddToSection(customerItems.Where(item => item.SearchResult.IsRejected).ToList(),
                         Resource.String.customer_rejected,
                         Resource.Color.red);

            Logger.Debug("Finished loading stuff into adapter");
            PersonSectionAdapter.NotifyDataSetChanged();

            // show textview if no customers
            if (noCustomers)
            {
                if (SearchHelper.Searching)
                {
                    this.HideSnackBar();
                }
                else
                {
                    // ShowNoSearchResults(GetString(Resource.String.no_customers));
                    if (this.ConnectedToNetwork)
                    {
                        this.ShowSnackBar(Resource.String.customers_refresh_prompt);
                    }
                    else
                    {
                        this.ShowSnackBar(Resource.String.customers_refresh_prompt_no_internet);
                    }
                }
            }
            else
            {
                this.HideSnackBar();
            }
        }
示例#3
0
        private void UpdateDataSet(bool isOnUiThread = false)
        {
            if (!isOnUiThread)
            {
                RunOnUiThread
                (
                    () =>
                {
                    UpdateDataSet(true);
                }
                );
                return;
            }

            Logger.Verbose("Refresh local list.");
            PersonSectionAdapter.ClearSections();

            // prepare the lists for each section
            List <ProspectItem> todayProspects      = new List <ProspectItem>();
            List <ProspectItem> overdueProspects    = new List <ProspectItem>();
            List <ProspectItem> tomorrowProspects   = new List <ProspectItem>();
            List <ProspectItem> laterProspects      = new List <ProspectItem>();
            List <ProspectItem> noReminderProspects = new List <ProspectItem>();

            // Get all the prospects
            Logger.Verbose("Retrieve all prospects.");
            List <ProspectSearchResult> prospects = SearchResults as List <ProspectSearchResult>;

            SetNewAdapter <ProspectItem>(new ProspectListAdapter(this));

            // remove converted prospects
            prospects = Enumerable.ToList(Enumerable.Where(prospects, prospect => !prospect.Converted));
            // store whether the original list has prospects
            bool noProspects = prospects.Count == 0;

            // Apply search filter
            if (CurrentFilter.IsBlank() == false)
            {
                prospects = prospects.Where
                            (
                    prosp => prosp.FullName.ToLower().Contains(CurrentFilter.ToLower()) ||
                    prosp.Phone.Contains(CurrentFilter)
                            ).ToList();
            }

            // Clear all sections
            PersonSectionAdapter.ClearSections();

            // process each prospect into its given section
            if (prospects.Count > 0)
            {
                foreach (var p in prospects)
                {
                    int          days         = GetDifferenceInDaysX(DateTime.Today, p.ReminderTime);
                    ProspectItem prospectItem = new ProspectItem(p);

                    if (p.SyncRecord != null)
                    {
                        prospectItem.SyncStatus = p.SyncRecord.Status;
                    }
                    else
                    {
                        prospectItem.SyncStatus = RecordStatus.Synced;
                    }

                    if (p.ReminderTime == DateTime.MinValue)
                    {
                        noReminderProspects.Add(prospectItem);
                    }
                    else if (days < 0)
                    {
                        overdueProspects.Add(prospectItem);
                    }
                    else if (days == 0)
                    {
                        todayProspects.Add(prospectItem);
                    }
                    else if (days == 1)
                    {
                        tomorrowProspects.Add(prospectItem);
                    }
                    else if (days > 1)
                    {
                        laterProspects.Add(prospectItem);
                    }
                }

                if (overdueProspects.Count > 0)
                {
                    ProspectItemListAdapter overdueAdapter = new ProspectItemListAdapter(this,
                                                                                         overdueProspects);
                    PersonSectionAdapter.AddSection(
                        GetString(Resource.String.prospects_list_title_overdue), overdueAdapter,
                        Resource.Color.red);
                }

                if (todayProspects.Count > 0)
                {
                    ProspectItemListAdapter todayAdapter = new ProspectItemListAdapter(this,
                                                                                       todayProspects);
                    PersonSectionAdapter.AddSection(
                        GetString(Resource.String.prospects_list_title_today), todayAdapter,
                        Resource.Color.green);
                }

                if (tomorrowProspects.Count > 0)
                {
                    ProspectItemListAdapter tomorrowAdapter = new ProspectItemListAdapter(this,
                                                                                          tomorrowProspects);
                    PersonSectionAdapter.AddSection(
                        GetString(Resource.String.prospects_list_title_tomorrow), tomorrowAdapter,
                        Resource.Color.orange);
                }

                if (laterProspects.Count > 0)
                {
                    ProspectItemListAdapter laterAdapter = new ProspectItemListAdapter(this,
                                                                                       laterProspects);
                    PersonSectionAdapter.AddSection(
                        GetString(Resource.String.prospects_list_title_later), laterAdapter,
                        Resource.Color.yellow);
                }

                if (noReminderProspects.Count > 0)
                {
                    ProspectItemListAdapter noReminderAdapter = new ProspectItemListAdapter(this,
                                                                                            noReminderProspects);
                    PersonSectionAdapter.AddSection(
                        GetString(Resource.String.prospects_list_title_none), noReminderAdapter,
                        Resource.Color.gray1);
                }
            }

            if (noProspects)
            {
                if (SearchHelper.Searching)
                {
                    this.HideSnackBar();
                }
                else
                {
                    if (this.ConnectedToNetwork)
                    {
                        this.ShowSnackBar(Resource.String.prospects_refresh_prompt);
                    }
                    else
                    {
                        this.ShowSnackBar(Resource.String.prospects_refresh_prompt_no_internet);
                    }
                }
            }
            else
            {
                this.HideSnackBar();
            }

            PersonSectionAdapter.NotifyDataSetChanged();
        }