Exemplo n.º 1
0
        private async Task LoadData(string filterType, bool isFilter)
        {
            reportListView.ItemClick -= ReportList_ItemClick;
            if (projectID != 0)
            {
                if (Utility.IsInternetAvailable(Application.Context))
                {
                    var dialog = new CustomDialogFragment();
                    dialog.Show(FragmentManager, "dialog");
                    try
                    {
                        if (!isFilter)
                        {
                            reportService       = new ReportService(userSession.AccessToken);
                            unOrderedReportList = await reportService.GetReportList(userSession.UserId, projectID);

                            orderedReportList = unOrderedReportList.OrderByDescending(a => a.CreatedDateTime.Date)
                                                .ThenByDescending(a => a.CreatedDateTime.TimeOfDay);
                            orderedReportList = FilterOptionList(orderedReportList, filterType);
                        }
                        else
                        {
                            orderedReportList = FilterOptionList(unOrderedReportList, filterType);
                        }

                        var reportList = orderedReportList.ToList();
                        emptyView.Visibility = reportList.Count > 0 ? ViewStates.Gone : ViewStates.Visible;

                        headerandItemsList = new List <Report>();
                        sectionHeader      = new TreeSet();

                        var todayheader = false;
                        var yesterday   = false;
                        var lastweek    = false;
                        var other       = false;

                        for (var i = 0; i < reportList.Count; i++)
                        {
                            if (reportList[i].CreatedDateTime.Date >= DateTime.Today)
                            {
                                if (todayheader == false)
                                {
                                    todayheader = true;
                                    Report temp = new Report();
                                    temp.ReportName = Resources.GetString(Resource.String.today);
                                    headerandItemsList.Add(temp);
                                    sectionHeader.Add(headerandItemsList.Count - 1);
                                }

                                headerandItemsList.Add(reportList[i]);
                            }
                            else if (reportList[i].CreatedDateTime.Date == DateTime.Today.AddDays(-1))
                            {
                                if (!yesterday)
                                {
                                    yesterday = true;
                                    Report temp2 = new Report();
                                    temp2.ReportName = Resources.GetString(Resource.String.yesterday);
                                    headerandItemsList.Add(temp2);
                                    sectionHeader.Add(headerandItemsList.Count - 1);
                                }

                                headerandItemsList.Add(reportList[i]);
                            }
                            else if (reportList[i].CreatedDateTime.Date <DateTime.Today.AddDays(-2) &&
                                                                         reportList[i].CreatedDateTime.Date> DateTime.Today.AddDays(-7))
                            {
                                if (!lastweek)
                                {
                                    lastweek = true;
                                    Report temp3 = new Report();
                                    temp3.ReportName = Resources.GetString(Resource.String.last_week);
                                    headerandItemsList.Add(temp3);
                                    sectionHeader.Add(headerandItemsList.Count - 1);
                                }

                                headerandItemsList.Add(reportList[i]);
                            }
                            else
                            {
                                if (!other)
                                {
                                    other = true;
                                    Report temp3 = new Report();
                                    temp3.ReportName = Resources.GetString(Resource.String.other);
                                    headerandItemsList.Add(temp3);
                                    sectionHeader.Add(headerandItemsList.Count - 1);
                                }

                                headerandItemsList.Add(reportList[i]);
                            }
                        }

                        listAdapter               = new ReportListArchiveAdapter(Application.Context, headerandItemsList, sectionHeader);
                        reportListView.Adapter    = listAdapter;
                        reportListView.ItemClick += ReportList_ItemClick;
                        listAdapter.NotifyDataSetChanged();
                        dialog.Dismiss();
                    }
                    catch (Exception ex)
                    {
                        Log.Debug("Exception", ex.ToString());
                    }
                }
                else
                {
                    Toast.MakeText(Application.Context, Resources.GetString(Resource.String.NoInternet),
                                   ToastLength.Short).Show();
                }
            }
            else
            {
                emptyView.Visibility = ViewStates.Visible;
            }
        }
Exemplo n.º 2
0
        private async void LoadData()
        {
            if (projectId != 0)
            {
                if (Utility.IsInternetAvailable(Application.Context))
                {
                    try
                    {
                        reportService = new ReportService(userSession.AccessToken);
                        var unOrderedReportList = await reportService.GetArchivedReportList(projectId);

                        var listBeforFilter = unOrderedReportList.Where(x => x.IsArchived).OrderByDescending(a => a.CreatedDateTime.Date).ThenByDescending(a => a.CreatedDateTime.TimeOfDay);
                        var resultList      = listBeforFilter.ToList();

                        emptyView.Visibility = resultList.Count == 0 ? ViewStates.Visible : ViewStates.Gone;

                        headerandItemsList = new List <Report>();
                        TreeSet sectionHeaders = new TreeSet();

                        var todayheader = false;
                        var yesterday   = false;
                        var lastweek    = false;
                        var other       = false;

                        for (int i = 0; i < resultList.Count; i++)
                        {
                            if (resultList[i].CreatedDateTime.Date >= DateTime.Today)
                            {
                                if (todayheader == false)
                                {
                                    todayheader = true;
                                    Report reportDataDataDto = new Report();
                                    reportDataDataDto.ReportName = Application.Context.Resources.GetString(Resource.String.today);
                                    headerandItemsList.Add(reportDataDataDto);
                                    sectionHeaders.Add(headerandItemsList.Count - 1);
                                }

                                headerandItemsList.Add(resultList[i]);
                            }
                            else if (resultList[i].CreatedDateTime.Date == DateTime.Today.AddDays(-1))
                            {
                                if (!yesterday)
                                {
                                    yesterday = true;
                                    Report reportDataDataDto = new Report();
                                    reportDataDataDto.ReportName = Application.Context.Resources.GetString(Resource.String.yesterday);
                                    headerandItemsList.Add(reportDataDataDto);
                                    sectionHeaders.Add(headerandItemsList.Count - 1);
                                }
                                headerandItemsList.Add(resultList[i]);
                            }


                            else if (resultList[i].CreatedDateTime.Date <DateTime.Today.AddDays(-2) && resultList[i].CreatedDateTime.Date> DateTime.Today.AddDays(-7))
                            {
                                if (!lastweek)
                                {
                                    lastweek = true;
                                    Report reportDataDataDto = new Report();
                                    reportDataDataDto.ReportName = Application.Context.Resources.GetString(Resource.String.last_week);
                                    headerandItemsList.Add(reportDataDataDto);
                                    sectionHeaders.Add(headerandItemsList.Count - 1);
                                }
                                headerandItemsList.Add(resultList[i]);
                            }
                            else
                            {
                                if (!other)
                                {
                                    other = true;
                                    Report reportDataDataDto = new Report();
                                    reportDataDataDto.ReportName = Application.Context.Resources.GetString(Resource.String.other);
                                    headerandItemsList.Add(reportDataDataDto);
                                    sectionHeaders.Add(headerandItemsList.Count - 1);
                                }

                                headerandItemsList.Add(resultList[i]);
                            }
                        }

                        listAdapter      = new ReportListArchiveAdapter(Application.Context, headerandItemsList, sectionHeaders);
                        ListView.Adapter = listAdapter;
                        listAdapter.NotifyDataSetChanged();
                    }

                    catch (Exception)
                    {
                        Log.Debug("Exception", "Archeive List");
                    }
                }
            }
            else
            {
                emptyView.Visibility = ViewStates.Visible;
            }
        }