Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kfrancis committed May 23, 2023
1 parent 5e01f0c commit 47d7968
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/NuSocial/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
Route="start" />

<FlyoutItem Title="{loc:Translate Profile}" Icon="{x:Static fa:FontAwesomeIcons.User}">
<ShellContent ContentTemplate="{DataTemplate views:MainView}" Route="profile" />
<ShellContent ContentTemplate="{DataTemplate views:ProfileView}" Route="profile" />
</FlyoutItem>

<FlyoutItem Title="{loc:Translate Home}" Icon="{x:Static fa:FontAwesomeIcons.House}">
<ShellContent ContentTemplate="{DataTemplate views:MainView}" Route="home" />
</FlyoutItem>

<FlyoutItem Title="{loc:Translate Relays}" Icon="{x:Static fa:FontAwesomeIcons.Globe}">
Expand Down
10 changes: 10 additions & 0 deletions src/NuSocial/Controls/ProfileImage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentView
x:Class="NuSocial.Controls.ProfileImage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Name="root">
<Grid>
<Image IsAnimationPlaying="{Binding IsAnimationPlaying, Source={x:Reference root}}" Source="{Binding Aspect, Source={x:Reference root}}" />
</Grid>
</ContentView>
128 changes: 128 additions & 0 deletions src/NuSocial/Controls/ProfileImage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using BindableProps;

namespace NuSocial.Controls;

public partial class ProfileImage : ContentView
{
[BindableProp]
private Aspect _aspect = Aspect.Fill;

[BindableProp(PropertyChangedDelegate = nameof(UpdateSize))]
private double _borderSize;

[BindableProp(PropertyChangedDelegate = nameof(UpdateIsCircularImage))]
private double _cornerRadius;

[BindableProp(PropertyChangedDelegate = nameof(UpdateIsCircularImage))]
private bool _isCircular = false;

private double _lastCornerRadius;

[BindableProp(PropertyChangedDelegate = nameof(UpdateSize))]
private double _size = 50.0;

[BindableProp(PropertyChangedDelegate = nameof(UpdateSource))]
private string _source = string.Empty;

[BindableProp]
private bool _isAnimationPlaying = false;

public ProfileImage()
{
InitializeComponent();

//UpdateBadgeType();

UpdateSize(this);

//UpdateStatusIndicatorPosition();
}

private static void UpdateBorder(BindableObject bindable)
{
if (bindable is ProfileImage control)
{
if (control.Size > 0)
{
if (control.BorderSize == 0)
{
//borderBoxView.IsVisible = false;
}
else
{
var cornerRadius = control.CornerRadius + control.BorderSize;
var heightRequest = control.Size + (control.BorderSize * 2);
var widthRequest = control.Size + (control.BorderSize * 2);

//borderBoxView.IsVisible = true;

//if (UXDivers.Grial.Effects.GetCornerRadius(borderBoxView) != cornerRadius || borderBoxView.HeightRequest != heightRequest || borderBoxView.WidthRequest != widthRequest)
//{
// borderBoxView.HeightRequest = heightRequest;
// borderBoxView.WidthRequest = widthRequest;
// UXDivers.Grial.Effects.SetCornerRadius(borderBoxView, cornerRadius);
//}
}
}
}
}

private static void UpdateSource(BindableObject bindable, object? oldValue = null, object? newValue = null)
{
if (bindable is ProfileImage control)
{
if (newValue is string newStr && !string.IsNullOrEmpty(newStr))
{
if (newStr.EndsWith(".gif", StringComparison.OrdinalIgnoreCase))
{
control.IsAnimationPlaying = true;
}
else
{
control.IsAnimationPlaying = false;
}
}
}
}

private static void UpdateCornerRadius(BindableObject bindable, object? oldValue = null, object? newValue = null)
{
if (bindable is ProfileImage control)
{
if (control.IsCircular && control.CornerRadius != control.Size / 2)
{
control.CornerRadius = control.Size / 2;
}

UpdateBorder(bindable);
}
}

private static void UpdateIsCircularImage(BindableObject bindable, object? oldValue = null, object? newValue = null)
{
if (bindable is ProfileImage control)
{
if (control.IsCircular)
{
control._lastCornerRadius = control.CornerRadius;
control.CornerRadius = control.Size / 2;
}
else
{
control.CornerRadius = control._lastCornerRadius;
control._lastCornerRadius = 0;
}
}
}

private static void UpdateSize(BindableObject bindable, object? oldValue = null, object? newValue = null)
{
if (bindable is ProfileImage control)
{
control.HeightRequest = control.Size + (control.BorderSize * 2);
control.WidthRequest = control.Size + (control.BorderSize * 2);

UpdateCornerRadius(bindable);
}
}
}
6 changes: 6 additions & 0 deletions src/NuSocial/Messages/NostrMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public NostrUserChangedMessage((string pubKey, string privKey) value) : base(val
{
}
}
public class NostrStateChangeMessage : ValueChangedMessage<bool?>
{
public NostrStateChangeMessage(bool? value = null) : base(value)
{
}
}

