Forráskód Böngészése

Moved DynamicTreeNodes into InABox.Mobile.Shared (temporarily?)

Frank van den Bos 2 éve
szülő
commit
ecee319317

+ 2 - 1
InABox.Mobile/InABox.Mobile.Android/Version_Android.cs

@@ -4,8 +4,9 @@ using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using Android.App;
 using Android.Content;
-using Android.Content.PM;
 using Android.Runtime;
+using Java.Net;
+using Xamarin.Android.Net;
 using Net = Android.Net;
 
 

+ 0 - 4
InABox.Mobile/InABox.Mobile.Shared/Bluetooth.cs

@@ -2,15 +2,11 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
-using System.Threading;
 using System.Threading.Tasks;
 using Plugin.BLE;
-using Plugin.BLE.Abstractions;
 using Plugin.BLE.Abstractions.Contracts;
 
 
-using Xamarin.Forms;
-
 namespace InABox.Mobile
 {
     public class Bluetooth

+ 132 - 0
InABox.Mobile/InABox.Mobile.Shared/DynamicTreeNodes.cs

@@ -0,0 +1,132 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Linq;
+using System.Linq.Expressions;
+using InABox.Core;
+using Xamarin.Forms;
+
+namespace InABox.Mobile
+{
+    public class DynamicTreeNode : INotifyPropertyChanged
+    {
+
+        private DynamicTreeNodes _owner;
+        
+        public ObservableCollection<DynamicTreeNode> Children => _owner.GetChilden(_id);
+        
+        private Guid _id;
+        public Guid ID 
+        {
+            get { return _id; }
+            set
+            {
+                _id = value;
+                RaisedOnPropertyChanged("ID");
+            }
+        }
+        
+        private Guid _parent;
+        public Guid Parent 
+        {
+            get { return _parent; }
+            set
+            {
+                _parent = value;
+                RaisedOnPropertyChanged("Parent");
+            }
+        }
+
+        private string _description;
+        public string Description
+        {
+            get { return _description; }
+            set
+            {
+                _description = value;
+                RaisedOnPropertyChanged("Description");
+            }
+        }
+   
+        private ImageSource? _image;
+        public ImageSource? Image
+        {
+            get { return _image; }
+            set
+            {
+                _image = value;
+                RaisedOnPropertyChanged("Image");
+            }
+        }
+
+        public event PropertyChangedEventHandler? PropertyChanged;
+
+        public void RaisedOnPropertyChanged(string propertyName)
+        {
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+        }
+
+        public DynamicTreeNode(DynamicTreeNodes owner)
+        {
+            _owner = owner;
+            _description = "";
+        }
+
+        public DynamicTreeNode(DynamicTreeNodes owner, Guid id, Guid parent) : this(owner)
+        {
+            _id = id;
+            _parent = parent;
+        }
+    }
+
+    public class DynamicTreeNodes 
+    {
+
+        private List<DynamicTreeNode> _nodes;
+        public ObservableCollection<DynamicTreeNode> Nodes => new ObservableCollection<DynamicTreeNode>(_nodes.Where(x => x.Parent == Guid.Empty));
+        
+        public DynamicTreeNode? this[Guid id] => _nodes.FirstOrDefault(x => x.ID == id);
+        
+        public DynamicTreeNodes()
+        {
+            _nodes = new List<DynamicTreeNode>();
+        }
+
+        public DynamicTreeNode Add(Guid id, Guid parent)
+        {
+            var node = new DynamicTreeNode(this, id, parent);
+            _nodes.Add(node);
+            return node;
+        }
+        
+        public DynamicTreeNode Find(Guid id) => _nodes.FirstOrDefault(x => x.ID == id);
+
+        public void GetChildren(List<Guid> nodes, Guid id)
+        {
+            nodes.Add(id);
+            var children = GetChilden(id);
+            foreach (var child in children)
+                GetChildren(nodes, child.ID);
+        }
+        
+        public ObservableCollection<DynamicTreeNode> GetChilden(Guid id)
+        {
+            
+            return new ObservableCollection<DynamicTreeNode>(_nodes.Where(x => x.Parent.Equals(id) && (x.ID != id)));
+        }
+
+        public void Load<T>(CoreTable table, Expression<Func<T, Guid>> id, Expression<Func<T, Guid>> parentid, Expression<Func<T, String>> description)
+        {
+            _nodes.Clear();
+            foreach (var row in table.Rows)
+            {
+                Guid _id = row.Get<T, Guid>(id);
+                Guid _parent = row.Get<T, Guid>(parentid);
+                String _description = row.Get<T, String>(description);
+                Add(_id, _parent).Description = _description;
+            }
+        }
+        
+    }
+}

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

@@ -6,6 +6,7 @@
     </PropertyGroup>
 
     <ItemGroup>
+        <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
         <PackageReference Include="Plugin.BLE" Version="2.1.3" />
         <PackageReference Include="Serilog" Version="3.0.1" />
         <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />