Ejemplo n.º 1
0
        private async void AnimeListOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
        {
            if (propertyChangedEventArgs.PropertyName == nameof(ViewModelLocator.AnimeList.AnimeGridItems))
            {
                if (ViewModel.AnimeGridItems != null)
                {
                    var footerParam = _loadMoreFooter.LayoutParameters;
                    footerParam.Height = ViewGroup.LayoutParams.WrapContent;

                    AnimeListPageGridView.InjectAnimeListAdapterWithFooter(Context, ViewModel.AnimeGridItems, AnimeListDisplayModes.IndefiniteGrid, _loadMoreFooter, AnimeListPageGridViewOnItemClick, true, _prevArgs != null);
                    _gridViewColumnHelper = new GridViewColumnHelper(AnimeListPageGridView, null, 2, 3);
                    //if row is not full we have to make this footer item bigger in order to avoid cutting of last row of items

                    SwipeRefreshLayout.ScrollingView = AnimeListPageGridView;

                    AnimeListPageListView.ClearFlingAdapter();
                    AnimeListPageCompactListView.ClearFlingAdapter();

                    await Task.Delay(250);

                    if (ViewModel.AnimeGridItems == null)
                    {
                        return;
                    }
                    if (_prevArgs != null)
                    {
                        var pos = _prevArgs.SelectedItemIndex;

                        AnimeListPageGridView.RequestFocusFromTouch();
                        AnimeListPageGridView.SetSelection(pos);
                        AnimeListPageGridView.RequestFocus();
                        _prevArgs = null;
                    }


                    if (ViewModel.AnimeGridItems.Count % _gridViewColumnHelper.LastColmuns != 0)
                    {
                        footerParam.Height = DimensionsHelper.DpToPx(315);
                    }

                    _loadMoreFooter.LayoutParameters = footerParam;
                }
            }
            else if (propertyChangedEventArgs.PropertyName == nameof(ViewModelLocator.AnimeList.AnimeListItems))
            {
                if (ViewModel.AnimeListItems != null)
                {
                    var footerParam = _loadMoreFooter.LayoutParameters;
                    footerParam.Height = ViewGroup.LayoutParams.WrapContent;
                    _loadMoreFooter.LayoutParameters = footerParam;

                    AnimeListPageListView.InjectAnimeListAdapterWithFooter(Context, ViewModel.AnimeListItems,
                                                                           AnimeListDisplayModes.IndefiniteList, _loadMoreFooter, AnimeListPageGridViewOnItemClick);


                    if (_prevArgs != null)
                    {
                        AnimeListPageListView.SmoothScrollToPosition(_prevArgs.SelectedItemIndex);
                        _prevArgs = null;
                    }

                    SwipeRefreshLayout.ScrollingView = AnimeListPageListView;

                    AnimeListPageGridView.ClearFlingAdapter();
                    AnimeListPageCompactListView.ClearFlingAdapter();
                }
            }
            else if (propertyChangedEventArgs.PropertyName == nameof(ViewModelLocator.AnimeList.AnimeCompactItems))
            {
                if (ViewModel.AnimeCompactItems != null)
                {
                    var footerParam = _loadMoreFooter.LayoutParameters;
                    footerParam.Height = ViewGroup.LayoutParams.WrapContent;
                    _loadMoreFooter.LayoutParameters = footerParam;
                    AnimeListPageCompactListView.InjectAnimeListAdapterWithFooter(Context, ViewModel.AnimeCompactItems, AnimeListDisplayModes.IndefiniteCompactList, _loadMoreFooter, AnimeListPageGridViewOnItemClick);

                    if (_prevArgs != null)
                    {
                        AnimeListPageListView.SmoothScrollToPosition(_prevArgs.SelectedItemIndex);
                        _prevArgs = null;
                    }

                    SwipeRefreshLayout.ScrollingView = AnimeListPageCompactListView;

                    AnimeListPageListView.ClearFlingAdapter();
                    AnimeListPageGridView.ClearFlingAdapter();
                }
            }
            else if (propertyChangedEventArgs.PropertyName == nameof(ViewModel.DisplayMode))
            {
                switch (ViewModel.DisplayMode)
                {
                case AnimeListDisplayModes.IndefiniteList:
                    AnimeListPageListView.Visibility = ViewStates.Visible;

                    AnimeListPageGridView.Visibility        = ViewStates.Gone;
                    AnimeListPageCompactListView.Visibility = ViewStates.Gone;
                    break;

                case AnimeListDisplayModes.IndefiniteGrid:
                    AnimeListPageGridView.Visibility = ViewStates.Visible;

                    AnimeListPageListView.Visibility        = ViewStates.Gone;
                    AnimeListPageCompactListView.Visibility = ViewStates.Gone;
                    break;

                case AnimeListDisplayModes.IndefiniteCompactList:
                    AnimeListPageCompactListView.Visibility = ViewStates.Visible;

                    AnimeListPageListView.Visibility = ViewStates.Gone;
                    AnimeListPageGridView.Visibility = ViewStates.Gone;
                    break;
                }
            }
            else if (propertyChangedEventArgs.PropertyName == nameof(ViewModel.CanLoadMore))
            {
                if (ViewModel.CanLoadMore)
                {
                    _loadMoreFooter.Visibility = ViewStates.Visible;
                }
                else
                {
                    _loadMoreFooter.Visibility = ViewStates.Invisible;
                }
            }
        }
Ejemplo n.º 2
0
        private async void AnimeListOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
        {
            if (propertyChangedEventArgs.PropertyName == nameof(ViewModelLocator.AnimeList.AnimeGridItems))
            {
                if (ViewModelLocator.AnimeList.AnimeGridItems != null)
                {
                    _animeListItemsAdapter = new AnimeListItemsAdapter(Activity,
                                                                       Resource.Layout.AnimeGridItem, ViewModelLocator.AnimeList.AnimeGridItems,
                                                                       (model, view, fling) =>
                                                                       new AnimeGridItemBindingInfo(view, model, fling)
                    {
                        OnItemClickAction = AnimeListPageGridViewOnItemClick
                    });
                    AnimeListPageGridView.Adapter = _animeListItemsAdapter;
                    _gridViewColumnHelper         = new GridViewColumnHelper(AnimeListPageGridView);
                    if (_prevArgs != null)
                    {
                        var pos = _prevArgs.SelectedItemIndex;
                        await Task.Delay(300);

                        AnimeListPageGridView.RequestFocusFromTouch();
                        AnimeListPageGridView.SetSelection(pos);
                        AnimeListPageGridView.RequestFocus();
                        _prevArgs = null;
                    }

                    AnimeListPageGridView.MakeFlingAware();

                    SwipeRefreshLayout.ScrollingView = AnimeListPageGridView;

                    AnimeListPageListView.Adapter        = null;
                    AnimeListPageCompactListView.Adapter = null;
                }
            }
            else if (propertyChangedEventArgs.PropertyName == nameof(ViewModelLocator.AnimeList.AnimeListItems))
            {
                if (ViewModelLocator.AnimeList.AnimeListItems != null)
                {
                    _animeListItemsAdapter = new AnimeListItemsAdapter(Activity,
                                                                       Resource.Layout.AnimeListItem, ViewModelLocator.AnimeList.AnimeListItems, (model, view, fling) => new AnimeListItemBindingInfo(view, model, fling)
                    {
                        OnItemClickAction = AnimeListPageGridViewOnItemClick
                    });
                    AnimeListPageListView.Adapter = _animeListItemsAdapter;
                    if (_prevArgs != null)
                    {
                        AnimeListPageListView.SmoothScrollToPosition(_prevArgs.SelectedItemIndex);
                        _prevArgs = null;
                    }

                    AnimeListPageListView.MakeFlingAware();

                    SwipeRefreshLayout.ScrollingView = AnimeListPageListView;

                    AnimeListPageGridView.Adapter        = null;
                    AnimeListPageCompactListView.Adapter = null;
                }
            }
            else if (propertyChangedEventArgs.PropertyName == nameof(ViewModelLocator.AnimeList.AnimeCompactItems))
            {
                if (ViewModelLocator.AnimeList.AnimeCompactItems != null)
                {
                    //AnimeListPageCompactListView.Adapter = new AnimeListItemsAdapter(Context as Activity,
                    //    Resource.Layout.AnimeGridItem, ViewModelLocator.AnimeList.AnimeCompactItems);

                    SwipeRefreshLayout.ScrollingView = AnimeListPageCompactListView;

                    AnimeListPageListView.Adapter = null;
                    AnimeListPageGridView.Adapter = null;
                }
            }
            else if (propertyChangedEventArgs.PropertyName == nameof(ViewModel.DisplayMode))
            {
                switch (ViewModel.DisplayMode)
                {
                case AnimeListDisplayModes.IndefiniteList:
                    AnimeListPageListView.Visibility = ViewStates.Visible;

                    AnimeListPageGridView.Visibility        = ViewStates.Gone;
                    AnimeListPageCompactListView.Visibility = ViewStates.Gone;
                    break;

                case AnimeListDisplayModes.IndefiniteGrid:
                    AnimeListPageGridView.Visibility = ViewStates.Visible;

                    AnimeListPageListView.Visibility        = ViewStates.Gone;
                    AnimeListPageCompactListView.Visibility = ViewStates.Gone;
                    break;

                case AnimeListDisplayModes.IndefiniteCompactList:
                    AnimeListPageCompactListView.Visibility = ViewStates.Visible;

                    AnimeListPageListView.Visibility = ViewStates.Gone;
                    AnimeListPageGridView.Visibility = ViewStates.Gone;
                    break;
                }
            }
        }