From e3a1b07172ec3253b1de7af5e450bcdfc48976c2 Mon Sep 17 00:00:00 2001 From: naoey Date: Sun, 25 Feb 2018 19:18:39 +0530 Subject: [PATCH] Create API request and reponse model. --- .../GetUserRecentActivitiesRequest.cs | 89 +++++++++++++++++++ .../PaginatedRecentActivityContainer.cs | 63 +++++++++++++ .../Profile/Sections/RecentSection.cs | 10 ++- osu.Game/Overlays/UserProfileOverlay.cs | 2 +- osu.Game/osu.Game.csproj | 4 +- 5 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 osu.Game/Online/API/Requests/GetUserRecentActivitiesRequest.cs create mode 100644 osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs diff --git a/osu.Game/Online/API/Requests/GetUserRecentActivitiesRequest.cs b/osu.Game/Online/API/Requests/GetUserRecentActivitiesRequest.cs new file mode 100644 index 0000000000..cb7d0323f4 --- /dev/null +++ b/osu.Game/Online/API/Requests/GetUserRecentActivitiesRequest.cs @@ -0,0 +1,89 @@ +using Newtonsoft.Json; +using osu.Game.Rulesets.Scoring; +using Humanizer; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using osu.Game.Rulesets; +using osu.Game.Overlays.Profile.Sections.Recent; + +namespace osu.Game.Online.API.Requests +{ + public class GetUserRecentActivitiesRequest : APIRequest> + { + } + + public class RecentActivity + { + [JsonProperty("id")] + public int ID; + + [JsonProperty("created_at")] + public DateTimeOffset CreatedAt; + + [JsonProperty] + private string type + { + set => Type = (RecentActivityType)Enum.Parse(typeof(RecentActivityType), value.Pascalize()); + } + + public RecentActivityType Type; + + [JsonProperty] + private string scoreRank + { + set => ScoreRank = (ScoreRank)Enum.Parse(typeof(ScoreRank), value); + } + + public ScoreRank ScoreRank; + + [JsonProperty("rank")] + public int Rank; + + [JsonProperty("mode")] + public string Mode; + + [JsonProperty("beatmap")] + public RecentActivityBeatmap Beatmap; + + [JsonProperty("user")] + public RecentActivityUser User; + + public class RecentActivityBeatmap + { + [JsonProperty("title")] + public string Title; + + [JsonProperty("url")] + public string Url; + } + + public class RecentActivityUser + { + [JsonProperty("username")] + public string Username; + + [JsonProperty("url")] + public string Url; + } + } + + public enum RecentActivityType + { + Achievement, + BeatmapPlaycount, + BeatmapsetApprove, + BeatmapsetDelete, + BeatmapsetRevive, + BeatmapsetUpdate, + Medal, + Rank, + RankLost, + UserSupportAgain, + UserSupportFirst, + UserSupportGift, + UsernameChange, + } +} diff --git a/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs b/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs new file mode 100644 index 0000000000..11b48ad68e --- /dev/null +++ b/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs @@ -0,0 +1,63 @@ +using osu.Framework.Configuration; +using osu.Game.Online.API.Requests; +using osu.Game.Users; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Overlays.Profile.Sections +{ + class PaginatedRecentActivityContainer : PaginatedContainer + { + public PaginatedRecentActivityContainer(Bindable user, string header, string missing) + : base(user, header, missing) + { + ItemsPerPage = 5; + } + + //protected override void ShowMore() + //{ + // base.ShowMore(); + + // var req = new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++ * ItemsPerPage); + + // req.Success += scores => + // { + // foreach (var s in scores) + // s.ApplyRuleset(Rulesets.GetRuleset(s.OnlineRulesetID)); + + // ShowMoreButton.FadeTo(scores.Count == ItemsPerPage ? 1 : 0); + // ShowMoreLoading.Hide(); + + // if (!scores.Any() && VisiblePages == 1) + // { + // MissingText.Show(); + // return; + // } + + // MissingText.Hide(); + + // foreach (OnlineScore score in scores) + // { + // DrawableProfileScore drawableScore; + + // switch (type) + // { + // default: + // drawableScore = new DrawablePerformanceScore(score, includeWeight ? Math.Pow(0.95, ItemsContainer.Count) : (double?)null); + // break; + // case ScoreType.Recent: + // drawableScore = new DrawableTotalScore(score); + // break; + // } + + // ItemsContainer.Add(drawableScore); + // } + // }; + + // Api.Queue(req); + //} + } +} diff --git a/osu.Game/Overlays/Profile/Sections/RecentSection.cs b/osu.Game/Overlays/Profile/Sections/RecentSection.cs index 78b139efe8..757e2457d2 100644 --- a/osu.Game/Overlays/Profile/Sections/RecentSection.cs +++ b/osu.Game/Overlays/Profile/Sections/RecentSection.cs @@ -7,6 +7,14 @@ namespace osu.Game.Overlays.Profile.Sections { public override string Title => "Recent"; - public override string Identifier => "recent_activities"; + public override string Identifier => "recent_activity"; + + public RecentSection() + { + Children = new[] + { + new PaginatedRecentActivityContainer(User, @"Recent", @"This user hasn't done anything notable recently!"), + }; + } } } diff --git a/osu.Game/Overlays/UserProfileOverlay.cs b/osu.Game/Overlays/UserProfileOverlay.cs index 59f940a19d..3bc12ccb24 100644 --- a/osu.Game/Overlays/UserProfileOverlay.cs +++ b/osu.Game/Overlays/UserProfileOverlay.cs @@ -82,7 +82,7 @@ namespace osu.Game.Overlays sections = new ProfileSection[] { //new AboutSection(), - //new RecentSection(), + new RecentSection(), new RanksSection(), //new MedalsSection(), new HistoricalSection(), diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 6a06bf540b..ad9105f1e8 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -293,12 +293,14 @@ + 20180125143340_Settings.cs + @@ -936,4 +938,4 @@ - + \ No newline at end of file