Esempio n. 1
0
        private void ConfigureSwipe(ConnectionManager connectionManager)
        {
            _swipeLayout = FindViewById <SwipeLayout>(Resource.Id.swipeLayout);

            _swipeLayout.SetShowMode(SwipeLayout.ShowMode.PullOut);

            var addFavoriteView = FindViewById(Resource.Id.leftBottomWrapper);

            _swipeLayout.AddDrag(SwipeLayout.DragEdge.Left, addFavoriteView);

            var removeFavoriteView = FindViewById(Resource.Id.rightBottomWrapper);

            _swipeLayout.AddDrag(SwipeLayout.DragEdge.Right, removeFavoriteView);

            View backgroundView = FindViewById <Button>(Resource.Id.addToFavorite);

            _swipeLayout.Opened += (sender, e) => {
                if (_swipeLayout.CurrentBottomView.FindViewById <Button>(Resource.Id.addToFavorite) != null)
                {
                    _favoriteView.SetImageResource(Resource.Drawable.Star);
                    backgroundView = FindViewById <Button>(Resource.Id.addToFavorite);
                    connectionManager.MarkFavorite(true, _article.ID);
                    _article.Favorite = true;
                }
                else
                {
                    _favoriteView.SetImageResource(Resource.Drawable.EmptyStar);
                    backgroundView = FindViewById <Button>(Resource.Id.removeFromFavorite);
                    connectionManager.MarkFavorite(false, _article.ID);
                    _article.Favorite = false;
                }

                backgroundView.SetBackgroundColor(Color.Green);

                _swipeLayout.Close();
            };

            _swipeLayout.Closed += (sender, e) =>
            {
                backgroundView.SetBackgroundColor(Color.Transparent);
            };

            _swipeLayout.Hover += (sender, e) =>
            {
                _swipeLayout.Close();
            };

            _swipeLayout.Click += delegate {
                string swipeStatus = _swipeLayout.OpenStatus.ToString();
                if (!swipeStatus.Equals("Open") && !swipeStatus.Equals("Middle"))
                {
                    Intent intent = new Intent(Context, typeof(ArticleActivity));
                    intent.PutExtra("sourceUri", _article.Link);
                    _activity.StartActivity(intent);
                }
                _swipeLayout.Close();
            };
        }
Esempio n. 2
0
        private async void SwipeOnOpenEvent(SwipeLayout sender)
        {
            Debug.WriteLine($"Attempting swipe for {ViewModel.Title}");
            if (_swipeCooldown)
            {
                return;
            }
            _swipeCooldown = true;

            var edge = sender.GetDragEdge();

            if (edge == SwipeLayout.DragEdge.Right)
            {
                ViewModel.IncrementWatchedCommand.Execute(null);
            }
            else if (edge == SwipeLayout.DragEdge.Left)
            {
                ViewModel.DecrementWatchedCommand.Execute(null);
            }
            await Task.Delay(500);

            sender.Close();

            _swipeCooldown = false;
        }