using ElmSharp;
namespace Xamarin.Forms.Platform.Tizen.Native
{
///
/// Extends the ListView class to provide TableView class implementation.
///
public class TableView : ListView
{
static readonly SectionCellRenderer _sectionCellRenderer = new SectionCellRenderer();
///
/// Initializes a new instance of the TableView class.
///
public TableView(EvasObject parent)
: base(parent) {
}
///
/// Sets the root of the table.
///
/// TableRoot, which is parent to one or more TableSections.
public void ApplyTableRoot(TableRoot root)
{
Clear();
foreach (TableSection ts in root)
{
if(!string.IsNullOrEmpty(ts.Title))
AddSectionTitle(ts.Title);
AddSource(ts);
}
}
protected override CellRenderer GetCellRenderer(Cell cell, bool isGroup = false)
{
if (cell.GetType() == typeof(SectionCell))
{
return _sectionCellRenderer;
}
return base.GetCellRenderer(cell, isGroup);
}
///
/// Sets the section title.
///
void AddSectionTitle(string title)
{
Cell cell = new SectionCell()
{
Text = title
};
AddCell(cell);
}
internal class SectionCellRenderer : GroupCellTextRenderer
{
public SectionCellRenderer()
{
DetailPart = "null";
}
protected SectionCellRenderer(string style) : base(style) { }
}
class SectionCell : TextCell
{
}
}
}