protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); var arry = new List <Stock>(); //DBLayer.Flush(); if (!DBLayer.GetRecords(ref arry)) { DBLayer.InitDB(); } //else if (arry.Count == 0) //{ // DBLayer.Seed(); //} SetContentView(Resource.Layout.Main); var fragments = new Android.Support.V4.App.Fragment[] { new HomeFragment(), new SummaryFragment() }; var titles = Android.Runtime.CharSequence.ArrayFromStringArray(new[] { "Home", "Summary" }); var vp = FindViewById <ViewPager>(Resource.Id.viewPager); var adapter = new TabAdapter(base.SupportFragmentManager, fragments, titles); vp.Adapter = adapter; }
private List <StockAdapterListItem> GetStockListForAdapter() { DBLayer.GetRecords(ref dbList); var respList = new List <StockAdapterListItem>(); foreach (var item in dbList) { var stockAdapterListItem = new StockAdapterListItem { Id = item.ID, Name = "Name: " + item.Name, Exchange = "Exchange: " + item.Exchange, Ticker = "Ticker: " + item.Ticker, Qty = "Units: " + item.Qty, IsShort = "Is this Short? " + (item.Short ? "Yes" : "No"), OriginalPrice = "Unit Cost: " + item.UnitCost, OriginalDate = "Transaction Date: " + item.PurchaseDate.ToString("%d MMM yyyy"), CurrentPrice = "Current Price: Press Sync button!", CurrentDate = "Current Date: Press Sync button!", ChangeFromLastTrade = "Change from last Trade: Press Sync button!", ChangePctFromLastTrade = "ChangePct from last Trade: Press Sync button!", TotalCost = "Total Cost: " + item.UnitCost * item.Qty + "", TotalCurrentCost = "Total Current Cost: Press Sync button!", TotalChange = "Total Change: Press Sync button!", TotalChangePct = "Total Change Pct: Press Sync button!" }; respList.Add(stockAdapterListItem); } return(respList); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var view = inflater.Inflate(Resource.Layout.Summary, container, false); var displayText = view.FindViewById <TextView>(Resource.Id.summaryText); displayText.Text = "This is the summary of your transactions"; decimal transactionCost = 0; decimal currentCost = 0; var records = new List <Stock>(); DBLayer.GetRecords(ref records); bool RecordStatus = GetCosts(ref transactionCost, ref currentCost, this.Activity.ApplicationContext, records); if (RecordStatus) { displayText.Text += "\nTotal cost: " + transactionCost.ToString() + "\nTotal Value: " + currentCost.ToString(); } else { displayText.Text += "\nPlease connect with net to find values"; } return(view); }
private List <StockItemGoogle> GetStocksInfo(Context ctx, List <Stock> stockList) { var stockGoogle = new List <StockItemGoogle>(); var records = new List <Stock>(); DBLayer.GetRecords(ref records); try { var list = new List <Stock>(); var count = list.Count; do { list = records.Skip(count).Take(10).ToList(); count += 10; var items = string.Join(",", list.Select(x => x.Exchange + ":" + x.Ticker).ToList()); using (var client = new HttpClient()) { var response = client.GetAsync("https://finance.google.com/finance?q=" + items).Result; var content = response.Content.ReadAsStringAsync().Result; content = Regex.Match(content, "rows\":(?<value>\\[.*}\\]),\"visible_cols").Value.Substring(6); content = content.Substring(0, content.LastIndexOf(",\"visible_cols")); var jArrayContent = JArray.Parse(content); stockGoogle.AddRange(GetStocksFromGoogleResponse(jArrayContent)); } } while (count < records.Count); } catch (HttpRequestException e) { Toast.MakeText(ctx, "Error while querying the google finance api\n" + e.Message, ToastLength.Long).Show(); } catch (Exception e) { Toast.MakeText(ctx, "Error while querying the google finance api\n" + e.Message, ToastLength.Long).Show(); } foreach (var item in stockGoogle) { foreach (var adapterItem in stockList) { if (adapterItem.Exchange.Contains(item.Exchange) && adapterItem.Ticker.Contains(item.Ticker)) { var stockListItemDB = GetItemFromList(item.Exchange, item.Ticker, stockList, adapterItem.Name); bool isShort = stockListItemDB.Short; adapterItem.CurrentUnitCost = item.Price; } } } return(stockGoogle); //Test comment }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.HomeAdd); var saveBtn = FindViewById <Button>(Resource.Id.btnHomeSave); var cancelBtn = FindViewById <Button>(Resource.Id.btnHomeCancel); var dateBtn = FindViewById <Button>(Resource.Id.btnHomeDate); var selectedDate = FindViewById <EditText>(Resource.Id.HomeAddDate); var id = Intent.GetStringExtra("Id") ?? null; if (!string.IsNullOrEmpty(id)) { Stock stock = DBLayer.GetRecordByID(int.Parse(id)); FindViewById <EditText>(Resource.Id.HomeAddName).Text = stock.Name; FindViewById <EditText>(Resource.Id.HomeAddSymbol).Text = stock.Ticker; FindViewById <EditText>(Resource.Id.HomeAddExchange).Text = stock.Exchange; FindViewById <EditText>(Resource.Id.HomeAddUnits).Text = stock.Qty.ToString(); FindViewById <EditText>(Resource.Id.HomeAddPrice).Text = stock.UnitCost.ToString(); FindViewById <EditText>(Resource.Id.HomeAddShort).Text = stock.Short ? "yes" : "no"; FindViewById <EditText>(Resource.Id.HomeAddDate).Text = stock.PurchaseDate.ToString("dddd, MMMM %d, yyyy"); } dateBtn.Click += (o, e) => { DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime time) { selectedDate.Text = time.ToLongDateString(); }); frag.Show(FragmentManager, DatePickerFragment.TAG); }; saveBtn.Click += (o, e) => { var date = FindViewById <EditText>(Resource.Id.HomeAddDate).Text; DateTime parsedDate = ParsedDate(date); var isShort = FindViewById <EditText>(Resource.Id.HomeAddShort).Text.ToUpper().StartsWith("Y"); var insert = new Stock { Name = FindViewById <EditText>(Resource.Id.HomeAddName).Text, PurchaseDate = parsedDate, Ticker = FindViewById <EditText>(Resource.Id.HomeAddSymbol).Text, Exchange = FindViewById <EditText>(Resource.Id.HomeAddExchange).Text, Qty = int.Parse(FindViewById <EditText>(Resource.Id.HomeAddUnits).Text), UnitCost = decimal.Parse(FindViewById <EditText>(Resource.Id.HomeAddPrice).Text), Short = isShort, }; if (!string.IsNullOrEmpty(id)) { insert.ID = int.Parse(id); } else { var refRecord = new List <Stock>(); DBLayer.GetRecords(ref refRecord); var record = refRecord.Where(x => x.Name.Trim() == insert.Name.Trim()); if (record.Any()) { Toast.MakeText(this, "Please Choose different name", ToastLength.Long).Show(); return; } } var resp = DBLayer.InsertUpdate(insert); Toast.MakeText(this, resp ? "success" : "fail", ToastLength.Long).Show(); var intent = new Intent(this, typeof(MainActivity)).SetFlags(ActivityFlags.NewTask); StartActivity(intent); }; cancelBtn.Click += (o, e) => { base.Finish(); }; }
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); }
public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent) { var view = convertView; if (view == null) { var inflater = activity.GetSystemService(Context.LayoutInflaterService) as LayoutInflater; view = inflater.Inflate(Resource.Layout.StocksViewGroupListItem, null); } var indicator = view.FindViewById <ImageView>(Resource.Id.groupImageIndicator); if (isExpanded) { indicator.SetImageResource(Android.Resource.Drawable.ArrowUpFloat); } else { indicator.SetImageResource(Android.Resource.Drawable.ArrowDownFloat); } var title = view.FindViewById <TextView>(Resource.Id.groupTitle); var price = view.FindViewById <TextView>(Resource.Id.groupPrice); var currentPrice = view.FindViewById <TextView>(Resource.Id.groupCurrentPrice); var listItem = items[groupPosition]; DBLayer.GetRecords(ref dbItems); Stock dbItem = null; try { dbItem = dbItems.FirstOrDefault(x => listItem.Name.Split(':')[1].Trim() == x.Name.Trim()); } catch (System.Exception e) { var msg = (dbItems.FirstOrDefault(x => listItem.Name.Split(':')[1].Trim() == x.Name.Trim()) == null) + listItem.Name; } //if (dbItem == null) // return view; title.Text = dbItem.Name.Trim(); var titleColor = Color.Snow; title.SetTextColor(titleColor); price.SetTextColor(titleColor); currentPrice.SetTextColor(titleColor); if (!IsFixed) { if (dbItem.Short) { currentPrice.Text = dbItem.UnitCost.ToString().Trim().PadRight(12).PadLeft(10); price.Text = "-".Trim().PadRight(12).PadLeft(10); } else { currentPrice.Text = "-".Trim().PadRight(12).PadLeft(10); price.Text = dbItem.UnitCost.ToString().Trim().PadRight(12).PadLeft(10); } } else { var googleItem = GetIndexForGoogle(dbItem.Exchange, dbItem.Ticker); if (dbItem.Short) { currentPrice.Text = dbItem.UnitCost.ToString().Trim().PadRight(12).PadLeft(10); price.Text = googleItem == null ? "Not Found" : (googleItem.Price.ToString().Trim() + "*").PadRight(12).PadLeft(10); if (googleItem == null || dbItem.UnitCost < googleItem.Price) { price.SetTextColor(Color.Red); } else { price.SetTextColor(Color.Green); } } else { price.Text = dbItem.UnitCost.ToString().Trim().PadRight(12).PadLeft(10); currentPrice.Text = googleItem == null ? "Not Found" : (googleItem.Price.ToString().Trim() + "*").PadRight(12).PadLeft(10); if (googleItem == null || dbItem.UnitCost > googleItem.Price) { currentPrice.SetTextColor(Color.Red); } else { currentPrice.SetTextColor(Color.Green); } } } return(view); }