diff options
author | Samantha Houts <samantha@teamredwall.com> | 2016-06-17 03:10:18 -0700 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-06-17 11:10:18 +0100 |
commit | 925fc0aa588a060eb23fa16c1d225dd030012c23 (patch) | |
tree | 83676c25c29d97d9250516b217020ba85425796d /Xamarin.Forms.Platform.Android | |
parent | d44396a4534b1e2bc81143c809e4adaee656ab15 (diff) | |
download | xamarin-forms-925fc0aa588a060eb23fa16c1d225dd030012c23.tar.gz xamarin-forms-925fc0aa588a060eb23fa16c1d225dd030012c23.tar.bz2 xamarin-forms-925fc0aa588a060eb23fa16c1d225dd030012c23.zip |
Prep Cell & friends for removal of InternalsVisibleTo (#142)
* Prep Cell & friends for removal of InternalsVisibleTo
Includes:
- Cell
- EntryCell
- ListView
- MenuItem
- TableView
- ViewCell
- Toolbar
Moved extensions to Internal & removed TPH
* Update docs
* [Controls] Ignore Issue2411 on iOS <9
* [Controls] Formatting for Issue2411
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
14 files changed, 110 insertions, 78 deletions
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs b/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs index 277be331..cb4fcdbb 100644 --- a/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs +++ b/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs @@ -653,12 +653,13 @@ namespace Xamarin.Forms.Platform.Android.AppCompat foreach (ToolbarItem item in _toolbarTracker.ToolbarItems) { + IMenuItemController controller = item; item.PropertyChanged += HandleToolbarItemPropertyChanged; if (item.Order == ToolbarItemOrder.Secondary) { IMenuItem menuItem = menu.Add(item.Text); - menuItem.SetEnabled(item.IsEnabled); - menuItem.SetOnMenuItemClickListener(new GenericMenuClickListener(item.Activate)); + menuItem.SetEnabled(controller.IsEnabled); + menuItem.SetOnMenuItemClickListener(new GenericMenuClickListener(controller.Activate)); } else { @@ -670,9 +671,9 @@ namespace Xamarin.Forms.Platform.Android.AppCompat if (iconBitmap != null) menuItem.SetIcon(iconBitmap); } - menuItem.SetEnabled(item.IsEnabled); + menuItem.SetEnabled(controller.IsEnabled); menuItem.SetShowAsAction(ShowAsAction.Always); - menuItem.SetOnMenuItemClickListener(new GenericMenuClickListener(item.Activate)); + menuItem.SetOnMenuItemClickListener(new GenericMenuClickListener(controller.Activate)); } } } diff --git a/Xamarin.Forms.Platform.Android/CellAdapter.cs b/Xamarin.Forms.Platform.Android/CellAdapter.cs index 58c35a89..4c8ac10d 100644 --- a/Xamarin.Forms.Platform.Android/CellAdapter.cs +++ b/Xamarin.Forms.Platform.Android/CellAdapter.cs @@ -202,7 +202,7 @@ namespace Xamarin.Forms.Platform.Android if (action.Command != null) action.Command.CanExecuteChanged += commandChanged; - if (!action.IsEnabled) + if (!((IMenuItemController)action).IsEnabled) item.SetEnabled(false); } } @@ -247,7 +247,7 @@ namespace Xamarin.Forms.Platform.Android void OnActionItemClickedImpl(IMenuItem item) { int index = item.ItemId; - MenuItem action = ActionModeContext.ContextActions[index]; + IMenuItemController action = ActionModeContext.ContextActions[index]; action.Activate(); } diff --git a/Xamarin.Forms.Platform.Android/Cells/BaseCellView.cs b/Xamarin.Forms.Platform.Android/Cells/BaseCellView.cs index 7ae8aad5..74c56dbd 100644 --- a/Xamarin.Forms.Platform.Android/Cells/BaseCellView.cs +++ b/Xamarin.Forms.Platform.Android/Cells/BaseCellView.cs @@ -9,6 +9,7 @@ using Android.Widget; using AView = Android.Views.View; using AColor = Android.Graphics.Color; using AColorDraw = Android.Graphics.Drawables.ColorDrawable; +using Xamarin.Forms.Internals; namespace Xamarin.Forms.Platform.Android { diff --git a/Xamarin.Forms.Platform.Android/Cells/CellFactory.cs b/Xamarin.Forms.Platform.Android/Cells/CellFactory.cs index 589236c3..0967fa16 100644 --- a/Xamarin.Forms.Platform.Android/Cells/CellFactory.cs +++ b/Xamarin.Forms.Platform.Android/Cells/CellFactory.cs @@ -2,6 +2,7 @@ using Android.Content; using Android.Views; using AView = Android.Views.View; using AListView = Android.Widget.ListView; +using Xamarin.Forms.Internals; namespace Xamarin.Forms.Platform.Android { diff --git a/Xamarin.Forms.Platform.Android/Cells/CellRenderer.cs b/Xamarin.Forms.Platform.Android/Cells/CellRenderer.cs index d9d4eee5..e62a8d4e 100644 --- a/Xamarin.Forms.Platform.Android/Cells/CellRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Cells/CellRenderer.cs @@ -5,6 +5,7 @@ using Android.Views; using Android.Widget; using AView = Android.Views.View; using Object = Java.Lang.Object; +using Xamarin.Forms.Internals; namespace Xamarin.Forms.Platform.Android { @@ -36,7 +37,7 @@ namespace Xamarin.Forms.Platform.Android if (renderHolder != null) { Cell oldCell = renderHolder.Renderer.Cell; - oldCell.SendDisappearing(); + ((ICellController)oldCell).SendDisappearing(); if (Cell != oldCell) SetRenderer(oldCell, null); @@ -54,7 +55,7 @@ namespace Xamarin.Forms.Platform.Android holder.Renderer = this; Cell.PropertyChanged += PropertyChangedHandler; - Cell.SendAppearing(); + ((ICellController)Cell).SendAppearing(); Performance.Stop(); @@ -85,9 +86,10 @@ namespace Xamarin.Forms.Platform.Android protected void WireUpForceUpdateSizeRequested(Cell cell, AView nativeCell) { - cell.ForceUpdateSizeRequested -= _onForceUpdateSizeRequested; + ICellController cellController = cell; + cellController.ForceUpdateSizeRequested -= _onForceUpdateSizeRequested; - _onForceUpdateSizeRequested = delegate + _onForceUpdateSizeRequested = (sender, e) => { // RenderHeight may not be changed, but that's okay, since we // don't actually use the height argument in the OnMeasure override. @@ -96,7 +98,7 @@ namespace Xamarin.Forms.Platform.Android nativeCell.SetMinimumWidth(nativeCell.MeasuredWidth); }; - cell.ForceUpdateSizeRequested += _onForceUpdateSizeRequested; + cellController.ForceUpdateSizeRequested += _onForceUpdateSizeRequested; } internal static CellRenderer GetRenderer(BindableObject cell) @@ -120,7 +122,6 @@ namespace Xamarin.Forms.Platform.Android } renderer.OnCellPropertyChanged(sender, e); - ; } class RendererHolder : Object diff --git a/Xamarin.Forms.Platform.Android/Cells/EntryCellRenderer.cs b/Xamarin.Forms.Platform.Android/Cells/EntryCellRenderer.cs index 00330928..e46422a0 100644 --- a/Xamarin.Forms.Platform.Android/Cells/EntryCellRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Cells/EntryCellRenderer.cs @@ -58,7 +58,7 @@ namespace Xamarin.Forms.Platform.Android void OnEditingCompleted() { - var entryCell = (EntryCell)Cell; + var entryCell = (IEntryCellController)Cell; entryCell.SendCompleted(); } diff --git a/Xamarin.Forms.Platform.Android/Cells/TextCellRenderer.cs b/Xamarin.Forms.Platform.Android/Cells/TextCellRenderer.cs index cbaaa2b7..b678ee1c 100644 --- a/Xamarin.Forms.Platform.Android/Cells/TextCellRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Cells/TextCellRenderer.cs @@ -3,6 +3,7 @@ using Android.Content; using Android.Views; using AView = Android.Views.View; using AColor = Android.Graphics.Color; +using Xamarin.Forms.Internals; namespace Xamarin.Forms.Platform.Android { @@ -59,7 +60,7 @@ namespace Xamarin.Forms.Platform.Android var cell = (TextCell)Cell; View.MainText = cell.Text; - if (!TemplatedItemsList<ItemsView<Cell>, Cell>.GetIsGroupHeader(cell)) + if (!cell.GetIsGroupHeader<ItemsView<Cell>, Cell>()) View.SetDefaultMainTextColor(Color.Accent); else View.SetDefaultMainTextColor(Color.Default); diff --git a/Xamarin.Forms.Platform.Android/Cells/ViewCellRenderer.cs b/Xamarin.Forms.Platform.Android/Cells/ViewCellRenderer.cs index 4bf83395..9604364a 100644 --- a/Xamarin.Forms.Platform.Android/Cells/ViewCellRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Cells/ViewCellRenderer.cs @@ -1,6 +1,7 @@ using Android.Content; using Android.Views; using AView = Android.Views.View; +using Xamarin.Forms.Internals; namespace Xamarin.Forms.Platform.Android { diff --git a/Xamarin.Forms.Platform.Android/Platform.cs b/Xamarin.Forms.Platform.Android/Platform.cs index 65c3b8cf..4561fa8f 100644 --- a/Xamarin.Forms.Platform.Android/Platform.cs +++ b/Xamarin.Forms.Platform.Android/Platform.cs @@ -15,6 +15,7 @@ using Android.Views; using Android.Widget; using Xamarin.Forms.Platform.Android.AppCompat; using FragmentManager = Android.Support.V4.App.FragmentManager; +using Xamarin.Forms.Internals; namespace Xamarin.Forms.Platform.Android { @@ -347,12 +348,13 @@ namespace Xamarin.Forms.Platform.Android foreach (ToolbarItem item in _toolbarTracker.ToolbarItems) { + IMenuItemController controller = item; item.PropertyChanged += HandleToolbarItemPropertyChanged; if (item.Order == ToolbarItemOrder.Secondary) { IMenuItem menuItem = menu.Add(item.Text); - menuItem.SetEnabled(item.IsEnabled); - menuItem.SetOnMenuItemClickListener(new GenericMenuClickListener(item.Activate)); + menuItem.SetEnabled(controller.IsEnabled); + menuItem.SetOnMenuItemClickListener(new GenericMenuClickListener(controller.Activate)); } else { @@ -363,9 +365,9 @@ namespace Xamarin.Forms.Platform.Android if (iconBitmap != null) menuItem.SetIcon(iconBitmap); } - menuItem.SetEnabled(item.IsEnabled); + menuItem.SetEnabled(controller.IsEnabled); menuItem.SetShowAsAction(ShowAsAction.Always); - menuItem.SetOnMenuItemClickListener(new GenericMenuClickListener(item.Activate)); + menuItem.SetOnMenuItemClickListener(new GenericMenuClickListener(controller.Activate)); } } } diff --git a/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs b/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs index 522ff4b2..667226f6 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs @@ -8,6 +8,7 @@ using Android.Views; using Android.Widget; using AView = Android.Views.View; using AListView = Android.Widget.ListView; +using Xamarin.Forms.Internals; namespace Xamarin.Forms.Platform.Android { @@ -31,6 +32,9 @@ namespace Xamarin.Forms.Platform.Android AView _lastSelected; WeakReference<Cell> _selectedCell; + IListViewController Controller => _listView; + ITemplatedItemsView<Cell> TemplatedItemsView => _listView; + public ListViewAdapter(Context context, AListView realListView, ListView listView) : base(context) { _context = context; @@ -40,8 +44,9 @@ namespace Xamarin.Forms.Platform.Android if (listView.SelectedItem != null) SelectItem(listView.SelectedItem); - listView.TemplatedItems.CollectionChanged += OnCollectionChanged; - listView.TemplatedItems.GroupedCollectionChanged += OnGroupedCollectionChanged; + var templatedItems = ((ITemplatedItemsView<Cell>)listView).TemplatedItems; + templatedItems.CollectionChanged += OnCollectionChanged; + templatedItems.GroupedCollectionChanged += OnGroupedCollectionChanged; listView.ItemSelected += OnItemSelected; realListView.OnItemClickListener = this; @@ -54,12 +59,13 @@ namespace Xamarin.Forms.Platform.Android { get { - int count = _listView.TemplatedItems.Count; + var templatedItems = TemplatedItemsView.TemplatedItems; + int count = templatedItems.Count; if (_listView.IsGroupingEnabled) { - for (var i = 0; i < _listView.TemplatedItems.Count; i++) - count += _listView.TemplatedItems.GetGroup(i).Count; + for (var i = 0; i < templatedItems.Count; i++) + count += templatedItems.GetGroup(i).Count; } return count; @@ -87,7 +93,7 @@ namespace Xamarin.Forms.Platform.Android return cell.BindingContext; } - return _listView.ListProxy[index]; + return TemplatedItemsView.ListProxy[index]; } } @@ -115,7 +121,7 @@ namespace Xamarin.Forms.Platform.Android itemTemplate = _listView.ItemTemplate; else { - group = _listView.TemplatedItems.GetGroupIndexFromGlobal(position, out row); + group = TemplatedItemsView.TemplatedItems.GetGroupIndexFromGlobal(position, out row); if (row == 0) { @@ -138,9 +144,9 @@ namespace Xamarin.Forms.Platform.Android { object item = null; if (_listView.IsGroupingEnabled) - item = _listView.TemplatedItems.GetGroup(group).ListProxy[row]; + item = ((ITemplatedItemsView<Cell>)TemplatedItemsView.TemplatedItems.GetGroup(group)).ListProxy[row]; else - item = _listView.TemplatedItems.ListProxy[position]; + item = ((ITemplatedItemsView<Cell>)TemplatedItemsView.TemplatedItems).ListProxy[position]; itemTemplate = selector.SelectTemplate(item, _listView); } int key; @@ -159,7 +165,7 @@ namespace Xamarin.Forms.Platform.Android Performance.Start(); - ListViewCachingStrategy cachingStrategy = _listView.CachingStrategy; + ListViewCachingStrategy cachingStrategy = Controller.CachingStrategy; var nextCellIsHeader = false; if (cachingStrategy == ListViewCachingStrategy.RetainElement || convertView == null) { @@ -170,7 +176,7 @@ namespace Xamarin.Forms.Platform.Android cell = cells[0]; if (cells.Count == 2) - nextCellIsHeader = TemplatedItemsList<ItemsView<Cell>, Cell>.GetIsGroupHeader(cells[1]); + nextCellIsHeader = cells[1].GetIsGroupHeader<ItemsView<Cell>, Cell>(); } if (cell == null) @@ -208,18 +214,20 @@ namespace Xamarin.Forms.Platform.Android ContextView = null; } // We are going to re-set the Platform here because in some cases (headers mostly) its possible this is unset and - // when the binding context gets updated the measure passes will all fail. By applying this hear the Update call + // when the binding context gets updated the measure passes will all fail. By applying this here the Update call // further down will result in correct layouts. cell.Platform = _listView.Platform; - cell.SendDisappearing(); + ICellController cellController = cell; + cellController.SendDisappearing(); int row = position; var group = 0; + var templatedItems = TemplatedItemsView.TemplatedItems; if (_listView.IsGroupingEnabled) - group = _listView.TemplatedItems.GetGroupIndexFromGlobal(position, out row); + group = templatedItems.GetGroupIndexFromGlobal(position, out row); - TemplatedItemsList<ItemsView<Cell>, Cell> templatedList = _listView.TemplatedItems.GetGroup(group); + var templatedList = templatedItems.GetGroup(group); if (_listView.IsGroupingEnabled) { @@ -231,7 +239,7 @@ namespace Xamarin.Forms.Platform.Android else templatedList.UpdateContent(cell, row); - cell.SendAppearing(); + cellController.SendAppearing(); if (cell.BindingContext == ActionModeObject) { @@ -277,7 +285,7 @@ namespace Xamarin.Forms.Platform.Android else bline = layout.GetChildAt(1); - bool isHeader = TemplatedItemsList<ItemsView<Cell>, Cell>.GetIsGroupHeader(cell); + bool isHeader = cell.GetIsGroupHeader<ItemsView<Cell>, Cell>(); Color separatorColor = _listView.SeparatorColor; @@ -320,19 +328,20 @@ namespace Xamarin.Forms.Platform.Android { ListView list = _listView; + ITemplatedItemsView<Cell> templatedItemsView = list; if (list.IsGroupingEnabled) { int leftOver; - list.TemplatedItems.GetGroupIndexFromGlobal(position, out leftOver); + templatedItemsView.TemplatedItems.GetGroupIndexFromGlobal(position, out leftOver); return leftOver > 0; } - if (list.CachingStrategy == ListViewCachingStrategy.RecycleElement) + if (((IListViewController)list).CachingStrategy == ListViewCachingStrategy.RecycleElement) { if (_enabledCheckCell == null) _enabledCheckCell = GetCellForPosition(position); else - list.TemplatedItems.UpdateContent(_enabledCheckCell, position); + templatedItemsView.TemplatedItems.UpdateContent(_enabledCheckCell, position); return _enabledCheckCell.IsEnabled; } @@ -349,8 +358,9 @@ namespace Xamarin.Forms.Platform.Android _realListView.OnItemClickListener = null; _realListView.OnItemLongClickListener = null; - _listView.TemplatedItems.CollectionChanged -= OnCollectionChanged; - _listView.TemplatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged; + var templatedItems = TemplatedItemsView.TemplatedItems; + templatedItems.CollectionChanged -= OnCollectionChanged; + templatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged; _listView.ItemSelected -= OnItemSelected; if (_lastSelected != null) @@ -372,7 +382,7 @@ namespace Xamarin.Forms.Platform.Android { Cell cell = null; - if (_listView.CachingStrategy == ListViewCachingStrategy.RecycleElement) + if (Controller.CachingStrategy == ListViewCachingStrategy.RecycleElement) { AView cellOwner = view; var layout = cellOwner as ConditionalFocusLayout; @@ -389,7 +399,7 @@ namespace Xamarin.Forms.Platform.Android Select(position, view); _fromNative = true; - _listView.NotifyRowTapped(position, cell); + Controller.NotifyRowTapped(position, cell); } // TODO: We can optimize this by storing the last position, group index and global index @@ -400,14 +410,15 @@ namespace Xamarin.Forms.Platform.Android if (position < 0) return cells; + var templatedItems = TemplatedItemsView.TemplatedItems; if (!_listView.IsGroupingEnabled) { for (var x = 0; x < take; x++) { - if (position + x >= _listView.TemplatedItems.Count) + if (position + x >= templatedItems.Count) return cells; - cells.Add(_listView.TemplatedItems[x + position]); + cells.Add(templatedItems[x + position]); } return cells; @@ -415,9 +426,9 @@ namespace Xamarin.Forms.Platform.Android var i = 0; var global = 0; - for (; i < _listView.TemplatedItems.Count; i++) + for (; i < templatedItems.Count; i++) { - TemplatedItemsList<ItemsView<Cell>, Cell> group = _listView.TemplatedItems.GetGroup(i); + var group = templatedItems.GetGroup(i); if (global == position || cells.Count > 0) { @@ -527,7 +538,7 @@ namespace Xamarin.Forms.Platform.Android void SelectItem(object item) { - int position = _listView.TemplatedItems.GetGlobalIndexOfItem(item); + int position = TemplatedItemsView.TemplatedItems.GetGlobalIndexOfItem(item); AView view = null; if (position != -1) view = _realListView.GetChildAt(position + 1 - _realListView.FirstVisiblePosition); diff --git a/Xamarin.Forms.Platform.Android/Renderers/ListViewRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/ListViewRenderer.cs index 5c69aa45..08bc2f50 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ListViewRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ListViewRenderer.cs @@ -5,6 +5,7 @@ using Android.Support.V4.Widget; using Android.Views; using AListView = Android.Widget.ListView; using AView = Android.Views.View; +using Xamarin.Forms.Internals; namespace Xamarin.Forms.Platform.Android { @@ -19,6 +20,8 @@ namespace Xamarin.Forms.Platform.Android ScrollToRequestedEventArgs _pendingScrollTo; SwipeRefreshLayout _refresh; + IListViewController Controller => Element; + ITemplatedItemsView<Cell> TemplatedItemsView => Element; public ListViewRenderer() { @@ -64,7 +67,7 @@ namespace Xamarin.Forms.Platform.Android _adapter = null; } - Element.ScrollToRequested -= OnScrollToRequested; + Controller.ScrollToRequested -= OnScrollToRequested; } base.Dispose(disposing); @@ -97,7 +100,7 @@ namespace Xamarin.Forms.Platform.Android if (e.OldElement != null) { - e.OldElement.ScrollToRequested -= OnScrollToRequested; + ((IListViewController)e.OldElement).ScrollToRequested -= OnScrollToRequested; if (_adapter != null) { @@ -124,7 +127,7 @@ namespace Xamarin.Forms.Platform.Android nativeListView.AddFooterView(_footerView, null, false); } - e.NewElement.ScrollToRequested += OnScrollToRequested; + ((IListViewController)e.NewElement).ScrollToRequested += OnScrollToRequested; nativeListView.DividerHeight = 0; nativeListView.Focusable = false; @@ -181,22 +184,24 @@ namespace Xamarin.Forms.Platform.Android Cell cell; int position; + var scrollArgs = (ITemplatedItemsListScrollToRequestedEventArgs)e; + var templatedItems = TemplatedItemsView.TemplatedItems; if (Element.IsGroupingEnabled) { - var results = Element.TemplatedItems.GetGroupAndIndexOfItem(e.Group, e.Item); + var results = templatedItems.GetGroupAndIndexOfItem(scrollArgs.Group, scrollArgs.Item); if (results.Item1 == -1 || results.Item2 == -1) return; - TemplatedItemsList<ItemsView<Cell>, Cell> group = Element.TemplatedItems.GetGroup(results.Item1); + var group = templatedItems.GetGroup(results.Item1); cell = group[results.Item2]; - position = Element.TemplatedItems.GetGlobalIndexForGroup(group) + results.Item2 + 1; + position = templatedItems.GetGlobalIndexForGroup(group) + results.Item2 + 1; } else { - position = Element.TemplatedItems.GetGlobalIndexOfItem(e.Item); - cell = Element.TemplatedItems[position]; + position = templatedItems.GetGlobalIndexOfItem(scrollArgs.Item); + cell = templatedItems[position]; } //Android offsets position of cells when using header @@ -241,7 +246,7 @@ namespace Xamarin.Forms.Platform.Android void UpdateFooter() { - var footer = (VisualElement)((IListViewController)Element).FooterElement; + var footer = (VisualElement)Controller.FooterElement; if (_footerRenderer != null && (footer == null || Registrar.Registered.GetHandlerType(footer.GetType()) != _footerRenderer.GetType())) { _footerView.Child = null; @@ -265,7 +270,7 @@ namespace Xamarin.Forms.Platform.Android void UpdateHeader() { - var header = (VisualElement)((IListViewController)Element).HeaderElement; + var header = (VisualElement)Controller.HeaderElement; if (_headerRenderer != null && (header == null || Registrar.Registered.GetHandlerType(header.GetType()) != _headerRenderer.GetType())) { _headerView.Child = null; diff --git a/Xamarin.Forms.Platform.Android/Renderers/TableViewModelRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/TableViewModelRenderer.cs index ef997d07..2633a776 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/TableViewModelRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/TableViewModelRenderer.cs @@ -11,6 +11,7 @@ namespace Xamarin.Forms.Platform.Android { readonly TableView _view; protected readonly Context Context; + ITableViewController Controller => _view; Cell _restoreFocus; public TableViewModelRenderer(Context context, AListView listView, TableView view) : base(context) @@ -18,7 +19,7 @@ namespace Xamarin.Forms.Platform.Android _view = view; Context = context; - view.ModelChanged += (sender, args) => NotifyDataSetChanged(); + Controller.ModelChanged += (sender, args) => NotifyDataSetChanged(); listView.OnItemClickListener = this; listView.OnItemLongClickListener = this; @@ -31,9 +32,10 @@ namespace Xamarin.Forms.Platform.Android var count = 0; //Get each adapter's count + 1 for the header - int section = _view.Model.GetSectionCount(); + ITableModel model = Controller.Model; + int section = model.GetSectionCount(); for (var i = 0; i < section; i++) - count += _view.Model.GetRowCount(i) + 1; + count += model.GetRowCount(i) + 1; return count; } @@ -55,11 +57,12 @@ namespace Xamarin.Forms.Platform.Android { //The headers count as a view type too var viewTypeCount = 1; + ITableModel model = Controller.Model; //Get each adapter's ViewTypeCount - int section = _view.Model.GetSectionCount(); + int section = model.GetSectionCount(); for (var i = 0; i < section; i++) - viewTypeCount += _view.Model.GetRowCount(i); + viewTypeCount += model.GetRowCount(i); return viewTypeCount; } @@ -165,17 +168,19 @@ namespace Xamarin.Forms.Platform.Android protected override void HandleItemClick(AdapterView parent, AView nview, int position, long id) { - int sectionCount = _view.Model.GetSectionCount(); + ITableModel model = Controller.Model; + + int sectionCount = model.GetSectionCount(); for (var sectionIndex = 0; sectionIndex < sectionCount; sectionIndex++) { if (position == 0) return; - int size = _view.Model.GetRowCount(sectionIndex) + 1; + int size = model.GetRowCount(sectionIndex) + 1; if (position < size) { - _view.Model.RowSelected(sectionIndex, position - 1); + model.RowSelected(sectionIndex, position - 1); return; } @@ -188,25 +193,26 @@ namespace Xamarin.Forms.Platform.Android isHeader = false; nextIsHeader = false; - int sectionCount = _view.Model.GetSectionCount(); + ITableModel model = Controller.Model; + int sectionCount = model.GetSectionCount(); for (var sectionIndex = 0; sectionIndex < sectionCount; sectionIndex ++) { - int size = _view.Model.GetRowCount(sectionIndex) + 1; + int size = model.GetRowCount(sectionIndex) + 1; if (position == 0) { isHeader = true; nextIsHeader = size == 0 && sectionIndex < sectionCount - 1; - Cell header = _view.Model.GetHeaderCell(sectionIndex); + Cell header = model.GetHeaderCell(sectionIndex); Cell resultCell = null; if (header != null) resultCell = header; if (resultCell == null) - resultCell = new TextCell { Text = _view.Model.GetSectionTitle(sectionIndex) }; + resultCell = new TextCell { Text = model.GetSectionTitle(sectionIndex) }; resultCell.Parent = _view; @@ -216,7 +222,7 @@ namespace Xamarin.Forms.Platform.Android if (position < size) { nextIsHeader = position == size - 1; - return (Cell)_view.Model.GetItem(sectionIndex, position - 1); + return (Cell)model.GetItem(sectionIndex, position - 1); } position -= size; diff --git a/Xamarin.Forms.Platform.Android/Renderers/ToolbarButton.cs b/Xamarin.Forms.Platform.Android/Renderers/ToolbarButton.cs index 74ff08b8..afa87107 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ToolbarButton.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ToolbarButton.cs @@ -6,15 +6,16 @@ namespace Xamarin.Forms.Platform.Android { internal sealed class ToolbarButton : global::Android.Widget.Button, IToolbarButton { + IMenuItemController Controller => Item; public ToolbarButton(Context context, ToolbarItem item) : base(context) { if (item == null) throw new ArgumentNullException("item", "you should specify a ToolbarItem"); Item = item; - Enabled = Item.IsEnabled; + Enabled = Controller.IsEnabled; Text = Item.Text; SetBackgroundColor(new Color(0, 0, 0, 0).ToAndroid()); - Click += (sender, e) => Item.Activate(); + Click += (sender, e) => Controller.Activate(); Item.PropertyChanged += HandlePropertyChanged; } @@ -29,8 +30,8 @@ namespace Xamarin.Forms.Platform.Android void HandlePropertyChanged(object sender, PropertyChangedEventArgs e) { - if (e.PropertyName == MenuItem.IsEnabledProperty.PropertyName) - Enabled = Item.IsEnabled; + if (e.PropertyName == Controller.IsEnabledPropertyName) + Enabled = Controller.IsEnabled; } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.Android/Renderers/ToolbarImageButton.cs b/Xamarin.Forms.Platform.Android/Renderers/ToolbarImageButton.cs index 6d18db54..b43d36dc 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ToolbarImageButton.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ToolbarImageButton.cs @@ -8,17 +8,18 @@ namespace Xamarin.Forms.Platform.Android { internal sealed class ToolbarImageButton : ImageButton, IToolbarButton { + IMenuItemController Controller => Item; public ToolbarImageButton(Context context, ToolbarItem item) : base(context) { if (item == null) throw new ArgumentNullException("item", "you should specify a ToolbarItem"); Item = item; - Enabled = item.IsEnabled; + Enabled = Controller.IsEnabled; Bitmap bitmap; bitmap = Context.Resources.GetBitmap(Item.Icon); SetImageBitmap(bitmap); SetBackgroundColor(new Color(0, 0, 0, 0).ToAndroid()); - Click += (sender, e) => item.Activate(); + Click += (sender, e) => Controller.Activate(); bitmap.Dispose(); Item.PropertyChanged += HandlePropertyChanged; } @@ -34,8 +35,8 @@ namespace Xamarin.Forms.Platform.Android void HandlePropertyChanged(object sender, PropertyChangedEventArgs e) { - if (e.PropertyName == MenuItem.IsEnabledProperty.PropertyName) - Enabled = Item.IsEnabled; + if (e.PropertyName == Controller.IsEnabledPropertyName) + Enabled = Controller.IsEnabled; } } }
\ No newline at end of file |