public FooterHolder(View root, LogTimeEntriesViewModel viewModel) : base(root)
 {
     retryLayout        = ItemView.FindViewById <RelativeLayout> (Resource.Id.RetryLayout);
     progressBar        = ItemView.FindViewById <ProgressBar> (Resource.Id.ProgressBar);
     retryButton        = ItemView.FindViewById <Button> (Resource.Id.RetryButton);
     retryButton.Click += async(sender, e) => await viewModel.LoadMore();
 }
Example #2
0
            public FooterHolder(View root, LogTimeEntriesViewModel viewModel) : base(root)
            {
                Vm           = viewModel;
                retryLayout  = ItemView.FindViewById <RelativeLayout> (Resource.Id.RetryLayout);
                retryButton  = ItemView.FindViewById <Button> (Resource.Id.RetryButton);
                progressBar  = ItemView.FindViewById <ProgressBar> (Resource.Id.ProgressBar);
                IsRecyclable = false;

                retryButton.Click += async(sender, e) => await Vm.LoadMore();

                hasMoreBinding  = this.SetBinding(() => Vm.HasMoreItems).WhenSourceChanges(SetFooterState);
                hasErrorBinding = this.SetBinding(() => Vm.HasLoadErrors).WhenSourceChanges(SetFooterState);

                SetFooterState();
            }
            public async override void Scrolled(UIScrollView scrollView)
            {
                var currentOffset = scrollView.ContentOffset.Y;
                var maximumOffset = scrollView.ContentSize.Height - scrollView.Frame.Height;

                if (isLoading)
                {
                    isLoading &= maximumOffset - currentOffset <= 200.0;
                }

                if (!isLoading && maximumOffset - currentOffset <= 200.0)
                {
                    isLoading = true;
                    await VM.LoadMore();
                }
            }
        public async override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NavigationItem.LeftBarButtonItem = new UIBarButtonItem(
                Image.IconNav.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal),
                UIBarButtonItemStyle.Plain, OnNavigationButtonTouched);

            EdgesForExtendedLayout = UIRectEdge.None;
            TableView.RegisterClassForCellReuse(typeof(TimeEntryCell), EntryCellId);
            TableView.RegisterClassForHeaderFooterViewReuse(typeof(SectionHeaderView), SectionHeaderId);
            TableView.SetEditing(false, true);

            // Create view model
            ViewModel = LogTimeEntriesViewModel.Init();

            var headerView = new TableViewRefreshView();

            RefreshControl = headerView;
            headerView.AdaptToTableView(TableView);
            headerView.ValueChanged += (sender, e) => ViewModel.TriggerFullSync();

            // Bindings
            syncBinding = this.SetBinding(() => ViewModel.IsAppSyncing).WhenSourceChanges(() => {
                if (!ViewModel.IsAppSyncing)
                {
                    headerView.EndRefreshing();
                }
            });
            hasMoreBinding    = this.SetBinding(() => ViewModel.HasMoreItems).WhenSourceChanges(SetFooterState);
            hasErrorBinding   = this.SetBinding(() => ViewModel.HasLoadErrors).WhenSourceChanges(SetFooterState);
            hasItemsBinding   = this.SetBinding(() => ViewModel.HasItems).WhenSourceChanges(SetCollectionState);
            loadMoreBinding   = this.SetBinding(() => ViewModel.HasItems).WhenSourceChanges(LoadMoreIfNeeded);
            collectionBinding = this.SetBinding(() => ViewModel.Collection).WhenSourceChanges(() => {
                TableView.Source = new TimeEntriesSource(this, ViewModel);
            });
            isRunningBinding = this.SetBinding(() => ViewModel.IsTimeEntryRunning).WhenSourceChanges(SetStartStopButtonState);
            durationBinding  = this.SetBinding(() => ViewModel.Duration).WhenSourceChanges(() => durationButton.SetTitle(ViewModel.Duration, UIControlState.Normal));

            // TODO: Review this line.
            // Get data to fill the list. For the moment,
            // until a screenloader is added to the screen
            // is better to load the items after create
            // the viewModel and show the loader from RecyclerView
            await ViewModel.LoadMore();
        }
            public async override void OnScrolled(RecyclerView recyclerView, int dx, int dy)
            {
                base.OnScrolled(recyclerView, dx, dy);

                visibleItemCount = recyclerView.ChildCount;
                totalItemCount   = linearLayoutManager.ItemCount;
                firstVisibleItem = linearLayoutManager.FindFirstVisibleItemPosition();

                if (loading)
                {
                    if (totalItemCount > previousTotal)
                    {
                        loading       = false;
                        previousTotal = totalItemCount;
                    }
                }

                if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold))
                {
                    loading = true;
                    // Request more entries.
                    await viewModel.LoadMore();
                }
            }