diff --git a/Billing.Shared/App.cs b/Billing.Shared/App.cs index 5bb2751..17e2bce 100644 --- a/Billing.Shared/App.cs +++ b/Billing.Shared/App.cs @@ -27,7 +27,7 @@ namespace Billing InitResources(); MainPage = new MainShell(); - Shell.Current.GoToAsync("//Bills"); + Shell.Current.GoToAsync("//Settings"); } public static void WriteAccounts() => StoreHelper.WriteAccounts(accounts); @@ -37,14 +37,13 @@ namespace Billing protected override void OnStart() { Helper.Debug($"personal folder: {StoreHelper.PersonalFolder}"); - Helper.Debug($"cache folder: {StoreHelper.CacheFolder}"); + Helper.Debug($"cache folder: {StoreHelper.CacheFolder}"); + + accounts = StoreHelper.GetAccounts(); + categories = StoreHelper.GetCategories(); + bills = StoreHelper.GetBills(); - Task.Run(() => - { - accounts = StoreHelper.GetAccounts(); - categories = StoreHelper.GetCategories(); - bills = StoreHelper.GetBills(); - }); + Shell.Current.GoToAsync("//Bills"); } protected override void OnResume() diff --git a/Billing.Shared/Languages/Resource.cs b/Billing.Shared/Languages/Resource.cs index 4ce5e2e..f802456 100644 --- a/Billing.Shared/Languages/Resource.cs +++ b/Billing.Shared/Languages/Resource.cs @@ -10,6 +10,10 @@ namespace Billing.Languages internal class Resource { public static string Ok => Text(nameof(Ok)); + public static string Yes => Text(nameof(Yes)); + public static string No => Text(nameof(No)); + public static string ConfirmDeleteAccount => Text(nameof(ConfirmDeleteAccount)); + public static string ConfirmDeleteBill => Text(nameof(ConfirmDeleteBill)); public static string TitleDateFormat => Text(nameof(TitleDateFormat)); public static string Cash => Text(nameof(Cash)); public static string CreditCard => Text(nameof(CreditCard)); @@ -23,6 +27,20 @@ namespace Billing.Languages public static string NeedAccount => Text(nameof(NeedAccount)); public static string AmountRequired => Text(nameof(AmountRequired)); + #region Categories + public static string Clothing => Text(nameof(Clothing)); + public static string Food => Text(nameof(Food)); + public static string Drinks => Text(nameof(Drinks)); + public static string Daily => Text(nameof(Daily)); + public static string Trans => Text(nameof(Trans)); + public static string Entertainment => Text(nameof(Entertainment)); + public static string Learn => Text(nameof(Learn)); + public static string Medical => Text(nameof(Medical)); + public static string Salary => Text(nameof(Salary)); + public static string Earnings => Text(nameof(Earnings)); + public static string Bonus => Text(nameof(Bonus)); + #endregion + static readonly Dictionary dict = new(); public static string Text(string name, params object[] args) diff --git a/Billing.Shared/Languages/en.xml b/Billing.Shared/Languages/en.xml index a5e2626..587d386 100644 --- a/Billing.Shared/Languages/en.xml +++ b/Billing.Shared/Languages/en.xml @@ -1,6 +1,10 @@ OK + About + Version + Preference + Primary Color Accounts Bills Settings @@ -44,4 +48,21 @@ Store Please create an account first. Please enter the amount. + Income + Spending + Clothing + Food + Drinks + Daily + Transportation + Entertainment + Learn + Medical + Salary + Earnings + Bonus + Yes + No + Are you sure you want to delete the account? + Are you sure you want to delete the billing? \ No newline at end of file diff --git a/Billing.Shared/Languages/zh-CN.xml b/Billing.Shared/Languages/zh-CN.xml index f3f2c7a..ca711b0 100644 --- a/Billing.Shared/Languages/zh-CN.xml +++ b/Billing.Shared/Languages/zh-CN.xml @@ -1,6 +1,10 @@ 确定 + 关于 + 版本号 + 偏好 + 主要配色 账户 账单 设置 @@ -44,4 +48,21 @@ 店铺 请先创建一个资金账户。 请输入金额。 + 收入 + 支出 + 衣物 + 食品 + 饮料 + 日常 + 交通 + 娱乐 + 学习 + 医疗 + 工资 + 收益 + 奖金 + + + 是否确认删除该账户? + 是否确认删除该账单? \ No newline at end of file diff --git a/Billing.Shared/Store/StoreHelper.cs b/Billing.Shared/Store/StoreHelper.cs index 4c161fd..a86e5b1 100644 --- a/Billing.Shared/Store/StoreHelper.cs +++ b/Billing.Shared/Store/StoreHelper.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Billing.Models; using Billing.UI; using Xamarin.Essentials; +using Resource = Billing.Languages.Resource; namespace Billing.Store { @@ -59,11 +60,18 @@ namespace Billing.Store list = new List { // TODO: sample categories - new() { Id = 0, Name = "早餐", Icon = "face" }, - new() { Id = 1, Name = "轻轨", Icon = "" }, - new() { Id = 2, Name = "公交车", Icon = "" }, - new() { Id = 3, Name = "出租车", Icon = "" }, - new() { Id = 4, Type = CategoryType.Income, Name = "投资", Icon = "#brand#btc" } + new() { Id = 1, Name = Resource.Clothing, Icon = "clothes" }, + new() { Id = 2, Name = Resource.Food, Icon = "food" }, + new() { Id = 3, Name = Resource.Drinks, Icon = "drink" }, + new() { Id = 4, Name = Resource.Daily, Icon = "daily" }, + new() { Id = 5, Name = Resource.Trans, Icon = "trans" }, + new() { Id = 6, Name = Resource.Entertainment, Icon = "face" }, + new() { Id = 7, Name = Resource.Learn, Icon = "learn" }, + new() { Id = 8, Name = Resource.Medical, Icon = "medical" }, + + new() { Id = 9, Type = CategoryType.Income, Name = Resource.Salary, Icon = "#brand#buffer" }, + new() { Id = 10, Type = CategoryType.Income, Name = Resource.Earnings, Icon = "#brand#btc" }, + new() { Id = 20, Type = CategoryType.Income, Name = Resource.Bonus, Icon = "dollar" } }; Task.Run(() => WriteCategoriesInternal(list)); } diff --git a/Billing.Shared/Themes/BaseTheme.cs b/Billing.Shared/Themes/BaseTheme.cs index e13bb04..70abb41 100644 --- a/Billing.Shared/Themes/BaseTheme.cs +++ b/Billing.Shared/Themes/BaseTheme.cs @@ -62,10 +62,26 @@ namespace Billing.Themes { Setters = { - new Setter { Property = Editor.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(Entry)) }, + new Setter { Property = Editor.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(Editor)) }, new Setter { Property = Editor.FontFamilyProperty, Value = robotoRegularFontFamily } } }); + Add(new Style(typeof(OptionDatePicker)) + { + Setters = + { + new Setter { Property = DatePicker.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(DatePicker)) }, + new Setter { Property = DatePicker.FontFamilyProperty, Value = robotoRegularFontFamily } + } + }); + Add(new Style(typeof(OptionTimePicker)) + { + Setters = + { + new Setter { Property = TimePicker.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(TimePicker)) }, + new Setter { Property = TimePicker.FontFamilyProperty, Value = robotoRegularFontFamily } + } + }); Add(new Style(typeof(Button)) { Setters = diff --git a/Billing.Shared/Themes/Light.cs b/Billing.Shared/Themes/Light.cs index e9a3409..2bfa5e0 100644 --- a/Billing.Shared/Themes/Light.cs +++ b/Billing.Shared/Themes/Light.cs @@ -1,4 +1,6 @@ -using Xamarin.Forms; +using Billing.UI; +using Xamarin.Essentials; +using Xamarin.Forms; namespace Billing.Themes { @@ -8,11 +10,25 @@ namespace Billing.Themes public static Light Instance => _instance ??= new Light(); - protected override Color PrimaryMauiColor => Color.FromRgb(0x18, 0x31, 0x53); + private Color primaryColor; + + protected override Color PrimaryMauiColor => primaryColor; protected override Color SecondaryMauiColor => Color.White; public Light() { + var color = Preferences.Get(Definition.PrimaryColorKey, "#183153"); + primaryColor = Color.FromHex(color); + + InitColors(); + InitResources(); + } + + public void RefreshColor(Color primary) + { + primaryColor = primary; + Clear(); + InitColors(); InitResources(); } @@ -35,7 +51,7 @@ namespace Billing.Themes Setters = { new Setter { Property = Shell.TabBarBackgroundColorProperty, Value = Color.White }, - new Setter { Property = Shell.TabBarTitleColorProperty, Value = PrimaryMauiColor }, + new Setter { Property = Shell.TabBarTitleColorProperty, Value = primaryColor }, new Setter { Property = Shell.TabBarUnselectedColorProperty, Value = Color.FromRgb(0x82, 0x82, 0x82) } } }); diff --git a/Billing.Shared/UI/Converters.cs b/Billing.Shared/UI/Converters.cs index 775cfde..9e89602 100644 --- a/Billing.Shared/UI/Converters.cs +++ b/Billing.Shared/UI/Converters.cs @@ -1,7 +1,6 @@ using Billing.Languages; using Billing.Models; using Billing.Themes; -using Billing.Views; using System; using System.Collections.Generic; using System.Globalization; @@ -26,9 +25,26 @@ namespace Billing.UI } } + public class NegativeConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool b) + { + return !b; + } + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + public class MoneyConverter : IValueConverter { - public bool MarkVisible { get; set; } = true; + public bool MarkVisible { get; set; } public bool Absolute { get; set; } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) @@ -89,14 +105,13 @@ namespace Billing.UI } } - public class UIBillConverter : IValueConverter + public class TimeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (value is UIBill bill) + if (value is DateTime time) { - var time = bill.DateCreation.ToString("HH:mm"); - return $"{time} ({bill.Wallet})"; + return time.ToString("HH:mm"); } return string.Empty; } @@ -152,6 +167,7 @@ namespace Billing.UI { "appstore", "\uf370" }, { "apple-pay", "\uf416" }, { "btc", "\uf15a" }, + { "buffer", "\uf837" }, { "jcb", "\uf24b" }, { "master-card", "\uf1f1" }, { "visa", "\uf1f0" }, diff --git a/Billing.Shared/UI/CustomControl.cs b/Billing.Shared/UI/CustomControl.cs index 3e72352..0f69c6a 100644 --- a/Billing.Shared/UI/CustomControl.cs +++ b/Billing.Shared/UI/CustomControl.cs @@ -29,4 +29,35 @@ namespace Billing.UI LongPressed?.Invoke(this, EventArgs.Empty); } } + + public class LongPressGrid : Grid + { + public static readonly BindableProperty LongCommandProperty = BindableProperty.Create(nameof(LongCommand), typeof(Command), typeof(LongPressGrid)); + public static readonly BindableProperty LongCommandParameterProperty = BindableProperty.Create(nameof(LongCommandParameter), typeof(object), typeof(LongPressGrid)); + + public Command LongCommand + { + get => (Command)GetValue(LongCommandProperty); + set => SetValue(LongCommandProperty, value); + } + public object LongCommandParameter + { + get => GetValue(LongCommandParameterProperty); + set => SetValue(LongCommandParameterProperty, value); + } + + public void TriggerLongPress() + { + var command = LongCommand; + if (command == null) + { + return; + } + var parameter = LongCommandParameter; + if (command.CanExecute(parameter)) + { + command.Execute(parameter); + } + } + } } \ No newline at end of file diff --git a/Billing.Shared/UI/Definition.cs b/Billing.Shared/UI/Definition.cs index 2157510..eecbcab 100644 --- a/Billing.Shared/UI/Definition.cs +++ b/Billing.Shared/UI/Definition.cs @@ -11,6 +11,8 @@ namespace Billing.UI { public static partial class Definition { + public static string PrimaryColorKey = "PrimaryColor"; + public static partial (string main, long build) GetVersion(); public static partial string GetCascadiaRegularFontFamily(); public static partial string GetCascadiaBoldFontFamily(); public static partial string GetRobotoCondensedRegularFontFamily(); @@ -84,6 +86,13 @@ namespace Billing.UI { await page.DisplayAlert(title ?? page.Title, message, Resource.Ok); } + + public static async Task ShowConfirm(this Page page, string message) + { + var yes = Resource.Yes; + var result = await page.DisplayActionSheet(message, Resource.No, yes); + return result == yes; + } } public static class ModelExtensionHelper diff --git a/Billing.Shared/UI/GroupStackLayout.cs b/Billing.Shared/UI/GroupStackLayout.cs index a61f7c9..ff6fb08 100644 --- a/Billing.Shared/UI/GroupStackLayout.cs +++ b/Billing.Shared/UI/GroupStackLayout.cs @@ -182,7 +182,7 @@ namespace Billing.UI } else { - lastHeight = rowHeight + spacing; + lastHeight += rowHeight + spacing; } } lastSizeRequest = new SizeRequest(new Size(widthConstraint, lastHeight)); diff --git a/Billing.Shared/UI/ItemSelectPage.cs b/Billing.Shared/UI/ItemSelectPage.cs index 32ba843..266c60e 100644 --- a/Billing.Shared/UI/ItemSelectPage.cs +++ b/Billing.Shared/UI/ItemSelectPage.cs @@ -11,6 +11,7 @@ namespace Billing.UI public ItemSelectPage(IEnumerable source) { + var iconConverter = new IconConverter(); var content = new ListView { ItemsSource = source, @@ -30,7 +31,7 @@ namespace Billing.UI Aspect = Aspect.AspectFit, VerticalOptions = LayoutOptions.Center } - .Binding(Image.SourceProperty, "Icon"), + .Binding(Image.SourceProperty, "Icon", converter: iconConverter), new Label { @@ -51,11 +52,12 @@ namespace Billing.UI Content = content; } - private void List_ItemTapped(object sender, ItemTappedEventArgs e) + private async void List_ItemTapped(object sender, ItemTappedEventArgs e) { if (e.Item is T t) { ItemTapped?.Invoke(this, t); + await Navigation.PopAsync(); } } } diff --git a/Billing.Shared/UI/OptionsCells.cs b/Billing.Shared/UI/OptionsCells.cs index ea973d8..c6712d2 100644 --- a/Billing.Shared/UI/OptionsCells.cs +++ b/Billing.Shared/UI/OptionsCells.cs @@ -6,6 +6,8 @@ namespace Billing.UI { public class OptionEntry : Entry { } public class OptionEditor : Editor { } + public class OptionDatePicker : DatePicker { } + public class OptionTimePicker : TimePicker { } public abstract class OptionCell : ViewCell { @@ -163,7 +165,6 @@ namespace Billing.UI { new Label { - HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Center } .Binding(Label.TextProperty, nameof(Detail)) @@ -207,7 +208,6 @@ namespace Billing.UI { WidthRequest = 26, HeightRequest = 20, - HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Center, Margin = new Thickness(6, 0) } @@ -248,6 +248,46 @@ namespace Billing.UI .Binding(Switch.IsToggledProperty, nameof(IsToggled), mode: BindingMode.TwoWay); } + public class OptionDatePickerCell : OptionCell + { + public static readonly BindableProperty DateProperty = BindableProperty.Create(nameof(Date), typeof(DateTime), typeof(OptionDatePickerCell)); + + public DateTime Date + { + get => (DateTime)GetValue(DateProperty); + set => SetValue(DateProperty, value); + } + + protected override View Content => new OptionDatePicker + { + HorizontalOptions = LayoutOptions.End, + VerticalOptions = LayoutOptions.Center + } + .Binding(DatePicker.DateProperty, nameof(Date), mode: BindingMode.TwoWay) + .DynamicResource(DatePicker.TextColorProperty, BaseTheme.TextColor) + .DynamicResource(VisualElement.BackgroundColorProperty, BaseTheme.OptionTintColor); + } + + public class OptionTimePickerCell : OptionCell + { + public static readonly BindableProperty TimeProperty = BindableProperty.Create(nameof(Time), typeof(TimeSpan), typeof(OptionTimePickerCell)); + + public TimeSpan Time + { + get => (TimeSpan)GetValue(TimeProperty); + set => SetValue(TimeProperty, value); + } + + protected override View Content => new OptionTimePicker + { + HorizontalOptions = LayoutOptions.End, + VerticalOptions = LayoutOptions.Center + } + .Binding(TimePicker.TimeProperty, nameof(Time), mode: BindingMode.TwoWay) + .DynamicResource(TimePicker.TextColorProperty, BaseTheme.TextColor) + .DynamicResource(VisualElement.BackgroundColorProperty, BaseTheme.OptionTintColor); + } + public class OptionEntryCell : OptionCell { public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(OptionEntryCell)); diff --git a/Billing.Shared/Views/AccountPage.xaml b/Billing.Shared/Views/AccountPage.xaml index 118af0c..9e9e1f5 100644 --- a/Billing.Shared/Views/AccountPage.xaml +++ b/Billing.Shared/Views/AccountPage.xaml @@ -13,7 +13,6 @@ - @@ -34,7 +33,7 @@ Text="{Binding Balance, Converter={StaticResource moneyConverter}}"/> + ColumnDefinitions="Auto, Auto" RowDefinitions="Auto, Auto" IsVisible="False"> - + - + - + @@ -67,11 +68,11 @@ + diff --git a/Billing.Shared/Views/AccountPage.xaml.cs b/Billing.Shared/Views/AccountPage.xaml.cs index a531815..bd0782d 100644 --- a/Billing.Shared/Views/AccountPage.xaml.cs +++ b/Billing.Shared/Views/AccountPage.xaml.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Billing.Languages; using Billing.Models; using Billing.UI; using Xamarin.Forms; @@ -20,6 +21,7 @@ namespace Billing.Views public List Accounts => (List)GetValue(AccountsProperty); public Command EditAccount { get; } + public Command DeleteAccount { get; } private readonly List accounts = new(); private bool initialized; @@ -27,6 +29,7 @@ namespace Billing.Views public AccountPage() { EditAccount = new Command(OnEditAccount); + DeleteAccount = new Command(OnDeleteAccount); SetValue(AccountsProperty, accounts); InitializeComponent(); @@ -34,7 +37,7 @@ namespace Billing.Views protected override void OnAppearing() { - if (!initialized) + if (!initialized || accounts.Count == 0) { initialized = true; accounts.Clear(); @@ -52,6 +55,12 @@ namespace Billing.Views } } groupLayout.Refresh(accounts); + RefreshBalance(); + } + + private void RefreshBalance() + { + SetValue(BalanceProperty, App.Accounts.Sum(a => a.Balance)); } private void AddToAccountGroup(Account account) @@ -94,6 +103,35 @@ namespace Billing.Views } } + private async void OnDeleteAccount(object o) + { + if (Tap.IsBusy) + { + return; + } + using (Tap.Start()) + { + if (o is Account account) + { + var result = await this.ShowConfirm(Resource.ConfirmDeleteAccount); + if (result) + { + var group = accounts.FirstOrDefault(a => a.Key == account.Category); + if (group == null) + { + Helper.Error("account.delete", "unexpected deleting account, cannot find the current category"); + return; + } + group.Remove(account); + groupLayout.Refresh(accounts); + RefreshBalance(); + + _ = Task.Run(App.WriteAccounts); + } + } + } + } + private void AccountChecked(object sender, AccountEventArgs e) { if (e.Account.Id < 0) @@ -102,6 +140,7 @@ namespace Billing.Views AddToAccountGroup(e.Account); } groupLayout.Refresh(accounts); + RefreshBalance(); Task.Run(App.WriteAccounts); } diff --git a/Billing.Shared/Views/AddAccountPage.xaml.cs b/Billing.Shared/Views/AddAccountPage.xaml.cs index bac3616..dafd178 100644 --- a/Billing.Shared/Views/AddAccountPage.xaml.cs +++ b/Billing.Shared/Views/AddAccountPage.xaml.cs @@ -152,10 +152,9 @@ namespace Billing.Views } } - private async void Category_ItemTapped(object sender, SelectItem e) + private void Category_ItemTapped(object sender, SelectItem e) { Category = e.Value; - await Navigation.PopAsync(); } } diff --git a/Billing.Shared/Views/AddBillPage.xaml b/Billing.Shared/Views/AddBillPage.xaml index fb85d3c..ee6f174 100644 --- a/Billing.Shared/Views/AddBillPage.xaml +++ b/Billing.Shared/Views/AddBillPage.xaml @@ -39,9 +39,11 @@ - + + diff --git a/Billing.Shared/Views/AddBillPage.xaml.cs b/Billing.Shared/Views/AddBillPage.xaml.cs index 9934f42..ad49b16 100644 --- a/Billing.Shared/Views/AddBillPage.xaml.cs +++ b/Billing.Shared/Views/AddBillPage.xaml.cs @@ -15,7 +15,8 @@ namespace Billing.Views private static readonly BindableProperty CategoryNameProperty = BindableProperty.Create(nameof(CategoryName), typeof(string), typeof(AddBillPage)); private static readonly BindableProperty WalletNameProperty = BindableProperty.Create(nameof(WalletName), typeof(string), typeof(AddBillPage)); private static readonly BindableProperty StoreProperty = BindableProperty.Create(nameof(Store), typeof(string), typeof(AddBillPage)); - private static readonly BindableProperty CreatedTimeProperty = BindableProperty.Create(nameof(CreatedTime), typeof(DateTime), typeof(AddBillPage)); + private static readonly BindableProperty CreatedDateProperty = BindableProperty.Create(nameof(CreatedDate), typeof(DateTime), typeof(AddBillPage)); + private static readonly BindableProperty CreatedTimeProperty = BindableProperty.Create(nameof(CreatedTime), typeof(TimeSpan), typeof(AddBillPage)); private static readonly BindableProperty NoteProperty = BindableProperty.Create(nameof(Note), typeof(string), typeof(AddBillPage)); public string Amount @@ -35,9 +36,14 @@ namespace Billing.Views get => (string)GetValue(StoreProperty); set => SetValue(StoreProperty, value); } - public DateTime CreatedTime + public DateTime CreatedDate { - get => (DateTime)GetValue(CreatedTimeProperty); + get => (DateTime)GetValue(CreatedDateProperty); + set => SetValue(CreatedDateProperty, value); + } + public TimeSpan CreatedTime + { + get => (TimeSpan)GetValue(CreatedTimeProperty); set => SetValue(CreatedTimeProperty, value); } public string Note @@ -86,14 +92,15 @@ namespace Billing.Views { if (bill != null) { - Amount = bill.Amount.ToString(CultureInfo.InvariantCulture); + Amount = Math.Abs(bill.Amount).ToString(CultureInfo.InvariantCulture); Name = bill.Name; walletId = bill.WalletId; categoryId = bill.CategoryId; SetValue(WalletNameProperty, App.Accounts.FirstOrDefault(a => a.Id == walletId)?.Name); SetValue(CategoryNameProperty, App.Categories.FirstOrDefault(c => c.Id == categoryId)?.Name); Store = bill.Store; - CreatedTime = bill.CreateTime; + CreatedDate = bill.CreateTime.Date; + CreatedTime = bill.CreateTime.TimeOfDay; Note = bill.Note; } else @@ -104,7 +111,8 @@ namespace Billing.Views var firstCategory = App.Categories.First(); categoryId = firstCategory.Id; SetValue(CategoryNameProperty, firstCategory.Name); - CreatedTime = createDate.Date.Add(DateTime.Now.TimeOfDay); + CreatedDate = createDate.Date; + CreatedTime = DateTime.Now.TimeOfDay; } } @@ -132,13 +140,18 @@ namespace Billing.Views amount *= -1; } await Navigation.PopAsync(); + var name = Name; + if (string.IsNullOrWhiteSpace(name)) + { + name = category.Name; + } if (bill != null) { bill.Amount = amount; - bill.Name = Name; + bill.Name = name; bill.CategoryId = categoryId; bill.WalletId = walletId; - bill.CreateTime = CreatedTime; + bill.CreateTime = CreatedDate.Date.Add(CreatedTime); bill.Store = Store; bill.Note = Note; } @@ -146,24 +159,66 @@ namespace Billing.Views { Id = -1, Amount = amount, - Name = Name, + Name = name, CategoryId = categoryId, WalletId = walletId, - CreateTime = CreatedTime, + CreateTime = CreatedDate.Date.Add(CreatedTime), Store = Store, Note = Note }); } } - private void OnSelectCategory() + private async void OnSelectCategory() { - - } - - private void OnSelectWallet() + if (Tap.IsBusy) + { + return; + } + using (Tap.Start()) + { + var source = App.Categories.Select(c => new SelectItem + { + Value = c.Id, + Name = c.Name, + Icon = c.Icon + }); + var page = new ItemSelectPage>(source); + page.ItemTapped += Category_ItemTapped; + await Navigation.PushAsync(page); + } + } + + private void Category_ItemTapped(object sender, SelectItem category) + { + categoryId = category.Value; + SetValue(CategoryNameProperty, category.Name); + } + + private async void OnSelectWallet() { - - } + if (Tap.IsBusy) + { + return; + } + using (Tap.Start()) + { + var source = App.Accounts.Select(a => new SelectItem + { + Value = a.Id, + Name = a.Name, + Icon = a.Icon + }); + var page = new ItemSelectPage>(source); + page.ItemTapped += Wallet_ItemTapped; + await Navigation.PushAsync(page); + } + } + + private void Wallet_ItemTapped(object sender, SelectItem account) + { + walletId = account.Value; + SetValue(WalletNameProperty, account.Name); + } } } \ No newline at end of file diff --git a/Billing.Shared/Views/BillPage.xaml b/Billing.Shared/Views/BillPage.xaml index daa1970..687a5ce 100644 --- a/Billing.Shared/Views/BillPage.xaml +++ b/Billing.Shared/Views/BillPage.xaml @@ -12,9 +12,11 @@ - + + + - + @@ -36,28 +38,51 @@ - - -