public class NostrPostMessage : ValueChangedMessage<NostrEvent?>
{
Expand Down
47 changes: 46 additions & 1 deletion src/NuSocial/Models/User.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nostr.Client.Keys;
using NBitcoin;
using Nostr.Client.Keys;
using SQLite;
using System.Text.Json.Serialization;

Expand All @@ -12,6 +13,50 @@ public class User
[Ignore]
public NostrPrivateKey? PrivateKey { get; set; }

//private TaprootKeyPair? _taprootKey;

//[Ignore]
//public TaprootKeyPair TaprootKeyPair
//{
// get
// {
// if (_taprootKey == null)
// {
// var key = Key.Parse(TaprootBech32m, Network.Main);
// var merkleRoot = RandomUtils.GetUInt256();
// _taprootKey = TaprootKeyPair.CreateTaprootPair(key, merkleRoot);
// }

// return _taprootKey;
// }
// set
// {
// _taprootKey = value;
// }
//}

//private string _taprootBech32m = string.Empty;
//public string TaprootBech32m
//{
// get
// {
// if (TaprootKeyPair != null)
// {
// return TaprootKeyPair.PubKey.GetAddress(Network.Main).PubKey.ToString();
// }
// else
// {
// return _taprootBech32m;
// }
// }
// set
// {
// _taprootBech32m = value;
// }
//}

public string Taproot { get; set; } = string.Empty;

public string? ProfileImageBlurHash { get; set; }

[PrimaryKey]
Expand Down
6 changes: 6 additions & 0 deletions src/NuSocial/NuSocial.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@
</ItemGroup>

<ItemGroup>
<Compile Update="Controls\ProfileImage.xaml.cs">
<DependentUpon>ProfileImage.xaml</DependentUpon>
</Compile>
<Compile Update="Views\MessagesView.xaml.cs">
<DependentUpon>MessagesView.xaml</DependentUpon>
</Compile>
Expand All @@ -181,6 +184,9 @@
</ItemGroup>

<ItemGroup>
<MauiXaml Update="Controls\ProfileImage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Core\View\LoadingIndicatorPopup.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
Expand Down
5 changes: 3 additions & 2 deletions src/NuSocial/Services/LocalStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,10 @@ private async Task DropAndReset<T>(Action? reset = null)
where T : new()
{
ArgumentNullException.ThrowIfNull(_database);
await _lock.WaitAsync().ConfigureAwait(false);

try
{
{
await _lock.WaitAsync().ConfigureAwait(false);
var entityType = typeof(T);
var entityProperties = entityType.GetProperties();
var needsReset = false;
Expand Down
8 changes: 8 additions & 0 deletions src/NuSocial/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,22 @@ public MainViewModel(IDialogService dialogService,
public override Task OnFirstAppear()
{
WeakReferenceMessenger.Default.Send<ResetNavMessage>(new());

WeakReferenceMessenger.Default.Register<NostrUserChangedMessage>(this, (r, m) =>
{
UpdateUser();
});

WeakReferenceMessenger.Default.Register<NostrPostMessage>(this, (r, m) =>
{
ReceivePost(m.Value);
});

WeakReferenceMessenger.Default.Register<NostrStateChangeMessage>(this, (r, m) =>
{
// Should we receive the state change message, cancel the nostr token to let other tasks continue.
_cts?.Cancel();
});
return Task.CompletedTask;
}

Expand Down
12 changes: 11 additions & 1 deletion src/NuSocial/ViewModels/ProfileViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using NuSocial.Core.ViewModel;
using CommunityToolkit.Mvvm.Messaging;
using NuSocial.Core.ViewModel;
using NuSocial.Messages;
using Volo.Abp.DependencyInjection;

namespace NuSocial.ViewModels;
Expand All @@ -8,4 +10,12 @@ public partial class ProfileViewModel : BaseViewModel, ITransientDependency
public ProfileViewModel(IDialogService dialogService, INavigationService navigationService) : base(dialogService, navigationService)
{
}

public override Task InitializeAsync()
{
// We need to cancel any work currently handling nostr information, so fire that message.
WeakReferenceMessenger.Default.Send<NostrStateChangeMessage>(new(false));

return Task.CompletedTask;
}
}
7 changes: 6 additions & 1 deletion src/NuSocial/ViewModels/RelaysViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using NuSocial.Core.ViewModel;
using CommunityToolkit.Mvvm.Messaging;
using NuSocial.Core.ViewModel;
using NuSocial.Messages;
using Volo.Abp.DependencyInjection;

namespace NuSocial.ViewModels;
Expand Down Expand Up @@ -35,6 +37,9 @@ public RelaysViewModel(IDialogService dialogService,

public override async Task InitializeAsync()
{
// We need to cancel any work currently handling nostr information, so fire that message.
WeakReferenceMessenger.Default.Send<NostrStateChangeMessage>(new(false));

Relays = await _db.GetRelaysAsync();
SetOptions(ViewType);
}
Expand Down
7 changes: 5 additions & 2 deletions src/NuSocial/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:converters="clr-namespace:NuSocial.Converters"
xmlns:fa="clr-namespace:FontAwesome"
xmlns:loc="clr-namespace:NuSocial.Helpers"
xmlns:local="clr-namespace:NuSocial.Controls"
xmlns:models="clr-namespace:NuSocial.Models"
xmlns:viewModels="clr-namespace:NuSocial.ViewModels"
Title="{Binding Title}"
Expand Down Expand Up @@ -37,17 +38,19 @@
<TapGestureRecognizer Command="{Binding Source={RelativeSource AncestorType={x:Type viewModels:MainViewModel}}, Path=GoToDetailsCommand}" CommandParameter="{Binding .}" />
</Grid.GestureRecognizers>
<Image
Grid.Row="1"
Grid.RowSpan="2"
Margin="0,0,10,0"
Margin="0,5,10,0"
Aspect="AspectFill"
HeightRequest="60"
IsAnimationPlaying="True"
VerticalOptions="Start"
WidthRequest="60">
<Image.Source>
<UriImageSource CacheValidity="00:00:15:00" Uri="{Binding Contact.Picture.Url}" />
</Image.Source>
<Image.Clip>
<RoundRectangleGeometry CornerRadius="15" Rect="0,0,60,60" />
<RoundRectangleGeometry CornerRadius="{StaticResource BaseButtonCornerRadius}" Rect="0,0,60,60" />
</Image.Clip>
</Image>
<Grid Grid.Column="1" ColumnDefinitions="Auto,Auto,*">
Expand Down
4 changes: 3 additions & 1 deletion src/NuSocial/Views/RelaysView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public RelaysView(RelaysViewModel vm, IStringLocalizer<NuSocialResource> loc) :
InitializeComponent();
}

public RelaysView() : this(Ioc.Default.GetRequiredService<RelaysViewModel>(), Ioc.Default.GetRequiredService<IStringLocalizer<NuSocialResource>>())
public RelaysView() :
this(Ioc.Default.GetRequiredService<RelaysViewModel>(),
Ioc.Default.GetRequiredService<IStringLocalizer<NuSocialResource>>())
{
}
}

0 comments on commit 47d7968

Please sign in to comment.