using Android.Content;
using Billing.Droid.Renderers;
using Billing.UI;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(LongPressButton), typeof(LongPressButtonRenderer))]
namespace Billing.Droid.Renderers
{
    public class LongPressButtonRenderer : ButtonRenderer
    {
        public LongPressButtonRenderer(Context context) : base(context)
        {
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
        {
            base.OnElementChanged(e);

            if (Element is LongPressButton && Control != null)
            {
                Control.LongClick += Control_LongClick;
            }
        }

        private void Control_LongClick(object sender, LongClickEventArgs e)
        {
            if (Element is LongPressButton button)
            {
                button.TriggerLongPress();
            }
        }
    }
}