123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using System;
- using System.Threading.Tasks;
- using InABox.Mobile;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using Xamarin.Forms.Xaml.Internals;
- using XF.Material.Forms.UI.Dialogs;
- namespace PRS.Mobile
- {
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class DocumentList
- {
- private ICoreRepository _itemsSource;
- public ICoreRepository ItemsSource
- {
- get => _itemsSource;
- set
- {
- _itemsSource = value;
- _imagelist.ItemsSource = value?.Items;
- _imagelist.LastUpdated = value?.LastUpdated ?? DateTime.MinValue;
- }
- }
- public Guid ParentID { get; set; }
- public event MobileListRefreshEvent RefreshRequested;
- public bool PullToRefresh
- {
- get => _imagelist.PullToRefresh;
- set => _imagelist.PullToRefresh = value;
- }
- public bool ShowRecordCount
- {
- get => _imagelist.ShowRecordCount;
- set => _imagelist.ShowRecordCount = value;
- }
-
- public DocumentList()
- {
- InitializeComponent();
- }
- private void Image_Clicked(object sender, EventArgs e)
- {
- if ((sender as MobileCard)?.BindingContext is IEntityDocumentShell shell)
- {
- if (shell.FileName.ToLower().EndsWith(".pdf"))
- {
- PDFViewer pdf = new PDFViewer(shell.DocumentID);
- Navigation.PushAsync(pdf);
- }
- else
- {
- ImageViewerPage img = new ImageViewerPage(shell.DocumentID);
- Navigation.PushAsync(img);
- }
- }
- }
- public async Task<bool> AddImage<T, TShell>(bool pdf = false, Func<TShell, Task<bool>> customiseshell = null)
- where T : MobileDocumentSource, new()
- where TShell : class, IEntityDocumentShell
- {
-
- MobileDocument file = null;
- try
- {
- file = await MobileDocument.From<T>();
- }
-
- catch (Exception e)
- {
- await MaterialDialog.Instance.AlertAsync(e.Message, "ERROR");
- }
-
- if (file != null)
- {
- var shell = ItemsSource.AddItem() as TShell;
- shell.ParentID = ParentID;
-
- bool confirm = (customiseshell == null)
- || await customiseshell.Invoke(shell);
-
- if (confirm)
- {
- using (await MaterialDialog.Instance.LoadingDialogAsync("Saving Image"))
- {
- var thumbnail = MobileUtils.ImageTools.CreateThumbnail(file.Data, 256, 256);
- shell.Thumbnail = thumbnail;
- if (pdf)
- file = file.ToPDF();
- shell.FileName = file.FileName;
- var docshell = EntityDocumentUtils.SaveDocument<TShell>(
- file,
- () => shell,
- "Created on Mobile Device"
- );
- Device.BeginInvokeOnMainThread(() =>
- {
- ItemsSource.Search();
- _imagelist.ItemsSource = null;
- _imagelist.ItemsSource = ItemsSource.Items;
- });
- return true;
- }
- }
- }
- return false;
- }
- private void _imagelist_OnRefreshRequested(object sender, MobileListRefreshEventArgs args)
- {
- RefreshRequested?.Invoke(this,args);
- }
- }
- }
|