first step
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user