Merge branch 'vnext' of github.com:pazof/yavsc into vnext

vnext
Paul Schneider 8 years ago
commit 6e6ba1e6ea
19 changed files with 297 additions and 183 deletions

@ -25,6 +25,7 @@ namespace BookAStar
using ViewModels.UserProfile; using ViewModels.UserProfile;
using Pages.UserProfile; using Pages.UserProfile;
using ViewModels.EstimateAndBilling; using ViewModels.EstimateAndBilling;
using System.Net;
public partial class App : Application // superclass new in 1.3 public partial class App : Application // superclass new in 1.3
{ {
@ -109,7 +110,7 @@ namespace BookAStar
BindingContext = page.BindingContext BindingContext = page.BindingContext
}); });
} }
DataManager.Current.AppState.SaveCollection(); DataManager.Current.AppState.SaveEntity();
} }
// called on app startup, after OnStartup, not on rotation // called on app startup, after OnStartup, not on rotation
@ -124,7 +125,7 @@ namespace BookAStar
pageType, true, pageState.BindingContext); pageType, true, pageState.BindingContext);
} }
DataManager.Current.AppState.Clear(); DataManager.Current.AppState.Clear();
DataManager.Current.AppState.SaveCollection(); DataManager.Current.AppState.SaveEntity();
} }
// FIXME Not called? // FIXME Not called?
@ -206,6 +207,7 @@ namespace BookAStar
masterDetail.Detail = new NavigationPage(home); masterDetail.Detail = new NavigationPage(home);
ToolbarItem tiSetts = new ToolbarItem() ToolbarItem tiSetts = new ToolbarItem()
{ {
// FIXME what for? Priority = 0,
Text = "Paramètres", Text = "Paramètres",
Icon = "ic_corp_icon.png", Icon = "ic_corp_icon.png",
Command = new Command( Command = new Command(
@ -290,7 +292,19 @@ namespace BookAStar
// Start the Hub connection // Start the Hub connection
public async void StartHubConnection () public async void StartHubConnection ()
{ {
await chatHubConnection.Start(); try
{
await chatHubConnection.Start();
}
catch (WebException webex )
{
// TODO use webex, set this cx down status somewhere,
// & display it & maybe try again later.
}
catch (Exception ex)
{
// TODO use ex
}
} }
public void SetupHubConnection() public void SetupHubConnection()

@ -61,6 +61,9 @@
<Compile Include="Pages\UserProfile\UserFiles.xaml.cs"> <Compile Include="Pages\UserProfile\UserFiles.xaml.cs">
<DependentUpon>UserFiles.xaml</DependentUpon> <DependentUpon>UserFiles.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Pages\UserProfile\UserProfilePage.xaml.cs">
<DependentUpon>UserProfilePage.xaml</DependentUpon>
</Compile>
<Compile Include="Settings\ChatSettings.cs" /> <Compile Include="Settings\ChatSettings.cs" />
<Compile Include="ViewModels\EditingViewModel.cs" /> <Compile Include="ViewModels\EditingViewModel.cs" />
<Compile Include="Pages\DocSigning.xaml.cs"> <Compile Include="Pages\DocSigning.xaml.cs">
@ -78,7 +81,6 @@
<Compile Include="Extensions\ImageResourceExtension.cs" /> <Compile Include="Extensions\ImageResourceExtension.cs" />
<Compile Include="Factories\ViewFactory.cs" /> <Compile Include="Factories\ViewFactory.cs" />
<Compile Include="Data\DataManager.cs" /> <Compile Include="Data\DataManager.cs" />
<Compile Include="Helpers\ObservableString.cs" />
<Compile Include="Interfaces\ILocalEntity.cs" /> <Compile Include="Interfaces\ILocalEntity.cs" />
<Compile Include="Data\LocaLEntity.cs" /> <Compile Include="Data\LocaLEntity.cs" />
<Compile Include="Helpers\NotIdentifiedException.cs" /> <Compile Include="Helpers\NotIdentifiedException.cs" />
@ -422,6 +424,12 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Pages\UserProfile\UserProfilePage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Import Project="..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" /> <Import Project="..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

@ -7,6 +7,7 @@
using Model.Social.Messaging; using Model.Social.Messaging;
using Model.FileSystem; using Model.FileSystem;
using ViewModels.EstimateAndBilling; using ViewModels.EstimateAndBilling;
using NonCrUD;
public class DataManager public class DataManager
{ {
@ -14,7 +15,7 @@
public RemoteEntityRO<BookQueryData, long> BookQueries { get; set; } public RemoteEntityRO<BookQueryData, long> BookQueries { get; set; }
public RemoteEntity<Estimate, long> Estimates { get; set; } public RemoteEntity<Estimate, long> Estimates { get; set; }
public RemoteEntity<Blog, long> Blogspot { get; set; } public RemoteEntity<Blog, long> Blogspot { get; set; }
internal RemoteEntity<UserDirectoryInfo, string> RemoteFiles { get; set; } internal RemoteFilesEntity RemoteFiles { get; set; }
public LocalEntity<ClientProviderInfo,string> Contacts { get; set; } public LocalEntity<ClientProviderInfo,string> Contacts { get; set; }
internal LocalEntity<PageState, int> AppState { get; set; } internal LocalEntity<PageState, int> AppState { get; set; }
@ -48,7 +49,7 @@
EstimationCache = new LocalEntity<EditEstimateViewModel, long>(e => e.Query.Id); EstimationCache = new LocalEntity<EditEstimateViewModel, long>(e => e.Query.Id);
EstimateLinesTemplates = new LocalEntity<BillingLine, string>(l => l.Description); EstimateLinesTemplates = new LocalEntity<BillingLine, string>(l => l.Description);
PrivateMessages = new LocalEntity<ChatMessage, int>(m=> m.GetHashCode()); PrivateMessages = new LocalEntity<ChatMessage, int>(m=> m.GetHashCode());
RemoteFiles = new RemoteEntity<UserDirectoryInfo, string> ("fs", d => d.SubPath); RemoteFiles = new RemoteFilesEntity ();
PrivateMessages.Load(); PrivateMessages.Load();
BookQueries.Load(); BookQueries.Load();

@ -40,14 +40,24 @@ namespace BookAStar.Data
return CurrentItem; return CurrentItem;
} }
public void Load() public virtual bool Load()
{ {
this.Populate<V>(); return this.Populate<V,K>();
} }
public void Load(string subKey) public virtual bool Load(string subKey)
{ {
this.Populate<V>(subKey); return (this.Populate<V,K>(subKey));
}
public virtual bool Seek(int index)
{
if (this.Count>index && index >=0)
{
CurrentItem = this[index];
return true;
}
return false;
} }
} }

@ -6,10 +6,17 @@ namespace BookAStar.Data.NonCrUD
{ {
using Helpers; using Helpers;
using Model.FileSystem; using Model.FileSystem;
using System.Linq;
/*
public class DirectoryEntryChangingEvent : EventArgs
{
public UserDirectoryInfo OldItem { get; set; }
public UserDirectoryInfo NewItem { get; set; }
}*/
public class RemoteFiles : RemoteEntity<UserDirectoryInfo, FileAddress> public class RemoteFilesEntity : RemoteEntity<UserDirectoryInfo, FileAddress>
{ {
public RemoteFiles() : base("fs", d => d) public RemoteFilesEntity() : base("fs", d => d)
{ {
} }
@ -23,14 +30,15 @@ namespace BookAStar.Data.NonCrUD
try try
{ {
var subpath = parameter as string; var subpath = parameter as string;
string path = ControllerUri.AbsolutePath + ((subpath != null) ? "/" + subpath : null); string path = ControllerUri.AbsoluteUri + ((subpath != null) ? "/" + subpath : null);
using (var response = await client.GetAsync(ControllerUri)) using (var response = await client.GetAsync(path))
{ {
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
{ {
var content = await response.Content.ReadAsStringAsync(); var content = await response.Content.ReadAsStringAsync();
var di = JsonConvert.DeserializeObject<UserDirectoryInfo>(content); var di = JsonConvert.DeserializeObject<UserDirectoryInfo>(content);
this.Merge(di); this.Merge(di);
this.SaveEntity();
} }
else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
throw new Exception("Bad request"); throw new Exception("Bad request");
@ -43,8 +51,32 @@ namespace BookAStar.Data.NonCrUD
throw new Exception("Remote call failed", ex); throw new Exception("Remote call failed", ex);
} }
} }
AfterExecuting();
}
/*
public override void Merge(UserDirectoryInfo item)
{
var key = GetKey(item);
DirectoryEntryChangingEvent itemChanged = null;
if (this.Any(x => GetKey(x).Equals(key)))
{
var old = LocalGet(key);
itemChanged = new DirectoryEntryChangingEvent
{
OldItem = old,
NewItem = item
};
Remove(old);
}
Add(item);
CurrentItem = item;
if (DirectoryEntryChanged != null && itemChanged != null)
DirectoryEntryChanged.Invoke(this, itemChanged);
} }
public event EventHandler<DirectoryEntryChangingEvent> DirectoryEntryChanged;
*/
} }
} }

@ -65,7 +65,7 @@ namespace BookAStar.Data
{ {
Merge(item); Merge(item);
} }
this.SaveCollection(); this.SaveEntity();
} }
} }
} }

@ -1,59 +0,0 @@
using System;
using System.Collections.Generic;
namespace BookAStar
{
public class ObservableString : IObservable<string>, IDisposable
{
public ObservableString(string data)
{
this.data = data;
}
private string data = null;
private List<IObserver<string>> observers = new List<IObserver<string>>();
public string Data
{
get
{
return data;
}
set
{
if (data != value)
{
data = value;
foreach (var obs in observers)
obs.OnCompleted();
}
}
}
public override string ToString()
{
return data;
}
public static explicit operator ObservableString (string data)
{
return new ObservableString(data);
}
public static explicit operator string (ObservableString observable)
{
return observable.ToString();
}
public void Dispose()
{
observers = null;
}
public IDisposable Subscribe(IObserver<string> observer)
{
observers.Add(observer);
return this;
}
}
}

@ -1,10 +1,11 @@
using System; using System;
using System.Collections;
namespace BookAStar namespace BookAStar
{ {
public interface ILoadable public interface ILoadable
{ {
void Load(); bool Load();
} }
public interface IPersistentOnDemand : ILoadable public interface IPersistentOnDemand : ILoadable
@ -12,7 +13,7 @@ namespace BookAStar
void Save(); void Save();
} }
public interface ILocalEntity<V, K> : ILoadable where K : IEquatable<K> public interface ILocalEntity<V, K> : IList, ILoadable where K : IEquatable<K>
{ {
V CurrentItem { get; } V CurrentItem { get; }
@ -22,5 +23,6 @@ namespace BookAStar
void Merge(V item); void Merge(V item);
bool Seek(int index);
} }
} }

