optimized and add diagnostic feature
This commit is contained in:
@ -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