do a lot of new things

This commit is contained in:
kawaiizenbo 2023-02-05 17:02:05 -07:00
parent 52fda5b93c
commit 3eb90fd9f7
9 changed files with 289 additions and 21 deletions

View file

@ -27,7 +27,7 @@ namespace WMstodon
{
HttpClient generic = new HttpClient();
generic.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", (string)localSettings.Values["accessToken"]);
HttpResponseMessage response = await generic.GetAsync(URL);
HttpResponseMessage response = await generic.GetAsync(new Uri(URL));
generic.Dispose();
return new KeyValuePair<HttpStatusCode, string>(response.StatusCode, await response.Content.ReadAsStringAsync());
}
@ -46,7 +46,7 @@ namespace WMstodon
{
HttpClient generic = new HttpClient();
generic.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", (string)localSettings.Values["accessToken"]);
HttpResponseMessage response = await generic.PostAsync(URL, data);
HttpResponseMessage response = await generic.PostAsync(new Uri(URL), data);
generic.Dispose();
return new KeyValuePair<HttpStatusCode, string>(response.StatusCode, await response.Content.ReadAsStringAsync());
}

View file

@ -0,0 +1,18 @@
<Page
x:Class="WMstodon.ImageViewerPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WMstodon"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Background="Black">
<Image x:Name="ImageElement" Margin="0" VerticalAlignment="Center"/>
<Grid x:Name="DescriptionGrid" Height="40" Margin="0" VerticalAlignment="Bottom" Background="#77000000">
<TextBlock x:Name="ImageDescriptionTextBlock" HorizontalAlignment="Left" Margin="10,0" TextWrapping="Wrap" Text="Loading..." VerticalAlignment="Center" Foreground="White"/>
</Grid>
<Button x:Name="BackButton" Content="Back" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Foreground="White" Width="75" Click="BackButton_Click"/>
</Grid>
</Page>

View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace WMstodon
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class ImageViewerPage : Page
{
public ImageViewerPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Attachment attachment = (Attachment)e.Parameter;
BitmapImage image = new BitmapImage();
image.UriSource = new Uri(attachment.url);
ImageElement.Source = image;
ImageDescriptionTextBlock.Text = attachment.description == null ? "" : attachment.description;
ImageDescriptionTextBlock.UpdateLayout();
DescriptionGrid.Height = ImageDescriptionTextBlock.Height + 20;
}
private void BackButton_Click(object sender, RoutedEventArgs e)
{
Frame.GoBack();
}
}
}

View file

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WMstodon
{
@ -87,7 +83,7 @@ namespace WMstodon
public bool muted { get; set; }
public bool bookmarked { get; set; }
public string content { get; set; }
public object reblog { get; set; }
public Status reblog { get; set; }
public MApplication application { get; set; }
public Account account { get; set; }
public Attachment[] media_attachments { get; set; }
@ -96,6 +92,7 @@ namespace WMstodon
public object[] emojis { get; set; }
public object card { get; set; }
public object poll { get; set; }
public string additional { get; set; }
}
public class Feed

View file

@ -9,9 +9,25 @@
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<ListView x:Name="feedListView" Margin="0,0,0,60" ItemsSource="{x:Bind Statuses}" SelectionChanged="FeedListView_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:Status">
<Grid Width="Auto" Height="Auto" Padding="0,3,0,3" Margin="0,0,0,15">
<Image HorizontalAlignment="Left" Height="32" Margin="0,0,0,0" VerticalAlignment="Top" Width="32">
<Image.Source>
<BitmapImage UriSource="{x:Bind account.avatar_static}" />
</Image.Source>
</Image>
<TextBlock Text="{x:Bind account.display_name}" Margin="36,0,0,0" FontSize="12"/>
<TextBlock Text="{x:Bind account.acct}" Margin="36,15,0,0" FontSize="12" Foreground="#FF777777"/>
<TextBlock Text="{x:Bind content}" Margin="0,30,0,0" FontSize="15" TextWrapping="Wrap" Height="Auto"/>
<TextBlock Text="{x:Bind additional}" Margin="0,0,0,-15" FontSize="12" Foreground="#FF777777" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Grid Height="60" Margin="0" VerticalAlignment="Bottom">
<Image x:Name="myAvatar" HorizontalAlignment="Left" Height="40" Margin="10,0,0,0" VerticalAlignment="Center" Width="40"/>
<Image x:Name="AvatarImage" HorizontalAlignment="Left" Height="40" Margin="10,0,0,0" VerticalAlignment="Center" Width="40"/>
<TextBlock x:Name="DisplayNameTextBlock" HorizontalAlignment="Left" Margin="60,0,0,30" TextWrapping="Wrap" Text="Loading..." VerticalAlignment="Bottom"/>
<TextBlock x:Name="UsernameTextBlock" HorizontalAlignment="Left" Margin="60,0,0,15" TextWrapping="Wrap" Text="Loading..." VerticalAlignment="Bottom" FontSize="12" Foreground="#FF777777"/>
<Button x:Name="LogOutButton" Content="Log Out" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalAlignment="Center" Width="75" Click="LogOutButton_Click"/>

View file

@ -1,20 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
@ -24,6 +16,7 @@ namespace WMstodon
{
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
Account myAccount;
public ObservableCollection<Status> Statuses { get; } = new ObservableCollection<Status>();
public MainPage()
{
@ -40,9 +33,40 @@ namespace WMstodon
BitmapImage bitmap = new BitmapImage();
bitmap.UriSource = new Uri(myAccount.avatar_static);
myAvatar.Source = bitmap;
AvatarImage.Source = bitmap;
//await LoadFeed();
await LoadFeed();
}
private async Task LoadFeed()
{
string feedJSON = ($"{{\"statuses\": {(await HTTPUtils.GETAsync("/api/v1/timelines/home")).Value}}}");
Feed feed = new Feed();
feed = JsonConvert.DeserializeObject<Feed>(feedJSON);
foreach (Status s in feed.statuses)
{
Status status = s;
string usernameFull = $"@{status.account.username}@{status.url.Split('/')[2]}";
if (status.reblog != null)
{
usernameFull = $"@{status.reblog.account.username}@{status.reblog.url.Split('/')[2]}";
status = status.reblog;
status.additional += $"Reblogged by {s.account.display_name} | ";
}
status.content = Windows.Data.Html.HtmlUtilities.ConvertToText(status.content);
if (status.media_attachments.Length != 0)
status.additional += $"{status.media_attachments.Length} " + (status.media_attachments.Length == 1 ? "attachment" : "attachments") + " | ";
if (status.sensitive)
{
status.content = status.spoiler_text;
status.additional += "Tap to view more | ";
}
if (status.account.display_name == "")
status.account.display_name = status.account.username;
status.additional += $"{status.favourites_count} Favorites, {status.reblogs_count} Reblogs, {status.replies_count} Replies";
status.account.acct = usernameFull;
Statuses.Add(status);
}
}
private async void LogOutButton_Click(object sender, RoutedEventArgs e)
@ -63,5 +87,11 @@ namespace WMstodon
Frame.Navigate(typeof(SelectInstancePage), null);
}
}
private void FeedListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Status passedStatus = (Status)feedListView.SelectedItem;
Frame.Navigate(typeof(StatusPage), passedStatus.url);
}
}
}

34
WMstodon/StatusPage.xaml Normal file
View file

@ -0,0 +1,34 @@
<Page
x:Class="WMstodon.StatusPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WMstodon"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Button x:Name="BackButton" Content="Back" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="75" Click="BackButton_Click"/>
<Image x:Name="AvatarImage" HorizontalAlignment="Left" Height="40" Margin="10,47,0,0" VerticalAlignment="Top" Width="40"/>
<TextBlock x:Name="DisplayNameTextBlock" HorizontalAlignment="Left" Margin="60,47,0,0" TextWrapping="Wrap" Text="Loading..." VerticalAlignment="Top"/>
<TextBlock x:Name="UsernameTextBlock" HorizontalAlignment="Left" Margin="60,65,0,0" TextWrapping="Wrap" Text="Loading..." VerticalAlignment="Top" FontSize="12" Foreground="#FF777777"/>
<ScrollViewer Margin="10,95,10,122">
<Grid>
<TextBlock x:Name="ContentTextBlock" HorizontalAlignment="Left" Margin="3,3,0,0" TextWrapping="Wrap" Text="Loading..." VerticalAlignment="Top"/>
<GridView x:Name="AttachmentImageGrid" ItemsSource="{x:Bind Attachments}" Margin="5,28,5,0" VerticalAlignment="Top">
<GridView.ItemTemplate>
<DataTemplate x:DataType="local:Attachment">
<Grid>
<Image Source="{x:Bind preview_url}" Tapped="Image_Tapped" />
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Grid>
</ScrollViewer>
<Button x:Name="ReplyButton" Content="Reply (0)" HorizontalAlignment="Stretch" Margin="10,0,10,10" VerticalAlignment="Bottom" Click="ReplyButton_Click"/>
<Button x:Name="ReblogButton" Content="Reblog (0)" HorizontalAlignment="Stretch" Margin="10,0,10,47" VerticalAlignment="Bottom" Click="ReblogButton_Click"/>
<Button x:Name="FavoriteButton" Content="Favorite (0)" HorizontalAlignment="Stretch" Margin="10,0,10,84" VerticalAlignment="Bottom" Click="FavoriteButton_Click"/>
</Grid>
</Page>

