private ViewItemPosition RecordCurrentPosition(AbsListView view)
        {
            var pos     = view.FirstVisiblePosition;
            var topItem = view.GetChildAt(0);
            var top     = topItem == null ? 0 : (topItem.Top - view.ListPaddingTop);

            return(new ViewItemPosition(pos, top));
        }
Exemple #2
0
                AView GetChild(AbsListView view)
                {
                    switch (_position)
                    {
                    case 0:
                        return(view.GetChildAt(0));

                    case 1:
                    case 2:
                        return(view.GetChildAt(view.ChildCount / 2));

                    case 3:
                        return(view.GetChildAt(view.ChildCount - 1));

                    default:
                        return(null);
                    }
                }
        /// <summary>
        /// Callback method to be invoked when the list or grid has been scrolled. This will be called after the scroll has completed
        /// </summary>
        /// <param name="view">The view whose scroll state is being reported</param>
        /// <param name="firstVisibleItem">The index of the first visible cell (ignore if visibleItemCount == 0)</param>
        /// <param name="visibleItemCount">The number of visible cells</param>
        /// <param name="totalItemCount">The number of items in the list adaptor</param>
        public void OnScroll(AbsListView listView, int firstVisibleItem, int visibleItemCount, int totalItemCount)
        {
            if (parentActivity == null || listView == null)
            {
                return;
            }

            if (totalItemCount == 0)
            {
                this.parentActivity.SwipeRefreshLayout.Enabled = true;
                return;
            }

            // Enable / Disable pull to refresh accordingly
            bool enable = false;

            if (listView.ChildCount > 0)
            {
                // check if the first item of the list is visible
                bool firstItemVisible = listView.FirstVisiblePosition == 0;
                // check if the top of the first item is visible
                bool topOfFirstItemVisible = listView.GetChildAt(0).Top == 0;
                // enabling or disabling the refresh layout
                enable = firstItemVisible && topOfFirstItemVisible;

                this.lastVisible = listView.LastVisiblePosition == totalItemCount - 1;
            }

            int currentPage = this.parentActivity.CurrentPage;
            var adapter     = listView.Adapter as MvxAdapter;

            if (adapter == null)
            {
                this.parentActivity.SwipeRefreshLayout.Enabled = enable;
                return;
            }

            var item = adapter.GetRawItem(totalItemCount - 1) as AbstractTicketBase;

            if (item == null)
            {
                this.parentActivity.SwipeRefreshLayout.Enabled = enable;
                return;
            }

            if (currentPage == TicketListView.CustomerTicketsPage && item.GetType() == typeof(CustomerTicket))
            {
                this.parentActivity.SwipeRefreshLayout.Enabled = enable;
            }

            if (currentPage == TicketListView.DsrTicketsPage && item.GetType() == typeof(DsrTicket))
            {
                this.parentActivity.SwipeRefreshLayout.Enabled = enable;
            }
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        public void OnScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
        {
            if (isFling)
            {
                return;
            }

            Android.Views.View firstCell = view.GetChildAt(0);

            if (firstCell == null)
            {
                return;
            }
            int distanceFromFirstCellToTop = view.FirstVisiblePosition * firstCell.Height - firstCell.Top;

            // ***
            if (previousDistanceFromFirstCellToTop != 0)
            {
                deltaHeight += Math.Abs(distanceFromFirstCellToTop - previousDistanceFromFirstCellToTop);
            }

            if (deltaHeight >= scope)
            {
                if (distanceFromFirstCellToTop < previousDistanceFromFirstCellToTop)
                {
                    //Scroll Up
                    if (!_viewModel.OptionMenuOpen)
                    {
                        _viewModel.OptionMenuOpen = true;
                    }
                    else
                    {
                        deltaHeight = 0;
                    }
                }
                else if (distanceFromFirstCellToTop > previousDistanceFromFirstCellToTop)
                {
                    //Scroll Down
                    if (_viewModel.OptionMenuOpen)
                    {
                        _viewModel.OptionMenuOpen = false;
                    }
                    else
                    {
                        deltaHeight = 0;
                    }
                }
            }
            previousDistanceFromFirstCellToTop = distanceFromFirstCellToTop;
        }
Exemple #6
0
        public void OnScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
        {
            if (!_listInstance.IsListenerActive)
            {
                return;
            }
            try {
                var currView       = _control.GetChildAt(0);
                int currViewPos    = currView.Top;
                int diffViewPos    = _prevViewPos - currViewPos;
                int currViewHeight = currView.Height;
                _scrollY += diffViewPos;
                if (firstVisibleItem > _prevIndex)
                {
                    _scrollY   += _prevViewHeight;
                    diffViewPos = 0;
                }
                else if (firstVisibleItem < _prevIndex)
                {
                    _scrollY   -= currViewHeight;
                    diffViewPos = 0;
                }
                _prevIndex      = firstVisibleItem;
                _prevViewPos    = currViewPos;
                _prevViewHeight = currViewHeight;
                if (diffViewPos < 0)
                {
                    _direction = ScrollDirection.Up;
                }
                else if (diffViewPos > 0)
                {
                    _direction = ScrollDirection.Down;
                }
                else
                {
                    _direction = ScrollDirection.None;
                }
                ScrollDirection direction = _direction;
                _scrollEventArgs.FirstVisibleItem = firstVisibleItem;
                _scrollEventArgs.VisibleItemCount = visibleItemCount;
                _scrollEventArgs.TotalItemCount   = totalItemCount;
                _scrollEventArgs.ScrollY          = _scrollY;
                _scrollEventArgs.Direction        = direction;

                _listInstance.OnScroll(this, _scrollEventArgs);
            } catch (Exception err) {
                System.Diagnostics.Debug.WriteLine(err);
            }
        }
Exemple #7
0
        /**
         * Returns the {@link View} that represents the item for given position.
         *
         * @param absListView the ListView that should be examined
         * @param position    the position for which the {@code View} should be returned.
         *
         * @return the {@code View}, or {@code null} if the position is not currently visible.
         */
        //@Nullable
        public static View getViewForPosition(AbsListView absListView, int position)
        {
            int  childCount = absListView.ChildCount;
            View downView   = null;

            for (int i = 0; i < childCount && downView == null; i++)
            {
                View child = absListView.GetChildAt(i);
                if (child != null && getPositionForView(absListView, child) == position)
                {
                    downView = child;
                }
            }
            return(downView);
        }
Exemple #8
0
        private bool CanScrollVertically(AbsListView view)
        {
            bool canScroll = false;

            if (view != null && view.ChildCount > 0)
            {
                bool isOnTop           = view.FirstVisiblePosition != 0 || view.GetChildAt(0).Top != 0;
                bool isAllItemsVisible = isOnTop && view.LastVisiblePosition == view.ChildCount;

                if (isOnTop || isAllItemsVisible)
                {
                    canScroll = true;
                }
            }

            return(canScroll);
        }
Exemple #9
0
 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 void OnScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
        {
            var headerView = view.GetChildAt(0);

            if (headerView != null)
            {
                _customListView.ShowShadow = headerView.Top < 0;

                int lastVisibleItem = firstVisibleItem + visibleItemCount;

                if (_customListView.TodaysFirst != -1 && _customListView.TodaysLast != -1 &&
                    (firstVisibleItem > _customListView.TodaysFirst || lastVisibleItem < _customListView.TodaysFirst) &&
                    (firstVisibleItem > _customListView.TodaysLast || lastVisibleItem < _customListView.TodaysLast))
                {
                    _customListView.ShowTodayButtonVisible = true;
                }
                else
                {
                    _customListView.ShowTodayButtonVisible = false;
                }
            }
        }
Exemple #11
0
 /**
  * @return Whether it is possible for the child view of this layout to
  *         scroll up. Override this if the child view is a custom view.
  */
 public bool canChildScrollUp()
 {
     //        //For make it can work when my recycler view is in Gone.
     //        return false;
     if (Build.VERSION.SdkInt < BuildVersionCodes.IceCreamSandwich)
     {// 14
         if (mTarget is AbsListView)
         {
             AbsListView absListView = (AbsListView)mTarget;
             return(absListView.ChildCount > 0 &&
                    (absListView.FirstVisiblePosition > 0 || absListView.GetChildAt(0)
                     .Top < absListView.PaddingTop));
         }
         else
         {
             return(ViewCompat.CanScrollVertically(mTarget, -1) || mTarget.ScrollY > 0);
         }
     }
     else
     {
         return(ViewCompat.CanScrollVertically(mTarget, -1));
     }
 }
        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 void OnScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
            {
                Debug.WriteLine("We are in on scroll");
                int topRowVerticalPosition = (view == null || view.ChildCount == 0) ? 0 : view.GetChildAt(0).Top;

                Debug.WriteLine("Top Row " + topRowVerticalPosition);
                srl.Enabled = (firstVisibleItem == 0 && topRowVerticalPosition >= 0);
                Debug.WriteLine("Enabled : " + srl.Enabled);
            }
Exemple #15
0
        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);
        }
 //@Nullable
 //@Override
 public View getChildAt(int index)
 {
     return(mAbsListView.GetChildAt(index));
 }