WIP Book queries
This commit is contained in:
parent
e000cb4299
commit
b78d3f64c1
5 changed files with 179 additions and 66 deletions
|
|
@ -43,26 +43,18 @@ namespace BookAStar.Droid.Services
|
|||
var topic = data.GetString("Topic");
|
||||
if (topic == "BookQuery")
|
||||
{
|
||||
DateTime startdate,enddate;
|
||||
DateTime eventdate,enddate;
|
||||
|
||||
var sdatestr = data.GetString("StartDate");
|
||||
DateTime.TryParse(sdatestr, out startdate);
|
||||
|
||||
var enddatestr = data.GetString("EndDate");
|
||||
DateTime.TryParse(enddatestr, out enddate);
|
||||
var sdatestr = data.GetString("EventDate");
|
||||
DateTime.TryParse(sdatestr, out eventdate);
|
||||
|
||||
var locationJson = data.GetString("Location");
|
||||
var location = JsonConvert.DeserializeObject<Location>(locationJson);
|
||||
var cid = long.Parse(data.GetString("CommandId"));
|
||||
var cid = long.Parse(data.GetString("Id"));
|
||||
var bq = new BookQueryData
|
||||
{
|
||||
Title = data.GetString("Title"),
|
||||
Description = data.GetString("Description"),
|
||||
Comment = data.GetString("Comment"),
|
||||
StartDate = startdate,
|
||||
EndDate = enddate,
|
||||
CommandId = cid,
|
||||
Address = location
|
||||
Id = cid,
|
||||
Location = location
|
||||
};
|
||||
|
||||
SendBookQueryNotification(bq);
|
||||
|
|
@ -96,19 +88,19 @@ namespace BookAStar.Droid.Services
|
|||
var count = bookquerynotifications.Length;
|
||||
var multiple = count > 1;
|
||||
var title =
|
||||
multiple ? $"{count} demandes" : bquery.Title;
|
||||
var message = bquery.Description;
|
||||
multiple ? $"{count} demandes" : bquery.Client.UserName;
|
||||
var message = $"{bquery.EventDate} {bquery.Client.UserName} {bquery.Location.Address}";
|
||||
|
||||
var intent = new Intent(this, typeof(MainActivity));
|
||||
intent.AddFlags(ActivityFlags.ClearTop);
|
||||
intent.PutExtra("BookQueryId", bquery.CommandId);
|
||||
intent.PutExtra("BookQueryId", bquery.Id);
|
||||
|
||||
var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
|
||||
Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
|
||||
int maxil = 5;
|
||||
for (int cn = 0; cn < count && cn < maxil; cn++)
|
||||
{
|
||||
inboxStyle.AddLine(bookquerynotifications[cn].Description);
|
||||
inboxStyle.AddLine(bookquerynotifications[cn].Client.UserName);
|
||||
}
|
||||
if (count > maxil)
|
||||
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.Diagnostics;
|
||||
using System.Net;
|
||||
|
|
@ -25,25 +27,32 @@ namespace BookAStar
|
|||
SettingsPage settingsPage;
|
||||
PinPage pinPage;
|
||||
ContentPage deviceInfoPage;
|
||||
BookQueryPage bookQueryPage;
|
||||
BookQueriesPage bookQueriesPage;
|
||||
public static IPlatform PlateformSpecificInstance { get; set; }
|
||||
public static string AppName { get; set; }
|
||||
public static App CurrentApp { get { return Current as App; } }
|
||||
|
||||
public DataManager DataManager { get; set; }
|
||||
|
||||
public App (IPlatform instance)
|
||||
{
|
||||
public App(IPlatform instance)
|
||||
{
|
||||
DataManager = new DataManager();
|
||||
deviceInfoPage = new DeviceInfoPage(instance.GetDeviceInfo());
|
||||
bookQueriesPage = new BookQueriesPage();
|
||||
|
||||
PlateformSpecificInstance = instance;
|
||||
searchPage = new SearchPage { Title = "Trouvez votre artiste"
|
||||
, Icon = "glyphish_07_map_marker.png"
|
||||
};
|
||||
mp = new NavigationPage (searchPage);
|
||||
settingsPage = new SettingsPage { Title = "Settings"
|
||||
, Icon = "ic_corp_icon.png"
|
||||
};
|
||||
searchPage = new SearchPage
|
||||
{
|
||||
Title = "Trouvez votre artiste",
|
||||
Icon = "glyphish_07_map_marker.png"
|
||||
};
|
||||
mp = new NavigationPage(searchPage);
|
||||
settingsPage = new SettingsPage
|
||||
{
|
||||
Title = "Settings",
|
||||
Icon = "ic_corp_icon.png"
|
||||
};
|
||||
|
||||
var r = this.Resources;
|
||||
//var hasLabelStyle = r.ContainsKey("labelStyle");
|
||||
|
|
@ -52,39 +61,53 @@ namespace BookAStar
|
|||
// null var appsstyle = settingsPage.Style;
|
||||
// appsstyle.CanCascade = true;
|
||||
MainPage = mp;
|
||||
ToolbarItem tiSetts = new ToolbarItem () { Text = "Settings"
|
||||
, Icon = "ic_corp_icon.png"
|
||||
ToolbarItem tiSetts = new ToolbarItem()
|
||||
{
|
||||
Text = "Settings",
|
||||
Icon = "ic_corp_icon.png"
|
||||
};
|
||||
mp.ToolbarItems.Add (tiSetts);
|
||||
tiSetts.Clicked += (object sender, EventArgs e) => {
|
||||
if (settingsPage.Parent==null)
|
||||
mp.Navigation.PushAsync(settingsPage);
|
||||
else {
|
||||
mp.ToolbarItems.Add(tiSetts);
|
||||
tiSetts.Clicked += (object sender, EventArgs e) =>
|
||||
{
|
||||
if (settingsPage.Parent == null)
|
||||
mp.Navigation.PushAsync(settingsPage);
|
||||
else
|
||||
{
|
||||
settingsPage.Focus();
|
||||
}
|
||||
};
|
||||
};
|
||||
ToolbarItem tiQueries = new ToolbarItem
|
||||
{
|
||||
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"
|
||||
};
|
||||
tiMap.Clicked += (object sender, EventArgs e) => {
|
||||
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"
|
||||
};
|
||||
tiMap.Clicked += (object sender, EventArgs e) =>
|
||||
{
|
||||
if (pinPage.Parent == null)
|
||||
mp.Navigation.PushAsync(pinPage);
|
||||
else pinPage.Focus();
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void ShowDeviceInfo()
|
||||
|
|
@ -97,13 +120,19 @@ namespace BookAStar
|
|||
public void PostDeviceInfo()
|
||||
{
|
||||
var res = PlateformSpecificInstance.InvokeApi(
|
||||
"gcm/register",
|
||||
"gcm/register",
|
||||
PlateformSpecificInstance.GetDeviceInfo());
|
||||
}
|
||||
|
||||
public void ShowBookQuery(long queryId)
|
||||
public void ShowBookQuery(BookQueryData data)
|
||||
{
|
||||
mp.Navigation.PushAsync(new BookQueryPage(queryId));
|
||||
bookQueriesPage.BindingContext = data;
|
||||
mp.Navigation.PushAsync(bookQueriesPage);
|
||||
}
|
||||
|
||||
public void CloseWindow()
|
||||
{
|
||||
mp.Navigation.PopAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,28 +9,25 @@ using System.Threading.Tasks;
|
|||
|
||||
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;
|
||||
public event EventHandler CanExecuteChanged;
|
||||
public bool IsExecuting { get; private set; }
|
||||
public ObservableCollection<V> LocalData;
|
||||
private Func<V, K> _getKey ;
|
||||
private HttpClient client;
|
||||
private Uri controllerUri;
|
||||
|
||||
protected Func<V, K> GetKey { get; set; }
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
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)
|
||||
throw new InvalidOperationException();
|
||||
_controller = controllerName;
|
||||
_getKey = getKey;
|
||||
LocalData = new ObservableCollection<V>();
|
||||
GetKey = getKey;
|
||||
client = new HttpClient();
|
||||
controllerUri = new Uri(MainSettings.YavscApiUrl + "/" + _controller);
|
||||
}
|
||||
|
|
@ -51,6 +48,9 @@ namespace BookAStar
|
|||
public async void Execute(object parameter)
|
||||
{
|
||||
BeforeExecute();
|
||||
// Update credentials
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(
|
||||
"Bearer", MainSettings.CurrentUser.YavscTokens.AccessToken);
|
||||
// Get the whole data
|
||||
|
||||
var response = await client.GetAsync(controllerUri);
|
||||
|
|
@ -61,25 +61,25 @@ namespace BookAStar
|
|||
// LocalData.Clear();
|
||||
foreach (var item in col)
|
||||
{
|
||||
Update(item);
|
||||
UpdateOrAdd(item);
|
||||
}
|
||||
}
|
||||
|
||||
AfterExecuting();
|
||||
}
|
||||
private void Update (V item)
|
||||
protected virtual void UpdateOrAdd (V item)
|
||||
{
|
||||
var key = _getKey(item);
|
||||
if (LocalData.Any(x => _getKey(x).Equals(key)))
|
||||
var key = GetKey(item);
|
||||
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)
|
||||
{
|
||||
return LocalData.Single(x => _getKey(x).Equals(key));
|
||||
return this.Single(x => GetKey(x).Equals(key));
|
||||
}
|
||||
|
||||
private void AfterExecuting()
|
||||
|
|
@ -102,7 +102,7 @@ namespace BookAStar
|
|||
var content = await response.Content.ReadAsStringAsync();
|
||||
item = JsonConvert.DeserializeObject<V>(content);
|
||||
// LocalData.Clear();
|
||||
Update(item);
|
||||
UpdateOrAdd(item);
|
||||
}
|
||||
|
||||
AfterExecuting();
|
||||
|
|
|
|||
46
BookAStar/BookAStar/Pages/BookQueriesPage.xaml
Normal file
46
BookAStar/BookAStar/Pages/BookQueriesPage.xaml
Normal file
|
|
@ -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>
|
||||
46
BookAStar/BookAStar/Pages/BookQueriesPage.xaml.cs
Normal file
46
BookAStar/BookAStar/Pages/BookQueriesPage.xaml.cs
Normal file
|
|
@ -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…
Add table
Add a link
Reference in a new issue