From ab27d82cd581acba8e738a33704484335edd0f69 Mon Sep 17 00:00:00 2001 From: naoey Date: Tue, 11 Jun 2019 23:01:01 +0530 Subject: [PATCH 1/7] Make beatmap download buttons inherit BeatmapDownloadTrackingComposite - Move DownloadTrackingComposite into the online namespace --- osu.Game/Database/ArchiveModelManager.cs | 4 +- .../Direct => Online}/DownloadState.cs | 2 +- .../DownloadTrackingComposite.cs | 53 ++++++++++--------- .../BeatmapSet/Buttons/DownloadButton.cs | 3 +- osu.Game/Overlays/BeatmapSet/Header.cs | 3 +- .../BeatmapDownloadTrackingComposite.cs | 16 ++++++ osu.Game/Overlays/Direct/DownloadButton.cs | 3 +- .../Overlays/Direct/DownloadProgressBar.cs | 3 +- 8 files changed, 55 insertions(+), 32 deletions(-) rename osu.Game/{Overlays/Direct => Online}/DownloadState.cs (89%) rename osu.Game/{Overlays/Direct => Online}/DownloadTrackingComposite.cs (63%) create mode 100644 osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs diff --git a/osu.Game/Database/ArchiveModelManager.cs b/osu.Game/Database/ArchiveModelManager.cs index 50cb9dac8b..ccaba99427 100644 --- a/osu.Game/Database/ArchiveModelManager.cs +++ b/osu.Game/Database/ArchiveModelManager.cs @@ -29,7 +29,7 @@ namespace osu.Game.Database /// /// The model type. /// The associated file join type. - public abstract class ArchiveModelManager : ICanAcceptFiles, IModelManager + public abstract class ArchiveModelManager : ICanAcceptFiles, IModelManager where TModel : class, IHasFiles, IHasPrimaryKey, ISoftDelete where TFileModel : INamedFileInfo, new() { @@ -44,7 +44,7 @@ namespace osu.Game.Database /// Fired when a new becomes available in the database. /// This is not guaranteed to run on the update thread. /// - public event ItemAddedDelegate ItemAdded; + public event Action ItemAdded; /// /// Fired when a is removed from the database. diff --git a/osu.Game/Overlays/Direct/DownloadState.cs b/osu.Game/Online/DownloadState.cs similarity index 89% rename from osu.Game/Overlays/Direct/DownloadState.cs rename to osu.Game/Online/DownloadState.cs index a301c6a3bd..72efbc286e 100644 --- a/osu.Game/Overlays/Direct/DownloadState.cs +++ b/osu.Game/Online/DownloadState.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -namespace osu.Game.Overlays.Direct +namespace osu.Game.Online { public enum DownloadState { diff --git a/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs b/osu.Game/Online/DownloadTrackingComposite.cs similarity index 63% rename from osu.Game/Overlays/Direct/DownloadTrackingComposite.cs rename to osu.Game/Online/DownloadTrackingComposite.cs index c1ff6ecb60..157211e6c2 100644 --- a/osu.Game/Overlays/Direct/DownloadTrackingComposite.cs +++ b/osu.Game/Online/DownloadTrackingComposite.cs @@ -7,18 +7,21 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; +using osu.Game.Database; using osu.Game.Online.API; -namespace osu.Game.Overlays.Direct +namespace osu.Game.Online { /// /// A component which tracks a beatmap through potential download/import/deletion. /// - public abstract class DownloadTrackingComposite : CompositeDrawable + public abstract class DownloadTrackingComposite : CompositeDrawable + where TModel : class + where TModelManager : class, IDownloadModelManager { - public readonly Bindable BeatmapSet = new Bindable(); + public readonly Bindable ModelInfo = new Bindable(); - private BeatmapManager beatmaps; + private TModelManager manager; /// /// Holds the current download state of the beatmap, whether is has already been downloaded, is in progress, or is not downloaded. @@ -27,34 +30,34 @@ namespace osu.Game.Overlays.Direct protected readonly Bindable Progress = new Bindable(); - protected DownloadTrackingComposite(BeatmapSetInfo beatmapSet = null) + protected DownloadTrackingComposite(TModel model = null) { - BeatmapSet.Value = beatmapSet; + ModelInfo.Value = model; } [BackgroundDependencyLoader(true)] - private void load(BeatmapManager beatmaps) + private void load(TModelManager manager) { - this.beatmaps = beatmaps; + this.manager = manager; - BeatmapSet.BindValueChanged(setInfo => + ModelInfo.BindValueChanged(modelInfo => { - if (setInfo.NewValue == null) + if (modelInfo.NewValue == null) attachDownload(null); - else if (beatmaps.GetAllUsableBeatmapSetsEnumerable().Any(s => s.OnlineBeatmapSetID == setInfo.NewValue.OnlineBeatmapSetID)) + else if (manager.IsAvailableLocally(modelInfo.NewValue)) State.Value = DownloadState.LocallyAvailable; else - attachDownload(beatmaps.GetExistingDownload(setInfo.NewValue)); + attachDownload(manager.GetExistingDownload(modelInfo.NewValue)); }, true); - beatmaps.DownloadBegan += download => + manager.DownloadBegan += download => { - if (download.Info.OnlineBeatmapSetID == BeatmapSet.Value?.OnlineBeatmapSetID) + if (download.Info.Equals(ModelInfo.Value)) attachDownload(download); }; - beatmaps.ItemAdded += setAdded; - beatmaps.ItemRemoved += setRemoved; + manager.ItemAdded += itemAdded; + manager.ItemRemoved += itemRemoved; } #region Disposal @@ -63,10 +66,10 @@ namespace osu.Game.Overlays.Direct { base.Dispose(isDisposing); - if (beatmaps != null) + if (manager != null) { - beatmaps.DownloadBegan -= attachDownload; - beatmaps.ItemAdded -= setAdded; + manager.DownloadBegan -= attachDownload; + manager.ItemAdded -= itemAdded; } State.UnbindAll(); @@ -76,9 +79,9 @@ namespace osu.Game.Overlays.Direct #endregion - private ArchiveDownloadModelRequest attachedRequest; + private ArchiveDownloadModelRequest attachedRequest; - private void attachDownload(ArchiveDownloadModelRequest request) + private void attachDownload(ArchiveDownloadModelRequest request) { if (attachedRequest != null) { @@ -118,13 +121,13 @@ namespace osu.Game.Overlays.Direct private void onRequestFailure(Exception e) => Schedule(() => attachDownload(null)); - private void setAdded(BeatmapSetInfo s, bool existing) => setDownloadStateFromManager(s, DownloadState.LocallyAvailable); + private void itemAdded(TModel s, bool existing) => setDownloadStateFromManager(s, DownloadState.LocallyAvailable); - private void setRemoved(BeatmapSetInfo s) => setDownloadStateFromManager(s, DownloadState.NotDownloaded); + private void itemRemoved(TModel s) => setDownloadStateFromManager(s, DownloadState.NotDownloaded); - private void setDownloadStateFromManager(BeatmapSetInfo s, DownloadState state) => Schedule(() => + private void setDownloadStateFromManager(TModel s, DownloadState state) => Schedule(() => { - if (s.OnlineBeatmapSetID != BeatmapSet.Value?.OnlineBeatmapSetID) + if (s.Equals(ModelInfo.Value)) return; State.Value = state; diff --git a/osu.Game/Overlays/BeatmapSet/Buttons/DownloadButton.cs b/osu.Game/Overlays/BeatmapSet/Buttons/DownloadButton.cs index 0a159507fe..3e8a5a8324 100644 --- a/osu.Game/Overlays/BeatmapSet/Buttons/DownloadButton.cs +++ b/osu.Game/Overlays/BeatmapSet/Buttons/DownloadButton.cs @@ -11,6 +11,7 @@ using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; +using osu.Game.Online; using osu.Game.Online.API; using osu.Game.Overlays.Direct; using osu.Game.Users; @@ -19,7 +20,7 @@ using osuTK.Graphics; namespace osu.Game.Overlays.BeatmapSet.Buttons { - public class DownloadButton : DownloadTrackingComposite, IHasTooltip + public class DownloadButton : BeatmapDownloadTrackingComposite, IHasTooltip { private readonly bool noVideo; diff --git a/osu.Game/Overlays/BeatmapSet/Header.cs b/osu.Game/Overlays/BeatmapSet/Header.cs index a0f71d05c0..d0c6e4aa62 100644 --- a/osu.Game/Overlays/BeatmapSet/Header.cs +++ b/osu.Game/Overlays/BeatmapSet/Header.cs @@ -13,6 +13,7 @@ using osu.Game.Beatmaps.Drawables; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; +using osu.Game.Online; using osu.Game.Overlays.BeatmapSet.Buttons; using osu.Game.Overlays.Direct; using osuTK; @@ -21,7 +22,7 @@ using DownloadButton = osu.Game.Overlays.BeatmapSet.Buttons.DownloadButton; namespace osu.Game.Overlays.BeatmapSet { - public class Header : DownloadTrackingComposite + public class Header : BeatmapDownloadTrackingComposite { private const float transition_duration = 200; private const float tabs_height = 50; diff --git a/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs b/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs new file mode 100644 index 0000000000..67fc5b48bd --- /dev/null +++ b/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs @@ -0,0 +1,16 @@ +using osu.Framework.Bindables; +using osu.Game.Beatmaps; +using osu.Game.Online; + +namespace osu.Game.Overlays.Direct +{ + public abstract class BeatmapDownloadTrackingComposite : DownloadTrackingComposite + { + public Bindable BeatmapSet => ModelInfo; + + public BeatmapDownloadTrackingComposite(BeatmapSetInfo set = null) + : base(set) + { + } + } +} diff --git a/osu.Game/Overlays/Direct/DownloadButton.cs b/osu.Game/Overlays/Direct/DownloadButton.cs index 3f44d854e5..348ce427bd 100644 --- a/osu.Game/Overlays/Direct/DownloadButton.cs +++ b/osu.Game/Overlays/Direct/DownloadButton.cs @@ -9,11 +9,12 @@ using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; +using osu.Game.Online; using osuTK; namespace osu.Game.Overlays.Direct { - public class DownloadButton : DownloadTrackingComposite + public class DownloadButton : BeatmapDownloadTrackingComposite { private readonly bool noVideo; private readonly SpriteIcon icon; diff --git a/osu.Game/Overlays/Direct/DownloadProgressBar.cs b/osu.Game/Overlays/Direct/DownloadProgressBar.cs index 57500b3531..a6cefaae84 100644 --- a/osu.Game/Overlays/Direct/DownloadProgressBar.cs +++ b/osu.Game/Overlays/Direct/DownloadProgressBar.cs @@ -7,11 +7,12 @@ using osu.Framework.Graphics; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.UserInterface; +using osu.Game.Online; using osuTK.Graphics; namespace osu.Game.Overlays.Direct { - public class DownloadProgressBar : DownloadTrackingComposite + public class DownloadProgressBar : BeatmapDownloadTrackingComposite { private readonly ProgressBar progressBar; From 41da491a7eb3d9287c7e1725214f4e456576bdd7 Mon Sep 17 00:00:00 2001 From: naoey Date: Tue, 11 Jun 2019 23:23:40 +0530 Subject: [PATCH 2/7] Make BeatmapSetInfo equatable --- osu.Game/Beatmaps/BeatmapSetInfo.cs | 4 +++- osu.Game/Online/DownloadTrackingComposite.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapSetInfo.cs b/osu.Game/Beatmaps/BeatmapSetInfo.cs index 390236e053..aa5ed48641 100644 --- a/osu.Game/Beatmaps/BeatmapSetInfo.cs +++ b/osu.Game/Beatmaps/BeatmapSetInfo.cs @@ -9,7 +9,7 @@ using osu.Game.Database; namespace osu.Game.Beatmaps { - public class BeatmapSetInfo : IHasPrimaryKey, IHasFiles, ISoftDelete + public class BeatmapSetInfo : IHasPrimaryKey, IHasFiles, ISoftDelete, IEquatable { public int ID { get; set; } @@ -46,5 +46,7 @@ namespace osu.Game.Beatmaps public override string ToString() => Metadata?.ToString() ?? base.ToString(); public bool Protected { get; set; } + + public bool Equals(BeatmapSetInfo other) => OnlineBeatmapSetID == other?.OnlineBeatmapSetID; } } diff --git a/osu.Game/Online/DownloadTrackingComposite.cs b/osu.Game/Online/DownloadTrackingComposite.cs index 157211e6c2..d233be19f5 100644 --- a/osu.Game/Online/DownloadTrackingComposite.cs +++ b/osu.Game/Online/DownloadTrackingComposite.cs @@ -16,7 +16,7 @@ namespace osu.Game.Online /// A component which tracks a beatmap through potential download/import/deletion. /// public abstract class DownloadTrackingComposite : CompositeDrawable - where TModel : class + where TModel : class, IEquatable where TModelManager : class, IDownloadModelManager { public readonly Bindable ModelInfo = new Bindable(); From 7495bc5d3a97f457407a8f561b16d4b856f058ea Mon Sep 17 00:00:00 2001 From: naoey Date: Wed, 12 Jun 2019 00:41:17 +0530 Subject: [PATCH 3/7] Post merge and inverted condition fix --- osu.Game/Online/DownloadTrackingComposite.cs | 4 ++-- osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/osu.Game/Online/DownloadTrackingComposite.cs b/osu.Game/Online/DownloadTrackingComposite.cs index d233be19f5..0cb3acf019 100644 --- a/osu.Game/Online/DownloadTrackingComposite.cs +++ b/osu.Game/Online/DownloadTrackingComposite.cs @@ -17,7 +17,7 @@ namespace osu.Game.Online /// public abstract class DownloadTrackingComposite : CompositeDrawable where TModel : class, IEquatable - where TModelManager : class, IDownloadModelManager + where TModelManager : class, IModelDownloader { public readonly Bindable ModelInfo = new Bindable(); @@ -127,7 +127,7 @@ namespace osu.Game.Online private void setDownloadStateFromManager(TModel s, DownloadState state) => Schedule(() => { - if (s.Equals(ModelInfo.Value)) + if (!s.Equals(ModelInfo.Value)) return; State.Value = state; diff --git a/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs b/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs index 67fc5b48bd..b6304b82c4 100644 --- a/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs +++ b/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs @@ -1,4 +1,7 @@ -using osu.Framework.Bindables; +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Bindables; using osu.Game.Beatmaps; using osu.Game.Online; From ba6546038c582d1d7249a078dac56624a49ac657 Mon Sep 17 00:00:00 2001 From: naoey Date: Wed, 12 Jun 2019 00:47:02 +0530 Subject: [PATCH 4/7] Make ModelInfo and abstract class constructor protected - Implementing classes would be better off exposing it if necessary under a different name --- osu.Game/Online/DownloadTrackingComposite.cs | 4 +--- osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/osu.Game/Online/DownloadTrackingComposite.cs b/osu.Game/Online/DownloadTrackingComposite.cs index 0cb3acf019..d07aed9206 100644 --- a/osu.Game/Online/DownloadTrackingComposite.cs +++ b/osu.Game/Online/DownloadTrackingComposite.cs @@ -2,11 +2,9 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; -using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Online.API; @@ -19,7 +17,7 @@ namespace osu.Game.Online where TModel : class, IEquatable where TModelManager : class, IModelDownloader { - public readonly Bindable ModelInfo = new Bindable(); + protected readonly Bindable ModelInfo = new Bindable(); private TModelManager manager; diff --git a/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs b/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs index b6304b82c4..6f348c4fd7 100644 --- a/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs +++ b/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs @@ -11,7 +11,7 @@ namespace osu.Game.Overlays.Direct { public Bindable BeatmapSet => ModelInfo; - public BeatmapDownloadTrackingComposite(BeatmapSetInfo set = null) + protected BeatmapDownloadTrackingComposite(BeatmapSetInfo set = null) : base(set) { } From 8efc504817e099a106e6d19312a479f01ea0cbb2 Mon Sep 17 00:00:00 2001 From: naoey Date: Wed, 26 Jun 2019 18:22:37 +0530 Subject: [PATCH 5/7] Post merge fixes --- osu.Game/Online/DownloadTrackingComposite.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Online/DownloadTrackingComposite.cs b/osu.Game/Online/DownloadTrackingComposite.cs index d07aed9206..18197a0b2c 100644 --- a/osu.Game/Online/DownloadTrackingComposite.cs +++ b/osu.Game/Online/DownloadTrackingComposite.cs @@ -50,7 +50,7 @@ namespace osu.Game.Online manager.DownloadBegan += download => { - if (download.Info.Equals(ModelInfo.Value)) + if (download.Model.Equals(ModelInfo.Value)) attachDownload(download); }; @@ -77,9 +77,9 @@ namespace osu.Game.Online #endregion - private ArchiveDownloadModelRequest attachedRequest; + private ArchiveDownloadRequest attachedRequest; - private void attachDownload(ArchiveDownloadModelRequest request) + private void attachDownload(ArchiveDownloadRequest request) { if (attachedRequest != null) { @@ -119,7 +119,7 @@ namespace osu.Game.Online private void onRequestFailure(Exception e) => Schedule(() => attachDownload(null)); - private void itemAdded(TModel s, bool existing) => setDownloadStateFromManager(s, DownloadState.LocallyAvailable); + private void itemAdded(TModel s) => setDownloadStateFromManager(s, DownloadState.LocallyAvailable); private void itemRemoved(TModel s) => setDownloadStateFromManager(s, DownloadState.NotDownloaded); From 768d6c2fb38b6aaabe95fe78d28d490997126a1f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 27 Jun 2019 00:29:09 +0900 Subject: [PATCH 6/7] ModelInfo -> Model --- osu.Game/Online/DownloadTrackingComposite.cs | 10 +++++----- .../Direct/BeatmapDownloadTrackingComposite.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Online/DownloadTrackingComposite.cs b/osu.Game/Online/DownloadTrackingComposite.cs index 18197a0b2c..7003506a13 100644 --- a/osu.Game/Online/DownloadTrackingComposite.cs +++ b/osu.Game/Online/DownloadTrackingComposite.cs @@ -17,7 +17,7 @@ namespace osu.Game.Online where TModel : class, IEquatable where TModelManager : class, IModelDownloader { - protected readonly Bindable ModelInfo = new Bindable(); + protected readonly Bindable Model = new Bindable(); private TModelManager manager; @@ -30,7 +30,7 @@ namespace osu.Game.Online protected DownloadTrackingComposite(TModel model = null) { - ModelInfo.Value = model; + Model.Value = model; } [BackgroundDependencyLoader(true)] @@ -38,7 +38,7 @@ namespace osu.Game.Online { this.manager = manager; - ModelInfo.BindValueChanged(modelInfo => + Model.BindValueChanged(modelInfo => { if (modelInfo.NewValue == null) attachDownload(null); @@ -50,7 +50,7 @@ namespace osu.Game.Online manager.DownloadBegan += download => { - if (download.Model.Equals(ModelInfo.Value)) + if (download.Model.Equals(Model.Value)) attachDownload(download); }; @@ -125,7 +125,7 @@ namespace osu.Game.Online private void setDownloadStateFromManager(TModel s, DownloadState state) => Schedule(() => { - if (!s.Equals(ModelInfo.Value)) + if (!s.Equals(Model.Value)) return; State.Value = state; diff --git a/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs b/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs index 6f348c4fd7..fd04a1541e 100644 --- a/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs +++ b/osu.Game/Overlays/Direct/BeatmapDownloadTrackingComposite.cs @@ -9,7 +9,7 @@ namespace osu.Game.Overlays.Direct { public abstract class BeatmapDownloadTrackingComposite : DownloadTrackingComposite { - public Bindable BeatmapSet => ModelInfo; + public Bindable BeatmapSet => Model; protected BeatmapDownloadTrackingComposite(BeatmapSetInfo set = null) : base(set) From 9edd98efdc9b6882368fedea9b27e17ecc338780 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 27 Jun 2019 00:29:38 +0900 Subject: [PATCH 7/7] Move disposal to end of class --- osu.Game/Online/DownloadTrackingComposite.cs | 38 ++++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/osu.Game/Online/DownloadTrackingComposite.cs b/osu.Game/Online/DownloadTrackingComposite.cs index 7003506a13..5eb2bb74bb 100644 --- a/osu.Game/Online/DownloadTrackingComposite.cs +++ b/osu.Game/Online/DownloadTrackingComposite.cs @@ -58,25 +58,6 @@ namespace osu.Game.Online manager.ItemRemoved += itemRemoved; } - #region Disposal - - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - - if (manager != null) - { - manager.DownloadBegan -= attachDownload; - manager.ItemAdded -= itemAdded; - } - - State.UnbindAll(); - - attachDownload(null); - } - - #endregion - private ArchiveDownloadRequest attachedRequest; private void attachDownload(ArchiveDownloadRequest request) @@ -130,5 +111,24 @@ namespace osu.Game.Online State.Value = state; }); + + #region Disposal + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + if (manager != null) + { + manager.DownloadBegan -= attachDownload; + manager.ItemAdded -= itemAdded; + } + + State.UnbindAll(); + + attachDownload(null); + } + + #endregion } }