@ -58,7 +58,7 @@ namespace BookAStar.Pages
private void OnEditEstimate(object sender, EventArgs ev) private void OnEditEstimate(object sender, EventArgs ev)
{ {
var bookQueryViewModel = (BookQueryViewModel)BindingContext; var bookQueryViewModel = (BookQueryViewModel) BindingContext;
var editEstimateViewModel = bookQueryViewModel.DraftEstimate; var editEstimateViewModel = bookQueryViewModel.DraftEstimate;
if (editEstimateViewModel == null) if (editEstimateViewModel == null)
@ -70,7 +70,7 @@ namespace BookAStar.Pages
if (estimateToEdit == null) if (estimateToEdit == null)
{ {
DataManager.Current.Contacts.Merge(BookQuery.Client); DataManager.Current.Contacts.Merge(BookQuery.Client);
DataManager.Current.Contacts.SaveCollection(); DataManager.Current.Contacts.SaveEntity();
estimateToEdit = new Estimate() estimateToEdit = new Estimate()
{ {
ClientId = BookQuery.Client.UserId, ClientId = BookQuery.Client.UserId,

@ -24,7 +24,7 @@ namespace BookAStar.Pages
private void EditEstimatePage_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) private void EditEstimatePage_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {
DataManager.Current.EstimationCache.SaveCollection(); DataManager.Current.EstimationCache.SaveEntity();
} }
protected override void OnSizeAllocated(double width, double height) protected override void OnSizeAllocated(double width, double height)
@ -47,7 +47,7 @@ namespace BookAStar.Pages
var lineView = new BillingLineViewModel(com) var lineView = new BillingLineViewModel(com)
{ ValidateCommand = new Command(() => { { ValidateCommand = new Command(() => {
bill.Add(com); bill.Add(com);
bill.SaveCollection(); DataManager.Current.EstimationCache.SaveEntity();
})}; })};
App.NavigationService.NavigateTo<EditBillingLinePage>( App.NavigationService.NavigateTo<EditBillingLinePage>(
true, true,
@ -60,7 +60,7 @@ namespace BookAStar.Pages
var lineView = new BillingLineViewModel(line) var lineView = new BillingLineViewModel(line)
{ {
ValidateCommand = new Command(() => { ValidateCommand = new Command(() => {
bill.SaveCollection(); DataManager.Current.EstimationCache.SaveEntity();
}) })
}; };
lineView.PropertyChanged += LineView_PropertyChanged; lineView.PropertyChanged += LineView_PropertyChanged;
@ -71,7 +71,7 @@ namespace BookAStar.Pages
private void LineView_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) private void LineView_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {
DataManager.Current.EstimationCache.SaveCollection(); DataManager.Current.EstimationCache.SaveEntity();
} }
protected void OnEstimateValidated(object sender, EventArgs e) protected void OnEstimateValidated(object sender, EventArgs e)
@ -88,9 +88,9 @@ namespace BookAStar.Pages
{ {
DataManager.Current.Estimates.Update(evm.Data); DataManager.Current.Estimates.Update(evm.Data);
} }
DataManager.Current.Estimates.SaveCollection(); DataManager.Current.Estimates.SaveEntity();
DataManager.Current.EstimationCache.Remove(evm); DataManager.Current.EstimationCache.Remove(evm);
DataManager.Current.EstimationCache.SaveCollection(); DataManager.Current.EstimationCache.SaveEntity();
Navigation.PopAsync(); Navigation.PopAsync();
} }
} }

