using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Comal.Classes; using InABox.Core; using InABox.Mobile; using Xamarin.Forms; using Xamarin.Forms.Xaml; namespace PRS.Mobile { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class DocScannerModule { private DataEntryTagModel _tags; private DataEntryDocumentModel _dataEntriesDocument; public DocScannerModule() { _dataEntriesDocument = new DataEntryDocumentModel(App.Data, () => new Filter(x => x.Employee.ID).IsEqualTo(App.Data.Me.ID) .And(x => x.Archived).IsEqualTo(DateTime.MinValue) ) { FileName = "scans.data" }; _tags = new DataEntryTagModel(App.Data, null) { FileName = "scantags.data" }; InitializeComponent(); ProgressVisible = true; RefreshData(false, true); } private void RefreshData(bool force, bool async) { _dataEntriesDocument.Refresh(force); Task[] tasks = new Task[] { //Task.Run(() => _dataEntriesDocument.Refresh(force)), Task.Run(() => _tags.Refresh(force)) }; if (async) Task.WhenAll(tasks).ContinueWith((_) => Device.BeginInvokeOnMainThread(RefreshScreen)); else { Task.WaitAll(tasks); RefreshScreen(); } } private void RefreshScreen() { ProgressVisible = false; _documents.ItemsSource = null; _documents.ItemsSource = _dataEntriesDocument; } private async Task ConfirmScan(DataEntryDocumentShell documentShell) { documentShell.EmployeeID = App.Data.Me.ID; if (!_tags.Any()) return true; var tag = await DisplayActionSheet("Select Tag", "Cancel", null, _tags.Items.Select(x => x.Name).ToArray()); documentShell.TagID = _tags.Items.FirstOrDefault(x => String.Equals(x.Name, tag))?.ID ?? Guid.Empty; return !string.Equals(tag,"Cancel"); } private async void TakePhoto_Clicked(object sender, EventArgs e) { await _documents.AddImage( PhotoUtils.CreateCameraOptions(), ConfirmScan); } private async void BrowseLibrary_Clicked(object sender, EventArgs e) { await _documents.AddImage( PhotoUtils.CreatePhotoLibraryOptions(), ConfirmScan); } private void _documents_OnRefreshRequested(object sender, MobileListRefreshEventArgs args) { RefreshData(true,false); } } }