diff --git a/BookAStar/BookAStar.Droid/MainActivity.cs b/BookAStar/BookAStar.Droid/MainActivity.cs index 3e632343..a170881a 100644 --- a/BookAStar/BookAStar.Droid/MainActivity.cs +++ b/BookAStar/BookAStar.Droid/MainActivity.cs @@ -107,8 +107,8 @@ namespace BookAStar.Droid LoadApplication(fapp); - CheckSharing(); - + var componentName = StartService(new Intent(this, typeof(YavscChooserTargetService))); + // TabLayoutResource = Resource.Layout.Tabbar; // ToolbarResource = Resource.Layout.Toolbar; /* diff --git a/BookAStar/BookAStar.Droid/Properties/AndroidManifest.xml b/BookAStar/BookAStar.Droid/Properties/AndroidManifest.xml index e9ef000a..1e31870f 100644 --- a/BookAStar/BookAStar.Droid/Properties/AndroidManifest.xml +++ b/BookAStar/BookAStar.Droid/Properties/AndroidManifest.xml @@ -1,7 +1,7 @@  - + @@ -17,21 +17,19 @@ - - - - - - + + + + + + diff --git a/BookAStar/BookAStar.Droid/Services/YavscChooserTargetService.cs b/BookAStar/BookAStar.Droid/Services/YavscChooserTargetService.cs index c18fba3e..36c14393 100644 --- a/BookAStar/BookAStar.Droid/Services/YavscChooserTargetService.cs +++ b/BookAStar/BookAStar.Droid/Services/YavscChooserTargetService.cs @@ -10,10 +10,19 @@ using Android.Runtime; using Android.Views; using Android.Widget; using Android.Service.Chooser; +using static Android.Manifest; namespace BookAStar.Droid { - [Service(Name = "fr.pschneider.bas.YavscChooserTargetService", Label = "Yavsc share service", Permission = "android.permission.BIND_CHOOSER_TARGET_SERVICE", Icon = "@drawable/icon", Exported = true)] + [Service( + Name = "fr.pschneider.bas.YavscChooserTargetService", + Label = "Yavsc share service", + Permission = Permission.BindChooserTargetService, + Icon = "@drawable/icon", + Exported = true, + Enabled = true + )] + [IntentFilter(new String[] { "android.service.chooser.ChooserTargetService" })] class YavscChooserTargetService : ChooserTargetService { public override IList OnGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) @@ -24,7 +33,7 @@ namespace BookAStar.Droid ChooserTarget t = new ChooserTarget( new Java.Lang.String( "BookingStar"), i, - .5f, new ComponentName(this.BaseContext, ".SendFilesActivity"), + .5f, new ComponentName(this, "BookAStar.SendFilesActivity"), null); var res = new List(); res.Add(t); @@ -35,10 +44,5 @@ namespace BookAStar.Droid { return base.OnBind(intent); } - - public override void OnCreate() - { - base.OnCreate(); - } } } \ No newline at end of file diff --git a/BookAStar/BookAStar/App.xaml b/BookAStar/BookAStar/App.xaml index cda14e18..31426f3f 100644 --- a/BookAStar/BookAStar/App.xaml +++ b/BookAStar/BookAStar/App.xaml @@ -23,7 +23,7 @@ - + diff --git a/BookAStar/BookAStar/App.xaml.cs b/BookAStar/BookAStar/App.xaml.cs index a5123f7b..cb690f7e 100644 --- a/BookAStar/BookAStar/App.xaml.cs +++ b/BookAStar/BookAStar/App.xaml.cs @@ -85,6 +85,7 @@ namespace BookAStar { // TODO save the navigation stack int position = 0; + foreach (Page page in MainPage.Navigation.NavigationStack) { diff --git a/BookAStar/BookAStar/BookAStar.csproj b/BookAStar/BookAStar/BookAStar.csproj index 77fb0a15..75f2f26a 100644 --- a/BookAStar/BookAStar/BookAStar.csproj +++ b/BookAStar/BookAStar/BookAStar.csproj @@ -48,7 +48,9 @@ + + diff --git a/BookAStar/BookAStar/Data/DataManager.cs b/BookAStar/BookAStar/Data/DataManager.cs index a2a45205..1a478437 100644 --- a/BookAStar/BookAStar/Data/DataManager.cs +++ b/BookAStar/BookAStar/Data/DataManager.cs @@ -1,12 +1,11 @@ -using System.Threading.Tasks; - -namespace BookAStar.Data +namespace BookAStar.Data { using Model; using Model.Blog; using Model.Workflow; using Model.UI; - + using ViewModels; + public class DataManager { // TODO estimatetemplate rating service product tag @@ -15,11 +14,20 @@ namespace BookAStar.Data public RemoteEntity Blogspot { get; set; } public LocalEntity Contacts { get; set; } internal LocalEntity AppState { get; set; } - protected static DataManager current = new DataManager(); + /// + /// They have no remote exisence ... + /// + internal LocalEntity EstimationCache { get; set; } + internal LocalEntity EstimateLinesTemplates { get; set; } + + protected static DataManager current ; + public static DataManager Current { get { + if (current == null) + current = new DataManager(); return current; } } @@ -34,17 +42,17 @@ namespace BookAStar.Data x=>x.Id); Contacts = new LocalEntity(c => c.UserId); AppState = new LocalEntity(s => s.Position); - + EstimationCache = new LocalEntity( + e => e.Query.Id); + EstimateLinesTemplates = new LocalEntity( + l => l.Description); BookQueries.Load(); Estimates.Load(); Blogspot.Load(); Contacts.Load(); AppState.Load(); - } - - public async Task GetBookQuery(long bookQueryId) - { - return await BookQueries.Get(bookQueryId); + EstimationCache.Load(); + EstimateLinesTemplates.Load(); } } } diff --git a/BookAStar/BookAStar/Data/LocaLEntity.cs b/BookAStar/BookAStar/Data/LocaLEntity.cs index 2030bab6..05ee3d58 100644 --- a/BookAStar/BookAStar/Data/LocaLEntity.cs +++ b/BookAStar/BookAStar/Data/LocaLEntity.cs @@ -32,6 +32,8 @@ namespace BookAStar.Data public V LocalGet(K key) { + if (!this.Any(x => GetKey(x).Equals(key))) + return default(V); CurrentItem = this.Single(x => GetKey(x).Equals(key)); return CurrentItem; } diff --git a/BookAStar/BookAStar/Data/LocalState.cs b/BookAStar/BookAStar/Data/LocalState.cs new file mode 100644 index 00000000..bdb82ae7 --- /dev/null +++ b/BookAStar/BookAStar/Data/LocalState.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BookAStar.Data +{ + public enum LocalState + { + UpToDate = 0, + New, + Edited, + Removed + } +} diff --git a/BookAStar/BookAStar/Data/RemoteEntity.cs b/BookAStar/BookAStar/Data/RemoteEntity.cs index 138b6143..ce70e52b 100644 --- a/BookAStar/BookAStar/Data/RemoteEntity.cs +++ b/BookAStar/BookAStar/Data/RemoteEntity.cs @@ -10,19 +10,19 @@ namespace BookAStar.Data { using Helpers; - public class RemoteEntity : LocalEntity, ICommand where K : IEquatable + public class RemoteEntity : LocalEntity, ICommand where K : IEquatable { private string _controller; public event EventHandler CanExecuteChanged; public bool IsExecuting { get; private set; } - + private Uri controllerUri; public bool CanExecute(object parameter) { return !IsExecuting && (MainSettings.CurrentUser != null); } - public RemoteEntity(string controllerName, Func getKey):base(getKey) + public RemoteEntity(string controllerName, Func getKey) : base(getKey) { if (string.IsNullOrWhiteSpace(controllerName)) throw new InvalidOperationException(); @@ -35,7 +35,8 @@ namespace BookAStar.Data if (IsExecuting) throw new InvalidOperationException("Already executing"); IsExecuting = true; - CanExecuteChanged.Invoke(this, new EventArgs()); + if (CanExecuteChanged != null) + CanExecuteChanged.Invoke(this, new EventArgs()); } /// @@ -65,7 +66,8 @@ namespace BookAStar.Data } } } - catch (WebException webex) { + catch (WebException webex) + { throw new ServiceNotAvailable("No remote entity", webex); } @@ -76,25 +78,26 @@ namespace BookAStar.Data private void AfterExecuting() { IsExecuting = false; - CanExecuteChanged.Invoke(this, new EventArgs()); + if (CanExecuteChanged!=null) + CanExecuteChanged.Invoke(this, new EventArgs()); } public async Task Get(K key) { var item = LocalGet(key); - if (item==null) item = await RemoteGet(key); + if (item == null) item = await RemoteGet(key); CurrentItem = item; return CurrentItem; } public async Task RemoteGet(K key) { - V item = default(V); - BeforeExecute(); + V item = default(V); + BeforeExecute(); // Get the whole data - var uri = new Uri(controllerUri.AbsolutePath+"/"+key.ToString()); + var uri = new Uri(controllerUri.AbsoluteUri + "/" + key.ToString()); - using (HttpClient client = new HttpClient()) + using (HttpClient client = UserHelpers.CreateClient()) { using (var response = await client.GetAsync(uri)) { @@ -111,6 +114,30 @@ namespace BookAStar.Data CurrentItem = item; return item; } - + + public async void Create(V item) + { + BeforeExecute(); + + using (HttpClient client = UserHelpers.CreateClient()) + { + HttpContent content = new StringContent( + JsonConvert.SerializeObject(item) + ); + using (var response = await client.PostAsync(controllerUri, content)) + { + if (!response.IsSuccessStatusCode) + // TODO throw custom exception, and catch to inform user + throw new Exception($"Create failed posting {item} @ {controllerUri.AbsolutePath}"); + var recontent = await response.Content.ReadAsStringAsync(); + JsonConvert.PopulateObject(recontent, item); + + } + } + + AfterExecuting(); + CurrentItem = item; + } + } } diff --git a/BookAStar/BookAStar/Helpers/MainSettings.cs b/BookAStar/BookAStar/Helpers/MainSettings.cs index 2f8bbd75..0e573ac7 100644 --- a/BookAStar/BookAStar/Helpers/MainSettings.cs +++ b/BookAStar/BookAStar/Helpers/MainSettings.cs @@ -156,12 +156,14 @@ namespace BookAStar if (olduserid != value.Id) { App.CurrentApp.PostDeviceInfo(); - UserChanged.Invoke(App.CurrentApp, new EventArgs()); + if (UserChanged!=null) + UserChanged.Invoke(App.CurrentApp, new EventArgs()); } } else if (olduserid != null) { - UserChanged.Invoke(App.CurrentApp, new EventArgs()); + if (UserChanged != null) + UserChanged.Invoke(App.CurrentApp, new EventArgs()); // TODO else Unregister this device } } @@ -267,7 +269,7 @@ namespace BookAStar { var key = $"{EntityDataSettingsPrefix}/{subKey}/{typeof(V).FullName}"; var data = AppSettings.GetValueOrDefault(key, null); - if (data != null) + if (!string.IsNullOrWhiteSpace(data)) { var items = JsonConvert.DeserializeObject>(data); if (items != null) diff --git a/BookAStar/BookAStar/Model/UI/PageState.cs b/BookAStar/BookAStar/Model/UI/PageState.cs index d5baed26..186da6da 100644 --- a/BookAStar/BookAStar/Model/UI/PageState.cs +++ b/BookAStar/BookAStar/Model/UI/PageState.cs @@ -1,4 +1,6 @@ -namespace BookAStar.Model.UI +using XLabs.Forms.Mvvm; + +namespace BookAStar.Model.UI { internal class PageState { diff --git a/BookAStar/BookAStar/Model/Workflow/Estimate.cs b/BookAStar/BookAStar/Model/Workflow/Estimate.cs index 578e82b3..277168f7 100644 --- a/BookAStar/BookAStar/Model/Workflow/Estimate.cs +++ b/BookAStar/BookAStar/Model/Workflow/Estimate.cs @@ -1,6 +1,7 @@ using BookAStar.Data; using BookAStar.Helpers; using BookAStar.Model.Interfaces; +using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; @@ -24,7 +25,7 @@ namespace BookAStar.Model.Workflow /// /// public IList AttachedGraphics { get; set; } - + [JsonIgnore] public string AttachedGraphicsString { get { return AttachedGraphics==null?null:string.Join(":", AttachedGraphics); } @@ -38,6 +39,7 @@ namespace BookAStar.Model.Workflow /// /// public IList AttachedFiles { get; set; } + [JsonIgnore] public string AttachedFilesString { get { return AttachedFiles == null ? null : string.Join(":", AttachedFiles); } @@ -47,19 +49,20 @@ namespace BookAStar.Model.Workflow public string OwnerId { get; set; } public string ClientId { get; set; } - + [JsonIgnore] public BookQueryData Query { get { if (CommandId.HasValue) { - return DataManager.Current.BookQueries.LocalGet(CommandId.Value); + var dm = DataManager.Current; + return dm.BookQueries.LocalGet(CommandId.Value); } return null; } } - + [JsonIgnore] public ClientProviderInfo Client { get @@ -68,7 +71,7 @@ namespace BookAStar.Model.Workflow } } - + [JsonIgnore] public decimal Total { get { return Bill?.Aggregate((decimal)0, (t, l) => t + l.Count * l.UnitaryCost) ?? (decimal)0; diff --git a/BookAStar/BookAStar/Pages/BookQueryPage.xaml b/BookAStar/BookAStar/Pages/BookQueryPage.xaml index 1ebee157..d8c19a23 100644 --- a/BookAStar/BookAStar/Pages/BookQueryPage.xaml +++ b/BookAStar/BookAStar/Pages/BookQueryPage.xaml @@ -27,7 +27,8 @@ -