@ -18,36 +18,18 @@
</Style> </Style>
</ResourceDictionary> </ResourceDictionary>
</ContentPage.Resources> </ContentPage.Resources>
<ScrollView> <ContentPage.Content>
<StackLayout Orientation="Vertical" > <ScrollView>
<StackLayout> <StackLayout BoxView.Color="{StaticResource ContentBackgroundColor}">
<lc:GesturesContentView ExcludeChildren="false" VisualElement.HeightRequest="{StaticResource BigUserAvatarSize}"> <Label Text="{Binding UserName}" Style="{StaticResource LabelPageHeadingStyle}"
<StackLayout> HorizontalTextAlignment="Center"
<Label Text="{Binding UserName}" Style="{StaticResource LabelPageHeadingStyle}" LineBreakMode="WordWrap" XAlign="Center"
HorizontalTextAlignment="Center"
LineBreakMode="WordWrap" XAlign="Center"
></Label> ></Label>
<Frame VisualElement.HeightRequest="{StaticResource BigUserAvatarSize}">
<lb:Gestures.Interests> <Image Source="{Binding Avatar}"
<lb:GestureCollection>
<lb:GestureInterest GestureType="LongPress"
GestureCommand="{Binding UserNameGesture}"
/>
</lb:GestureCollection>
</lb:Gestures.Interests>
<Image Source="{Binding Avatar}" Aspect="AspectFit"
VisualElement.HeightRequest="{StaticResource BigUserAvatarSize}" /> VisualElement.HeightRequest="{StaticResource BigUserAvatarSize}" />
<views:RatingView Rating="{Binding Rating, Mode=TwoWay}" x:Name="ratingView" />
</Frame>
</StackLayout>
</lc:GesturesContentView>
<views:RatingView Rating="{Binding Rating, Mode=TwoWay}" x:Name="ratingView"/>
</StackLayout>
<Button Text="{Binding PerformerStatus}" Clicked="OnViewPerformerStatus" /> <Button Text="{Binding PerformerStatus}" Clicked="OnViewPerformerStatus" />
<Button Text="{Binding UserQueries}" Clicked="OnViewUserQueries" <Button Text="{Binding UserQueries}" Clicked="OnViewUserQueries"
@ -63,11 +45,11 @@
<Switch HorizontalOptions="End" IsToggled="{Binding AllowUseMyPosition, Mode=TwoWay}"/> <Switch HorizontalOptions="End" IsToggled="{Binding AllowUseMyPosition, Mode=TwoWay}"/>
</StackLayout> </StackLayout>
<StackLayout Orientation="Horizontal" VerticalOptions="Start" <StackLayout Orientation="Horizontal" VerticalOptions="Start"
VisualElement.IsVisible="{Binding UserIsPro}"> VisualElement.IsVisible="{Binding UserIsPro}" >
<Label Text="Ne recevoir de demande de devis que de la part de professionnels uniquement" <Label Text="Ne recevoir de demande de devis que de la part de professionnels uniquement" />
StyleClass="Header"/>
<Switch HorizontalOptions="End" IsToggled="{Binding AllowProBookingOnly, Mode=TwoWay}"/> <Switch HorizontalOptions="End" IsToggled="{Binding AllowProBookingOnly, Mode=TwoWay}"/>
</StackLayout> </StackLayout>
</StackLayout> </StackLayout>
</ScrollView> </ScrollView>
</ContentPage.Content>
</ContentPage> </ContentPage>

