Exemplo n.º 1
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var  item = items[position];
            View view = convertView;

            if (view == null)
            {
                view = activity.LayoutInflater.Inflate(Resource.Layout.StocksViewListItem, null);
            }

            view.FindViewById <TextView>(Resource.Id.Name).Text                   = item.Name;
            view.FindViewById <TextView>(Resource.Id.Exchange).Text               = item.Exchange;
            view.FindViewById <TextView>(Resource.Id.Ticker).Text                 = item.Ticker;
            view.FindViewById <TextView>(Resource.Id.Qty).Text                    = item.Qty;
            view.FindViewById <TextView>(Resource.Id.IsShort).Text                = item.IsShort;
            view.FindViewById <TextView>(Resource.Id.OriginalPrice).Text          = item.OriginalPrice;
            view.FindViewById <TextView>(Resource.Id.OriginalDate).Text           = item.OriginalDate;
            view.FindViewById <TextView>(Resource.Id.CurrentPrice).Text           = item.CurrentPrice;
            view.FindViewById <TextView>(Resource.Id.CurrentDate).Text            = item.CurrentDate;
            view.FindViewById <TextView>(Resource.Id.ChangeFromLastTrade).Text    = item.ChangeFromLastTrade;
            view.FindViewById <TextView>(Resource.Id.ChangePctFromLastTrade).Text = item.ChangePctFromLastTrade;
            view.FindViewById <TextView>(Resource.Id.TotalCost).Text              = item.TotalCost;
            view.FindViewById <TextView>(Resource.Id.TotalCurrentCost).Text       = item.TotalCurrentCost;
            view.FindViewById <TextView>(Resource.Id.TotalChange).Text            = item.TotalChange;
            view.FindViewById <TextView>(Resource.Id.TotalChangePct).Text         = item.TotalChangePct;

            var chgLastTrade    = view.FindViewById <TextView>(Resource.Id.ChangeFromLastTrade);
            var chgPctLastTrade = view.FindViewById <TextView>(Resource.Id.ChangePctFromLastTrade);
            var totalChange     = view.FindViewById <TextView>(Resource.Id.TotalChange);
            var totalChangePct  = view.FindViewById <TextView>(Resource.Id.TotalChangePct);



            var name         = view.FindViewById <TextView>(Resource.Id.Name);
            var ex           = view.FindViewById <TextView>(Resource.Id.Exchange);
            var t            = view.FindViewById <TextView>(Resource.Id.Ticker);
            var qty          = view.FindViewById <TextView>(Resource.Id.Qty);
            var isShort      = view.FindViewById <TextView>(Resource.Id.IsShort);
            var origPrice    = view.FindViewById <TextView>(Resource.Id.OriginalPrice);
            var origDt       = view.FindViewById <TextView>(Resource.Id.OriginalDate);
            var curPrice     = view.FindViewById <TextView>(Resource.Id.CurrentPrice);
            var curDt        = view.FindViewById <TextView>(Resource.Id.CurrentDate);
            var totalCost    = view.FindViewById <TextView>(Resource.Id.TotalCost);
            var totalCurCost = view.FindViewById <TextView>(Resource.Id.TotalCurrentCost);


            FixColor(chgLastTrade);
            FixColor(chgPctLastTrade);
            FixColor(totalChange);
            FixColor(totalChangePct);

            MakeYellow(ex, chgLastTrade);
            MakeYellow(t, chgLastTrade);
            MakeYellow(qty, chgLastTrade);
            MakeYellow(isShort, chgLastTrade);
            MakeYellow(origPrice, chgLastTrade);
            MakeYellow(origDt, chgLastTrade);
            MakeYellow(curPrice, chgLastTrade);
            MakeYellow(curDt, chgLastTrade);
            MakeYellow(totalCost, chgLastTrade);
            MakeYellow(totalCurCost, chgLastTrade);

            name.SetTextColor(Color.Chocolate);

            view.FindViewById <Button>(Resource.Id.btnRemove).Click += (o, e) => {
                DBLayer.Delete(new Stock()
                {
                    ID = item.Id
                });
                this.NotifyDataSetChanged();
            };

            return(view);
        }
        public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
        {
            var view = convertView;

            if (view == null)
            {
                var inflater = activity.GetSystemService(Context.LayoutInflaterService) as LayoutInflater;
                view = inflater.Inflate(Resource.Layout.StocksViewListItem, null);
            }
            var item = items[groupPosition];

            view.FindViewById <TextView>(Resource.Id.Name).Text                   = item.Name;
            view.FindViewById <TextView>(Resource.Id.Exchange).Text               = item.Exchange;
            view.FindViewById <TextView>(Resource.Id.Ticker).Text                 = item.Ticker;
            view.FindViewById <TextView>(Resource.Id.Qty).Text                    = item.Qty;
            view.FindViewById <TextView>(Resource.Id.IsShort).Text                = item.IsShort;
            view.FindViewById <TextView>(Resource.Id.OriginalPrice).Text          = item.OriginalPrice;
            view.FindViewById <TextView>(Resource.Id.OriginalDate).Text           = item.OriginalDate;
            view.FindViewById <TextView>(Resource.Id.CurrentPrice).Text           = item.CurrentPrice;
            view.FindViewById <TextView>(Resource.Id.CurrentDate).Text            = item.CurrentDate;
            view.FindViewById <TextView>(Resource.Id.ChangeFromLastTrade).Text    = item.ChangeFromLastTrade;
            view.FindViewById <TextView>(Resource.Id.ChangePctFromLastTrade).Text = item.ChangePctFromLastTrade;
            view.FindViewById <TextView>(Resource.Id.TotalCost).Text              = item.TotalCost;
            view.FindViewById <TextView>(Resource.Id.TotalCurrentCost).Text       = item.TotalCurrentCost;
            view.FindViewById <TextView>(Resource.Id.TotalChange).Text            = item.TotalChange;
            view.FindViewById <TextView>(Resource.Id.TotalChangePct).Text         = item.TotalChangePct;

            if (!view.FindViewById <Button>(Resource.Id.btnRemove).HasOnClickListeners)
            {
                view.FindViewById <Button>(Resource.Id.btnRemove).Click += (o, e) =>
                {
                    DBLayer.Delete(new Stock()
                    {
                        ID = item.Id
                    });
                    this.activity.Recreate();
                };
            }

            var ctx = this.activity.ApplicationContext;

            if (!view.FindViewById <Button>(Resource.Id.btnEdit).HasOnClickListeners)
            {
                view.FindViewById <Button>(Resource.Id.btnEdit).Click += (o, e) =>
                {
                    var intent = new Intent(ctx, typeof(HomeAdd)).SetFlags(ActivityFlags.NewTask);
                    intent.PutExtra("Id", item.Id.ToString());
                    ctx.StartActivity(intent);
                };
            }

            //if (!IsFixed)
            //    return view;

            var chgLastTrade    = view.FindViewById <TextView>(Resource.Id.ChangeFromLastTrade);
            var chgPctLastTrade = view.FindViewById <TextView>(Resource.Id.ChangePctFromLastTrade);
            var totalChange     = view.FindViewById <TextView>(Resource.Id.TotalChange);
            var totalChangePct  = view.FindViewById <TextView>(Resource.Id.TotalChangePct);



            var name         = view.FindViewById <TextView>(Resource.Id.Name);
            var ex           = view.FindViewById <TextView>(Resource.Id.Exchange);
            var t            = view.FindViewById <TextView>(Resource.Id.Ticker);
            var qty          = view.FindViewById <TextView>(Resource.Id.Qty);
            var isShort      = view.FindViewById <TextView>(Resource.Id.IsShort);
            var origPrice    = view.FindViewById <TextView>(Resource.Id.OriginalPrice);
            var origDt       = view.FindViewById <TextView>(Resource.Id.OriginalDate);
            var curPrice     = view.FindViewById <TextView>(Resource.Id.CurrentPrice);
            var curDt        = view.FindViewById <TextView>(Resource.Id.CurrentDate);
            var totalCost    = view.FindViewById <TextView>(Resource.Id.TotalCost);
            var totalCurCost = view.FindViewById <TextView>(Resource.Id.TotalCurrentCost);


            FixColor(chgLastTrade);
            FixColor(chgPctLastTrade);
            FixColor(totalChange);
            FixColor(totalChangePct);

            MakeYellow(ex, chgLastTrade);
            MakeYellow(t, chgLastTrade);
            MakeYellow(qty, chgLastTrade);
            MakeYellow(isShort, chgLastTrade);
            MakeYellow(origPrice, chgLastTrade);
            MakeYellow(origDt, chgLastTrade);
            MakeYellow(curPrice, chgLastTrade);
            MakeYellow(curDt, chgLastTrade);
            MakeYellow(totalCost, chgLastTrade);
            MakeYellow(totalCurCost, chgLastTrade);

            name.SetTextColor(Color.Chocolate);



            return(view);
        }