Explorar el Código

Fixed Image Rotation Cropping issues on iOS devices
Added "IsChanged" to MobileViewModel
Fixed some Converter Issues
Added "DuplicateInstance" to allow for "Complete & Duplicate" in Digital Forms

Frank van den Bos hace 1 año
padre
commit
cf6c6f4285

+ 8 - 0
InABox.Core/DigitalForms/DataModel/DigitalFormDataModel.cs

@@ -190,6 +190,14 @@ namespace InABox.Core
         {
         }
 
+        public void DuplicateInstance()
+        {
+            var formid = Instance.Form.ID;
+            Instance = new TInstance();
+            Instance.Parent.ID = Entity.ID;
+            Instance.Form.ID = formid;
+        }
+
         private void DoUpdate()
         {
             BeforeModelSaved?.Invoke(this);

+ 2 - 0
InABox.Core/DigitalForms/DataModel/IDigitalFormDataModel.cs

@@ -26,6 +26,8 @@ namespace InABox.Core
         /// <param name="callback">The callback to call once the update is finished, or <c>null</c> for synchronous execution.</param>
         void Update(Action<IDigitalFormDataModel>? callback);
 
+        void DuplicateInstance();
+
         object? GetEntityValue(string name);
         void SetEntityValue(string name, object? value);
     }

+ 4 - 4
InABox.Mobile/InABox.Mobile.Shared/Components/MobileListView/MobileListView.xaml.cs

@@ -16,7 +16,7 @@ namespace InABox.Mobile
         public static readonly BindableProperty PullToRefreshProperty = BindableProperty.Create(
             nameof(PullToRefresh), 
             typeof(bool), 
-            typeof(MobileCollectionView),
+            typeof(MobileListView),
             false);
 
         public bool PullToRefresh
@@ -72,7 +72,7 @@ namespace InABox.Mobile
         public static readonly BindableProperty LastUpdatedProperty = BindableProperty.Create(
             nameof(LastUpdated), 
             typeof(DateTime), 
-            typeof(MobileCollectionView));
+            typeof(MobileListView));
         
         public DateTime LastUpdated
         {
@@ -87,7 +87,7 @@ namespace InABox.Mobile
         public static readonly BindableProperty ShowRecordCountProperty = BindableProperty.Create(
             nameof(ShowRecordCount), 
             typeof(bool), 
-            typeof(MobileCollectionView), 
+            typeof(MobileListView), 
             false);
 
         public bool ShowRecordCount
@@ -103,7 +103,7 @@ namespace InABox.Mobile
         public static readonly BindableProperty EmptyTextProperty = BindableProperty.Create(
             nameof(EmptyText), 
             typeof(string), 
-            typeof(MobileCollectionView), 
+            typeof(MobileListView), 
             "No Data Available");
 
         public string EmptyText

+ 7 - 0
InABox.Mobile/InABox.Mobile.Shared/Components/MobileView/MobileViewModel.cs

@@ -1,3 +1,4 @@
+using System;
 using InABox.Core;
 using Xamarin.Forms;
 
@@ -35,9 +36,15 @@ namespace InABox.Mobile
                 SetValue(ItemProperty,value);
                 DoLoad();
                 OnLoaded();
+                OnPropertyChanged(nameof(IsChanged));
             }
         }
         
         protected abstract void DoLoad();
+
+        public abstract bool IsChanged { get; }
+
+        public void DoChanged() => OnPropertyChanged(nameof(IsChanged));
+
     }
 }

+ 10 - 0
InABox.Mobile/InABox.Mobile.Shared/Converters/IntToBooleanConverter.cs

@@ -14,6 +14,11 @@ namespace InABox.Mobile
         {
             return value == Value ? Result : !Result;
         }
+
+        public IntToBooleanConverter()
+        {
+            Result = true;
+        }
         
     }
     
@@ -29,5 +34,10 @@ namespace InABox.Mobile
             return value >= MinValue && value <= MaxValue  ? Result : !Result;
         }
         
+        public DoubleToBooleanConverter()
+        {
+            Result = true;
+        }
+        
     }
 }

+ 2 - 1
InABox.Mobile/InABox.Mobile.Shared/Converters/MultiConverters/Matcher/AbstractMatcher.cs

@@ -26,7 +26,7 @@ namespace InABox.Mobile
         
         protected override bool Convert(IEnumerable<T> value, object parameter = null)
         {
-            return Type switch
+            var result = Type switch
             {
                 MatchType.Any => Comparison == MatchComparison.EqualTo
                     ? value.Any(x => Equals(Value, x))
@@ -36,6 +36,7 @@ namespace InABox.Mobile
                     : value.All(x => !Equals(Value, x)),
                 _ => false
             };
+            return result;
         }
     }
 }

+ 7 - 1
InABox.Mobile/InABox.Mobile.Shared/Converters/MultiConverters/Matcher/BooleanMatcher.cs

@@ -1,4 +1,10 @@
 namespace InABox.Mobile
 {
-    public class BooleanMatcher : AbstractMatcher<bool> { }
+    public class BooleanMatcher : AbstractMatcher<bool>
+    {
+        public BooleanMatcher()
+        {
+            Value = true;
+        }
+    }
 }