@ -6,6 +6,7 @@ namespace BookAStar.Pages.UserProfile
{ {
using Data; using Data;
using ViewModels.UserProfile; using ViewModels.UserProfile;
public partial class DashboardPage : ContentPage public partial class DashboardPage : ContentPage
{ {
@ -23,10 +24,12 @@ namespace BookAStar.Pages.UserProfile
ShowPage<AccountChooserPage>(null, true); ShowPage<AccountChooserPage>(null, true);
}); });
} }
public void OnManageFiles(object sender, EventArgs e) public void OnManageFiles(object sender, EventArgs e)
{ {
ShowPage<UserFiles>(new object[] { new DirectoryInfoViewModel() }, true); ShowPage<UserFiles>(null, true);
} }
public void OnViewPerformerStatus(object sender, EventArgs e) public void OnViewPerformerStatus(object sender, EventArgs e)
{ {
ShowPage<AccountChooserPage>(null, true); ShowPage<AccountChooserPage>(null, true);

@ -1,35 +1,49 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="BookAStar.Pages.UserProfile.UserFiles"> x:Class="BookAStar.Pages.UserProfile.UserFiles"
<Label Text="{Binding SubPath}" VerticalOptions="Center" HorizontalOptions="Center" /> Style="{StaticResource PageStyle}">
<ListView x:Name="dirlist" ItemsSource="{Binding SubDirectories}" <ScrollView>
RefreshCommand="{Binding RefreshCommand}" > <StackLayout>
<ListView.ItemTemplate > <StackLayout Orientation="Horizontal">
<DataTemplate> <Label Text="Dossiers:" />
<ViewCell> <Label Text="{Binding UserName}" HorizontalOptions="Start" />
<ViewCell.View> <Label Text="{Binding SubPath}" HorizontalOptions="Start" />
<StackLayout Orientation="Horizontal"> </StackLayout>
<Label Text="{Binding Name}" /> <ListView x:Name="filelist" ItemsSource="{Binding SubDirectories}"
<Label Text="{Binding Size}" /> RefreshCommand="{Binding RefreshCommand}"
<Label Text="{Binding CreationTime, StringFormat='créé {0:dddd d MMMM à HH:mm}'}" /> SeparatorVisibility="Default"
<Label Text="{Binding LastModified, StringFormat='modifié {0:dddd d MMMM à HH:mm}'}" /> VerticalOptions="Start">
</StackLayout> <ListView.ItemTemplate >
</ViewCell.View> <DataTemplate>
</ViewCell> <ViewCell>
</DataTemplate> <ViewCell.View>
</ListView.ItemTemplate> <Label Text="{Binding .}" />
</ListView> </ViewCell.View>
<ListView x:Name="filelist" ItemsSource="{Binding FileInfo}" </ViewCell>
RefreshCommand="{Binding RefreshCommand}"> </DataTemplate>
<ListView.ItemTemplate > </ListView.ItemTemplate>
<DataTemplate> </ListView>
<ViewCell> <ListView x:Name="dirlist" ItemsSource="{Binding FileInfo}"
<ViewCell.View> RefreshCommand="{Binding RefreshCommand}"
<Label Text="{Binding .}" /> SeparatorVisibility="Default"
</ViewCell.View> VerticalOptions="Start" >
</ViewCell> <ListView.ItemTemplate >
</DataTemplate> <DataTemplate>
</ListView.ItemTemplate> <ViewCell>
</ListView> <ViewCell.View>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Name}" />
<Label Text="{Binding Size, StringFormat='{0}b'}" />
<Label Text="{Binding CreationTime, StringFormat='créé {0:dddd d MMMM à HH:mm}'}" />
<Label Text="{Binding LastModified, StringFormat='modifié {0:dddd d MMMM à HH:mm}'}" />
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ScrollView>
</ContentPage> </ContentPage>

@ -4,31 +4,49 @@ namespace BookAStar.Pages.UserProfile
{ {
using ViewModels.UserProfile; using ViewModels.UserProfile;
using Data; using Data;
using System.Windows.Input;
public partial class UserFiles : ContentPage public partial class UserFiles : ContentPage
{ {
protected DirectoryInfoViewModel model; protected DirectoryInfoViewModel model;
public UserFiles() public UserFiles()
{ {
InitializeComponent(); InitializeComponent();
var current = DataManager.Current.RemoteFiles.CurrentItem;
var currentDir = DataManager.Current.RemoteFiles.CurrentItem; if (current != null)
BindingContext = new DirectoryInfoViewModel(current);
BindingContext = new DirectoryInfoViewModel(currentDir) else BindingContext = new DirectoryInfoViewModel
{ {
RefreshCommand = new Command(() => UserName = MainSettings.UserName
{
DataManager.Current.RemoteFiles.Execute(null);
this.dirlist.EndRefresh();
this.filelist.EndRefresh();
})
}; };
} }
public UserFiles(DirectoryInfoViewModel model)
{
InitializeComponent();
BindingContext = model;
}
protected override void OnBindingContextChanged() protected override void OnBindingContextChanged()
{ {
model = BindingContext as DirectoryInfoViewModel;
if (model != null)
model.RefreshCommand = new Command(() =>
{
DataManager.Current.RemoteFiles.Execute(null);
var item = DataManager.Current.RemoteFiles.CurrentItem;
if (item != null)
model.InnerModel = item;
// this.dirlist.EndRefresh();
// this.filelist.EndRefresh();
});
base.OnBindingContextChanged(); base.OnBindingContextChanged();
} }
protected override void OnAppearing()
{
base.OnAppearing();
model.RefreshCommand.Execute(model.SubPath);
}
} }
} }

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="BookAStar.Pages.UserProfile.UserProfilePage">
<Label Text="{Binding UserName}" VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace BookAStar.Pages.UserProfile
{
public partial class UserProfilePage : ContentPage
{
public UserProfilePage()
{
InitializeComponent();
}
}
}

@ -265,9 +265,9 @@ namespace BookAStar
/// <typeparam name="V"></typeparam> /// <typeparam name="V"></typeparam>
/// <param name="collection"></param> /// <param name="collection"></param>
/// <param name="subKey"></param> /// <param name="subKey"></param>
public static void Populate<V>(this IList<V> collection, string subKey = null) public static bool Populate<V,K>(this ILocalEntity<V, K> collection, string subKey = null) where K : IEquatable<K>
{ {
var key = $"{EntityDataSettingsPrefix}/{subKey}/{typeof(V).FullName}"; var key = GetCollectionKey<V>(subKey);
var data = AppSettings.GetValueOrDefault<string>(key, null); var data = AppSettings.GetValueOrDefault<string>(key, null);
if (!string.IsNullOrWhiteSpace(data)) if (!string.IsNullOrWhiteSpace(data))
{ {
@ -275,7 +275,15 @@ namespace BookAStar
if (items != null) if (items != null)
foreach (var item in items) foreach (var item in items)
collection.Add(item); collection.Add(item);
var cursorKey = GetCursorKey<V>(subKey);
var index = AppSettings.GetValueOrDefault<int>(cursorKey, -1);
if (index>=0)
{
collection.Seek(index);
}
return true;
} }
return false;
} }
/// <summary> /// <summary>
@ -284,11 +292,25 @@ namespace BookAStar
/// <typeparam name="V"></typeparam> /// <typeparam name="V"></typeparam>
/// <param name="collection"></param> /// <param name="collection"></param>
/// <param name="subKey"></param> /// <param name="subKey"></param>
public static void SaveCollection<V>(this IList<V> collection, string subKey=null) public static void SaveEntity<V,K>(this ILocalEntity<V, K> collection, string subKey=null) where K : IEquatable<K>
{ {
if (collection == null) return; if (collection == null) return;
var key = $"{EntityDataSettingsPrefix}/{subKey}/{typeof(V).FullName}"; var key = GetCollectionKey<V>(subKey);
var cursorKey = GetCursorKey<V>(subKey);
AppSettings.AddOrUpdateValue(key, JsonConvert.SerializeObject(collection)); AppSettings.AddOrUpdateValue(key, JsonConvert.SerializeObject(collection));
if (collection.CurrentItem!=null)
{
int index = collection.IndexOf(collection.CurrentItem) ;
AppSettings.AddOrUpdateValue<int>(cursorKey, index);
}
}
private static string GetCursorKey<V>(string subKey)
{
return $"{EntityDataSettingsPrefix}/{subKey}/{typeof(V).FullName}/c";
}
private static string GetCollectionKey<V>(string subKey)
{
return $"{EntityDataSettingsPrefix}/{subKey}/{typeof(V).FullName}";
} }
} }
} }

