示例#1
0
        private void InvokeDataFetched(ReportingLevelEntity entity)
        {
            if (this.DataFetched == null)
            {
                return;
            }

            this.DataFetched.Invoke(this, new ReportingStatsDataFetchedEvent(entity));
        }
示例#2
0
        public async Task <ReportingLevelEntity> GetReportingStats(bool ignoreCache = false)
        {
            ReportingLevelEntity entity;

            this._selectionCache = await this.GetSelectionCache();

            if (Resolver.Instance.Get <IConnectivityService>().HasConnection())
            {
                entity = await this._reportingLevelStatsService.RetrieveStats(this._selectionCache, ignoreCache);
            }
            else
            {
                entity = await this._reportingLevelStatsService.RetrieveStats(this._selectionCache);
            }

            if (entity == null || !entity.HasValidData)
            {
                if (entity == null)
                {
                    entity = new ReportingLevelEntity();
                }

                this.InvokeDataFetched(entity);
                return(entity);
            }

            this.UpdateSummary(entity.Sales);
            this.InvokeDataFetched(entity);

            this._currentEntity       = entity;
            this.Title                = entity.Name;
            this.LevelUpButtonEnabled = this._selectionCache.SelectedLevel != (int)SalesAreaHierarchy.Country;

            if (this._selectionCache.SelectedPeriod == null)
            {
                this._selectionCache.SelectedPeriod = this._reportingLevelStatsService.FirstPeriod(entity.ReportStats);
            }

            this.SelectedPeriod = this._selectionCache == null ? "-" : this._selectionCache.SelectedPeriod;
            var hasPrevious = this._reportingLevelStatsService.PreviousPeriod(entity.ReportStats, this.SelectedPeriod) != null;

            this.HasPrevious = hasPrevious;

            var selectedPeriod = this._selectionCache != null ? this._selectionCache.SelectedPeriod : string.Empty;
            var hasNext        = this._reportingLevelStatsService.NextPeriod(entity.ReportStats, selectedPeriod) != null;

            this.HasNext = hasNext;

            return(entity);
        }
        private void DataFetched(object sender, ReportingStatsDataFetchedEvent e)
        {
            ReportingLevelEntity reportingLevelEntity = e.Entity;

            if (reportingLevelEntity == null || !reportingLevelEntity.HasValidData)
            {
                if (reportingLevelEntity != null)
                {
                    this.ShowStatus(reportingLevelEntity.Status);
                }
            }
            else
            {
                var vm = this.GetTypeSafeViewModel <ReportingLevelStatsFragmentViewModel>();

                // if no selection period, take the first one
                var selectionPeriod = vm.GetSelectedPeriod(reportingLevelEntity.ReportStats);

                this.ActivityBase.SetScreenTitle(reportingLevelEntity.StatsType);

                // before we continue, let's filter period stuff
                ReportStat[] stats = reportingLevelEntity.ReportStats.Where(r => r.Date == selectionPeriod).ToArray();

                List <Row> rows = new List <Row>();
                rows.AddRange(stats.Select(r => new Row
                {
                    IsSelected = false,
                    Tag        = new ReportingLevelEntity.Item
                    {
                        Level  = r.Level,
                        ItemId = r.ItemId
                    },
                    Items = new List <string>
                    {
                        r.Rank.ToString(),
                        r.Name,
                        r.Sales.ToString(),
                        r.Prospects.ToString()
                    }
                }));

                this._curreRows = rows;
                this.RemoveNonHeaderRows();

                foreach (var row in rows)
                {
                    LayoutInflater inflater = LayoutInflater.FromContext(this.Activity);
                    LinearLayout   view     = (LinearLayout)inflater.Inflate(Resource.Layout.layout_sales_stats_row, null);

                    view.SetOnClickListener(this);
                    view.SetBackgroundColor(row.IsSelected ? Resources.GetColor(Resource.Color.grey_light) : Resources.GetColor(Resource.Color.white));

                    List <TextView> rowViews = new List <TextView>
                    {
                        view.FindViewById <TextView>(Resource.Id.stats_row_column_1),
                        view.FindViewById <TextView>(Resource.Id.stats_row_column_2),
                        view.FindViewById <TextView>(Resource.Id.stats_row_column_3),
                        view.FindViewById <TextView>(Resource.Id.stats_row_column_4),
                        view.FindViewById <TextView>(Resource.Id.stats_row_column_5),
                        view.FindViewById <TextView>(Resource.Id.stats_row_column_6),
                        view.FindViewById <TextView>(Resource.Id.stats_row_column_7)
                    };

                    for (int i = 0; i < this.Columns.Length; i++)
                    {
                        ColumnInfo column = this.Columns[i];
                        rowViews[i].Gravity          = column.Gravity;
                        rowViews[i].LayoutParameters = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WrapContent, column.Weight);
                        rowViews[i].Visibility       = ViewStates.Visible;
                        rowViews[i].Text             = row.Items[i] ?? string.Empty;
                    }

                    this._mainContainer.AddView(view);
                }

                this.ShowStatus(reportingLevelEntity.Status);
            }

            if (Build.VERSION.SdkInt == BuildVersionCodes.Kitkat)
            {
                // Hack to make Title/Period bar update on android 4.4.4
                this._topContainer.RequestLayout();
                this._periodContainer.RequestLayout();
            }

            this._swipeRefreshable.SetIsBusy(false);
        }
        public void ConvertReportingLevelEntityTest()
        {
            ReportingLevelEntity result = JsonConvert.DeserializeObject <ReportingLevelEntity>(json);

            Assert.That(result.Name, Is.EqualTo("Service Center One"));
        }
示例#5
0
 public ReportingStatsDataFetchedEvent(ReportingLevelEntity entity)
 {
     this.Entity = entity;
 }