diff --git a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml b/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml
index c773b8d..bc6b75d 100644
--- a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml
+++ b/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml
@@ -4,9 +4,9 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="MatrixRoomUtils.Desktop.Components.NavigationStack">
- <DockPanel x:Name="dock">
- <StackPanel x:Name="navPanel"></StackPanel>
- <UserControl x:Name="content"></UserControl>
- </DockPanel>
-
-</UserControl>
+ <StackPanel x:Name="dock">
+ <Label>NagivationStack</Label>
+ <StackPanel x:Name="navPanel" Orientation="Horizontal"></StackPanel>
+ <ContentControl x:Name="content"></ContentControl>
+ </StackPanel>
+</UserControl>
\ No newline at end of file
diff --git a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs b/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs
index d6343e2..92c617b 100644
--- a/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs
+++ b/MatrixRoomUtils.Desktop/Components/NavigationStack.axaml.cs
@@ -1,4 +1,5 @@
using Avalonia.Controls;
+using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
namespace MatrixRoomUtils.Desktop.Components;
@@ -8,12 +9,24 @@ public partial class NavigationStack : UserControl {
InitializeComponent();
}
- private void InitializeComponent() {
- AvaloniaXamlLoader.Load(this);
+ // private void InitializeComponent() {
+ // AvaloniaXamlLoader.Load(this);
+ // buildView();
+ // }
+
+ protected override void OnLoaded(RoutedEventArgs e) {
+ base.OnLoaded(e);
buildView();
}
-
+
private void buildView() {
+ if (navPanel is null) {
+ Console.WriteLine("NavigationStack buildView called while navpanel is null!");
+ // await Task.Delay(100);
+ // if (navPanel is null)
+ // await buildView();
+ // else Console.WriteLine("navpanel is not null!");
+ }
navPanel.Children.Clear();
foreach (var item in _stack) {
Button btn = new() {
@@ -25,7 +38,7 @@ public partial class NavigationStack : UserControl {
};
navPanel.Children.Add(btn);
}
- content = Current?.View ?? new UserControl();
+ content.Content = Current?.View ?? new UserControl();
}
@@ -44,13 +57,16 @@ public partial class NavigationStack : UserControl {
Name = name,
View = view
});
+ buildView();
}
public void Pop() {
_stack.RemoveAt(_stack.Count - 1);
+ buildView();
}
public void PopTo(int index) {
_stack.RemoveRange(index, _stack.Count - index);
+ buildView();
}
}
diff --git a/MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml b/MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml
new file mode 100644
index 0000000..0e43d99
--- /dev/null
+++ b/MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml
@@ -0,0 +1,21 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:components="clr-namespace:MatrixRoomUtils.Desktop.Components.Pages"
+ xmlns:components1="clr-namespace:MatrixRoomUtils.Desktop.Components"
+ xmlns:abstractions="clr-namespace:MatrixRoomUtils.Abstractions;assembly=MatrixRoomUtils.Abstractions"
+
+ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+ x:Class="MatrixRoomUtils.Desktop.Components.Pages.RoomList"
+ x:DataType="components:RoomList"
+ DataContext="{Binding $self}"
+ >
+ <ListBox ItemsSource="{Binding Rooms}">
+ <ListBox.ItemTemplate>
+ <DataTemplate DataType="abstractions:RoomInfo">
+ <components1:RoomListEntry Room="{Binding Path=.}"/>
+ </DataTemplate>
+ </ListBox.ItemTemplate>
+ </ListBox>
+</UserControl>
diff --git a/MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml.cs b/MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml.cs
new file mode 100644
index 0000000..53c3063
--- /dev/null
+++ b/MatrixRoomUtils.Desktop/Components/Pages/RoomList.axaml.cs
@@ -0,0 +1,15 @@
+using System.Collections.ObjectModel;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using MatrixRoomUtils.Abstractions;
+
+namespace MatrixRoomUtils.Desktop.Components.Pages;
+
+public partial class RoomList : UserControl {
+ private ObservableCollection<RoomInfo> Rooms { get; set; } = new();
+
+ public RoomList() {
+ InitializeComponent();
+ }
+}
\ No newline at end of file
diff --git a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml
index 09fe52b..db22ccc 100644
--- a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml
+++ b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml
@@ -2,10 +2,15 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:components="clr-namespace:MatrixRoomUtils.Desktop.Components"
mc:Ignorable="d" d:DesignWidth="250" d:DesignHeight="32"
- x:Class="MatrixRoomUtils.Desktop.Components.RoomListEntry">
+ x:Class="MatrixRoomUtils.Desktop.Components.RoomListEntry"
+
+ x:DataType="components:RoomListEntry"
+ DataContext="{Binding $self}"
+ >
<StackPanel Orientation="Horizontal">
<Image MaxWidth="64" x:Name="RoomIcon"></Image>
- <Label x:Name="RoomName"></Label>
+ <Label x:Name="RoomName" Content="{Binding Room.RoomName}"></Label>
</StackPanel>
</UserControl>
diff --git a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs
index 69458aa..73115a2 100644
--- a/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs
+++ b/MatrixRoomUtils.Desktop/Components/RoomListEntry.axaml.cs
@@ -7,29 +7,28 @@ using LibMatrix.EventTypes.Spec.State.RoomInfo;
using LibMatrix.Helpers;
using LibMatrix.Interfaces.Services;
using LibMatrix.Services;
+using MatrixRoomUtils.Abstractions;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
namespace MatrixRoomUtils.Desktop.Components;
public partial class RoomListEntry : UserControl {
- private readonly IServiceScopeFactory _serviceScopeFactory;
- private readonly RoomInfo _roomInfo;
+ public RoomInfo Room { get; set; }
- public RoomListEntry(IServiceScopeFactory serviceScopeFactory, RoomInfo roomInfo) {
- _serviceScopeFactory = serviceScopeFactory;
- _roomInfo = roomInfo;
+ public RoomListEntry() {
InitializeComponent();
}
protected override void OnLoaded(RoutedEventArgs e) {
base.OnLoaded(e);
- RoomName.Content = _roomInfo.Room.RoomId;
+ RoomName.Content = Room.Room.RoomId;
Task.WhenAll(GetRoomName(), GetRoomIcon());
}
private async Task GetRoomName() {
try {
- var nameEvent = await _roomInfo.GetStateEvent("m.room.name");
+ var nameEvent = await Room.GetStateEvent("m.room.name");
if (nameEvent?.TypedContent is RoomNameEventContent nameData)
RoomName.Content = nameData.Name;
}
@@ -41,18 +40,22 @@ public partial class RoomListEntry : UserControl {
private async Task GetRoomIcon() {
try {
- var avatarEvent = await _roomInfo.GetStateEvent("m.room.avatar");
+ using var hc = new HttpClient();
+ var avatarEvent = await Room.GetStateEvent("m.room.avatar");
if (avatarEvent?.TypedContent is RoomAvatarEventContent avatarData) {
var mxcUrl = avatarData.Url;
- await using var svc = _serviceScopeFactory.CreateAsyncScope();
- var hs = await svc.ServiceProvider.GetService<MRUStorageWrapper>()?.GetCurrentSessionOrPrompt()!;
- var hsResolver = svc.ServiceProvider.GetService<HomeserverResolverService>();
- var storage = svc.ServiceProvider.GetService<TieredStorageService>()?.CacheStorageProvider;
- var resolvedUrl = await hsResolver.ResolveMediaUri(hs.ServerName, mxcUrl);
+ var resolvedUrl = await Room.Room.GetResolvedRoomAvatarUrlAsync();
+
+ // await using var svc = _serviceScopeFactory.CreateAsyncScope();
+ // var hs = await svc.ServiceProvider.GetService<MRUStorageWrapper>()?.GetCurrentSessionOrPrompt()!;
+ // var hsResolver = svc.ServiceProvider.GetService<HomeserverResolverService>();
+ // var storage = svc.ServiceProvider.GetService<TieredStorageService>()?.CacheStorageProvider;
+ // var resolvedUrl = await hsResolver.ResolveMediaUri(hs.ServerName, mxcUrl);
+ var storage = new FileStorageProvider("cache");
var storageKey = $"media/{mxcUrl.Replace("mxc://", "").Replace("/", ".")}";
try {
if (!await storage.ObjectExistsAsync(storageKey))
- await storage.SaveStreamAsync(storageKey, await hs.ClientHttpClient.GetStreamAsync(resolvedUrl));
+ await storage.SaveStreamAsync(storageKey, await hc.GetStreamAsync(resolvedUrl));
RoomIcon.Source = new Bitmap(await storage.LoadStreamAsync(storageKey) ?? throw new NullReferenceException());
}
|