@ -5,28 +5,71 @@ using XLabs.Forms.Mvvm;
namespace BookAStar.ViewModels.UserProfile namespace BookAStar.ViewModels.UserProfile
{ {
using System.ComponentModel;
using Model.FileSystem; using Model.FileSystem;
public class DirectoryInfoViewModel : ViewModel public class DirectoryInfoViewModel : ViewModel
{ {
public ObservableString SubPath { get; set; } private string subPath;
public ObservableCollection<string> SubDirectories { get; set; } public string SubPath
public ObservableCollection<UserFileInfo> FileInfo { get; set; }
public ICommand RefreshCommand { get; set; }
public DirectoryInfoViewModel (UserDirectoryInfo model=null)
{ {
Data.DataManager.Current.RemoteFiles.CollectionChanged += RemoteFiles_CollectionChanged; get { return subPath; }
set { SetProperty<string>(ref subPath, value); }
}
private string userName;
public string UserName
{
get { return userName; }
set { SetProperty<string>(ref userName, value); }
}
private ObservableCollection<string> subDirectories;
public ObservableCollection<string> SubDirectories
{
get { return subDirectories; }
set { SetProperty< ObservableCollection < string >>( ref subDirectories, value) ; }
}
if (model == null) private ObservableCollection<UserFileInfo> fileInfo;
model = Data.DataManager.Current.RemoteFiles.CurrentItem; public ObservableCollection<UserFileInfo> FileInfo
SubDirectories = new ObservableCollection<string> (model.SubDirectories); {
SubPath = new ObservableString (model.SubPath); get { return fileInfo; }
FileInfo = new ObservableCollection<Model.FileSystem.UserFileInfo> (model.Files); set { SetProperty<ObservableCollection<UserFileInfo>> ( ref fileInfo, value ); }
}
UserDirectoryInfo model;
public UserDirectoryInfo InnerModel {
get { return model; }
set {
if (SetProperty<UserDirectoryInfo>(ref model, value))
if (model == null)
{
SubDirectories = new ObservableCollection<string>();
FileInfo = new ObservableCollection<UserFileInfo>();
SubPath = "<no path>";
UserName = "<no user>";
}
else
{
SubDirectories = new ObservableCollection<string>(model.SubDirectories);
FileInfo = new ObservableCollection<UserFileInfo>(model.Files);
SubPath = model.SubPath;
UserName = model.UserName;
}
}
}
public DirectoryInfoViewModel(UserDirectoryInfo model = null)
{
this.InnerModel = model;
} }
private void RemoteFiles_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) private ICommand refreshCommand;
public ICommand RefreshCommand
{ {
throw new System.NotImplementedException(); get { return refreshCommand; }
set { SetProperty<ICommand>(ref refreshCommand, value); }
} }
} }
} }

