Commit cd9cc8c0 authored by HankG's avatar HankG

Add initial people view list XAML, VM, and Person VM, w/simple defaults

parent e2cb7680
......@@ -10,6 +10,7 @@
<NoWarn>1701;1702;1303</NoWarn>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models" />
<Folder Include="Models\" />
<Compile Update="**\*.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
......@@ -18,7 +19,6 @@
<SubType>Designer</SubType>
</AvaloniaResource>
<AvaloniaResource Include="Assets\**" />
<Folder Include="Services" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.9.0-preview7" />
......
using System;
using System.IO;
using Avalonia.Media.Imaging;
using MySocialPortalLib.Service;
namespace MySocialPortalDesktop.Services
{
public static class DefaultValueService
{
private const string DefaultProfileImageName = "default_profile_icon.png";
private static Lazy<Bitmap> DefaultProfileImageLazy = new Lazy<Bitmap>(BuildDefaultProfileImage);
public static Bitmap DefaultProfileImage = DefaultProfileImageLazy.Value;
private static Bitmap BuildDefaultProfileImage()
{
try
{
string directory = DirectoryServices.Instance.ProfileImagesDirectory();
return new Bitmap(Path.Combine(directory, DefaultProfileImageName));
}
catch
{
return null;
}
}
}
}
\ No newline at end of file
......@@ -25,11 +25,14 @@ namespace MySocialPortalDesktop.ViewModels
public ObservableCollection<PostViewModel> PostViewModels { get; }
public PeopleListViewModel PeopleListViewModel { get; }
public MainWindowViewModel()
{
PostViewModels = new ObservableCollection<PostViewModel>();
TwitterConnector = SocialMediaConnectorFactory.GetNewTwitterConnector();
ImportedPosts = new List<Post>();
PeopleListViewModel = new PeopleListViewModel();
LoadInitialPosts();
}
......
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using MySocialPortalDesktop.Factory;
namespace MySocialPortalDesktop.ViewModels
{
public class PeopleListViewModel
{
public ObservableCollection<PersonViewModel> People { get; }
public PeopleListViewModel()
{
var allPeople = RepositoryFactory.Instance.MainPeopleRepository.ListAll();
var peopleVms = allPeople?.Select(p => new PersonViewModel(p)) ?? new List<PersonViewModel>();
People = new ObservableCollection<PersonViewModel>(peopleVms);
}
}
}
\ No newline at end of file
using System.Linq;
using Avalonia.Media.Imaging;
using MySocialPortalDesktop.Services;
using MySocialPortalLib.Model;
using ReactiveUI;
namespace MySocialPortalDesktop.ViewModels
{
public class PersonViewModel : ViewModelBase
{
private string _displayName;
private string _displayUsername;
private Bitmap _displayIcon;
private Person _person;
public string DisplayName
{
get => _displayName;
set => this.RaiseAndSetIfChanged(ref _displayName, value);
}
public string DisplayUsername
{
get => _displayUsername;
set => this.RaiseAndSetIfChanged(ref _displayUsername, value);
}
public Bitmap DisplayIcon
{
get => _displayIcon;
set => this.RaiseAndSetIfChanged(ref _displayIcon, value);
}
public Person Person
{
get => _person;
set
{
this.RaiseAndSetIfChanged(ref _person, value);
UpdatePersonData();
}
}
public PersonViewModel(Person person)
{
Person = person;
}
private void UpdatePersonData()
{
DisplayName = string.IsNullOrWhiteSpace(Person.Name) ? "" : Person.Name;
var username = Person?.SocialMediaAccounts?.Values?.First()?.ProfileId ?? "N/A";
DisplayUsername = username;
DisplayIcon = DefaultValueService.DefaultProfileImage;
}
}
}
\ No newline at end of file
......@@ -8,14 +8,12 @@ using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using LinqToTwitter.Net;
using MySocialPortalDesktop.Services;
namespace MySocialPortalDesktop.ViewModels
{
public class PostViewModel : ViewModelBase
{
private const string DefaultProfileImageName = "default_profile_icon.png";
private static Bitmap DefaultImage = BuildDefaultProfileImage();
private string _body;
private DateTime _date;
private string _title;
......@@ -66,7 +64,7 @@ namespace MySocialPortalDesktop.ViewModels
Post = post;
Title = "Unknown Author";
Body = post.Body;
ProfileImage = DefaultImage;
ProfileImage = DefaultValueService.DefaultProfileImage;
Date = post.PostDateTime.LocalDateTime;
var author = RepositoryFactory.Instance.MainPeopleRepository.FindById(post.UserId);
......@@ -126,18 +124,5 @@ namespace MySocialPortalDesktop.ViewModels
Console.WriteLine(e);
}
}
private static Bitmap BuildDefaultProfileImage()
{
try
{
string directory = DirectoryServices.Instance.ProfileImagesDirectory();
return new Bitmap(Path.Combine(directory, DefaultProfileImageName));
}
catch
{
return null;
}
}
}
}
\ No newline at end of file
......@@ -4,8 +4,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="clr-namespace:MySocialPortalDesktop.Views;assembly=MySocialPortalDesktop"
mc:Ignorable="d" d:DesignWidth="450" d:DesignHeight="450"
Width="450" Height="800"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600"
Width="800" Height="600"
x:Class="MySocialPortalDesktop.Views.MainWindow"
Icon="/Assets/avalonia-logo.ico"
Title="MySocialPortalDesktop">
......@@ -22,16 +22,29 @@
<MenuItem Header="Exit" Command="{Binding DoExit}"/>
</MenuItem>
</Menu>
<Grid RowDefinitions="Auto,*,Auto" ColumnDefinitions="*">
<Button Grid.Row="0" Grid.Column="0" Width="100" Content="Load Newer" Command="{Binding LoadNewer}"/>
<ListBox Grid.Row="1" Grid.Column="0" Items="{Binding PostViewModels}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<views:PostView Name="PostsView" DataContext="{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Grid.Row="2" Grid.Column="0" Width="100" Content="Load Older" Command="{Binding LoadOlder}"/>
<Grid Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="300" Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<views:PeopleListView Grid.Row="0" Grid.Column="0" DataContext="{Binding PeopleListViewModel}"/>
<GridSplitter Grid.Row="0" Grid.Column="1"/>
<Grid Grid.Row="0" Grid.Column="2" Name="TimelineGrid" RowDefinitions="Auto,*,Auto" ColumnDefinitions="*">
<Button Grid.Row="0" Grid.Column="0" Width="100" Content="Load Newer" Command="{Binding LoadNewer}"/>
<ListBox Grid.Row="1" Grid.Column="0" Items="{Binding PostViewModels}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<views:PostView Name="PostsView" DataContext="{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Grid.Row="2" Grid.Column="0" Width="100" Content="Load Older" Command="{Binding LoadOlder}"/>
</Grid>
</Grid>
</DockPanel>
</Window>
<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:vm="clr-namespace:MySocialPortalDesktop.ViewModels;assembly=MySocialPortalDesktop"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="MySocialPortalDesktop.Views.PeopleListView">
<UserControl.Styles>
<Style Selector="TextBlock.RealName">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="14"/>
</Style>
<Style Selector="TextBlock.Username">
<Setter Property="FontStyle" Value="Italic"/>
<Setter Property="FontSize" Value="12"/>
</Style>
</UserControl.Styles>
<Grid RowDefinitions="Auto,*" ColumnDefinitions="*">
<ListBox Grid.Row="1" Grid.Column="0" Name="FriendsList" Items="{Binding People}">
<ListBox.DataTemplates>
<DataTemplate DataType="vm:PersonViewModel">
<Grid RowDefinitions="Auto, Auto" ColumnDefinitions="Auto, Auto">
<Image Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Margin="5" Source="{Binding DisplayIcon}" Width="50" Height="50"/>
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding DisplayName}" Classes="RealName"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding DisplayUsername}" Classes="Username"/>
</Grid>
</DataTemplate>
</ListBox.DataTemplates>
</ListBox>
</Grid>
</UserControl>
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace MySocialPortalDesktop.Views
{
public class PeopleListView : UserControl
{
public PeopleListView()
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment