Browse Source

PRS Mobile 1.04.1

Frank van den Bos 1 year ago
parent
commit
f83dfa2bb1

+ 37 - 24
InABox.Mobile/InABox.Mobile.Shared/Components/MobileGrid/MobileGrid.xaml

@@ -2,9 +2,10 @@
 
 <ContentView xmlns="http://xamarin.com/schemas/2014/forms"
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
-             xmlns:xForms="clr-namespace:Syncfusion.SfDataGrid.XForms;assembly=Syncfusion.SfDataGrid.XForms"
+             xmlns:grid="clr-namespace:Syncfusion.SfDataGrid.XForms;assembly=Syncfusion.SfDataGrid.XForms"
              xmlns:ui="clr-namespace:XF.Material.Forms.UI;assembly=XF.Material"
              xmlns:mobile="clr-namespace:InABox.Mobile;assembly=InABox.Mobile.Shared"
+             xmlns:pull="clr-namespace:Syncfusion.SfPullToRefresh.XForms;assembly=Syncfusion.SfPullToRefresh.XForms"
              x:Class="InABox.Mobile.MobileGrid" 
              x:DataType="mobile:MobileGrid"
              >
@@ -29,29 +30,41 @@
             <mobile:MobileCard
                 Grid.Row="1"
                 BackgroundColor="WhiteSmoke">
-                
-                <xForms:SfDataGrid 
-                    x:Name="Grid" 
-                    AutoGenerateColumns="False"
-                    SelectionMode="Single"
-                    GridViewCreated="Grid_OnGridViewCreated"
-                    SelectionChanged="Grid_OnSelectionChanged"
-                    GridTapped="Grid_OnGridTapped"
-                    AllowPullToRefresh="True"
-                    >
-                    <xForms:SfDataGrid.GridStyle>
-                        <xForms:DefaultStyle 
-                            GridCellBorderWidth="0"
-                            RowBackgroundColor="White"
-                            RowForegroundColor="Black"
-                            AlternatingRowColor="WhiteSmoke"
-                            SelectionBackgroundColor="Purple"
-                            SelectionForegroundColor="White"
-                            HeaderForegroundColor="DimGray"
-                            HeaderBackgroundColor="Transparent"
-                            HeaderCellBorderWidth="0"/>
-                    </xForms:SfDataGrid.GridStyle>
-                </xForms:SfDataGrid>
+                <!-- <pull:SfPullToRefresh -->
+                <!--     Refreshing="SfPullToRefresh_OnRefreshing" -->
+                <!--     x:Name="pullToRefresh" -->
+                <!--     IsRefreshing="False"  -->
+                <!--     PullingThreshold="100" -->
+                <!--     RefreshContentHeight="0" -->
+                <!--     RefreshContentThreshold="0" -->
+                <!--     RefreshContentWidth="0" -->
+                <!--     TransitionMode="Push"> -->
+                <!--      -->
+                <!--     <pull:SfPullToRefresh.PullableContent> -->
+                        <grid:SfDataGrid 
+                            x:Name="Grid" 
+                            AutoGenerateColumns="False"
+                            SelectionMode="Single"
+                            GridViewCreated="Grid_OnGridViewCreated"
+                            SelectionChanged="Grid_OnSelectionChanged"
+                            GridTapped="Grid_OnGridTapped"
+                            AllowPullToRefresh="True"
+                            >
+                            <grid:SfDataGrid.GridStyle>
+                                <grid:DefaultStyle 
+                                    GridCellBorderWidth="0"
+                                    RowBackgroundColor="White"
+                                    RowForegroundColor="Black"
+                                    AlternatingRowColor="WhiteSmoke"
+                                    SelectionBackgroundColor="Purple"
+                                    SelectionForegroundColor="White"
+                                    HeaderForegroundColor="DimGray"
+                                    HeaderBackgroundColor="Transparent"
+                                    HeaderCellBorderWidth="0"/>
+                            </grid:SfDataGrid.GridStyle>
+                        </grid:SfDataGrid>
+                <!--     </pull:SfPullToRefresh.PullableContent> -->
+                <!-- </pull:SfPullToRefresh> -->
                 
             </mobile:MobileCard>
             

+ 19 - 5
InABox.Mobile/InABox.Mobile.Shared/Components/MobileGrid/MobileGrid.xaml.cs

@@ -1,8 +1,10 @@
 using System;
 using System.Collections;
 using System.Linq;
+using System.Threading.Tasks;
 using System.Windows.Input;
 using InABox.Core;
+using InABox.Mobile.Shared;
 using Syncfusion.Data.Extensions;
 using Syncfusion.SfDataGrid.XForms;
 using Xamarin.Forms;
@@ -20,22 +22,21 @@ namespace InABox.Mobile
 
     public class PullToRefreshCommand : ICommand
     {
-
+    
         private readonly MobileGrid _grid;
         
         public bool CanExecute(object parameter)
         {
             return _grid.PullToRefresh;
         }
-
+    
         public void Execute(object parameter)
         {
-            
             _grid.RequestRefresh();
         }
-
+    
         public event EventHandler CanExecuteChanged;
-
+    
         public PullToRefreshCommand(MobileGrid grid)
         {
             _grid = grid;
@@ -165,7 +166,10 @@ namespace InABox.Mobile
 
         internal void RequestRefresh()
         {
+            var src = ItemsSource;
+            ItemsSource = null;
             RefreshRequested?.Invoke(this, new MobileGridRefreshRequestArgs());
+            ItemsSource = src;
         }
 
         private String _searchText = "";
@@ -260,5 +264,15 @@ namespace InABox.Mobile
             
         }
         
+        // private void SfPullToRefresh_OnRefreshing(object sender, EventArgs e)
+        // {
+        //     pullToRefresh.IsRefreshing = true;
+        //     var _items = ItemsSource;
+        //     ItemsSource = null;
+        //     RefreshRequested?.Invoke(this, new MobileGridRefreshRequestArgs());
+        //     pullToRefresh.IsRefreshing = false;
+        //     ItemsSource = _items;
+        // }
+        
     }
 }

+ 2 - 1
InABox.Mobile/InABox.Mobile.Shared/Components/MobileList/MobileList.xaml

@@ -28,7 +28,8 @@
                     SelectionMode="None">
                     <CollectionView.EmptyView>
                         <ui:MaterialLabel 
-                            Text="No Data Available" 
+                            x:Name="_emptylist"
+                            Text="No Data Avalable" 
                             VerticalOptions="CenterAndExpand" 
                             VerticalTextAlignment="Center"
                             HorizontalOptions="CenterAndExpand"

+ 1 - 0
InABox.Mobile/InABox.Mobile.Shared/Components/MobileList/MobileList.xaml.cs

@@ -97,6 +97,7 @@ namespace InABox.Mobile
                 _numrecords.Text = $"{(ItemsSource as IList)?.Count ?? 0} records";
                 _numrecords.IsVisible = ShowRecordCount && ItemsSource is IList;
                 _refreshcard.IsVisible = _lastupdate.IsVisible || _pulltorefresh.IsVisible || _numrecords.IsVisible;
+                _emptylist.IsVisible = !ShowRecordCount;
             });
         }
 

+ 40 - 8
InABox.Mobile/InABox.Mobile.Shared/DataModels/CoreRepository.cs

@@ -5,6 +5,7 @@ using System.ComponentModel;
 using System.IO;
 using System.Linq;
 using System.Linq.Expressions;
+using System.Reflection;
 using System.Runtime.CompilerServices;
 using System.Threading.Tasks;
 using InABox.Clients;
@@ -58,6 +59,17 @@ namespace InABox.Mobile
         
         protected CoreRepository(IModelHost host, Func<Filter<TEntity>> baseFilter)
         {
+            _items = new CoreObservableCollection<TItem>();   
+            BindingBase.EnableCollectionSynchronization(_items, null, 
+                (collection, context, method, access) =>
+                {
+                    lock (collection)
+                    {
+                        method?.Invoke();
+                    }
+                }
+            );
+            
             Reset();
             Host = host;
             BaseFilter = baseFilter;
@@ -208,8 +220,8 @@ namespace InABox.Mobile
         private IList<TItem> _allitems;
 
         private CoreTable _table = new CoreTable();
-        
-        private readonly CoreObservableCollection<TItem> _items = new CoreObservableCollection<TItem>();
+
+        private readonly CoreObservableCollection<TItem> _items;
         public IList<TItem> Items => _items;
         IEnumerable ICoreRepository.Items => Items;
         
@@ -296,7 +308,11 @@ namespace InABox.Mobile
             _items.ReplaceRange(items);
             OnPropertyChanged(nameof(Items));
         }
-        
+ 
+        void ICoreRepository.Search(Func<object,bool> method)
+            => Search((o) => method(o as TItem));
+
+
         #endregion
         
         protected virtual Expression<Func<TEntity, object>> ImageColumn => null;
@@ -323,6 +339,7 @@ namespace InABox.Mobile
                 );
             }
             
+            
         }  
         
         protected virtual void BeforeLoad(MultiQuery query)
