<commit_before>﻿using System;
using System.Threading.Tasks;
using HipMobileUI.Controls;
using Xamarin.Forms;
using Rectangle = Xamarin.Forms.Rectangle;

namespace HipMobileUI.Views
{
    public class BottomSheetView : ContentView {

        private readonly double BottomSheetExtensionFraction = 0.4;
        private BottomSheetState bottomSheetState = BottomSheetState.Collapsed;

        public BottomSheetView()
        {
            var layout = new AbsoluteLayout ();

            MainContentView = new ContentView ();
            AbsoluteLayout.SetLayoutFlags (MainContentView, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds (MainContentView, new Rectangle(0,0,1,0.9));

            BottomSheetContentView = new ContentView();
            BottomSheetContentView.BackgroundColor = Color.White;
            AbsoluteLayout.SetLayoutFlags(BottomSheetContentView, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(BottomSheetContentView, new Rectangle(0, 1, 1, 0.1));
            var gestureRecognizer = new PanGestureRecognizer ();
            gestureRecognizer.PanUpdated+=GestureRecognizerOnPanUpdated;
            BottomSheetContentView.GestureRecognizers.Add (gestureRecognizer);

            button = new FloatingActionButton
            {
                NormalColor = (Color) Application.Current.Resources ["AccentColor"],
                Command = new Command (ButtonOnClicked),
                Icon = "ic_keyboard_arrow_up"
            };
            AbsoluteLayout.SetLayoutFlags(button, AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(button, new Rectangle(0.9, 0.92, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));

            layout.Children.Add (MainContentView);
            layout.Children.Add(BottomSheetContentView);
            layout.Children.Add (button);

            Content = layout;
        }

        private async void GestureRecognizerOnPanUpdated (object sender, PanUpdatedEventArgs panUpdatedEventArgs)
        {
            if (panUpdatedEventArgs.StatusType == GestureStatus.Running)
            {
                // Set the state to pending if not done already
                if (bottomSheetState == BottomSheetState.Collapsed || bottomSheetState == BottomSheetState.Extended)
                {
                    await SetBottomSheetPending();
                }
                // Update the swipe direction
                bottomSheetState = panUpdatedEventArgs.TotalY < 0 ? BottomSheetState.Extending : BottomSheetState.Collapsing;
            }
            else if(panUpdatedEventArgs.StatusType == GestureStatus.Completed)
            {
                // Perform final animation
                if (bottomSheetState == BottomSheetState.Extending)
                {
                    await ExtendBottomSheet ();
                }
                else if (bottomSheetState == BottomSheetState.Collapsing)
                {
                    await CollapseBottomSheet ();
                }
            }
        }

        private async void ButtonOnClicked ()
        {
            if (bottomSheetState == BottomSheetState.Collapsed)
            {
                await ExtendBottomSheet ();
            }
            else if (bottomSheetState == BottomSheetState.Extended)
            {
                await CollapseBottomSheet ();
            }
        }

        #region bottomsheet manipulation

        private async Task ExtendBottomSheet() {
            Rectangle bottomSheetRect = new Rectangle
            {
                Left = 0,
                Top = Height * (1 - BottomSheetExtensionFraction),
                Size = new Size(Width, Height * BottomSheetExtensionFraction)
            };
            Rectangle buttonRect = new Rectangle
            {
                Top = bottomSheetRect.Top - button.Height / 2,
                Size = new Size (button.Width, button.Height),
                X = button.X
            };
            await Task.WhenAll(BottomSheetContentView.LayoutTo(bottomSheetRect), button.LayoutTo(buttonRect), button.RotateXTo(180));
            bottomSheetState = BottomSheetState.Extended;
        }

        private async Task CollapseBottomSheet()
        {
            Rectangle bottomSheetRect = new Rectangle
            {
                Left = 0,
                Top = Height * 0.9,
                Size = new Size(Width, Height * 0.1)
            };
            Rectangle buttonRect = new Rectangle
            {
                Top = bottomSheetRect.Top - button.Height / 2,
                Size = new Size(button.Width, button.Height),
                X = button.X
            };
            await Task.WhenAll(BottomSheetContentView.LayoutTo(bottomSheetRect), button.LayoutTo(buttonRect), button.RotateXTo(0));
            bottomSheetState = BottomSheetState.Collapsed;
        }

        private async Task SetBottomSheetPending()
        {
            Rectangle bottomSheetRect = new Rectangle
            {
                Left = 0,
                Top = Height * (1 - BottomSheetExtensionFraction / 2),
                Size = new Size(Width, Height * BottomSheetExtensionFraction /2)
            };
            Rectangle buttonRect = new Rectangle
            {
                Top = bottomSheetRect.Top - button.Height / 2,
                Size = new Size(button.Width, button.Height),
                X = button.X
            };
            await Task.WhenAll(BottomSheetContentView.LayoutTo(bottomSheetRect), button.LayoutTo(buttonRect));
        }
<commit_msg>Renamed field for Resharper code quality check<commit_after>﻿using System;
using System.Threading.Tasks;
using HipMobileUI.Controls;
using Xamarin.Forms;
using Rectangle = Xamarin.Forms.Rectangle;

namespace HipMobileUI.Views
{
    public class BottomSheetView : ContentView {

        private readonly double bottomSheetExtensionFraction = 0.4;
        private BottomSheetState bottomSheetState = BottomSheetState.Collapsed;

        public BottomSheetView()
        {
            var layout = new AbsoluteLayout ();

            MainContentView = new ContentView ();
            AbsoluteLayout.SetLayoutFlags (MainContentView, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds (MainContentView, new Rectangle(0,0,1,0.9));

            BottomSheetContentView = new ContentView();
            BottomSheetContentView.BackgroundColor = Color.White;
            AbsoluteLayout.SetLayoutFlags(BottomSheetContentView, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(BottomSheetContentView, new Rectangle(0, 1, 1, 0.1));
            var gestureRecognizer = new PanGestureRecognizer ();
            gestureRecognizer.PanUpdated+=GestureRecognizerOnPanUpdated;
            BottomSheetContentView.GestureRecognizers.Add (gestureRecognizer);

            button = new FloatingActionButton
            {
                NormalColor = (Color) Application.Current.Resources ["AccentColor"],
                Command = new Command (ButtonOnClicked),
                Icon = "ic_keyboard_arrow_up"
            };
            AbsoluteLayout.SetLayoutFlags(button, AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(button, new Rectangle(0.9, 0.92, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));

            layout.Children.Add (MainContentView);
            layout.Children.Add(BottomSheetContentView);
            layout.Children.Add (button);

            Content = layout;
        }

        private async void GestureRecognizerOnPanUpdated (object sender, PanUpdatedEventArgs panUpdatedEventArgs)
        {
            if (panUpdatedEventArgs.StatusType == GestureStatus.Running)
            {
                // Set the state to pending if not done already
                if (bottomSheetState == BottomSheetState.Collapsed || bottomSheetState == BottomSheetState.Extended)
                {
                    await SetBottomSheetPending();
                }
                // Update the swipe direction
                bottomSheetState = panUpdatedEventArgs.TotalY < 0 ? BottomSheetState.Extending : BottomSheetState.Collapsing;
            }
            else if(panUpdatedEventArgs.StatusType == GestureStatus.Completed)
            {
                // Perform final animation
                if (bottomSheetState == BottomSheetState.Extending)
                {
                    await ExtendBottomSheet ();
                }
                else if (bottomSheetState == BottomSheetState.Collapsing)
                {
                    await CollapseBottomSheet ();
                }
            }
        }

        private async void ButtonOnClicked ()
        {
            if (bottomSheetState == BottomSheetState.Collapsed)
            {
                await ExtendBottomSheet ();
            }
            else if (bottomSheetState == BottomSheetState.Extended)
            {
                await CollapseBottomSheet ();
            }
        }

        #region bottomsheet manipulation

        private async Task ExtendBottomSheet() {
            Rectangle bottomSheetRect = new Rectangle
            {
                Left = 0,
                Top = Height * (1 - bottomSheetExtensionFraction),
                Size = new Size(Width, Height * bottomSheetExtensionFraction)
            };
            Rectangle buttonRect = new Rectangle
            {
                Top = bottomSheetRect.Top - button.Height / 2,
                Size = new Size (button.Width, button.Height),
                X = button.X
            };
            await Task.WhenAll(BottomSheetContentView.LayoutTo(bottomSheetRect), button.LayoutTo(buttonRect), button.RotateXTo(180));
            bottomSheetState = BottomSheetState.Extended;
        }

        private async Task CollapseBottomSheet()
        {
            Rectangle bottomSheetRect = new Rectangle
            {
                Left = 0,
                Top = Height * 0.9,
                Size = new Size(Width, Height * 0.1)
            };
            Rectangle buttonRect = new Rectangle
            {
                Top = bottomSheetRect.Top - button.Height / 2,
                Size = new Size(button.Width, button.Height),
                X = button.X
            };
            await Task.WhenAll(BottomSheetContentView.LayoutTo(bottomSheetRect), button.LayoutTo(buttonRect), button.RotateXTo(0));
            bottomSheetState = BottomSheetState.Collapsed;
        }

        private async Task SetBottomSheetPending()
        {
            Rectangle bottomSheetRect = new Rectangle
            {
                Left = 0,
                Top = Height * (1 - bottomSheetExtensionFraction / 2),
                Size = new Size(Width, Height * bottomSheetExtensionFraction /2)
            };
            Rectangle buttonRect = new Rectangle
            {
                Top = bottomSheetRect.Top - button.Height / 2,
                Size = new Size(button.Width, button.Height),
                X = button.X
            };
            await Task.WhenAll(BottomSheetContentView.LayoutTo(bottomSheetRect), button.LayoutTo(buttonRect));
        }

{'fraction_non_alphanumeric': 0.07441358856834726, 'fraction_numerical': 0.006470746832030197, 'mean_word_length': 1.8222165863555668, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4322484', 'n_tokens_mistral': 2794, 'n_tokens_neox': 2571, 'n_words': 560}