Core update. Base core features are done (main app doesn't compile)
Related Work Items: #416, #422, #423, #424
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Http;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using FoxTube.Services;
|
||||
using FoxTube.Utils;
|
||||
|
||||
namespace FoxTube.Models.Collections
|
||||
{
|
||||
public class InboxCollection : ViewCollection<InboxItem>
|
||||
{
|
||||
private int _pageNumber = 0;
|
||||
private HttpClient _httpClient = new HttpClient();
|
||||
|
||||
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)
|
||||
{
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml.Data;
|
||||
|
||||
namespace FoxTube.Models.Collections
|
||||
{
|
||||
public abstract class ViewCollection<T> : ObservableCollection<T>, ISupportIncrementalLoading
|
||||
{
|
||||
public int ItemsPerRequest { get; set; }
|
||||
public bool HasMoreItems { get; protected set; } = true;
|
||||
|
||||
public IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count) =>
|
||||
AsyncInfo.Run((c) => LoadItems());
|
||||
|
||||
public abstract Task<LoadMoreItemsResult> LoadItems();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using FoxTube.Services;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
@@ -20,7 +21,7 @@ namespace FoxTube.Models
|
||||
public async Task CommenceDownload(IStreamInfo stream, IStorageFile destination)
|
||||
{
|
||||
Path = destination.Path;
|
||||
YoutubeClient client = new YoutubeClient(UserManagement.Service.HttpClient);
|
||||
YoutubeClient client = new YoutubeClient(UserService.Service.HttpClient);
|
||||
|
||||
State = DownloadState.Downloading;
|
||||
Task task = client.Videos.Streams.DownloadAsync(stream, Path, DownloadPercentage, CTS.Token);
|
||||
|
||||
@@ -13,6 +13,7 @@ using System.Threading.Tasks;
|
||||
using Windows.Storage;
|
||||
using YouTube;
|
||||
using YoutubeExplode;
|
||||
using FoxTube.Services;
|
||||
|
||||
namespace FoxTube.Models
|
||||
{
|
||||
@@ -36,10 +37,10 @@ namespace FoxTube.Models
|
||||
catch (Exception e)
|
||||
{
|
||||
Metrics.SendReport(new Exception("Failed to unsubscribe", e));
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
UserManagement.SubscriptionsChangedInvoker(this, subscription);
|
||||
UserService.SubscriptionsChangedInvoker(this, subscription);
|
||||
Subscriptions.Remove(subscription);
|
||||
|
||||
SaveSubscriptions();
|
||||
@@ -77,7 +78,7 @@ namespace FoxTube.Models
|
||||
};
|
||||
Subscriptions.Add(subscription);
|
||||
|
||||
UserManagement.SubscriptionsChangedInvoker(this, subscription);
|
||||
UserService.SubscriptionsChangedInvoker(this, subscription);
|
||||
|
||||
SaveSubscriptions();
|
||||
return true;
|
||||
@@ -86,7 +87,7 @@ namespace FoxTube.Models
|
||||
|
||||
private void SaveSubscriptions()
|
||||
{
|
||||
Dictionary<string, string> subs = Subscriptions.Select(i =>
|
||||
Dictionary<string, string> subs = Subscriptions.Select(i =>
|
||||
new KeyValuePair<string, string>(i.ChannelId, i.Avatar.Default__?.Url))
|
||||
as Dictionary<string, string>;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Google.Apis.YouTube.v3.Data;
|
||||
using FoxTube.Services;
|
||||
using Google.Apis.YouTube.v3.Data;
|
||||
using System;
|
||||
using YoutubeExplode;
|
||||
|
||||
@@ -36,7 +37,7 @@ namespace FoxTube.Models
|
||||
|
||||
private async void LoadInfo()
|
||||
{
|
||||
YoutubeClient client = new YoutubeClient(UserManagement.Service.HttpClient);
|
||||
YoutubeClient client = new YoutubeClient(UserService.Service.HttpClient);
|
||||
|
||||
AdditionalMeta = await client.Videos.GetAsync(Meta.Id);
|
||||
ChannelMeta = await client.Channels.GetByVideoAsync(Meta.Id);
|
||||
|
||||
Reference in New Issue
Block a user