public static FlingAdapterRegistration InjectFlingAdapter <T>( this AbsListView container, IList <T> items, Func <int, View> containerTemplate, Action <View, int, T> dataTemplateBasic, Action <View, int, T> dataTemplateFling, Action <View, int, T> dataTemplateFull, View footer = null, bool skipBugFix = false) where T : class { var registration = new FlingAdapterRegistration(container); container.MakeFlingAware(b => { if (registration.FlingState == b) { return; } registration.FlingState = b; if (!b) { for (int i = 0; i < container.ChildCount; i++) { var view = container.GetChildAt(i); var item = view.Tag.Unwrap <T>(); if (view.Tag?.ToString() == "Footer") { continue; } dataTemplateFull(view, items.IndexOf(item), item); } } }); container.Adapter = items.GetAdapter((i, arg2, arg3) => { var root = arg3 ?? containerTemplate(i); root.Tag = arg2.Wrap(); dataTemplateBasic?.Invoke(root, i, arg2); if (registration.FlingState) { dataTemplateFling(root, i, arg2); } else { dataTemplateFull(root, i, arg2); } return(root); }); return(registration); }
public static void InjectFlingAdapter <T>(this AbsListView container, IList <T> items, Action <View, T> dataTemplateFull, Action <View, T> dataTemplateFling, Func <View> containerTemplate) where T : class { if (!FlingStates.ContainsKey(container)) { FlingStates.Add(container, false); } container.MakeFlingAware(b => { if (FlingStates[container] == b) { return; } FlingStates[container] = b; if (!b) { for (int i = 0; i < container.ChildCount; i++) { var view = container.GetChildAt(i); dataTemplateFull(view, view.Tag.Unwrap <T>()); } } }); container.Adapter = items.GetAdapter((i, arg2, arg3) => { var root = arg3 ?? containerTemplate(); root.Tag = arg2.Wrap(); if (FlingStates[container]) { dataTemplateFling(root, arg2); } else { dataTemplateFull(root, arg2); } return(root); }); }
public static void InjectFlingAdapter <T, TViewHolder>(this AbsListView container, IList <T> items, Func <View, TViewHolder> holderFactory, Action <View, int, T, TViewHolder> dataTemplateFull, Action <View, int, T, TViewHolder> dataTemplateFling, Action <View, int, T, TViewHolder> dataTemplateBasic, Func <int, View> containerTemplate, View footer = null, bool skipBugFix = false, Action onScrolled = null) where T : class { if (!FlingStates.ContainsKey(container)) { FlingStates.Add(container, false); } if (!ViewHolders.ContainsKey(container)) { ViewHolders.Add(container, new Dictionary <View, object>()); } if (onScrolled == null) { container.MakeFlingAware(b => { if (FlingStates[container] == b) { return; } FlingStates[container] = b; if (!b) { for (int i = 0; i < container.ChildCount; i++) { var view = container.GetChildAt(i); var item = view.Tag.Unwrap <T>(); if (view.Tag?.ToString() == "Footer") { continue; } dataTemplateFull(view, items.IndexOf(item), item, (TViewHolder)ViewHolders[container][view]); } } }); } else { container.MakeFlingAware(b => { onScrolled.Invoke(); if (FlingStates[container] == b) { return; } FlingStates[container] = b; if (!b) { for (int i = 0; i < container.ChildCount; i++) { var view = container.GetChildAt(i); var item = view.Tag.Unwrap <T>(); if (view.Tag?.ToString() == "Footer") { continue; } dataTemplateFull(view, items.IndexOf(item), item, (TViewHolder)ViewHolders[container][view]); } } }); } if (footer == null) { container.Adapter = items.GetAdapter((i, arg2, arg3) => { TViewHolder holder; View root = null; if (arg3 == null) { root = containerTemplate(i); ViewHolders[container][root] = holder = holderFactory(root); } else { root = arg3; holder = (TViewHolder)ViewHolders[container][root]; } root.Tag = arg2.Wrap(); dataTemplateBasic.Invoke(root, i, arg2, holder); if (FlingStates[container]) { dataTemplateFling(root, i, arg2, holder); } else { dataTemplateFull(root, i, arg2, holder); } return(root); }); } else { container.Adapter = items.GetAdapter((i, arg2, arg3) => { TViewHolder holder; View root = null; if (arg3 == null) { root = containerTemplate(i); ViewHolders[container][root] = holder = holderFactory(root); } else { root = arg3; holder = (TViewHolder)ViewHolders[container][root]; } root.Tag = arg2.Wrap(); if (FlingStates[container]) { dataTemplateFling(root, i, arg2, holder); } else { dataTemplateFull(root, i, arg2, holder); } return(root); }, footer, container is GridView && !skipBugFix); } }
public static void InjectFlingAdapter <T>(this AbsListView container, IList <T> items, Action <View, int, T> dataTemplateFull, Action <View, int, T> dataTemplateFling, Func <int, View> containerTemplate, Action <View, int, T> dataTemplateBasic = null, View footer = null, bool skipBugFix = false) where T : class { if (!FlingStates.ContainsKey(container)) { FlingStates.Add(container, false); } container.MakeFlingAware(b => { if (FlingStates[container] == b) { return; } FlingStates[container] = b; if (!b) { for (int i = 0; i < container.ChildCount; i++) { var view = container.GetChildAt(i); var item = view.Tag.Unwrap <T>(); if (view.Tag?.ToString() == "Footer") { continue; } dataTemplateFull(view, items.IndexOf(item), item); } } }); if (footer == null) { container.Adapter = items.GetAdapter((i, arg2, arg3) => { var root = arg3 ?? containerTemplate(i); root.Tag = arg2.Wrap(); dataTemplateBasic?.Invoke(root, i, arg2); if (FlingStates[container]) { dataTemplateFling(root, i, arg2); } else { dataTemplateFull(root, i, arg2); } return(root); }); } else { container.Adapter = items.GetAdapter((i, arg2, arg3) => { var root = arg3 ?? containerTemplate(i); root.Tag = arg2.Wrap(); if (FlingStates[container]) { dataTemplateFling(root, i, arg2); } else { dataTemplateFull(root, i, arg2); } return(root); }, footer, container is GridView && !skipBugFix); } }
public static FlingAdapterRegistration <TViewHolder> InjectFlingAdapter <T, TViewHolder>( this AbsListView container, IList <T> items, Func <View, TViewHolder> holderFactory, Func <int, View> containerTemplate, Action <View, int, T, TViewHolder> dataTemplateBasic, Action <View, int, T, TViewHolder> dataTemplateFling, Action <View, int, T, TViewHolder> dataTemplateFull, View footer = null, bool skipBugFix = false, Action onScrolled = null) where T : class { var registration = new FlingAdapterRegistration <TViewHolder>(container); if (onScrolled == null) { container.MakeFlingAware(b => { if (registration.FlingState == b) { return; } registration.FlingState = b; if (!b) { for (int i = 0; i < container.ChildCount; i++) { var view = container.GetChildAt(i); var item = view.Tag.Unwrap <T>(); if (view.Tag?.ToString() == "Footer") { continue; } dataTemplateFull(view, items.IndexOf(item), item, registration.ViewHolders[view]); } } }); } else { container.MakeFlingAware(b => { onScrolled.Invoke(); if (registration.FlingState == b) { return; } registration.FlingState = b; if (!b) { for (int i = 0; i < container.ChildCount; i++) { var view = container.GetChildAt(i); var item = view.Tag.Unwrap <T>(); if (view.Tag?.ToString() == "Footer") { continue; } dataTemplateFull(view, items.IndexOf(item), item, registration.ViewHolders[view]); } } }); } container.Adapter = items.GetAdapter((i, arg2, arg3) => { TViewHolder holder; View root = null; if (arg3 == null) { root = containerTemplate(i); registration.ViewHolders[root] = holder = holderFactory(root); } else { root = arg3; holder = registration.ViewHolders[root]; } root.Tag = arg2.Wrap(); dataTemplateBasic.Invoke(root, i, arg2, holder); if (registration.FlingState) { dataTemplateFling(root, i, arg2, holder); } else { dataTemplateFull(root, i, arg2, holder); } return(root); }); return(registration); }