Make IAPIProvider read-only bindables into IBindables

This commit is contained in:
Dean Herbert
2020-12-18 15:16:36 +09:00
parent 8a01e567a1
commit 206bf3713e
15 changed files with 41 additions and 30 deletions

View File

@ -39,11 +39,15 @@ namespace osu.Game.Online.API
private string password;
public Bindable<User> LocalUser { get; } = new Bindable<User>(createGuestUser());
public IBindable<User> LocalUser => localUser;
public IBindableList<User> Friends => friends;
public IBindable<UserActivity> Activity => activity;
public BindableList<User> Friends { get; } = new BindableList<User>();
private Bindable<User> localUser { get; } = new Bindable<User>(createGuestUser());
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
private BindableList<User> friends { get; } = new BindableList<User>();
private Bindable<UserActivity> activity { get; } = new Bindable<UserActivity>();
protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password));
@ -63,10 +67,10 @@ namespace osu.Game.Online.API
authentication.TokenString = config.Get<string>(OsuSetting.Token);
authentication.Token.ValueChanged += onTokenChanged;
LocalUser.BindValueChanged(u =>
localUser.BindValueChanged(u =>
{
u.OldValue?.Activity.UnbindFrom(Activity);
u.NewValue.Activity.BindTo(Activity);
u.OldValue?.Activity.UnbindFrom(activity);
u.NewValue.Activity.BindTo(activity);
}, true);
var thread = new Thread(run)
@ -138,10 +142,10 @@ namespace osu.Game.Online.API
var userReq = new GetUserRequest();
userReq.Success += u =>
{
LocalUser.Value = u;
localUser.Value = u;
// todo: save/pull from settings
LocalUser.Value.Status.Value = new UserStatusOnline();
localUser.Value.Status.Value = new UserStatusOnline();
failureCount = 0;
@ -343,7 +347,7 @@ namespace osu.Game.Online.API
return true;
}
public bool IsLoggedIn => LocalUser.Value.Id > 1;
public bool IsLoggedIn => localUser.Value.Id > 1;
public void Queue(APIRequest request)
{
@ -376,8 +380,8 @@ namespace osu.Game.Online.API
// Scheduled prior to state change such that the state changed event is invoked with the correct user and their friends present
Schedule(() =>
{
LocalUser.Value = createGuestUser();
Friends.Clear();
localUser.Value = createGuestUser();
friends.Clear();
});
state.Value = APIState.Offline;