diff --git a/Billing.Shared/UI/Converters.cs b/Billing.Shared/UI/Converters.cs index 051f20b..e901b78 100644 --- a/Billing.Shared/UI/Converters.cs +++ b/Billing.Shared/UI/Converters.cs @@ -14,6 +14,10 @@ namespace Billing.UI { if (value is DateTime date) { + if (date.Year <= 1900) + { + return null; + } return date.ToString(Resource.TitleDateFormat); } return value; diff --git a/Billing.Shared/Views/BillPage.xaml.cs b/Billing.Shared/Views/BillPage.xaml.cs index 6560468..4c1c91e 100644 --- a/Billing.Shared/Views/BillPage.xaml.cs +++ b/Billing.Shared/Views/BillPage.xaml.cs @@ -12,11 +12,9 @@ namespace Billing.Views { public partial class BillPage : BillingPage { - private static readonly DateTime dateNow = DateTime.Today; - - private static readonly BindableProperty SelectedDateProperty = Helper.Create(nameof(SelectedDate), defaultValue: dateNow, propertyChanged: OnSelectedDateChanged); + private static readonly BindableProperty SelectedDateProperty = Helper.Create(nameof(SelectedDate), propertyChanged: OnSelectedDateChanged); private static readonly BindableProperty BillsProperty = Helper.Create, BillPage>(nameof(Bills)); - private static readonly BindableProperty NoBillsProperty = Helper.Create(nameof(NoBills)); + private static readonly BindableProperty NoBillsProperty = Helper.Create(nameof(NoBills), defaultValue: true); private static readonly BindableProperty IncomeProperty = Helper.Create(nameof(Income)); private static readonly BindableProperty SpendingProperty = Helper.Create(nameof(Spending)); private static readonly BindableProperty BalanceProperty = Helper.Create(nameof(Balance)); @@ -46,6 +44,8 @@ namespace Billing.Views public Command EditBilling { get; } public Command DeleteBilling { get; } + private bool initialized; + public BillPage() { TitleDateTap = new Command(OnTitleDateTapped); @@ -54,8 +54,15 @@ namespace Billing.Views DeleteBilling = new Command(OnDeleteBilling); InitializeComponent(); + } - billingDate.SetDateTime(dateNow); + public override void OnLoaded() + { + if (!initialized) + { + initialized = true; + billingDate.SetDateTime(DateTime.Today); + } } private void OnDateSelected(object sender, DateEventArgs e) @@ -109,7 +116,10 @@ namespace Billing.Views private void TitlePicker_DateSelected(object sender, DateChangedEventArgs e) { - billingDate.SetDateTime(e.NewDate); + if (e.NewDate.Year > 1900) + { + billingDate.SetDateTime(e.NewDate); + } } private void OnTitleDateLongPressed() diff --git a/Billing/Billing.Android/Billing.Android.csproj b/Billing/Billing.Android/Billing.Android.csproj index a0284ef..3d67096 100644 --- a/Billing/Billing.Android/Billing.Android.csproj +++ b/Billing/Billing.Android/Billing.Android.csproj @@ -85,6 +85,7 @@ + diff --git a/Billing/Billing.Android/Renderers/BillingPageRenderer.cs b/Billing/Billing.Android/Renderers/BillingPageRenderer.cs new file mode 100644 index 0000000..93554ef --- /dev/null +++ b/Billing/Billing.Android/Renderers/BillingPageRenderer.cs @@ -0,0 +1,25 @@ +using Android.Content; +using Billing.Droid.Renderers; +using Billing.UI; +using Xamarin.Forms; +using Xamarin.Forms.Platform.Android; + +[assembly: ExportRenderer(typeof(BillingPage), typeof(BillingPageRenderer))] +namespace Billing.Droid.Renderers +{ + public class BillingPageRenderer : PageRenderer + { + public BillingPageRenderer(Context context) : base(context) + { + } + + protected override void OnAttachedToWindow() + { + base.OnAttachedToWindow(); + if (Element is BillingPage page) + { + page.OnLoaded(); + } + } + } +}