예제 #1
0
 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();
 }
예제 #2
0
        public void SetViewModel(LogTimeEntriesViewModel viewModel)
        {
            ViewModel = viewModel;

            // TODO: investigate why WhenSourceChanges doesn't work. :(
            isRunningBinding = this.SetBinding(() => ViewModel.IsTimeEntryRunning, () => IsRunning);
            durationBinding  = this.SetBinding(() => ViewModel.Duration, () => DurationTextView.Text);
            descBinding      = this.SetBinding(() => ViewModel.Description, () => DescriptionTextView.Text)
                               .ConvertSourceToTarget(desc => desc != string.Empty ? desc : activity.ApplicationContext.Resources.GetText(Resource.String.TimerComponentNoDescription));
            projectBinding = this.SetBinding(() => ViewModel.ProjectName, () => ProjectTextView.Text)
                             .ConvertSourceToTarget(proj => proj != string.Empty ? proj : activity.ApplicationContext.Resources.GetText(Resource.String.TimerComponentNoProject));
        }
예제 #3
0
        public async override void OnViewCreated(View view, Bundle savedInstanceState)
        {
            base.OnViewCreated(view, savedInstanceState);
            viewModel = new LogTimeEntriesViewModel();
            await viewModel.Init();

            binding = Binding.Create(() =>
                                     HasMore == viewModel.CollectionView.HasMore &&
                                     ItemCount == viewModel.ItemCount &&
                                     CollectionView == viewModel.CollectionView &&
                                     IsRunning == viewModel.IsTimeEntryRunning);

            startStopBtn.Click += async(sender, e) => await viewModel.StartStopTimeEntry();
        }
예제 #4
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();
            }
예제 #5
0
        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();
        }
예제 #6
0
        public async override void OnViewCreated(View view, Bundle savedInstanceState)
        {
            base.OnViewCreated(view, savedInstanceState);

            // init viewModel
            ViewModel = LogTimeEntriesViewModel.Init();

            collectionBinding = this.SetBinding(() => ViewModel.Collection).WhenSourceChanges(() => {
                logAdapter = new LogTimeEntriesAdapter(recyclerView, ViewModel);
                recyclerView.SetAdapter(logAdapter);
            });
            hasMoreBinging  = this.SetBinding(() => ViewModel.HasMoreItems).WhenSourceChanges(SetFooterState);
            hasErrorBinding = this.SetBinding(() => ViewModel.HasLoadErrors).WhenSourceChanges(SetFooterState);
            hasItemsBinding = this.SetBinding(() => ViewModel.HasItems).WhenSourceChanges(SetCollectionState);
            fabBinding      = this.SetBinding(() => ViewModel.IsTimeEntryRunning, () => StartStopBtn.ButtonAction)
                              .ConvertSourceToTarget(isRunning => isRunning ? FABButtonState.Stop : FABButtonState.Start);

            newMenuBinding = this.SetBinding(() => ViewModel.IsTimeEntryRunning)
                             .WhenSourceChanges(() => {
                if (AddNewMenuItem != null)
                {
                    AddNewMenuItem.SetVisible(!ViewModel.IsTimeEntryRunning);
                }
            });

            // Pass ViewModel to TimerComponent.
            timerComponent.SetViewModel(ViewModel);
            StartStopBtn.Click += StartStopClick;
            SetupRecyclerView(ViewModel);

            // 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();

            // Subscribe to sync messages
            var bus = ServiceContainer.Resolve <MessageBus> ();

            drawerSyncFinished = bus.Subscribe <SyncFinishedMessage> (SyncFinished);
        }
예제 #7
0
        private void SetupRecyclerView(LogTimeEntriesViewModel viewModel)
        {
            // Touch listeners.
            itemTouchListener = new ItemTouchListener(recyclerView, this);
            recyclerView.AddOnItemTouchListener(itemTouchListener);

            // Scroll listener
            recyclerView.AddOnScrollListener(
                new ScrollListener((LinearLayoutManager)recyclerView.GetLayoutManager(), viewModel));

            var touchCallback = new SwipeDismissCallback(ItemTouchHelper.Up | ItemTouchHelper.Down, ItemTouchHelper.Left, this);
            var touchHelper   = new ItemTouchHelper(touchCallback);

            touchHelper.AttachToRecyclerView(recyclerView);

            // Decorations.
            dividerDecoration = new DividerItemDecoration(Activity, DividerItemDecoration.VerticalList);
            shadowDecoration  = new ShadowItemDecoration(Activity);
            recyclerView.AddItemDecoration(dividerDecoration);
            recyclerView.AddItemDecoration(shadowDecoration);
            recyclerView.GetItemAnimator().SupportsChangeAnimations = false;
        }
예제 #8
0
 public ScrollListener(LinearLayoutManager linearLayoutManager, LogTimeEntriesViewModel viewModel)
 {
     this.linearLayoutManager = linearLayoutManager;
     this.viewModel           = viewModel;
 }
예제 #9
0
 public TimeEntriesSource(LogViewController owner, LogTimeEntriesViewModel viewModel) : base(owner.TableView, viewModel.Collection)
 {
     this.owner = owner;
     VM         = viewModel;
 }
예제 #10
0
 public LogTimeEntriesAdapter(RecyclerView owner, LogTimeEntriesViewModel viewModel)
     : base(owner, viewModel.Collection)
 {
     ViewModel = viewModel;
     lastTimeEntryContinuedTime = Time.UtcNow;
 }