Quellcode durchsuchen

Finish Doc Scanner Module
Improved Document List Features
Changing Settings now Resets Cache Data

Frank van den Bos vor 1 Jahr
Ursprung
Commit
26253c72b9

+ 1 - 1
prs.mobile.new/PRS.Mobile.Droid/Properties/AndroidManifest.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="725100" android:versionName="7.25.1" package="comal.timesheets.Android">
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="726000" android:versionName="7.26.0" package="comal.timesheets.Android">
 	<uses-sdk android:minSdkVersion="29" android:targetSdkVersion="33" />
 	<queries>
 		<intent>

+ 1 - 1
prs.mobile.new/PRS.Mobile.iOS/Info.plist

@@ -27,7 +27,7 @@
 	<key>CFBundleIdentifier</key>
 	<string>com.prsdigital.prssiteapp</string>
 	<key>CFBundleVersion</key>
-	<string>7.25</string>
+	<string>7.26</string>
 	<key>UILaunchStoryboardName</key>
 	<string>LaunchScreen</string>
 	<key>CFBundleName</key>

+ 5 - 1
prs.mobile.new/PRS.Mobile/Components/DocumentList/DocumentList.xaml

@@ -6,7 +6,8 @@
              xmlns:mobile="clr-namespace:InABox.Mobile;assembly=InABox.Mobile.Shared"
              xmlns:ui="clr-namespace:XF.Material.Forms.UI;assembly=XF.Material"
              xmlns:converters="http://xamarin.com/schemas/2020/toolkit"
-             x:Class="PRS.Mobile.DocumentList">
+             x:Class="PRS.Mobile.DocumentList"
+             x:DataType="local:DocumentList">
     
     <mobile:BaseMobileView.Resources>
         <converters:ByteArrayToImageSourceConverter x:Key="ByteArrayToImageSourceConverter"/>
@@ -16,6 +17,9 @@
         
         <mobile:MobileList 
             x:Name="_imagelist"
+            PullToRefresh="False"
+            RefreshRequested="_imagelist_OnRefreshRequested"
+            ShowRecordCount="False"
         >
             <!-- ItemsSource="{Binding Documents.Items}" -->
             <mobile:MobileList.ItemTemplate>

+ 53 - 27
prs.mobile.new/PRS.Mobile/Components/DocumentList/DocumentList.xaml.cs

@@ -3,6 +3,7 @@ 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
@@ -18,11 +19,26 @@ namespace PRS.Mobile
             set
             {
                 _itemsSource = value;
-                _imagelist.ItemsSource = value.Items;
+                _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()
         {
@@ -46,7 +62,7 @@ namespace PRS.Mobile
             }
         }
 
-        public async Task<bool> AddImage<T, TShell>(bool pdf = false, Action<TShell> customiseshell = null) 
+        public async Task<bool> AddImage<T, TShell>(bool pdf = false, Func<TShell, Task<bool>> customiseshell = null) 
             where T : MobileDocumentSource, new() 
             where TShell : class, IEntityDocumentShell
         {
@@ -64,33 +80,38 @@ namespace PRS.Mobile
             
             if (file != null)
             {
-                using (await MaterialDialog.Instance.LoadingDialogAsync("Saving Image"))
+                var shell = ItemsSource.AddItem() as TShell;
+                shell.ParentID = ParentID;
+                
+                bool confirm = (customiseshell == null) 
+                    || await customiseshell.Invoke(shell);
+                
+                if (confirm)
                 {
-                    var thumbnail = MobileUtils.ImageTools.CreateThumbnail(file.Data, 256, 256);
-                    
-                    if (pdf)
-                        file = file.ToPDF();
-                    
-                    var docshell = EntityDocumentUtils.SaveDocument<TShell>(
-                        file,
-                        () =>
-                        {
-                            var shell = ItemsSource.AddItem() as TShell;
-                            shell.ParentID = ParentID;
-                            shell.FileName = file.FileName;
-                            shell.Thumbnail = thumbnail;
-                            customiseshell?.Invoke(shell);
-                            return shell;
-                        },
-                        "Created on Mobile Device"
-                    );
-                    Device.BeginInvokeOnMainThread(() =>
+                    using (await MaterialDialog.Instance.LoadingDialogAsync("Saving Image"))
                     {
-                        ItemsSource.Search();
-                        _imagelist.ItemsSource = null;
-                        _imagelist.ItemsSource = ItemsSource.Items;
-                    });
-                    return true;
+                        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;
+                    }
                 }
 
             }
@@ -99,5 +120,10 @@ namespace PRS.Mobile
 
 
         }
+
+        private void _imagelist_OnRefreshRequested(object sender, MobileListRefreshEventArgs args)
+        {
+            RefreshRequested?.Invoke(this,args);
+        }
     }
 }

+ 1 - 0
prs.mobile.new/PRS.Mobile/Data Models/Lists/Scan/ScanModel.cs

@@ -12,4 +12,5 @@ namespace PRS.Mobile
         {
         }
     }
+    
 }

+ 14 - 0
prs.mobile.new/PRS.Mobile/Data Models/Lists/ScanTag/ScanTagModel.cs