110
WMstodon/StatusPage.xaml.cs Normal file
View file

@ -0,0 +1,110 @@
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using Newtonsoft.Json;
using Windows.Data.Html;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
namespace WMstodon
{
public sealed partial class StatusPage : Page
{
Status status = new Status();
public ObservableCollection<Attachment> Attachments { get; } = new ObservableCollection<Attachment>();
public StatusPage()
{
this.InitializeComponent();
}
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
string statusURL = e.Parameter.ToString();
string statusJSON =
(await HTTPUtils.GETAsync("https://" + statusURL.Split('/')[2] + "/api/v1/statuses/" + statusURL.Split('/').Last())).Value;
status = JsonConvert.DeserializeObject<Status>(statusJSON);
DisplayNameTextBlock.Text = status.account.display_name == "" ? status.account.username : status.account.display_name;
UsernameTextBlock.Text = $"@{status.account.username}@{status.url.Split('/')[2]}";
BitmapImage avatar = new BitmapImage();
avatar.UriSource = new Uri(status.account.avatar_static);
AvatarImage.Source = avatar;
ContentTextBlock.Text = HtmlUtilities.ConvertToText(status.content);
if (status.sensitive) ContentTextBlock.Text = status.spoiler_text + status.content;
foreach (Attachment a in status.media_attachments)
{
Attachments.Add(a);
}
ContentTextBlock.UpdateLayout();
AttachmentImageGrid.Margin = new Thickness(5, 8 + ContentTextBlock.ActualHeight, 5, 0);
FavoriteButton.Content = $"{(status.favourited ? "Unfavorite" : "Favorite")} ({status.favourites_count})";
ReblogButton.Content = $"{(status.reblogged ? "Unreblog" : "Reblog")} ({status.reblogs_count})";
ReplyButton.Content = $"Reply ({status.replies_count})";
}
private void BackButton_Click(object sender, RoutedEventArgs e)
{
Frame.GoBack();
}
private async void FavoriteButton_Click(object sender, RoutedEventArgs e)
{
if (!status.favourited)
{
await HTTPUtils.POSTAsync($"/api/v1/statuses/{status.id}/favourite", null);
}
else
{
await HTTPUtils.POSTAsync($"/api/v1/statuses/{status.id}/unfavourite", null);
}
FavoriteButton.Content = $"{(status.favourited ? "Unfavorite" : "Favorite")} ({status.favourites_count})";
}
private async void ReblogButton_Click(object sender, RoutedEventArgs e)
{
if (!status.reblogged)
{
await HTTPUtils.POSTAsync($"/api/v1/statuses/{status.id}/reblog", null);
}
else
{
await HTTPUtils.POSTAsync($"/api/v1/statuses/{status.id}/unreblog", null);
}
ReblogButton.Content = $"{(status.reblogged ? "Unreblog" : "Reblog")} ({status.reblogs_count})";
}
private void ReplyButton_Click(object sender, RoutedEventArgs e)
{
}
private void AttachmentImage_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
if (status.media_attachments[0].description != "")
{
ContentDialog confirmLogoutDialog = new ContentDialog
{
Title = "Image Description",
Content = status.media_attachments[0].description,
CloseButtonText = "Dismiss"
};
}
}
private void Image_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
Attachment passedAttachment = (Attachment)AttachmentImageGrid.SelectedItem;
Frame.Navigate(typeof(ImageViewerPage), passedAttachment);
}
}
}

View file

@ -120,6 +120,9 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="HTTPUtils.cs" />
<Compile Include="ImageViewerPage.xaml.cs">
<DependentUpon>ImageViewerPage.xaml</DependentUpon>
</Compile>
<Compile Include="JSONClasses.cs" />
<Compile Include="LoginPage.xaml.cs">
<DependentUpon>LoginPage.xaml</DependentUpon>
@ -131,6 +134,9 @@
<Compile Include="SelectInstancePage.xaml.cs">
<DependentUpon>SelectInstancePage.xaml</DependentUpon>
</Compile>
<Compile Include="StatusPage.xaml.cs">
<DependentUpon>StatusPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
@ -192,6 +198,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="ImageViewerPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="LoginPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -204,6 +214,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="StatusPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">