complete account page

This commit is contained in:
2022-03-02 17:31:49 +08:00
parent aa38e186c7
commit 51f8e4f2e8
26 changed files with 547 additions and 76 deletions

View File

@@ -1,5 +1,7 @@
using Billing.Languages;
using Billing.Models;
using Billing.Themes;
using Billing.Views;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -20,18 +22,23 @@ namespace Billing.UI
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
throw new NotImplementedException();
}
}
public class MoneyConverter : IValueConverter
{
public bool MarkVisible { get; set; } = true;
public bool Absolute { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is decimal d)
{
if (Absolute)
{
d = Math.Abs(d);
}
var number = d.ToString("n2");
if (MarkVisible)
{
@@ -60,6 +67,46 @@ namespace Billing.UI
}
}
public class BalanceColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var resource = Application.Current.Resources;
if (value is decimal d)
{
if (d >= 0)
{
return resource[BaseTheme.GreenColor];
}
return resource[BaseTheme.RedColor];
}
return resource[BaseTheme.TextColor];
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class UIBillConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is UIBill bill)
{
var time = bill.DateCreation.ToString("HH:mm");
return $"{time} ({bill.Wallet})";
}
return string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class NotNullConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
@@ -69,7 +116,7 @@ namespace Billing.UI
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
throw new NotImplementedException();
}
}
@@ -93,7 +140,7 @@ namespace Billing.UI
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
throw new NotImplementedException();
}
}
@@ -151,7 +198,7 @@ namespace Billing.UI
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
throw new NotImplementedException();
}
}
}

View File

@@ -1,4 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;
using Billing.Models;
using Xamarin.Forms;
namespace Billing.UI
@@ -75,6 +79,51 @@ namespace Billing.UI
}
}
public static class ModelExtensionHelper
{
public static List<T> FromStream<T>(Stream stream) where T : IModel, new()
{
XDocument doc = XDocument.Load(stream);
var root = doc.Root;
var list = new List<T>();
foreach (XElement ele in root.Elements("item"))
{
if (ele.Attribute("null")?.Value == "1")
{
list.Add(default);
}
else
{
T value = new();
value.OnXmlDeserialize(ele);
list.Add(value);
}
}
return list;
}
public static void ToStream<T>(this IEnumerable<T> list, Stream stream) where T : IModel
{
XElement root = new("root");
foreach (var t in list)
{
XElement item = new("item");
if (t == null)
{
item.Add(new XAttribute("null", 1));
}
else
{
t.OnXmlSerialize(item);
}
root.Add(item);
}
XDocument doc = new(new XDeclaration("1.0", "utf-8", "yes"), root);
doc.Save(stream, SaveOptions.DisableFormatting);
}
}
public class Tap : IDisposable
{
private readonly static object sync = new();

View File

@@ -1,7 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using Xamarin.Forms;
namespace Billing.UI