@@ -337,10 +354,25 @@ namespace InABox.Mobile
         
         protected void DoLoad()
         {
-            DoBeforeLoad();
-            _query.Query();
-            DoAfterLoad();
-            LastUpdated = DateTime.Now;
+
+            try
+            {
+                DoBeforeLoad();
+                BeforeLoad(_query);
+                Task.Run(() =>
+                {
+                    _query.Query();
+                    DoAfterLoad();
+                }).Wait();
+                Search();
+                AfterLoad(_query);
+                LastUpdated = DateTime.Now;
+            }
+            catch (Exception e)
+            {
+                MobileLogging.Log(e,"CoreRepository");
+            }
+
         }
         
         protected void DoAfterLoad()
@@ -354,7 +386,7 @@ namespace InABox.Mobile
                 _query.Get<Document>().IntoDictionary<Document, Guid, byte[]>(Images, x => x.ID,
                     r => r.Get<Document, byte[]>(x => x.Data));
             }
-            AfterLoad(_query);            
+           
         }
         
         #endregion

+ 2 - 0
InABox.Mobile/InABox.Mobile.Shared/DataModels/ICoreRepository.cs

@@ -2,6 +2,7 @@ using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.ComponentModel;
+using System.Linq.Expressions;
 using Xamarin.Forms;
 
 namespace InABox.Mobile
@@ -37,6 +38,7 @@ namespace InABox.Mobile
         void DeleteItem(object item);
         IEnumerable Items { get; }
         void Search();
+        void Search(Func<object,bool> predicate);
         
         void ToggleSelection(object item);
         void SelectItem(object item);

+ 1 - 4
InABox.Mobile/InABox.Mobile.Shared/InABox.Mobile.Shared.csproj

@@ -25,6 +25,7 @@
         <PackageReference Include="Syncfusion.Licensing" Version="22.1.39" />
         <PackageReference Include="Syncfusion.Xamarin.SfDataGrid" Version="22.1.39" />
         <PackageReference Include="Syncfusion.Xamarin.SfPopupLayout" Version="22.1.39" />
+        <PackageReference Include="Syncfusion.Xamarin.SfPullToRefresh" Version="22.1.39" />
         <PackageReference Include="Xam.Plugin.Media" Version="6.0.2" />
         <PackageReference Include="Xamarin.Essentials" Version="1.7.7" />
         <PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" />
@@ -54,8 +55,4 @@
       <None Remove="Images\cross.svg" />
       <SharedImage Include="Images\sharedcross.svg" BaseSize="30, 30" />
     </ItemGroup>
-
-    <ItemGroup>
-      <Folder Include="DataModels\Lists\" />
-    </ItemGroup>
 </Project>

+ 25 - 0
InABox.Mobile/InABox.Mobile.Shared/TaskExtensions.cs

@@ -1,9 +1,29 @@
 using System;
+using System.Runtime.CompilerServices;
+using System.Threading;
 using System.Threading.Tasks;
 using Xamarin.Forms;
 
 namespace InABox.Mobile.Shared
 {
+    
+    public struct SynchronizationContextAwaiter : INotifyCompletion
+    {
+        private static readonly SendOrPostCallback _postCallback = state => ((Action)state)();
+
+        private readonly SynchronizationContext _context;
+        public SynchronizationContextAwaiter(SynchronizationContext context)
+        {
+            _context = context;
+        }
+
+        public bool IsCompleted => _context == SynchronizationContext.Current;
+
+        public void OnCompleted(Action continuation) => _context.Post(_postCallback, continuation);
+
+        public void GetResult() { }
+    }
+    
     public static class TaskExtensions
     {
         public static void BeginInvokeOnMainThread(this Task task, Action<Task> action)
@@ -13,5 +33,10 @@ namespace InABox.Mobile.Shared
                 Device.BeginInvokeOnMainThread(() => action(task));
             });
         }
+        
+        public static SynchronizationContextAwaiter GetAwaiter(this SynchronizationContext context)
+        {
+            return new SynchronizationContextAwaiter(context);
+        }
     }
 }

+ 9 - 9
InABox.Mobile/InABox.Mobile.iOS/MobileEditorRenderer.cs

@@ -41,14 +41,14 @@ namespace InABox.Mobile.iOS
             }
         }
         
-        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
-        {
-            base.OnElementPropertyChanged(sender, e);
-            if (Control != null)
-            {
-                // just change this statement to the one that works.
-                Control.SelectedTextRange = Control.GetTextRange(fromPosition: Control.BeginningOfDocument, toPosition: Control.BeginningOfDocument);
-            }
-        }
+        // protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+        // {
+        //     base.OnElementPropertyChanged(sender, e);
+        //     if (Control != null)
+        //     {
+        //         // just change this statement to the one that works.
+        //         Control.SelectedTextRange = Control.GetTextRange(fromPosition: Control.BeginningOfDocument, toPosition: Control.BeginningOfDocument);
+        //     }
+        // }
     }
 }