Refactored core
UI navigation framework Related Work Items: #408, #414, #416
This commit is contained in:
@@ -20,9 +20,6 @@ namespace FoxTube.Services
|
||||
{
|
||||
public static class UserService
|
||||
{
|
||||
public const string UsersStorageKey = "UserService.Users";
|
||||
public const string LastUserInfoKey = "UserService.LastUser";
|
||||
|
||||
public const int MaxUsersCount = 1;
|
||||
|
||||
#region Private members
|
||||
@@ -74,9 +71,6 @@ namespace FoxTube.Services
|
||||
public static event EventHandler<bool> UserStateUpdated;
|
||||
public static event EventHandler<Subscription> SubscriptionsChanged;
|
||||
|
||||
static UserService() =>
|
||||
Initialize();
|
||||
|
||||
public static async Task<bool> AddUser()
|
||||
{
|
||||
int queueIndex = Users.ToList().FindIndex(i => i == null);
|
||||
@@ -117,10 +111,10 @@ namespace FoxTube.Services
|
||||
return false;
|
||||
}
|
||||
|
||||
public static async void Initialize()
|
||||
public static async Task Initialize()
|
||||
{
|
||||
Users = JsonConvert.DeserializeObject<Userinfoplus[]>(Storage.Registry.Values[UsersStorageKey] as string ?? "") ?? new Userinfoplus[MaxUsersCount];
|
||||
int? lastUserIndex = Storage.Registry.Values[LastUserInfoKey] as int?;
|
||||
Users = JsonConvert.DeserializeObject<Userinfoplus[]>(StorageService.UserInfos ?? "") ?? new Userinfoplus[MaxUsersCount];
|
||||
int? lastUserIndex = StorageService.LastUserIndex;
|
||||
|
||||
if (lastUserIndex.HasValue && Users[lastUserIndex.Value] != null ||
|
||||
(lastUserIndex = Users.ToList().FindIndex(i => i != null)) > -1)
|
||||
@@ -146,12 +140,11 @@ namespace FoxTube.Services
|
||||
|
||||
await CurrentUser.Credential.RevokeTokenAsync(CancellationToken.None);
|
||||
|
||||
Storage.Registry.Values.Remove($"Subscriptions.{CurrentUser.UserInfo.Id}");
|
||||
CurrentUser = null;
|
||||
Users[Users.ToList().FindIndex(i => i.Id == userId)] = null;
|
||||
|
||||
Storage.Registry.Values[UsersStorageKey] = JsonConvert.SerializeObject(Users);
|
||||
Storage.Registry.Values[LastUserInfoKey] = null;
|
||||
StorageService.UserInfos = JsonConvert.SerializeObject(Users);
|
||||
StorageService.LastUserIndex = null;
|
||||
|
||||
if (Users.Any(i => i != null))
|
||||
await SwitchUser(Users.ToList().FindIndex(i => i != null));
|
||||
@@ -202,8 +195,8 @@ namespace FoxTube.Services
|
||||
CurrentUser = await User.GetUser(credential);
|
||||
Users[userIndex] = CurrentUser.UserInfo;
|
||||
|
||||
Storage.Registry.Values[UsersStorageKey] = JsonConvert.SerializeObject(Users);
|
||||
Storage.Registry.Values[LastUserInfoKey] = userIndex;
|
||||
StorageService.UserInfos = JsonConvert.SerializeObject(Users);
|
||||
StorageService.LastUserIndex = userIndex;
|
||||
|
||||
credential.RefreshTokenUpdated += (s, e) => UpdateToken(CurrentUser.UserInfo.Id, credential.Token.RefreshToken);
|
||||
UpdateToken(CurrentUser.UserInfo.Id, credential.Token.RefreshToken);
|
||||
|
||||
Reference in New Issue
Block a user