Skip to content

Commit

Permalink
ListItemAdapter changes - not convinced yet - see JonPryor's points o…
Browse files Browse the repository at this point in the history
…n stackoverflow.com/questions/13842864/why-does-the-gref-go-too-high-when-i-put-a-mvxbindablespinner-in-a-mvxbindableli
  • Loading branch information
slodge committed Dec 21, 2012
1 parent 90d3f87 commit 91bbc38
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private IMvxViewTypeResolver ViewTypeResolver

public View OnCreateView(string name, Context context, IAttributeSet attrs)
{
View view = CreateView(name, context, attrs);
var view = CreateView(name, context, attrs);
if (view != null)
{
BindView(view, context, attrs);
Expand All @@ -75,33 +75,38 @@ public View OnCreateView(string name, Context context, IAttributeSet attrs)

private void BindView(View view, Context context, IAttributeSet attrs)
{
var typedArray = context.ObtainStyledAttributes(attrs, MvxAndroidBindingResource.Instance.BindingStylableGroupId);

int numStyles = typedArray.IndexCount;
for (var i = 0; i < numStyles; ++i)
using (
var typedArray = context.ObtainStyledAttributes(attrs,
MvxAndroidBindingResource.Instance
.BindingStylableGroupId))
{
var attributeId = typedArray.GetIndex(i);

if (attributeId == MvxAndroidBindingResource.Instance.BindingBindId)
int numStyles = typedArray.IndexCount;
for (var i = 0; i < numStyles; ++i)
{
try
var attributeId = typedArray.GetIndex(i);

if (attributeId == MvxAndroidBindingResource.Instance.BindingBindId)
{
var bindingText = typedArray.GetString(attributeId);
var newBindings = this.GetService<IMvxBinder>().Bind(_source, view, bindingText);
if (newBindings != null)
try
{
var asList = newBindings.ToList();
_viewBindings[view] = asList;
var bindingText = typedArray.GetString(attributeId);
var newBindings = this.GetService<IMvxBinder>().Bind(_source, view, bindingText);
if (newBindings != null)
{
var asList = newBindings.ToList();
_viewBindings[view] = asList;
}
}
catch (Exception exception)
{
MvxBindingTrace.Trace(MvxTraceLevel.Error, "Exception thrown during the view binding {0}",
exception.ToLongString());
throw;
}
}
catch (Exception exception)
{
MvxBindingTrace.Trace(MvxTraceLevel.Error, "Exception thrown during the view binding {0}", exception.ToLongString());
throw;
}
}
typedArray.Recycle();
}
typedArray.Recycle();
}

private View CreateView(string name, Context context, IAttributeSet attrs)
Expand Down Expand Up @@ -138,7 +143,8 @@ private View CreateView(string name, Context context, IAttributeSet attrs)
public void StoreBindings(View view)
{
MvxBindingTrace.Trace(MvxTraceLevel.Diagnostic, "Storing bindings on {0} views", _viewBindings.Count);
view.SetTag(MvxAndroidBindingResource.Instance.BindingTagUnique, new MvxJavaContainer<Dictionary<View, IList<IMvxUpdateableBinding>>>(_viewBindings));
var tag = new MvxJavaContainer<Dictionary<View, IList<IMvxUpdateableBinding>>>(_viewBindings);
view.SetTag(MvxAndroidBindingResource.Instance.BindingTagUnique, tag);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,24 @@ public int GetPosition(object item)
}

public override Object GetItem(int position)
{
// we return null to Java here
// - see @JonPryor's answer in http://stackoverflow.com/questions/13842864/why-does-the-gref-go-too-high-when-i-put-a-mvxbindablespinner-in-a-mvxbindableli/13995199#comment19319057_13995199
return null;

//var item = GetRawItem(position);
//if (item == null)
// return null;
//var wrapped = new MvxJavaContainer<object>(item);
//wrapped.Dispose();
//return wrapped;
}

public object GetRawItem(int position)
{
if (_itemsSource == null)
return null;
return new MvxJavaContainer<object>(_itemsSource[position]);
return _itemsSource[position];
}

public override long GetItemId(int position)
Expand Down Expand Up @@ -163,9 +177,9 @@ private View GetView(int position, View convertView, ViewGroup parent, int templ
return null;
}

var source = _itemsSource[position];

return GetBindableView(convertView, source, templateId);
var rawItem = GetRawItem(position);
var toReturn = GetBindableView(convertView, rawItem, templateId);
return toReturn;
}

protected virtual View GetSimpleView(View convertView, object source)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,14 @@ private void SetupItemClickListener()
{
if (this.ItemClick == null)
return;
var item = Adapter.GetItem(args.Position) as MvxJavaContainer;
var item = Adapter.GetRawItem(args.Position);
if (item == null)
return;
if (item.Object == null)
if (!this.ItemClick.CanExecute(item))
return;
if (!this.ItemClick.CanExecute(item.Object))
return;
this.ItemClick.Execute(item.Object);
this.ItemClick.Execute(item);
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ private void SetupHandleItemSelected()
{
base.ItemSelected += (sender, args) =>
{
var item = Adapter.GetItem(args.Position) as MvxJavaContainer;
if (this.HandleItemSelected == null || item == null || !this.HandleItemSelected.CanExecute(item.Object) || item.Object == null)
var item = Adapter.GetRawItem(args.Position);
if (this.HandleItemSelected == null
|| item == null
|| !this.HandleItemSelected.CanExecute(item))
return;
this.HandleItemSelected.Execute(item.Object);
this.HandleItemSelected.Execute(item);
};
}
}
Expand Down

0 comments on commit 91bbc38

Please sign in to comment.