first step

This commit is contained in:
gaoyuan
2022-03-02 22:29:13 +08:00
parent 51f8e4f2e8
commit 9929eee056
17 changed files with 343 additions and 60 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Billing.Models;
using Billing.UI;
using Xamarin.Essentials;
@ -52,7 +53,21 @@ namespace Billing.Store
private List<Category> GetCategoriesInternal()
{
return GetList<Category>(Path.Combine(PersonalFolder, categoryFile));
var list = GetList<Category>(Path.Combine(PersonalFolder, categoryFile));
if (list == null || list.Count == 0)
{
list = new List<Category>
{
// TODO: sample categories
new() { Id = 0, Name = "早餐", Icon = "face" },
new() { Id = 1, Name = "轻轨", Icon = "" },
new() { Id = 2, Name = "公交车", Icon = "" },
new() { Id = 3, Name = "出租车", Icon = "" },
new() { Id = 4, Type = CategoryType.Income, Name = "投资", Icon = "#brand#btc" }
};
Task.Run(() => WriteCategoriesInternal(list));
}
return list;
}
private void WriteCategoriesInternal(IEnumerable<Category> categories)
@ -71,7 +86,7 @@ namespace Billing.Store
}
try
{
using var stream = File.OpenWrite(filename);
using var stream = File.Open(filename, FileMode.Create);
list.ToStream(stream);
}
catch (Exception ex)