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);
        }
Example #2
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();
        }