Skip to content

Instantly share code, notes, and snippets.

View MartinZikmund's full-sized avatar
⌨️
Coding

Martin Zikmund MartinZikmund

⌨️
Coding
View GitHub Profile
public partial class MainViewModel : PageViewModel
{
private readonly IBlueskyService _blueskyService;
public MainViewModel(INavigationService navigationService, IBlueskyService blueskyService) : base(navigationService)
{
_blueskyService = blueskyService;
}
[ObservableProperty]
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListView SelectionMode="None" ItemsSource="{x:Bind ViewModel.Feed, Mode=OneWay}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="vm:FeedItemViewModel">
<StackPanel CornerRadius="8" Margin="8,4,8,4" Padding="8" Spacing="8" Background="{ThemeResource ButtonBackground}">
<TextBlock Text="{x:Bind Text}" TextWrapping="WrapWholeWords" />
using Birdsky.Core.Services.Bluesky;
using Birdsky.Services.Navigation;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MZikmund.Toolkit.WinUI.Infrastructure;
namespace Birdsky.Core.ViewModels;
public partial class LoginViewModel : PageViewModel
{
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
ViewModel!.AppPassword = ((PasswordBox)sender).Password;
}
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Spacing="10">
<TextBox Header="Handle" Text="{Binding Handle, Mode=TwoWay}" Width="300" />
<PasswordBox Header="App Password" Width="300" PasswordChanged="PasswordBox_PasswordChanged" />
<Button Content="Login" Command="{Binding LoginCommand}" Width="300" />
</StackPanel>
public class CredentialsService : ICredentialsService
{
private const string AppName = "MyBlueskyClient";
private readonly PasswordVault _passwordVault;
private readonly ApplicationDataContainer _localSettings = ApplicationData.Current.LocalSettings;
public CredentialsService()
{
if (ApiInformation.IsMethodPresent(typeof(PasswordCredential).FullName, "Retrieve"))
public class BlueskyService : IBlueskyService
{
private readonly ICredentialsService _credentialsService;
private ATProtocol _client;
private Session? _session;
public BlueskyService(ICredentialsService credentialsService)
{
_client = new ATProtocolBuilder().EnableAutoRenewSession(true).Build();
_credentialsService = credentialsService;
await _blueskyService.PostAsync(Text);
public record class FeedItemViewModel(string Author, string Text, long Likes, long Reposts, long Replies);
var items = timelineData.Feed
.Select(f => f.Post)
.Where(p => p is not null)
.Select(post => new FeedItemViewModel(
post!.Author?.DisplayName ?? "",
(post.Record as Post)?.Text ?? "",
post.LikeCount ?? 0,
post.RepostCount ?? 0,
var timeline = await client.GetTimelineAsync();
if (timeline?.AsT0 is { Feed: { } } timelineData)
{
var posts = timelineData.Feed;
// ...
}