public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            ((HomeActivity)Activity).SupportActionBar.SetDisplayShowTitleEnabled(false);
            ((HomeActivity)Activity).SupportActionBar.SetDisplayShowCustomEnabled(true);
            ((HomeActivity)Activity).SupportActionBar.SetCustomView(Resource.Layout.layout_spinnerAccounts);
            HasOptionsMenu = true;

            view                = inflater.Inflate(Resource.Layout.fragment_overview, null);
            listView            = view.FindViewById <ListView>(Resource.Id.listViewTransactions);
            listView.ItemClick += OnListItemClick;

            listOfAccounts.Insert(0, new Account()
            {
                Name = "All accounts", Id = 0
            });

            spinnerAccounts = Activity.FindViewById <Spinner>(Resource.Id.spinnerAccounts);
            adapterAccounts = new ArrayAdapter <Account>(Activity, Resource.Layout.spinner_item, listOfAccounts);
            adapterAccounts.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            spinnerAccounts.Adapter = adapterAccounts;

            spinnerAccounts.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(SpinnerTransactionAccount_ItemClick);

            FloatingActionButton fab = view.FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click += (o, e) =>
            {
                if (SilverCoinsManager.GetAccounts().ToList().Any())
                {
                    Intent intent = new Intent(fab.Context, typeof(SaveTransactionActivity));
                    StartActivity(intent);
                }
                else
                {
                    new Android.Support.V7.App.AlertDialog.Builder(Activity)
                    .SetCancelable(true)
                    .SetMessage("You need to create account first!")
                    .SetPositiveButton("OK", (sender, args) =>
                    {
                        Intent intent = new Intent(fab.Context, typeof(SaveAccountActivity));
                        StartActivity(intent);
                    })
                    .SetNegativeButton("Cancel", (sender, args) => { })
                    .Show();
                }
            };

            return(view);
        }
Beispiel #2
0
        internal static List <ObservableArrayList> ColumnChartData(Account account)
        {
            List <ObservableArrayList> dataModel = new List <ObservableArrayList>();

            if (account.Id == 0)
            {
                var accounts = SilverCoinsManager.GetAccounts().ToList();

                foreach (var item in accounts)
                {
                    dataModel.Add(GetBalanceGroupByMonthPerAccount(item));
                }
            }
            else
            {
                dataModel.Add(GetBalanceGroupByMonthPerAccount(account));
            }

            return(dataModel);
        }
Beispiel #3
0
        internal static void ImportTransactionsFromList(IEnumerable <TransactionImportExport> transactionsForImport)
        {
            if (transactionsForImport.Any())
            {
                // Get list of accounts and categories from document
                var accountsForImport = transactionsForImport.Select(x => new Account
                {
                    Name        = x.Account,
                    Currency    = x.Currency,
                    Balance     = Convert.ToDecimal(x.Balance),
                    CreatedDate = DateTime.Today,
                    Description = string.Empty,
                    Icon        = Resource.Drawable.cash
                });

                var categoriesForImport = transactionsForImport.Select(x => new Category
                {
                    Name        = x.Category,
                    Type        = x.Type == Category.CategoryTypes.Expense.ToString() ? Category.CategoryTypes.Expense : Category.CategoryTypes.Income,
                    Description = string.Empty,
                    CreatedDate = DateTime.Today,
                    Visible     = 1,
                    Icon        = Resource.Drawable.salary
                });

                var accounts   = SilverCoinsManager.GetAccounts();
                var categories = SilverCoinsManager.GetCategories();

                // Find accounts and categories that do not exist in database
                var newAccounts   = accountsForImport.Where(x => !accounts.Any(s => s.Name == x.Name));
                var newCategories = categoriesForImport.Where(x => !categories.Any(s => s.Name == x.Name));

                // Insert missing accounts and categories
                if (newAccounts.Any())
                {
                    foreach (var account in newAccounts)
                    {
                        SilverCoinsManager.SaveAccount(account);
                    }
                }

                if (newCategories.Any())
                {
                    foreach (var category in newCategories)
                    {
                        SilverCoinsManager.SaveCategory(category);
                    }
                }

                foreach (var transaction in transactionsForImport)
                {
                    SilverCoinsManager.SaveTransaction(new Transaction
                    {
                        Name        = transaction.Name,
                        Account     = SilverCoinsManager.GetAccountByName(transaction.Account).Id,
                        Category    = SilverCoinsManager.GetCategoryByName(transaction.Category).Id,
                        Amount      = Convert.ToDecimal(transaction.Amount),
                        PaymentType = transaction.PaymentType,
                        Type        = transaction.Type,
                        CreatedDate = DateTime.Now
                    });
                }
            }
        }