private void DataFetched(object sender, StatsListFetchedEvent e)
        {
            var rows        = e.Rows;
            var currentRows = this._mainContainer.ChildCount - HeaderViewCount;

            if (rows == null || rows.Count <= 0)
            {
                this._swipeRefreshable.SetIsBusy(false);
                if (!ActivityBase.ConnectedToNetwork && currentRows == 0)
                {
                    this._snackBar = this.ActivityBase.ShowSnackbar(Resource.Id.pager, Resource.String.stats_refresh_prompt);
                }
                else if (!ActivityBase.ConnectedToNetwork && currentRows > 0)
                {
                    Toast.MakeText(this.Activity, Resource.String.unable_to_sync_internet, ToastLength.Long).Show();
                }

                return;
            }

            this.RemoveNonHeaderRows();

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

                // view.Tag = row.Tag;
                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._swipeRefreshable.SetIsBusy(false);

            if (this._snackBar != null)
            {
                this._snackBar.Dismiss();
            }
        }
Example #2
0
        private void UnitsFetched(object sender, StatsListFetchedEvent e)
        {
            var      rows    = e.Rows;
            ICulture culture = Resolver.Instance.Get <ICulture>();

            if (rows == null || rows.Count <= 0)
            {
                this._swipeRefreshable.SetIsBusy(false);
                if (!ActivityBase.ConnectedToNetwork && this._historyTable.ChildCount == 0)
                {
                    this._snackBar = this.ActivityBase.ShowSnackbar(Resource.Id.pager, Resource.String.stats_refresh_prompt);
                }
                else if (!ActivityBase.ConnectedToNetwork && this._historyTable.ChildCount > 0)
                {
                    Toast.MakeText(this.Activity, Resource.String.unable_to_sync_internet, ToastLength.Long).Show();
                }

                return;
            }

            _historyTable.RemoveAllViews();

            foreach (var item in rows.Take(_displayCount))
            {
                DateTime rowDate;
                DateTime.TryParseExact(item.Items[1], culture.GetShortDateFormat(), CultureInfo.InvariantCulture, DateTimeStyles.None, out rowDate);
                View rowView = this.BindingInflate(Resource.Layout.layout_units_history_row, null);

                rowView.FindViewById <TextView>(Resource.Id.valueDay).Text = item.Items[0];

                rowView.FindViewById <TextView>(Resource.Id.valueDate).Text = item.Items[1];

                rowView.FindViewById <TextView>(Resource.Id.valueAcquired).Text = item.Items[2];
                rowView.FindViewById <TextView>(Resource.Id.valueStarted).Text  = item.Items[3];
                rowView.FindViewById <TextView>(Resource.Id.valueRemoved).Text  = item.Items[4];

                if (rowDate == DateTime.Today)
                {
                    rowView.FindViewById <TextView>(Resource.Id.today_text).Visibility =
                        ViewStates.Visible;
                }

                _historyTable.AddView(rowView);
            }

            this._swipeRefreshable.SetIsBusy(false);
            if (this._snackBar != null)
            {
                this._snackBar.Dismiss();
            }
        }