optimized and add diagnostic feature
This commit is contained in:
@ -13,6 +13,11 @@
|
||||
<ToolbarItem Order="Primary" IconImageSource="check.png" Command="{Binding CheckBill}"/>
|
||||
</ContentPage.ToolbarItems>
|
||||
|
||||
<ContentPage.Resources>
|
||||
<ui:IconConverter x:Key="iconConverter"/>
|
||||
<ui:TintColorConverter x:Key="tintColorConverter"/>
|
||||
</ContentPage.Resources>
|
||||
|
||||
<ContentPage.Content>
|
||||
<TableView Intent="Settings" HasUnevenRows="True">
|
||||
<TableSection Title=" ">
|
||||
@ -29,14 +34,18 @@
|
||||
Title="{r:Text Name}"
|
||||
Text="{Binding Name, Mode=TwoWay}"
|
||||
Placeholder="{r:Text NamePlaceholder}"/>
|
||||
<ui:OptionSelectCell Height="44" Icon="project.png"
|
||||
Title="{r:Text Category}"
|
||||
Detail="{Binding CategoryName}"
|
||||
Command="{Binding SelectCategory}"/>
|
||||
<ui:OptionSelectCell Height="44" Icon="wallet.png"
|
||||
Title="{r:Text Account}"
|
||||
Detail="{Binding WalletName}"
|
||||
Command="{Binding SelectWallet}"/>
|
||||
<ui:OptionImageCell Height="44" Icon="project.png"
|
||||
Title="{r:Text Category}"
|
||||
Detail="{Binding Category.Name}"
|
||||
ImageSource="{Binding Category.Icon, Converter={StaticResource iconConverter}}"
|
||||
TintColor="{Binding Category.TintColor, Converter={StaticResource tintColorConverter}}"
|
||||
Command="{Binding SelectCategory}"/>
|
||||
<ui:OptionImageCell Height="44" Icon="wallet.png"
|
||||
Title="{r:Text Account}"
|
||||
Detail="{Binding Wallet.Name}"
|
||||
ImageSource="{Binding Wallet.Icon, Converter={StaticResource iconConverter}}"
|
||||
TintColor="{DynamicResource PrimaryColor}"
|
||||
Command="{Binding SelectWallet}"/>
|
||||
<ui:OptionEntryCell Height="44" Icon="online.png"
|
||||
Title="{r:Text Store}"
|
||||
Text="{Binding Store, Mode=TwoWay}"/>
|
||||
|
@ -3,6 +3,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using Billing.Languages;
|
||||
using Billing.Models;
|
||||
using Billing.Store;
|
||||
using Billing.UI;
|
||||
using Xamarin.Forms;
|
||||
|
||||
@ -12,8 +13,8 @@ namespace Billing.Views
|
||||
{
|
||||
private static readonly BindableProperty AmountProperty = Helper.Create<string, AddBillPage>(nameof(Amount));
|
||||
private static readonly BindableProperty NameProperty = Helper.Create<string, AddBillPage>(nameof(Name));
|
||||
private static readonly BindableProperty CategoryNameProperty = Helper.Create<string, AddBillPage>(nameof(CategoryName));
|
||||
private static readonly BindableProperty WalletNameProperty = Helper.Create<string, AddBillPage>(nameof(WalletName));
|
||||
private static readonly BindableProperty CategoryProperty = Helper.Create<Category, AddBillPage>(nameof(Category));
|
||||
private static readonly BindableProperty WalletProperty = Helper.Create<Account, AddBillPage>(nameof(Wallet));
|
||||
private static readonly BindableProperty StoreProperty = Helper.Create<string, AddBillPage>(nameof(Store));
|
||||
private static readonly BindableProperty CreatedDateProperty = Helper.Create<DateTime, AddBillPage>(nameof(CreatedDate));
|
||||
private static readonly BindableProperty CreatedTimeProperty = Helper.Create<TimeSpan, AddBillPage>(nameof(CreatedTime));
|
||||
@ -29,8 +30,8 @@ namespace Billing.Views
|
||||
get => (string)GetValue(NameProperty);
|
||||
set => SetValue(NameProperty, value);
|
||||
}
|
||||
public string CategoryName => (string)GetValue(CategoryNameProperty);
|
||||
public string WalletName => (string)GetValue(WalletNameProperty);
|
||||
public Category Category => (Category)GetValue(CategoryProperty);
|
||||
public Account Wallet => (Account)GetValue(WalletProperty);
|
||||
public string Store
|
||||
{
|
||||
get => (string)GetValue(StoreProperty);
|
||||
@ -61,8 +62,7 @@ namespace Billing.Views
|
||||
private readonly Bill bill;
|
||||
private readonly DateTime createDate;
|
||||
|
||||
private int walletId;
|
||||
private int categoryId;
|
||||
private bool categoryChanged;
|
||||
|
||||
public AddBillPage(DateTime date)
|
||||
{
|
||||
@ -94,10 +94,9 @@ namespace Billing.Views
|
||||
{
|
||||
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);
|
||||
SetValue(WalletProperty, App.Accounts.FirstOrDefault(a => a.Id == bill.WalletId) ?? Account.Empty);
|
||||
SetValue(CategoryProperty, App.Categories.FirstOrDefault(c => c.Id == bill.CategoryId) ?? Category.Empty);
|
||||
categoryChanged = true;
|
||||
Store = bill.Store;
|
||||
CreatedDate = bill.CreateTime.Date;
|
||||
CreatedTime = bill.CreateTime.TimeOfDay;
|
||||
@ -105,12 +104,8 @@ namespace Billing.Views
|
||||
}
|
||||
else
|
||||
{
|
||||
var first = App.Accounts.First();
|
||||
walletId = first.Id;
|
||||
SetValue(WalletNameProperty, first.Name);
|
||||
var firstCategory = App.Categories.First();
|
||||
categoryId = firstCategory.Id;
|
||||
SetValue(CategoryNameProperty, firstCategory.Name);
|
||||
SetValue(WalletProperty, App.Accounts.FirstOrDefault() ?? Account.Empty);
|
||||
SetValue(CategoryProperty, App.Categories.FirstOrDefault() ?? Category.Empty);
|
||||
CreatedDate = createDate.Date;
|
||||
CreatedTime = DateTime.Now.TimeOfDay;
|
||||
}
|
||||
@ -138,8 +133,9 @@ namespace Billing.Views
|
||||
await this.ShowMessage(Resource.AmountRequired);
|
||||
return;
|
||||
}
|
||||
var category = Category;
|
||||
var wallet = Wallet;
|
||||
amount = Math.Abs(amount);
|
||||
var category = App.Categories.FirstOrDefault(c => c.Id == categoryId);
|
||||
if (category.Type == CategoryType.Spending)
|
||||
{
|
||||
amount *= -1;
|
||||
@ -154,8 +150,8 @@ namespace Billing.Views
|
||||
{
|
||||
bill.Amount = amount;
|
||||
bill.Name = name;
|
||||
bill.CategoryId = categoryId;
|
||||
bill.WalletId = walletId;
|
||||
bill.CategoryId = category.Id;
|
||||
bill.WalletId = wallet.Id;
|
||||
bill.CreateTime = CreatedDate.Date.Add(CreatedTime);
|
||||
bill.Store = Store;
|
||||
bill.Note = Note;
|
||||
@ -164,15 +160,17 @@ namespace Billing.Views
|
||||
{
|
||||
Amount = amount,
|
||||
Name = name,
|
||||
CategoryId = categoryId,
|
||||
WalletId = walletId,
|
||||
CategoryId = category.Id,
|
||||
WalletId = wallet.Id,
|
||||
CreateTime = CreatedDate.Date.Add(CreatedTime),
|
||||
Store = Store,
|
||||
Note = Note
|
||||
});
|
||||
|
||||
category.LastAccountId = walletId;
|
||||
category.LastAccountId = wallet.Id;
|
||||
category.LastUsed = DateTime.Now;
|
||||
|
||||
await StoreHelper.SaveCategoryItemAsync(category);
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,7 +182,7 @@ namespace Billing.Views
|
||||
}
|
||||
using (Tap.Start())
|
||||
{
|
||||
var page = new CategorySelectPage(categoryId);
|
||||
var page = new CategorySelectPage(categoryChanged ? Category.Id : -1);
|
||||
page.CategoryTapped += CategorySelectPage_Tapped;
|
||||
await Navigation.PushAsync(page);
|
||||
}
|
||||
@ -192,16 +190,16 @@ namespace Billing.Views
|
||||
|
||||
private void CategorySelectPage_Tapped(object sender, UICategory e)
|
||||
{
|
||||
categoryId = e.Category.Id;
|
||||
SetValue(CategoryProperty, e.Category);
|
||||
categoryChanged = true;
|
||||
if (e.Category.LastAccountId != null)
|
||||
{
|
||||
var wallet = App.Accounts.FirstOrDefault(a => a.Id == e.Category.LastAccountId.Value);
|
||||
if (wallet != null)
|
||||
{
|
||||
SetValue(WalletNameProperty, wallet.Name);
|
||||
SetValue(WalletProperty, wallet);
|
||||
}
|
||||
}
|
||||
SetValue(CategoryNameProperty, e.Name);
|
||||
}
|
||||
|
||||
private async void OnSelectWallet()
|
||||
@ -212,22 +210,15 @@ namespace Billing.Views
|
||||
}
|
||||
using (Tap.Start())
|
||||
{
|
||||
var source = App.Accounts.Select(a => new SelectItem<int>
|
||||
{
|
||||
Value = a.Id,
|
||||
Name = a.Name,
|
||||
Icon = a.Icon
|
||||
});
|
||||
var page = new ItemSelectPage<SelectItem<int>>(source);
|
||||
var page = new ItemSelectPage<Account>(App.Accounts);
|
||||
page.ItemTapped += Wallet_ItemTapped;
|
||||
await Navigation.PushAsync(page);
|
||||
}
|
||||
}
|
||||
|
||||
private void Wallet_ItemTapped(object sender, SelectItem<int> account)
|
||||
private void Wallet_ItemTapped(object sender, Account account)
|
||||
{
|
||||
walletId = account.Value;
|
||||
SetValue(WalletNameProperty, account.Name);
|
||||
SetValue(WalletProperty, account);
|
||||
}
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@
|
||||
<ui:BalanceColorConverter x:Key="colorConverter"/>
|
||||
<ui:TimeConverter x:Key="timeConverter"/>
|
||||
<ui:IconConverter x:Key="iconConverter"/>
|
||||
<ui:TintColorConverter x:Key="tintColorConverter"/>
|
||||
</ContentPage.Resources>
|
||||
|
||||
<Shell.TitleView>
|
||||
@ -101,7 +102,7 @@
|
||||
CommandParameter="{Binding .}"/>
|
||||
</Grid.GestureRecognizers>
|
||||
<ui:TintImage Source="{Binding Icon, Converter={StaticResource iconConverter}}"
|
||||
ui:TintHelper.TintColor="{Binding TintColor}"
|
||||
ui:TintHelper.TintColor="{Binding TintColor, Converter={StaticResource tintColorConverter}}"
|
||||
WidthRequest="26" HeightRequest="20" VerticalOptions="Center"/>
|
||||
<Label Grid.Column="1" Text="{Binding Name}" TextColor="{DynamicResource TextColor}"
|
||||
VerticalOptions="Center"
|
||||
|
@ -85,7 +85,9 @@ namespace Billing.Views
|
||||
|
||||
private void UpdateBill(UIBill bill)
|
||||
{
|
||||
bill.Icon = App.Categories.FirstOrDefault(c => c.Id == bill.Bill.CategoryId)?.Icon ?? Definition.DefaultIcon;
|
||||
var category = App.Categories.FirstOrDefault(c => c.Id == bill.Bill.CategoryId);
|
||||
bill.Icon = category?.Icon ?? Definition.DefaultIcon;
|
||||
bill.TintColor = category?.TintColor ?? Definition.TransparentColor;
|
||||
bill.Name = bill.Bill.Name;
|
||||
bill.DateCreation = bill.Bill.CreateTime;
|
||||
bill.Amount = bill.Bill.Amount;
|
||||
@ -207,7 +209,7 @@ namespace Billing.Views
|
||||
public class UIBill : BindableObject
|
||||
{
|
||||
public static readonly BindableProperty IconProperty = Helper.Create<string, UIBill>(nameof(Icon));
|
||||
public static readonly BindableProperty TintColorProperty = Helper.Create<Color, UIBill>(nameof(TintColor));
|
||||
public static readonly BindableProperty TintColorProperty = Helper.Create<long, UIBill>(nameof(TintColor));
|
||||
public static readonly BindableProperty NameProperty = Helper.Create<string, UIBill>(nameof(Name));
|
||||
public static readonly BindableProperty DateCreationProperty = Helper.Create<DateTime, UIBill>(nameof(DateCreation));
|
||||
public static readonly BindableProperty AmountProperty = Helper.Create<decimal, UIBill>(nameof(Amount));
|
||||
@ -218,9 +220,9 @@ namespace Billing.Views
|
||||
get => (string)GetValue(IconProperty);
|
||||
set => SetValue(IconProperty, value);
|
||||
}
|
||||
public Color TintColor
|
||||
public long TintColor
|
||||
{
|
||||
get => (Color)GetValue(TintColorProperty);
|
||||
get => (long)GetValue(TintColorProperty);
|
||||
set => SetValue(TintColorProperty, value);
|
||||
}
|
||||
public string Name
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
<ContentPage.Resources>
|
||||
<ui:IconConverter x:Key="iconConverter"/>
|
||||
<ui:TintColorConverter x:Key="tintColorConverter"/>
|
||||
</ContentPage.Resources>
|
||||
|
||||
<ScrollView>
|
||||
@ -32,7 +33,7 @@
|
||||
CommandParameter="{Binding .}"/>
|
||||
</Grid.GestureRecognizers>
|
||||
<ui:TintImage Source="{Binding Icon, Converter={StaticResource iconConverter}}"
|
||||
ui:TintHelper.TintColor="{Binding TintColor}"
|
||||
ui:TintHelper.TintColor="{Binding TintColor, Converter={StaticResource tintColorConverter}}"
|
||||
WidthRequest="26" HeightRequest="20" VerticalOptions="Center"/>
|
||||
<Label Grid.Column="1" Text="{Binding Name}" TextColor="{DynamicResource TextColor}"
|
||||
HorizontalOptions="FillAndExpand" VerticalOptions="Center"
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Billing.Languages;
|
||||
using Billing.Models;
|
||||
using Billing.Store;
|
||||
using Billing.Themes;
|
||||
using Billing.UI;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@ -68,9 +67,7 @@ namespace Billing.Views
|
||||
Icon = category.Icon,
|
||||
Name = category.Name,
|
||||
IsTopCategory = IsTopCategory,
|
||||
TintColor = category.TintColor.IsTransparent() ?
|
||||
BaseTheme.CurrentPrimaryColor :
|
||||
category.TintColor.ToColor()
|
||||
TintColor = category.TintColor
|
||||
};
|
||||
}
|
||||
|
||||
@ -180,9 +177,7 @@ namespace Billing.Views
|
||||
{
|
||||
c.Name = c.Category.Name;
|
||||
c.Icon = c.Category.Icon;
|
||||
c.TintColor = c.Category.TintColor.IsTransparent() ?
|
||||
BaseTheme.CurrentPrimaryColor :
|
||||
c.Category.TintColor.ToColor();
|
||||
c.TintColor = c.Category.TintColor;
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +186,7 @@ namespace Billing.Views
|
||||
public static readonly BindableProperty IsCheckedProperty = Helper.Create<bool, UICategory>(nameof(IsChecked));
|
||||
public static readonly BindableProperty IconProperty = Helper.Create<string, UICategory>(nameof(Icon));
|
||||
public static readonly BindableProperty NameProperty = Helper.Create<string, UICategory>(nameof(Name));
|
||||
public static readonly BindableProperty TintColorProperty = Helper.Create<Color, UICategory>(nameof(TintColor));
|
||||
public static readonly BindableProperty TintColorProperty = Helper.Create<long, UICategory>(nameof(TintColor));
|
||||
public static readonly BindableProperty IsTopCategoryProperty = Helper.Create<bool, UICategory>(nameof(IsTopCategory));
|
||||
|
||||
public bool IsChecked
|
||||
@ -209,9 +204,9 @@ namespace Billing.Views
|
||||
get => (string)GetValue(NameProperty);
|
||||
set => SetValue(NameProperty, value);
|
||||
}
|
||||
public Color TintColor
|
||||
public long TintColor
|
||||
{
|
||||
get => (Color)GetValue(TintColorProperty);
|
||||
get => (long)GetValue(TintColorProperty);
|
||||
set => SetValue(TintColorProperty, value);
|
||||
}
|
||||
public bool IsTopCategory
|
||||
@ -232,6 +227,10 @@ namespace Billing.Views
|
||||
{
|
||||
public string Key { get; }
|
||||
|
||||
public CategoryGrouping(string key) : base()
|
||||
{
|
||||
Key = key;
|
||||
}
|
||||
public CategoryGrouping(string key, IEnumerable<UICategory> categories) : base(categories)
|
||||
{
|
||||
Key = key;
|
||||
|
@ -13,6 +13,7 @@
|
||||
<ContentPage.Resources>
|
||||
<ui:IconConverter x:Key="iconConverter"/>
|
||||
<ui:SelectBackgroundColorConverter x:Key="backgroundConverter"/>
|
||||
<ui:TintColorConverter x:Key="tintColorConverter"/>
|
||||
</ContentPage.Resources>
|
||||
|
||||
<Grid ColumnDefinitions=".5*, .5*">
|
||||
@ -36,7 +37,7 @@
|
||||
CommandParameter="{Binding .}"/>
|
||||
</Grid.GestureRecognizers>
|
||||
<ui:TintImage Source="{Binding Icon, Converter={StaticResource iconConverter}}"
|
||||
ui:TintHelper.TintColor="{Binding TintColor}"
|
||||
ui:TintHelper.TintColor="{Binding TintColor, Converter={StaticResource tintColorConverter}}"
|
||||
WidthRequest="26" HeightRequest="20" VerticalOptions="Center"/>
|
||||
<Label Grid.Column="1" Text="{Binding Name}" TextColor="{DynamicResource TextColor}"
|
||||
HorizontalOptions="FillAndExpand" VerticalOptions="Center"
|
||||
@ -58,7 +59,7 @@
|
||||
CommandParameter="{Binding .}"/>
|
||||
</Grid.GestureRecognizers>
|
||||
<ui:TintImage Source="{Binding Icon, Converter={StaticResource iconConverter}}"
|
||||
ui:TintHelper.TintColor="{Binding TintColor}"
|
||||
ui:TintHelper.TintColor="{Binding TintColor, Converter={StaticResource tintColorConverter}}"
|
||||
WidthRequest="26" HeightRequest="20" VerticalOptions="Center"/>
|
||||
<Label Grid.Column="1" Text="{Binding Name}" TextColor="{DynamicResource TextColor}"
|
||||
HorizontalOptions="FillAndExpand" VerticalOptions="Center"
|
||||
|
@ -1,6 +1,5 @@
|
||||
using Billing.Languages;
|
||||
using Billing.Models;
|
||||
using Billing.Themes;
|
||||
using Billing.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -31,12 +30,10 @@ namespace Billing.Views
|
||||
public event EventHandler<UICategory> CategoryTapped;
|
||||
|
||||
private readonly int categoryId;
|
||||
private readonly Color defaultColor;
|
||||
|
||||
public CategorySelectPage(int id)
|
||||
{
|
||||
categoryId = id;
|
||||
defaultColor = BaseTheme.CurrentPrimaryColor;
|
||||
TapTopCategory = new Command(OnTopCategoryTapped);
|
||||
TapSubCategory = new Command(OnSubCategoryTapped);
|
||||
|
||||
@ -45,6 +42,22 @@ namespace Billing.Views
|
||||
new(Resource.Spending, App.Categories.Where(c => c.Type == CategoryType.Spending && c.ParentId == null).Select(c => WrapCategory(c))),
|
||||
new(Resource.Income, App.Categories.Where(c => c.Type == CategoryType.Income && c.ParentId == null).Select(c => WrapCategory(c)))
|
||||
};
|
||||
UICategory last;
|
||||
if (App.Categories.Any(c => c.LastUsed != null))
|
||||
{
|
||||
last = new UICategory(null)
|
||||
{
|
||||
IsChecked = true,
|
||||
Icon = "rank",
|
||||
Name = Resource.LastSelected,
|
||||
TintColor = Definition.TransparentColor
|
||||
};
|
||||
TopCategories.Insert(0, new(Resource.Recent) { last });
|
||||
}
|
||||
else
|
||||
{
|
||||
last = null;
|
||||
}
|
||||
|
||||
UICategory cat;
|
||||
var category = App.Categories.FirstOrDefault(c => c.Id == categoryId);
|
||||
@ -58,7 +71,7 @@ namespace Billing.Views
|
||||
}
|
||||
else
|
||||
{
|
||||
cat = TopCategories.SelectMany(g => g).FirstOrDefault(c => c.Category.Id == category.ParentId);
|
||||
cat = TopCategories.SelectMany(g => g).FirstOrDefault(c => c.Category?.Id == category.ParentId) ?? last;
|
||||
}
|
||||
DoRefreshSubCategories(cat);
|
||||
|
||||
@ -72,7 +85,7 @@ namespace Billing.Views
|
||||
IsChecked = c.Id == categoryId,
|
||||
Icon = c.Icon,
|
||||
Name = c.Name,
|
||||
TintColor = c.TintColor.IsTransparent() ? defaultColor : c.TintColor.ToColor()
|
||||
TintColor = c.TintColor
|
||||
};
|
||||
}
|
||||
|
||||
@ -83,7 +96,18 @@ namespace Billing.Views
|
||||
{
|
||||
m.IsChecked = m == category;
|
||||
}
|
||||
SubCategories = App.Categories.Where(c => c.ParentId == category.Category.Id).Select(c => WrapCategory(c)).ToList();
|
||||
if (category == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (category.Category == null)
|
||||
{
|
||||
SubCategories = App.Categories.Where(c => c.ParentId != null && c.LastUsed != null).OrderByDescending(c => c.LastUsed).Take(10).Select(c => WrapCategory(c)).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
SubCategories = App.Categories.Where(c => c.ParentId == category.Category.Id).Select(c => WrapCategory(c)).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnTopCategoryTapped(object o)
|
||||
@ -97,7 +121,7 @@ namespace Billing.Views
|
||||
if (o is UICategory category)
|
||||
{
|
||||
DoRefreshSubCategories(category);
|
||||
if (SubCategories.Count == 0)
|
||||
if (SubCategories?.Count == 0)
|
||||
{
|
||||
CategoryTapped?.Invoke(this, category);
|
||||
await Navigation.PopAsync();
|
||||
|
@ -66,6 +66,7 @@ namespace Billing.Views
|
||||
new() { Icon = "taxi" },
|
||||
new() { Icon = "fitness" },
|
||||
new() { Icon = "party" },
|
||||
new() { Icon = "share" },
|
||||
};
|
||||
source.AddRange(IconConverter.IconPreset.Select(icon => new BillingIcon { Icon = $"#brand#{icon.Key}" }));
|
||||
foreach (var icon in source)
|
||||
|
@ -49,6 +49,7 @@
|
||||
<ui:BalanceColorConverter x:Key="colorConverter"/>
|
||||
<ui:TimeConverter x:Key="timeConverter" IncludeDate="True"/>
|
||||
<ui:IconConverter x:Key="iconConverter"/>
|
||||
<ui:TintColorConverter x:Key="tintColorConverter"/>
|
||||
<Style x:Key="titleLabel" TargetType="Label">
|
||||
<Setter Property="FontSize" Value="16"/>
|
||||
<Setter Property="Margin" Value="10, 20, 10, 10"/>
|
||||
@ -116,7 +117,7 @@
|
||||
CommandParameter="{Binding .}"/>
|
||||
</Grid.GestureRecognizers>
|
||||
<ui:TintImage Source="{Binding Icon, Converter={StaticResource iconConverter}}"
|
||||
ui:TintHelper.TintColor="{Binding TintColor}"
|
||||
ui:TintHelper.TintColor="{Binding TintColor, Converter={StaticResource tintColorConverter}}"
|
||||
WidthRequest="26" HeightRequest="20" VerticalOptions="Center"/>
|
||||
<Label Grid.Column="1" Text="{Binding Name}" TextColor="{DynamicResource TextColor}"
|
||||
VerticalOptions="Center"
|
||||
|
@ -12,7 +12,7 @@
|
||||
Shell.TabBarIsVisible="True">
|
||||
|
||||
<ContentPage.ToolbarItems>
|
||||
<ToolbarItem Order="Primary" IconImageSource="project.png" Command="{Binding ShareCommand}"/>
|
||||
<ToolbarItem Order="Primary" IconImageSource="share.png" Command="{Binding ShareCommand}"/>
|
||||
</ContentPage.ToolbarItems>
|
||||
|
||||
<TableView Intent="Settings" HasUnevenRows="True">
|
||||
@ -39,5 +39,10 @@
|
||||
</Grid>
|
||||
</ViewCell>
|
||||
</TableSection>
|
||||
<TableSection Title="{r:Text Diagnostic}">
|
||||
<ui:OptionSelectCell Height="36" Title="{r:Text ShareLogs}"
|
||||
Detail="{Binding ManyRecords}"
|
||||
Command="{Binding ShareLogsCommand}"/>
|
||||
</TableSection>
|
||||
</TableView>
|
||||
</ui:BillingPage>
|
@ -1,8 +1,10 @@
|
||||
using System.IO;
|
||||
using Billing.Store;
|
||||
using Billing.Themes;
|
||||
using Billing.UI;
|
||||
using Xamarin.Essentials;
|
||||
using Xamarin.Forms;
|
||||
using Resource = Billing.Languages.Resource;
|
||||
|
||||
namespace Billing.Views
|
||||
{
|
||||
@ -10,6 +12,7 @@ namespace Billing.Views
|
||||
{
|
||||
private static readonly BindableProperty VersionProperty = Helper.Create<string, SettingPage>(nameof(Version));
|
||||
private static readonly BindableProperty PrimaryColorProperty = Helper.Create<string, SettingPage>(nameof(PrimaryColor));
|
||||
private static readonly BindableProperty ManyRecordsProperty = Helper.Create<string, SettingPage>(nameof(ManyRecords));
|
||||
|
||||
public string Version => (string)GetValue(VersionProperty);
|
||||
public string PrimaryColor
|
||||
@ -17,38 +20,43 @@ namespace Billing.Views
|
||||
get => (string)GetValue(PrimaryColorProperty);
|
||||
set => SetValue(PrimaryColorProperty, value);
|
||||
}
|
||||
public string ManyRecords => (string)GetValue(ManyRecordsProperty);
|
||||
|
||||
public Command ShareCommand { get; }
|
||||
public Command CategoryCommand { get; }
|
||||
public Command ColorPickerCommand { get; }
|
||||
public Command ShareLogsCommand { get; }
|
||||
|
||||
public SettingPage()
|
||||
{
|
||||
ShareCommand = new Command(OnShareCommand);
|
||||
CategoryCommand = new Command(OnCategoryCommand);
|
||||
ColorPickerCommand = new Command(OnColorPickerCommand);
|
||||
ShareLogsCommand = new Command(OnShareLogsCommand);
|
||||
InitializeComponent();
|
||||
|
||||
var (main, build) = Definition.GetVersion();
|
||||
SetValue(VersionProperty, $"{main} ({build})");
|
||||
}
|
||||
|
||||
protected override void OnAppearing()
|
||||
protected override async void OnAppearing()
|
||||
{
|
||||
base.OnAppearing();
|
||||
|
||||
//SetValue(VersionProperty, $"{AppInfo.VersionString} ({AppInfo.BuildString})");
|
||||
var colorString = Preferences.Get(Definition.PrimaryColorKey, Helper.DEFAULT_COLOR);
|
||||
PrimaryColor = Helper.WrapColorString(colorString);
|
||||
|
||||
var count = await StoreHelper.GetLogsCount();
|
||||
SetValue(ManyRecordsProperty, string.Format(Resource.ManyRecords, count));
|
||||
}
|
||||
|
||||
protected override void OnDisappearing()
|
||||
{
|
||||
base.OnDisappearing();
|
||||
|
||||
var color = PrimaryColor;
|
||||
Preferences.Set(Definition.PrimaryColorKey, color);
|
||||
Light.Instance.RefreshColor(Color.FromHex(color));
|
||||
Preferences.Set(Definition.PrimaryColorKey, PrimaryColor);
|
||||
//Light.Instance.RefreshColor(Color.FromHex(color));
|
||||
}
|
||||
|
||||
private async void OnShareCommand()
|
||||
@ -61,7 +69,7 @@ namespace Billing.Views
|
||||
{
|
||||
await Share.RequestAsync(new ShareFileRequest
|
||||
{
|
||||
File = new ShareFile(StoreHelper.DatabasePath)
|
||||
File = new ShareFile(StoreHelper.DatabasePath, "application/vnd.sqlite3")
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -84,6 +92,67 @@ namespace Billing.Views
|
||||
if (o is Color color)
|
||||
{
|
||||
PrimaryColor = Helper.WrapColorString(color.ToHex());
|
||||
Light.Instance.RefreshColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnShareLogsCommand()
|
||||
{
|
||||
if (Tap.IsBusy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
using (Tap.Start())
|
||||
{
|
||||
string file;
|
||||
var count = await StoreHelper.GetLogsCount();
|
||||
if (count > 0)
|
||||
{
|
||||
file = await StoreHelper.ExportLogs();
|
||||
}
|
||||
else
|
||||
{
|
||||
file = StoreHelper.GetLogFile();
|
||||
}
|
||||
if (file != null && File.Exists(file))
|
||||
{
|
||||
#if __IOS__
|
||||
var sendEmail = Resource.SendEmail;
|
||||
var shareLogs = Resource.ShareLogs;
|
||||
var result = await DisplayActionSheet(Resource.HowToShareDiagnostic, Resource.Cancel, null, sendEmail, shareLogs);
|
||||
if (result == sendEmail)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Email.ComposeAsync(new EmailMessage
|
||||
{
|
||||
To = { "tsorgy@gmail.com " },
|
||||
Subject = Resource.ShareLogs,
|
||||
Attachments =
|
||||
{
|
||||
new(file, "text/csv")
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Helper.Error("email.send", ex);
|
||||
}
|
||||
}
|
||||
else if (result == shareLogs)
|
||||
{
|
||||
await Share.RequestAsync(new ShareFileRequest
|
||||
{
|
||||
File = new ShareFile(file, "text/csv")
|
||||
});
|
||||
}
|
||||
#else
|
||||
await Share.RequestAsync(new ShareFileRequest
|
||||
{
|
||||
File = new ShareFile(file, "text/csv")
|
||||
});
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user