mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 17:37:23 +09:00
Replace ObservableCollection with BindableCollection
This commit is contained in:
parent
cd2737156f
commit
a14b6ac9df
@ -31,6 +31,9 @@ namespace osu.Game.Online.Chat
|
|||||||
@"#lobby"
|
@"#lobby"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private readonly BindableCollection<Channel> availableChannels = new BindableCollection<Channel>();
|
||||||
|
private readonly BindableCollection<Channel> joinedChannels = new BindableCollection<Channel>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The currently opened channel
|
/// The currently opened channel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -39,12 +42,12 @@ namespace osu.Game.Online.Chat
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Channels the player has joined
|
/// The Channels the player has joined
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ObservableCollection<Channel> JoinedChannels { get; } = new ObservableCollection<Channel>(); //todo: should be publicly readonly
|
public IBindableCollection<Channel> JoinedChannels => joinedChannels;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The channels available for the player to join
|
/// The channels available for the player to join
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ObservableCollection<Channel> AvailableChannels { get; } = new ObservableCollection<Channel>(); //todo: should be publicly readonly
|
public IBindableCollection<Channel> AvailableChannels => availableChannels;
|
||||||
|
|
||||||
private IAPIProvider api;
|
private IAPIProvider api;
|
||||||
private ScheduledDelegate fetchMessagesScheduleder;
|
private ScheduledDelegate fetchMessagesScheduleder;
|
||||||
@ -344,9 +347,10 @@ namespace osu.Game.Online.Chat
|
|||||||
{
|
{
|
||||||
if (channel == null) return;
|
if (channel == null) return;
|
||||||
|
|
||||||
if (channel == CurrentChannel.Value) CurrentChannel.Value = null;
|
if (channel == CurrentChannel.Value)
|
||||||
|
CurrentChannel.Value = null;
|
||||||
|
|
||||||
JoinedChannels.Remove(channel);
|
joinedChannels.Remove(channel);
|
||||||
|
|
||||||
if (channel.Joined.Value)
|
if (channel.Joined.Value)
|
||||||
{
|
{
|
||||||
|
@ -20,6 +20,7 @@ using osu.Game.Online.Chat;
|
|||||||
using osu.Game.Overlays.Chat;
|
using osu.Game.Overlays.Chat;
|
||||||
using osu.Game.Overlays.Chat.Selection;
|
using osu.Game.Overlays.Chat.Selection;
|
||||||
using osu.Game.Overlays.Chat.Tabs;
|
using osu.Game.Overlays.Chat.Tabs;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
@ -181,28 +182,6 @@ namespace osu.Game.Overlays
|
|||||||
channelSelection.OnRequestLeave = channel => channelManager.LeaveChannel(channel);
|
channelSelection.OnRequestLeave = channel => channelManager.LeaveChannel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void joinedChannelsChanged(object sender, NotifyCollectionChangedEventArgs args)
|
|
||||||
{
|
|
||||||
switch (args.Action)
|
|
||||||
{
|
|
||||||
case NotifyCollectionChangedAction.Add:
|
|
||||||
foreach (Channel newChannel in args.NewItems)
|
|
||||||
{
|
|
||||||
channelTabControl.AddChannel(newChannel);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case NotifyCollectionChangedAction.Remove:
|
|
||||||
foreach (Channel removedChannel in args.OldItems)
|
|
||||||
{
|
|
||||||
channelTabControl.RemoveChannel(removedChannel);
|
|
||||||
loadedChannels.Remove(loadedChannels.Find(c => c.Channel == removedChannel));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void currentChannelChanged(Channel channel)
|
private void currentChannelChanged(Channel channel)
|
||||||
{
|
{
|
||||||
if (channel == null)
|
if (channel == null)
|
||||||
@ -322,19 +301,35 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
this.channelManager = channelManager;
|
this.channelManager = channelManager;
|
||||||
channelManager.CurrentChannel.ValueChanged += currentChannelChanged;
|
channelManager.CurrentChannel.ValueChanged += currentChannelChanged;
|
||||||
channelManager.JoinedChannels.CollectionChanged += joinedChannelsChanged;
|
channelManager.JoinedChannels.ItemsAdded += onChannelAddedToJoinedChannels;
|
||||||
channelManager.AvailableChannels.CollectionChanged += availableChannelsChanged;
|
channelManager.JoinedChannels.ItemsRemoved += onChannelRemovedFromJoinedChannels;
|
||||||
|
channelManager.AvailableChannels.ItemsAdded += availableChannelsChanged;
|
||||||
|
channelManager.AvailableChannels.ItemsRemoved += availableChannelsChanged;
|
||||||
|
|
||||||
//for the case that channelmanager was faster at fetching the channels than our attachment to CollectionChanged.
|
//for the case that channelmanager was faster at fetching the channels than our attachment to CollectionChanged.
|
||||||
channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
|
channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
|
||||||
joinedChannelsChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, channelManager.JoinedChannels));
|
foreach (Channel channel in channelManager.JoinedChannels)
|
||||||
|
channelTabControl.AddChannel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void availableChannelsChanged(object sender, NotifyCollectionChangedEventArgs e)
|
private void onChannelAddedToJoinedChannels(IEnumerable<Channel> channels)
|
||||||
{
|
{
|
||||||
channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
|
foreach (Channel channel in channels)
|
||||||
|
channelTabControl.AddChannel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onChannelRemovedFromJoinedChannels(IEnumerable<Channel> channels)
|
||||||
|
{
|
||||||
|
foreach (Channel channel in channels)
|
||||||
|
{
|
||||||
|
channelTabControl.RemoveChannel(channel);
|
||||||
|
loadedChannels.Remove(loadedChannels.Find(c => c.Channel == channel));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void availableChannelsChanged(IEnumerable<Channel> channels)
|
||||||
|
=> channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
@ -342,8 +337,10 @@ namespace osu.Game.Overlays
|
|||||||
if (channelManager != null)
|
if (channelManager != null)
|
||||||
{
|
{
|
||||||
channelManager.CurrentChannel.ValueChanged -= currentChannelChanged;
|
channelManager.CurrentChannel.ValueChanged -= currentChannelChanged;
|
||||||
channelManager.JoinedChannels.CollectionChanged -= joinedChannelsChanged;
|
channelManager.JoinedChannels.ItemsAdded -= onChannelAddedToJoinedChannels;
|
||||||
channelManager.AvailableChannels.CollectionChanged -= availableChannelsChanged;
|
channelManager.JoinedChannels.ItemsRemoved -= onChannelRemovedFromJoinedChannels;
|
||||||
|
channelManager.AvailableChannels.ItemsAdded -= availableChannelsChanged;
|
||||||
|
channelManager.AvailableChannels.ItemsRemoved -= availableChannelsChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user