Refactored core
UI navigation framework Related Work Items: #408, #414, #416
This commit is contained in:
@@ -1,45 +1,49 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Http;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using FoxTube.Services;
|
||||
using FoxTube.Utils;
|
||||
using Google.Apis.Blogger.v3;
|
||||
using Google.Apis.Blogger.v3.Data;
|
||||
|
||||
namespace FoxTube.Models.Collections
|
||||
{
|
||||
public class InboxCollection : ViewCollection<InboxItem>
|
||||
public class InboxCollection : ViewCollection<Post>
|
||||
{
|
||||
private int _pageNumber = 0;
|
||||
private HttpClient _httpClient = new HttpClient();
|
||||
private string nextPageToken;
|
||||
|
||||
public override async Task<LoadMoreItemsResult> LoadItems()
|
||||
{
|
||||
// TODO: Add backend
|
||||
HttpResponseMessage response = await _httpClient.GetAsync($"https://xfox111.net/API/FoxTube/Inbox?" +
|
||||
$"lang={Storage.GetValue<string>(Storage.Settings.UILanguage)}&" +
|
||||
$"currentVersion={Metrics.CurrentVersion}&" +
|
||||
$"itemsCount={ItemsPerRequest}&" +
|
||||
$"iteration={_pageNumber}");
|
||||
|
||||
if (!response.IsSuccessStatusCode || response.StatusCode == System.Net.HttpStatusCode.NoContent)
|
||||
try
|
||||
{
|
||||
PostsResource.ListRequest request = InboxService.Service.Posts.List(SecretConstants.BlogId);
|
||||
request.FetchImages = false;
|
||||
request.PageToken = nextPageToken;
|
||||
request.Labels = "FoxTube";
|
||||
request.MaxResults = ItemsPerRequest;
|
||||
request.OrderBy = PostsResource.ListRequest.OrderByEnum.UPDATED;
|
||||
|
||||
PostList response = await request.ExecuteAsync();
|
||||
|
||||
foreach (Post post in response.Items)
|
||||
Items.Add(post);
|
||||
|
||||
HasMoreItems = !string.IsNullOrWhiteSpace(nextPageToken = response.NextPageToken);
|
||||
|
||||
return new LoadMoreItemsResult
|
||||
{
|
||||
Count = (uint)response.Items.Count
|
||||
};
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Metrics.SendReport(new Exception("Unable to load inbox", e));
|
||||
HasMoreItems = false;
|
||||
return new LoadMoreItemsResult
|
||||
{
|
||||
Count = 0
|
||||
};
|
||||
}
|
||||
|
||||
InboxItem[] newItems = JsonConvert.DeserializeObject<InboxItem[]>(await response.Content.ReadAsStringAsync());
|
||||
foreach (InboxItem item in newItems)
|
||||
Items.Add(item);
|
||||
|
||||
_pageNumber++;
|
||||
|
||||
return new LoadMoreItemsResult
|
||||
{
|
||||
Count = (uint)newItems.Length
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace FoxTube.Models.Collections
|
||||
{
|
||||
public abstract class ViewCollection<T> : ObservableCollection<T>, ISupportIncrementalLoading
|
||||
{
|
||||
public int ItemsPerRequest { get; set; }
|
||||
public int ItemsPerRequest { get; set; } = 25;
|
||||
public bool HasMoreItems { get; protected set; } = true;
|
||||
|
||||
public IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count) =>
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace FoxTube.Models
|
||||
{
|
||||
public class InboxItem
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public string DefaultIcon { get; set; }
|
||||
public string Avatar { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Content { get; set; }
|
||||
|
||||
public DateTime TimeStamp { get; set; }
|
||||
public string Type { get; set; }
|
||||
|
||||
public string ShortTimeStamp => $"{TimeStamp.ToShortDateString()} {TimeStamp.ToShortTimeString()}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FoxTube.Models
|
||||
{
|
||||
public class SearchParameters
|
||||
{
|
||||
public SearchParameters(string query)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,10 @@ using Google.Apis.Oauth2.v2.Data;
|
||||
using Google.Apis.Services;
|
||||
using Google.Apis.YouTube.v3;
|
||||
using Google.Apis.YouTube.v3.Data;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using YouTube;
|
||||
using YoutubeExplode;
|
||||
using FoxTube.Services;
|
||||
@@ -42,8 +40,6 @@ namespace FoxTube.Models
|
||||
|
||||
UserService.SubscriptionsChangedInvoker(this, subscription);
|
||||
Subscriptions.Remove(subscription);
|
||||
|
||||
SaveSubscriptions();
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@@ -79,21 +75,10 @@ namespace FoxTube.Models
|
||||
Subscriptions.Add(subscription);
|
||||
|
||||
UserService.SubscriptionsChangedInvoker(this, subscription);
|
||||
|
||||
SaveSubscriptions();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveSubscriptions()
|
||||
{
|
||||
Dictionary<string, string> subs = Subscriptions.Select(i =>
|
||||
new KeyValuePair<string, string>(i.ChannelId, i.Avatar.Default__?.Url))
|
||||
as Dictionary<string, string>;
|
||||
|
||||
ApplicationData.Current.RoamingSettings.Values[$"Subscriptions.{UserInfo.Id}"] = JsonConvert.SerializeObject(subs);
|
||||
}
|
||||
|
||||
public static async Task<User> GetUser(UserCredential credential)
|
||||
{
|
||||
User user = new User
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
using FoxTube.Services;
|
||||
using Google.Apis.YouTube.v3.Data;
|
||||
using System;
|
||||
using YoutubeExplode;
|
||||
|
||||
namespace FoxTube.Models
|
||||
{
|
||||
public class VideoItem
|
||||
{
|
||||
public Video Meta { get; set; }
|
||||
public YoutubeExplode.Videos.Video AdditionalMeta { get; set; }
|
||||
public YoutubeExplode.Channels.Channel ChannelMeta { get; set; }
|
||||
|
||||
public string TimeLabel { get; set; }
|
||||
public string ViewsLabel { get; set; }
|
||||
public int LiveLabelOpacity => Meta?.LiveStreamingDetails == null ? 0 : 1;
|
||||
public string LiveLabel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Meta?.LiveStreamingDetails == null)
|
||||
return "";
|
||||
else if (Meta.LiveStreamingDetails.ActualStartTime.HasValue)
|
||||
return "LIVE";
|
||||
else if (Meta.LiveStreamingDetails.ScheduledStartTime.HasValue)
|
||||
return $"Live in {Meta.LiveStreamingDetails.ScheduledStartTime - DateTime.Now}";
|
||||
else
|
||||
return "Upcoming";
|
||||
}
|
||||
}
|
||||
|
||||
public VideoItem(Video meta)
|
||||
{
|
||||
Meta = meta;
|
||||
LoadInfo();
|
||||
}
|
||||
|
||||
private async void LoadInfo()
|
||||
{
|
||||
YoutubeClient client = new YoutubeClient(UserService.Service.HttpClient);
|
||||
|
||||
AdditionalMeta = await client.Videos.GetAsync(Meta.Id);
|
||||
ChannelMeta = await client.Channels.GetByVideoAsync(Meta.Id);
|
||||
|
||||
TimeLabel = $"{AdditionalMeta?.Duration} • {AdditionalMeta.UploadDate.DateTime.GetFriendlyDate()}";
|
||||
ViewsLabel = $"{AdditionalMeta?.Engagement.ViewCount} views";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user