WIP Book queries

main
Paul Schneider 9 years ago
parent 0f9565fd46
commit 4a168d1699
5 changed files with 179 additions and 66 deletions

@ -43,26 +43,18 @@ namespace BookAStar.Droid.Services
var topic = data.GetString("Topic"); var topic = data.GetString("Topic");
if (topic == "BookQuery") if (topic == "BookQuery")
{ {
DateTime startdate,enddate; DateTime eventdate,enddate;
var sdatestr = data.GetString("StartDate"); var sdatestr = data.GetString("EventDate");
DateTime.TryParse(sdatestr, out startdate); DateTime.TryParse(sdatestr, out eventdate);
var enddatestr = data.GetString("EndDate");
DateTime.TryParse(enddatestr, out enddate);
var locationJson = data.GetString("Location"); var locationJson = data.GetString("Location");
var location = JsonConvert.DeserializeObject<Location>(locationJson); var location = JsonConvert.DeserializeObject<Location>(locationJson);
var cid = long.Parse(data.GetString("CommandId")); var cid = long.Parse(data.GetString("Id"));
var bq = new BookQueryData var bq = new BookQueryData
{ {
Title = data.GetString("Title"), Id = cid,
Description = data.GetString("Description"), Location = location
Comment = data.GetString("Comment"),
StartDate = startdate,
EndDate = enddate,
CommandId = cid,
Address = location
}; };
SendBookQueryNotification(bq); SendBookQueryNotification(bq);
@ -96,19 +88,19 @@ namespace BookAStar.Droid.Services
var count = bookquerynotifications.Length; var count = bookquerynotifications.Length;
var multiple = count > 1; var multiple = count > 1;
var title = var title =
multiple ? $"{count} demandes" : bquery.Title; multiple ? $"{count} demandes" : bquery.Client.UserName;
var message = bquery.Description; var message = $"{bquery.EventDate} {bquery.Client.UserName} {bquery.Location.Address}";
var intent = new Intent(this, typeof(MainActivity)); var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop); intent.AddFlags(ActivityFlags.ClearTop);
intent.PutExtra("BookQueryId", bquery.CommandId); intent.PutExtra("BookQueryId", bquery.Id);
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
Notification.InboxStyle inboxStyle = new Notification.InboxStyle(); Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
int maxil = 5; int maxil = 5;
for (int cn = 0; cn < count && cn < maxil; cn++) for (int cn = 0; cn < count && cn < maxil; cn++)
{ {
inboxStyle.AddLine(bookquerynotifications[cn].Description); inboxStyle.AddLine(bookquerynotifications[cn].Client.UserName);
} }
if (count > maxil) if (count > maxil)
inboxStyle.SetSummaryText($"Plus {count - maxil} autres"); inboxStyle.SetSummaryText($"Plus {count - maxil} autres");

@ -1,4 +1,6 @@
using BookAStar.Model.Auth.Account; using BookAStar.Model;
using BookAStar.Model.Auth.Account;
using BookAStar.Pages;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Net; using System.Net;
@ -25,25 +27,32 @@ namespace BookAStar
SettingsPage settingsPage; SettingsPage settingsPage;
PinPage pinPage; PinPage pinPage;
ContentPage deviceInfoPage; ContentPage deviceInfoPage;
BookQueryPage bookQueryPage;
BookQueriesPage bookQueriesPage;
public static IPlatform PlateformSpecificInstance { get; set; } public static IPlatform PlateformSpecificInstance { get; set; }
public static string AppName { get; set; } public static string AppName { get; set; }
public static App CurrentApp { get { return Current as App; } } public static App CurrentApp { get { return Current as App; } }
public DataManager DataManager { get; set; } public DataManager DataManager { get; set; }
public App (IPlatform instance) public App(IPlatform instance)
{ {
DataManager = new DataManager(); DataManager = new DataManager();
deviceInfoPage = new DeviceInfoPage(instance.GetDeviceInfo()); deviceInfoPage = new DeviceInfoPage(instance.GetDeviceInfo());
bookQueriesPage = new BookQueriesPage();
PlateformSpecificInstance = instance; PlateformSpecificInstance = instance;
searchPage = new SearchPage { Title = "Trouvez votre artiste" searchPage = new SearchPage
, Icon = "glyphish_07_map_marker.png" {
}; Title = "Trouvez votre artiste",
mp = new NavigationPage (searchPage); Icon = "glyphish_07_map_marker.png"
settingsPage = new SettingsPage { Title = "Settings" };
, Icon = "ic_corp_icon.png" mp = new NavigationPage(searchPage);
}; settingsPage = new SettingsPage
{
Title = "Settings",
Icon = "ic_corp_icon.png"
};
var r = this.Resources; var r = this.Resources;
//var hasLabelStyle = r.ContainsKey("labelStyle"); //var hasLabelStyle = r.ContainsKey("labelStyle");
@ -52,39 +61,53 @@ namespace BookAStar
// null var appsstyle = settingsPage.Style; // null var appsstyle = settingsPage.Style;
// appsstyle.CanCascade = true; // appsstyle.CanCascade = true;
MainPage = mp; MainPage = mp;
ToolbarItem tiSetts = new ToolbarItem () { Text = "Settings" ToolbarItem tiSetts = new ToolbarItem()
, Icon = "ic_corp_icon.png" {
Text = "Settings",
Icon = "ic_corp_icon.png"
}; };
mp.ToolbarItems.Add (tiSetts); mp.ToolbarItems.Add(tiSetts);
tiSetts.Clicked += (object sender, EventArgs e) => { tiSetts.Clicked += (object sender, EventArgs e) =>
if (settingsPage.Parent==null) {
mp.Navigation.PushAsync(settingsPage); if (settingsPage.Parent == null)
else { mp.Navigation.PushAsync(settingsPage);
else
{
settingsPage.Focus(); settingsPage.Focus();
} }
}; };
ToolbarItem tiQueries = new ToolbarItem ToolbarItem tiQueries = new ToolbarItem
{ {
Text = "Demandes" Text = "Demandes"
}; };
tiQueries.Clicked += (object sender, EventArgs e) => {
mp.Navigation.PushAsync(new Pages.MakeAnEstimatePage());
tiQueries.Clicked += (object sender, EventArgs e) =>
{
if (bookQueriesPage.Parent == null)
mp.Navigation.PushAsync(bookQueriesPage);
else bookQueriesPage.Focus();
};
mp.ToolbarItems.Add(tiQueries);
ToolbarItem tiMap = new ToolbarItem
{
Text = "Carte",
Icon = "glyphish_07_map_marker.png"
};
mp.ToolbarItems.Add(tiMap);
pinPage = new PinPage
{
Title = "Carte",
Icon = "glyphish_07_map_marker.png"
}; };
mp.ToolbarItems.Add(tiQueries); tiMap.Clicked += (object sender, EventArgs e) =>
ToolbarItem tiMap = new ToolbarItem { Text = "Carte", {
Icon = "glyphish_07_map_marker.png"
};
mp.ToolbarItems.Add (tiMap);
pinPage = new PinPage { Title = "Carte",
Icon = "glyphish_07_map_marker.png"
};
tiMap.Clicked += (object sender, EventArgs e) => {
if (pinPage.Parent == null) if (pinPage.Parent == null)
mp.Navigation.PushAsync(pinPage); mp.Navigation.PushAsync(pinPage);
else pinPage.Focus(); else pinPage.Focus();
}; };
} }
public void ShowDeviceInfo() public void ShowDeviceInfo()
@ -97,13 +120,19 @@ namespace BookAStar
public void PostDeviceInfo() public void PostDeviceInfo()
{ {
var res = PlateformSpecificInstance.InvokeApi( var res = PlateformSpecificInstance.InvokeApi(
"gcm/register", "gcm/register",
PlateformSpecificInstance.GetDeviceInfo()); PlateformSpecificInstance.GetDeviceInfo());
} }
public void ShowBookQuery(long queryId) public void ShowBookQuery(BookQueryData data)
{
bookQueriesPage.BindingContext = data;
mp.Navigation.PushAsync(bookQueriesPage);
}
public void CloseWindow()
{ {
mp.Navigation.PushAsync(new BookQueryPage(queryId)); mp.Navigation.PopAsync();
} }
} }
} }

