2022-06-22 13:02:33 +09:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2022-06-21 23:00:03 +01:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2024-02-22 19:40:02 -08:00
|
|
|
|
using System.Linq;
|
2022-06-21 23:00:03 +01:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Localisation;
|
2022-07-27 16:46:23 +09:00
|
|
|
|
using osu.Game.Collections;
|
2022-06-21 23:00:03 +01:00
|
|
|
|
using osu.Game.Database;
|
|
|
|
|
using osu.Game.Localisation;
|
2022-07-27 15:59:36 +09:00
|
|
|
|
using osu.Game.Overlays.Notifications;
|
2022-06-21 23:00:03 +01:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|
|
|
|
{
|
2022-11-24 14:32:20 +09:00
|
|
|
|
public partial class CollectionsSettings : SettingsSubsection
|
2022-06-21 23:00:03 +01:00
|
|
|
|
{
|
2022-09-16 21:08:25 +09:00
|
|
|
|
protected override LocalisableString Header => CommonStrings.Collections;
|
2022-06-21 23:00:03 +01:00
|
|
|
|
|
2022-07-27 15:59:36 +09:00
|
|
|
|
[Resolved]
|
|
|
|
|
private RealmAccess realm { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
2022-07-28 14:35:27 +09:00
|
|
|
|
private INotificationOverlay? notificationOverlay { get; set; }
|
2022-07-27 15:59:36 +09:00
|
|
|
|
|
2022-06-22 13:07:44 +09:00
|
|
|
|
[BackgroundDependencyLoader]
|
2023-01-09 21:17:40 +03:00
|
|
|
|
private void load(IDialogOverlay? dialogOverlay)
|
2022-06-21 23:00:03 +01:00
|
|
|
|
{
|
2022-06-21 23:41:25 +01:00
|
|
|
|
Add(new DangerousSettingsButton
|
|
|
|
|
{
|
|
|
|
|
Text = MaintenanceSettingsStrings.DeleteAllCollections,
|
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
2022-07-27 15:59:36 +09:00
|
|
|
|
dialogOverlay?.Push(new MassDeleteConfirmationDialog(deleteAllCollections));
|
2022-06-21 23:41:25 +01:00
|
|
|
|
}
|
|
|
|
|
});
|
2022-06-21 23:00:03 +01:00
|
|
|
|
}
|
2022-07-27 15:59:36 +09:00
|
|
|
|
|
|
|
|
|
private void deleteAllCollections()
|
|
|
|
|
{
|
2024-02-22 19:40:02 -08:00
|
|
|
|
bool anyDeleted = realm.Write(r =>
|
|
|
|
|
{
|
|
|
|
|
if (r.All<BeatmapCollection>().Any())
|
|
|
|
|
{
|
|
|
|
|
r.RemoveAll<BeatmapCollection>();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
notificationOverlay?.Post(new ProgressCompletionNotification { Text = anyDeleted ? MaintenanceSettingsStrings.DeletedAllCollections : MaintenanceSettingsStrings.NoCollectionsFoundToDelete });
|
2022-07-27 15:59:36 +09:00
|
|
|
|
}
|
2022-06-21 23:00:03 +01:00
|
|
|
|
}
|
|
|
|
|
}
|