@ -14,8 +14,8 @@
</ResourceDictionary> </ResourceDictionary>
</ContentView.Resources> </ContentView.Resources>
<ContentView.Content> <ContentView.Content>
<StackLayout> <StackLayout>
<StackLayout Orientation="Horizontal" HeightRequest="70"> <StackLayout Orientation="Horizontal" >
<Grid> <Grid>
<Grid.Behaviors> <Grid.Behaviors>
<behaviors:StarBehavior x:Name="starOne" GroupName="myStar"/> <behaviors:StarBehavior x:Name="starOne" GroupName="myStar"/>
@ -61,8 +61,7 @@
<Image x:Name="starSelectedFour" <Image x:Name="starSelectedFour"
Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}" Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}"
IsVisible="{Binding Source={x:Reference starFour}, IsVisible="{Binding Source={x:Reference starFour}, Path=IsStarred}" />
Path=IsStarred}"/>
</Grid> </Grid>
<Grid > <Grid >
<Grid.Behaviors> <Grid.Behaviors>
@ -73,9 +72,9 @@
<Image x:Name="starSelectedFive" <Image x:Name="starSelectedFive"
Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}" Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}"
IsVisible="{Binding Source={x:Reference starFive}, IsVisible="{Binding Source={x:Reference starFive}, Path=IsStarred}" />
Path=IsStarred}"/>
</Grid> </Grid>
</StackLayout> </StackLayout>
<StackLayout> <StackLayout>
<StackLayout.Resources> <StackLayout.Resources>
@ -85,7 +84,7 @@
</StackLayout.Resources> </StackLayout.Resources>
<Label Text="{Binding Source={x:Reference starFive}, Path=Rating, Converter={StaticResource ratingText}}" ></Label> <Label Text="{Binding Source={x:Reference starFive}, Path=Rating, Converter={StaticResource ratingText}}" ></Label>
</StackLayout> </StackLayout>
</StackLayout> </StackLayout>
</ContentView.Content> </ContentView.Content>
</ContentView> </ContentView>

Loading…