@ -9,28 +9,25 @@ using System.Threading.Tasks;
namespace BookAStar namespace BookAStar
{ {
public class RemoteEntity<V,K> : ICommand where K : IEquatable<K> public class RemoteEntity<V,K> : ObservableCollection<V>, ICommand where K : IEquatable<K>
{ {
private string _controller; private string _controller;
public event EventHandler CanExecuteChanged; public event EventHandler CanExecuteChanged;
public bool IsExecuting { get; private set; } public bool IsExecuting { get; private set; }
public ObservableCollection<V> LocalData;
private Func<V, K> _getKey ;
private HttpClient client; private HttpClient client;
private Uri controllerUri; private Uri controllerUri;
protected Func<V, K> GetKey { get; set; }
public bool CanExecute(object parameter) public bool CanExecute(object parameter)
{ {
return !IsExecuting; return !IsExecuting;
} }
public RemoteEntity(string controllerName, Func<V,K> getKey) public RemoteEntity(string controllerName, Func<V,K> getKey):base()
{ {
if (string.IsNullOrWhiteSpace(controllerName) || getKey == null) if (string.IsNullOrWhiteSpace(controllerName) || getKey == null)
throw new InvalidOperationException(); throw new InvalidOperationException();
_controller = controllerName; _controller = controllerName;
_getKey = getKey; GetKey = getKey;
LocalData = new ObservableCollection<V>();
client = new HttpClient(); client = new HttpClient();
controllerUri = new Uri(MainSettings.YavscApiUrl + "/" + _controller); controllerUri = new Uri(MainSettings.YavscApiUrl + "/" + _controller);
} }
@ -51,6 +48,9 @@ namespace BookAStar
public async void Execute(object parameter) public async void Execute(object parameter)
{ {
BeforeExecute(); BeforeExecute();
// Update credentials
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(
"Bearer", MainSettings.CurrentUser.YavscTokens.AccessToken);
// Get the whole data // Get the whole data
var response = await client.GetAsync(controllerUri); var response = await client.GetAsync(controllerUri);
@ -61,25 +61,25 @@ namespace BookAStar
// LocalData.Clear(); // LocalData.Clear();
foreach (var item in col) foreach (var item in col)
{ {
Update(item); UpdateOrAdd(item);
} }
} }
AfterExecuting(); AfterExecuting();
} }
private void Update (V item) protected virtual void UpdateOrAdd (V item)
{ {
var key = _getKey(item); var key = GetKey(item);
if (LocalData.Any(x => _getKey(x).Equals(key))) if (this.Any(x => GetKey(x).Equals(key)))
{ {
LocalData.Remove(LocalGet(key)); Remove(LocalGet(key));
} }
LocalData.Add(item); Add(item);
} }
public V LocalGet(K key) public V LocalGet(K key)
{ {
return LocalData.Single(x => _getKey(x).Equals(key)); return this.Single(x => GetKey(x).Equals(key));
} }
private void AfterExecuting() private void AfterExecuting()
@ -102,7 +102,7 @@ namespace BookAStar
var content = await response.Content.ReadAsStringAsync(); var content = await response.Content.ReadAsStringAsync();
item = JsonConvert.DeserializeObject<V>(content); item = JsonConvert.DeserializeObject<V>(content);
// LocalData.Clear(); // LocalData.Clear();
Update(item); UpdateOrAdd(item);
} }
AfterExecuting(); AfterExecuting();

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BookAStar.Views;assembly=BookAStar"
x:Class="BookAStar.Pages.BookQueriesPage">
<StackLayout>
<ListView x:Name="list"
HasUnevenRows="true" ItemTapped="OnViewDetail">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Orientation="Horizontal">
<StackLayout Orientation="Vertical">
<Label Text="{Binding Title}" FontSize="12"/>
<Label Text="{Binding Description}"/>
<Label Text="{Binding Comment}"/>
<Label Text="{Binding CommandId}"/>
<StackLayout Orientation="Horizontal">
<StackLayout>
<Label Text="Date:" FontAttributes="Italic"/>
<Label Text="{Binding StartDate, StringFormat='{0:jj/MM/yyyy}'}" VerticalOptions="End"/>
</StackLayout>
<StackLayout>
<Label Text="Heure:" FontAttributes="Italic" />
<Label Text="{Binding StartDate, StringFormat='{0:H:mm}'}" VerticalOptions="End"/>
</StackLayout>
<StackLayout>
<Label Text="Lieu:" FontAttributes="Italic" VerticalOptions="End"/>
<Label Text="{Binding Location.Address}"/>
</StackLayout>
</StackLayout>
</StackLayout>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>

@ -0,0 +1,46 @@
using BookAStar.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
namespace BookAStar.Pages
{
public partial class BookQueriesPage : ContentPage
{
public BookQueriesPage()
{
InitializeComponent();
BindingContext = App.CurrentApp.DataManager.BookQueries;
list.ItemsSource = BindingContext as ObservableCollection<BookQueryData>;
list.RefreshCommand = BindingContext as ICommand;
list.IsPullToRefreshEnabled = true;
}
public RemoteEntity<BookQueryData,long> Queries
{
get
{
return BindingContext!=null? BindingContext as RemoteEntity<BookQueryData, long>:null;
}
}
protected override void OnAppearing()
{
base.OnAppearing();
if (!Queries.IsExecuting)
Queries.Execute(null);
}
private void OnViewDetail(object sender, ItemTappedEventArgs e)
{
BookQueryData data = e.Item as BookQueryData;
App.CurrentApp.ShowBookQuery(data);
throw new NotImplementedException();
}
}
}
Loading…