+ 23 - 0
InABox.Mobile/InABox.Mobile.Shared/Converters/StringArrayToBooleanConverter.cs

@@ -0,0 +1,23 @@
+using System.Linq;
+
+namespace InABox.Mobile
+{
+    public class StringArrayToBooleanConverter : AbstractConverter<string[],bool>
+    {
+        public bool HasValue { get; set; }
+
+        protected override bool Convert(string[] value, object? parameter = null)
+        {
+            var empty = value?.Any() != true;
+            return HasValue 
+                ? !empty 
+                : empty;
+        }
+
+        public StringArrayToBooleanConverter()
+        {
+            HasValue = true;
+        }
+        
+    }
+}

+ 68 - 19
InABox.Mobile/InABox.Mobile.iOS/ImageToolsiOS.cs

@@ -134,31 +134,80 @@ namespace InABox.Mobile.iOS
 
         private UIImage RotateImage(UIImage source, float rotation)
         {
-            CGImage imgRef = source.CGImage;
-            float width = imgRef.Width;
-            float height = imgRef.Height;
-            CGAffineTransform transform = CGAffineTransform.MakeIdentity();
-            RectangleF bounds = new RectangleF(0, 0, width, height);
+            UIImage imageToReturn = null;
+            float radians = -1 * ((float)(rotation * Math.PI) / 180);
+            bool isLandscape = false;
 
-            float angle = Convert.ToSingle((rotation / 180f) * Math.PI);
-            transform = CGAffineTransform.MakeRotation(angle);
+            var x = source.Size.Width / 2;
+            var y = source.Size.Height / 2;
 
-            UIGraphics.BeginImageContext(bounds.Size);
+            //https://stackoverflow.com/a/8536553
+            CGAffineTransform transform = new CGAffineTransform((nfloat)Math.Cos(radians), (nfloat)Math.Sin(radians), -(nfloat)Math.Sin(radians), (nfloat)Math.Cos(radians), (nfloat)(x - x * Math.Cos(radians)) + (nfloat)(y * Math.Sin(radians)), (nfloat)(y - x * Math.Sin(radians) - y * Math.Cos(radians)));
 
-            CGContext context = UIGraphics.GetCurrentContext();
+            var diff = (source.Size.Height - source.Size.Width) / 2;
+            bool translateWidthAndHeight = false;
+            if (rotation == 90)
+            {
+                translateWidthAndHeight = true;
 
-            context.TranslateCTM(width / 2, height / 2);
-            context.SaveState();
-            context.ConcatCTM(transform);
-            context.SaveState();
-            context.ConcatCTM(CGAffineTransform.MakeScale(1.0f, -1.0f));
+                transform.Translate(diff, -diff);
+            }
+            else if (rotation == 180)
+            {
+                //Transform.Translate(image.Size.Width, -image.Size.Height);
+            }
+            else if (rotation == 270)
+            {
+                translateWidthAndHeight = true;
+                transform.Translate(diff, -diff);
+            }
+            else if (rotation == 360)
+            {
 
-            context.DrawImage(new RectangleF(-width / 2, -height / 2, width, height), imgRef);
-            context.RestoreState();
+            }
 
-            UIImage result = UIGraphics.GetImageFromCurrentImageContext();
-            UIGraphics.EndImageContext();
-            return result;
+            if (translateWidthAndHeight)
+            {
+                //now draw image
+                using (var context = new CGBitmapContext(IntPtr.Zero,
+                                                        (int)source.Size.Height,
+                                                        (int)source.Size.Width,
+                                                        source.CGImage.BitsPerComponent,
+                                                        source.CGImage.BitsPerComponent * (int)source.Size.Width,
+                                                        source.CGImage.ColorSpace,
+                                                        source.CGImage.BitmapInfo))
+                {
+                    context.ConcatCTM(transform);
+                    context.DrawImage(new RectangleF(PointF.Empty, new SizeF((float)source.Size.Width, (float)source.Size.Height)), source.CGImage);
+
+                    using (var imageRef = context.ToImage())
+                    {
+                        imageToReturn = new UIImage(imageRef);
+                    }
+                }
+            }
+            else
+            {
+                //now draw image
+                using (var context = new CGBitmapContext(IntPtr.Zero,
+                                                        (int)source.Size.Width,
+                                                        (int)source.Size.Height,
+                                                        source.CGImage.BitsPerComponent,
+                                                        source.CGImage.BitsPerComponent * (int)source.Size.Height,
+                                                        source.CGImage.ColorSpace,
+                                                        source.CGImage.BitmapInfo))
+                {
+                    context.ConcatCTM(transform);
+                    context.DrawImage(new RectangleF(PointF.Empty, new SizeF((float)source.Size.Width, (float)source.Size.Height)), source.CGImage);
+
+                    using (var imageRef = context.ToImage())
+                    {
+                        imageToReturn = new UIImage(imageRef);
+                    }
+                }
+            }
+
+            return imageToReturn;
         }
 
         private UIImage ScaleImage(UIImage sourceImage, Size? constraints)