|
|
@@ -6,6 +6,7 @@ using Syncfusion.XForms.PopupLayout;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
+using System.Collections.Specialized;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
@@ -22,7 +23,7 @@ namespace comal.timesheets
|
|
|
}
|
|
|
|
|
|
public delegate void DataGridOptionsSet(string title, DataGridSaveType savetype = DataGridSaveType.None);
|
|
|
- public delegate void DataGridItemSelected(DataGridViewModelItem item);
|
|
|
+ public delegate object DataGridItemSelected(DataGridViewModelItem item);
|
|
|
[XamlCompilation(XamlCompilationOptions.Compile)]
|
|
|
public partial class MobileDataGrid : ContentView
|
|
|
{
|
|
|
@@ -48,7 +49,7 @@ namespace comal.timesheets
|
|
|
popupLayout = new SfPopupLayout();
|
|
|
popupLayout.PopupView.WidthRequest = 600;
|
|
|
popupLayout.PopupView.HeightRequest = 600;
|
|
|
- popupLayout.PopupView.HeaderTitle = "Image";
|
|
|
+ popupLayout.PopupView.HeaderTitle = "Detail";
|
|
|
popupLayout.PopupView.AcceptButtonText = "Close";
|
|
|
}
|
|
|
|
|
|
@@ -67,10 +68,12 @@ namespace comal.timesheets
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Never pass CurrentItems into this function - create an intermediate list first
|
|
|
+ /// Never pass CurrentItems into this function
|
|
|
+ /// - Create an intermediate list first
|
|
|
+ /// - CurrentItems gets cleared in order to be reset properly
|
|
|
/// </summary>
|
|
|
/// <param name="items"></param>
|
|
|
- private void Refresh(List<DataGridViewModelItem> items)
|
|
|
+ public void Refresh(List<DataGridViewModelItem> items, bool RefreshFromExternal = false)
|
|
|
{
|
|
|
itemsListView.ItemsSource = items;
|
|
|
countLbl.Text = items.Count + " Records";
|
|
|
@@ -104,6 +107,8 @@ namespace comal.timesheets
|
|
|
SelectListViewTemplate(item);
|
|
|
}
|
|
|
|
|
|
+ //only way to reliably get the desired layout/correct bindings dynamically - viewcells are predefined in DataGrid/View/Templates folder.
|
|
|
+ //Mobiles will only ever want 4 columns maximum, so the predefined templates are a small tradeoff
|
|
|
private void SelectListViewTemplate(DataGridViewModelItem item)
|
|
|
{
|
|
|
var template = new DataTemplate();
|
|
|
@@ -112,12 +117,12 @@ namespace comal.timesheets
|
|
|
switch (item.Data.Count)
|
|
|
{
|
|
|
case 2:
|
|
|
- template = new DataTemplate(() =>
|
|
|
+ template = new DataTemplate(() =>
|
|
|
{
|
|
|
var cell = new ViewCell2Columns();
|
|
|
cell.OnCellTapped += Row_Tapped;
|
|
|
return cell;
|
|
|
- });
|
|
|
+ });
|
|
|
break;
|
|
|
case 3:
|
|
|
template = new DataTemplate(() =>
|
|
|
@@ -158,7 +163,7 @@ namespace comal.timesheets
|
|
|
cell.OnImageTapped += Image_Tapped;
|
|
|
return cell;
|
|
|
});
|
|
|
- break;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
itemsListView.ItemTemplate = template;
|
|
|
@@ -232,12 +237,25 @@ namespace comal.timesheets
|
|
|
#endregion
|
|
|
|
|
|
#region Events
|
|
|
+ /// <summary>
|
|
|
+ /// Depending on the selection mode of the supplied entity grid, tap will do different things
|
|
|
+ /// - Does not apply to images
|
|
|
+ /// - Multi select mode adds to selection (or removes it if already selected)
|
|
|
+ /// - Single select mode adds to selection (or removes it if already selected), removes any other selected items
|
|
|
+ /// - None does not select or deselect
|
|
|
+ ///
|
|
|
+ /// - NOTE that Item Selected event can return an object - e.g. a view to be displayed in a popup (since grids don't have access to popups)
|
|
|
+ /// - This allows different selection reactions to be defined at the grid level, or even different reactions for the same grid depending on where it is called from
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
private void Row_Tapped(object sender, EventArgs e)
|
|
|
{
|
|
|
var item = itemsListView.SelectedItem as DataGridViewModelItem;
|
|
|
if (item == null)
|
|
|
return;
|
|
|
- if (SaveType != DataGridSaveType.None)
|
|
|
+
|
|
|
+ if (SaveType == DataGridSaveType.Single || SaveType == DataGridSaveType.Multiple)
|
|
|
{
|
|
|
switch (SaveType)
|
|
|
{
|
|
|
@@ -255,9 +273,23 @@ namespace comal.timesheets
|
|
|
list.Add(i);
|
|
|
Refresh(list);
|
|
|
}
|
|
|
- else if (SaveType == DataGridSaveType.None)
|
|
|
+
|
|
|
+ var obj = OnItemSelected?.Invoke(item);
|
|
|
+ ProcessReturnObj(obj, item);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ProcessReturnObj(object obj, DataGridViewModelItem item)
|
|
|
+ {
|
|
|
+ if (obj == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (obj is View)
|
|
|
{
|
|
|
- OnItemSelected?.Invoke(item);
|
|
|
+ popupLayout.PopupView.ContentTemplate = new DataTemplate(() =>
|
|
|
+ {
|
|
|
+ return obj;
|
|
|
+ });
|
|
|
+ Device.BeginInvokeOnMainThread(() => { popupLayout.Show(); });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -337,7 +369,6 @@ namespace comal.timesheets
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private void Filters_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
|
|
{
|
|
|
if (bSearching)
|
|
|
@@ -533,7 +564,7 @@ namespace comal.timesheets
|
|
|
|| GetStringValue(property, item).Contains(value.ToLower())
|
|
|
|| GetStringValue(property, item).Contains(SearchUtils.LowerCaseFirst(value))
|
|
|
|| GetStringValue(property, item).Contains(SearchUtils.UpperCaseFirst(value))
|
|
|
- || GetStringValue(property, item).Contains(SearchUtils.UpperCaseSecond(value))
|
|
|
+ || GetStringValue(property, item).Contains(SearchUtils.UpperCaseSecond(value))
|
|
|
)
|
|
|
{
|
|
|
if (!intermediatelist.Contains(item))
|
|
|
@@ -657,7 +688,9 @@ namespace comal.timesheets
|
|
|
public bool ImageColVisible { get; set; }
|
|
|
public bool Col3IsVisible { get; set; }
|
|
|
|
|
|
- public DataGridViewModelItem(Guid id, List<Tuple<string, string>> data, Image image = null, Guid imageid = new Guid())
|
|
|
+ public string ExtraDetail { get; set; }
|
|
|
+
|
|
|
+ public DataGridViewModelItem(Guid id, List<Tuple<string, string>> data, Image image = null, Guid imageid = new Guid(), string extradetail = "")
|
|
|
{
|
|
|
ID = id;
|
|
|
ImageID = imageid;
|
|
|
@@ -676,6 +709,7 @@ namespace comal.timesheets
|
|
|
ColWidth3 = data.Count > 3 ? new GridLength(1, GridUnitType.Star) : new GridLength(0, GridUnitType.Auto);
|
|
|
Col3IsVisible = data.Count > 3 ? true : false;
|
|
|
IsSelected = false;
|
|
|
+ ExtraDetail = extradetail;
|
|
|
}
|
|
|
}
|
|
|
}
|