@@ -0,0 +1,14 @@
+using System;
+using Comal.Classes;
+using InABox.Core;
+using InABox.Mobile;
+
+namespace PRS.Mobile
+{
+    public class ScanTagModel : CoreRepository<ScanTagModel, ScanTagShell, ScanTag>
+    {
+        public ScanTagModel(IModelHost host, Func<Filter<ScanTag>> baseFilter) : base(host, baseFilter)
+        {
+        }
+    }
+}

+ 16 - 0
prs.mobile.new/PRS.Mobile/Data Models/Lists/ScanTag/ScanTagShell.cs

@@ -0,0 +1,16 @@
+using System;
+using Comal.Classes;
+using InABox.Mobile;
+
+namespace PRS.Mobile
+{
+    public class ScanTagShell : Shell<ScanTagModel, ScanTag>
+    {
+        protected override void ConfigureColumns(ShellColumns<ScanTagModel, ScanTag> columns)
+        {
+            columns.Map(nameof(Name), x => x.Name);
+        }
+
+        public String Name => Get<String>();
+    }
+}

+ 29 - 15
prs.mobile.new/PRS.Mobile/Main/SettingsPage.xaml.cs

@@ -38,13 +38,23 @@ namespace PRS.Mobile
         {
             Navigation.PopAsync();
         }
-
+        
         private async void Save_OnClicked(object sender, EventArgs args)
         {
-            _settings.URLs = stringList.SaveItems();
-            _settings.UserID = userIDEnt.Text?.Trim() ?? "";
-            _settings.Password = passwordEnt.Text?.Trim() ?? "";
-            new LocalConfiguration<DatabaseSettings>().Save(_settings);
+
+            var urls = stringList.SaveItems();
+            var user = userIDEnt.Text?.Trim() ?? "";
+            var pass = passwordEnt.Text?.Trim() ?? "";
+
+            if (!urls.SequenceEqual(_settings.URLs) ||
+                (!String.Equals(user, _settings.UserID) || !String.Equals(pass, _settings.Password)))
+            {
+                _settings.URLs = urls;
+                _settings.UserID = user;
+                _settings.Password = pass;
+                new LocalConfiguration<DatabaseSettings>().Save(_settings);
+                DoClearCaches();
+            }
 
             ClientFactory.InvalidateUser();
             if (App.Current.Properties.ContainsKey("SessionID"))
@@ -122,6 +132,7 @@ namespace PRS.Mobile
                 _settings.UserID = "GUEST";
                 _settings.Password = "guest";
                 new LocalConfiguration<DatabaseSettings>().Save(_settings);
+                DoClearCaches();
                 Device.BeginInvokeOnMainThread(Populate);
             }
         }
@@ -150,17 +161,20 @@ namespace PRS.Mobile
             var confirm = await MaterialDialog.Instance.ConfirmAsync("Are your sure you wish to clear your caches?",
                 "Clear Caches", "OK", "Cancel");
             if (confirm == true)
+                DoClearCaches();
+        }
+
+        private void DoClearCaches()
+        {
+            ProgressVisible = true;
+            var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
+            var files = Directory.GetFiles(path);
+            Task.Run(() =>
             {
-                ProgressVisible = true;
-                var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
-                var files = Directory.GetFiles(path);
-                Task.Run(() =>
-                {
-                    foreach (var file in files)
-                        File.Delete(file);
-                }).Wait();
-                ProgressVisible = false;
-            }
+                foreach (var file in files)
+                    File.Delete(file);
+            }).Wait();
+            ProgressVisible = false;
         }
     }
 }

+ 7 - 0
prs.mobile.new/PRS.Mobile/MainPage.xaml

@@ -177,6 +177,13 @@
                         Text="Orders"
                         Image="shoppingcart"
                         Clicked="PurchaseOrderListTapped"
+                        IsEnabled="False"/> 
+                    
+                    <mobile:MobileToolItem
+                        x:Name="Scans"
+                        Text="Doc Scanner"
+                        Image="camera"
+                        Clicked="ScanModuleTapped"
                         IsEnabled="False"/>  
                                 
                     <mobile:MobileToolItem

+ 4 - 5
prs.mobile.new/PRS.Mobile/MainPage.xaml.cs

@@ -3,7 +3,6 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading;
 using System.Threading.Tasks;
-using System.Windows.Input;
 using Xamarin.Forms;
 using InABox.Core;
 using InABox.Clients;
@@ -11,7 +10,6 @@ using InABox.Mobile;
 using Comal.Classes;
 using InABox.Configuration;
 using JetBrains.Annotations;
-using Xamarin.Forms.Xaml;
 using XF.Material.Forms.UI.Dialogs;
 using Comal.Classes.SecurityDescriptors;
 
@@ -169,6 +167,7 @@ namespace PRS.Mobile
             Meetings.IsVisible = Security.IsAllowed<ViewMobileMeetingsModule>();
             Products.IsVisible = Security.IsAllowed<ViewMobileProductsModule>();
             PurchaseOrders.IsVisible = Security.IsAllowed<ViewMobilePurchaseOrdersModule>();
+            Scans.IsVisible = Security.IsAllowed<ViewMobileScansModule>();
             StoreRequis.IsVisible = Security.IsAllowed<ViewMobileStoreRequisModule>();
             MyTasks.IsVisible = Security.IsAllowed<ViewMobileMyTasksModule>();
             Warehousing.IsVisible = Security.IsAllowed<ViewMobileWarehousingModule>();
@@ -360,6 +359,7 @@ namespace PRS.Mobile
             Notifications.IsEnabled = App.Data.IsConnected();
             Products.IsEnabled = App.Data.IsConnected();
             PurchaseOrders.IsEnabled = App.Data.IsConnected();
+            Scans.IsEnabled = App.Data.IsConnected();
             Site.IsEnabled = App.Data.IsConnected();
             StoreRequis.IsEnabled = App.Data.IsConnected();
             MyTasks.IsEnabled = App.Data.IsConnected();
@@ -877,8 +877,7 @@ namespace PRS.Mobile
         public void WarehouseModuleTapped(object sender, EventArgs args) => Navigation.PushAsync(new WarehouseModule());
 
         public void UpdatePageTapped(object sender, EventArgs args) => Navigation.PushAsync(new UpdatePage());
-
-
-
+        
+        private void ScanModuleTapped(object sender, EventArgs e) => Navigation.PushAsync(new ScanModule());
     }
 }

+ 7 - 3
prs.mobile.new/PRS.Mobile/Modules/Scans/ScanModule.xaml

@@ -4,8 +4,8 @@
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              xmlns:mobile="clr-namespace:InABox.Mobile;assembly=InABox.Mobile.Shared"
              xmlns:local="clr-namespace:PRS.Mobile;assembly=PRS.Mobile"
-             x:Class="PRS.Mobile.Modules.Scans.ScanModule">
-    
+             x:Class="PRS.Mobile.ScanModule"
+             Title="Submitted Documents">
     <mobile:MobilePage.PrimaryMenu>
         
         <mobile:MobileMenuButton
@@ -20,7 +20,11 @@
     
     <mobile:MobilePage.PageContent>
         <local:DocumentList
-            x:Name="_documents" />
+            x:Name="_documents" 
+            PullToRefresh="True"
+            RefreshRequested="_documents_OnRefreshRequested"
+            ShowRecordCount = "True"
+            Margin="5"/>
     </mobile:MobilePage.PageContent>
     
 </mobile:MobilePage>

+ 32 - 7
prs.mobile.new/PRS.Mobile/Modules/Scans/ScanModule.xaml.cs

@@ -9,11 +9,12 @@ using InABox.Mobile;
 using Xamarin.Forms;
 using Xamarin.Forms.Xaml;
 
-namespace PRS.Mobile.Modules.Scans
+namespace PRS.Mobile
 {
     [XamlCompilation(XamlCompilationOptions.Compile)]
     public partial class ScanModule
     {
+        private ScanTagModel _tags;
         private ScanModel _scans;
         
         public ScanModule()
@@ -22,37 +23,61 @@ namespace PRS.Mobile.Modules.Scans
                 () => new Filter<Scan>(x => x.Employee.ID).IsEqualTo(App.Data.Me.ID)
                     .And(x => x.Processed).IsEqualTo(false)
             ) { FileName = "scans.data" };
+            _tags = new ScanTagModel(App.Data, null) { FileName = "scantags.data" };
+            
             InitializeComponent();
+            ProgressVisible = true;
             RefreshData(false, true);
         }
 
         private void RefreshData(bool force, bool async)
         {
+            Task[] tasks = new Task[]
+            {
+                Task.Run(() => _scans.Refresh(force)),
+                Task.Run(() => _tags.Refresh(force))
+            };
             if (async)
-                _scans.Refresh(force, () => Device.BeginInvokeOnMainThread(RefreshScreen));
+                Task.WhenAll(tasks).ContinueWith((_) => Device.BeginInvokeOnMainThread(RefreshScreen));
             else
             {
-                _scans.Refresh(force);
+                Task.WaitAll(tasks);
                 RefreshScreen();
             }
         }
 
         private void RefreshScreen()
         {
+            ProgressVisible = false;
             _documents.ItemsSource = null;
             _documents.ItemsSource = _scans;
         }
 
+        private async Task<bool> ConfirmScan(ScanShell shell)
+        {
+            shell.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());
+            shell.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<MobileDocumentCameraSource,ScanShell>(
-                true, (shell) => shell.EmployeeID = App.Data.Me.ID);
+            await _documents.AddImage<MobileDocumentCameraSource,ScanShell>(false, ConfirmScan);
         }
 
         private async void BrowseLibrary_Clicked(object sender, EventArgs e)
         {
-            await _documents.AddImage<MobileDocumentLibrarySource,ScanShell>(
-                true, (shell) => shell.EmployeeID = App.Data.Me.ID);
+            await _documents.AddImage<MobileDocumentLibrarySource,ScanShell>(false, ConfirmScan);
+        }
+
+        private void _documents_OnRefreshRequested(object sender, MobileListRefreshEventArgs args)
+        {
+            RefreshData(true,false);
         }
     }
 }