optimized and add diagnostic feature

This commit is contained in:
2022-03-15 15:17:02 +08:00
parent 77b4e54734
commit 5b209cc19c
45 changed files with 380 additions and 122 deletions

View File

@ -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();