<commit_before>using System;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.OS;
using BuildIt.Bot.Client.Impl.Droid.Utilities;
using BuildIt.Bot.Client.Interfaces;
using Gcm.Client;
using Xamarin.Forms;
using Constants = BuildIt.Bot.Client.Impl.Droid.Utilities.Constants;
using Debug = System.Diagnostics.Debug;

namespace BuildIt.Bot.Client.Impl.Droid
{
    /// <summary>
    /// All of the activities MUST derive from this class
    /// </summary>
    public abstract class BotClientActivityBase : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, IPushRegistrationService
    {
        /// <summary>
        /// 
        /// </summary>
        public Func<string> RetrieveCurrentRegistrationId { private get; set; }

        /// <summary>
        /// 
        /// </summary>
        public Action<string> RegistrationSuccessful { private get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Action<Exception> RegistrationFailure { private get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="bundle"></param>
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            TryCleaningToastNotificationHistory();
        }

        /// <summary>
        /// 
        /// </summary>
        protected override void OnResume()
        {
            base.OnResume();

            MessagingCenter.Subscribe<GcmService, string>(this, null, (service, s) => { RegistrationSuccessful?.Invoke(s); });
            MessagingCenter.Subscribe<GcmService, Exception>(this, null, (service, e) => { RegistrationFailure?.Invoke(e); });

            Settings.Instance.IsAppInForeground = true;
        }

        /// <summary>
        /// 
        /// </summary>
        protected override void OnPause()
        {
            base.OnPause();

            MessagingCenter.Unsubscribe<GcmService, string>(this, null);
            MessagingCenter.Unsubscribe<GcmService, Exception>(this, null);

            Settings.Instance.IsAppInForeground = false;
        }

        /// <summary>
        /// 
        /// </summary>
        protected void InitNotifications(string googleApiConsoleAppProjectNumber)
        {
            try
            {
                Settings.Instance.RegistrationId = RetrieveCurrentRegistrationId?.Invoke();

                //Check to see that GCM is supported and that the manifest has the correct information
                GcmClient.CheckDevice(this);
                GcmClient.CheckManifest(this);

                //Call to Register the device for Push Notifications
                GcmClient.Register(this, googleApiConsoleAppProjectNumber);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        private bool IsLaunchedByPushNotification()
        {
            return Intent.GetBooleanExtra(Constants.PushNotificationExtra, false);
        }<commit_msg>Adding some necessary code for MessagingCenter subscription<commit_after>using System;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.OS;
using BuildIt.Bot.Client.Impl.Droid.Utilities;
using BuildIt.Bot.Client.Interfaces;
using Gcm.Client;
using Xamarin.Forms;
using Constants = BuildIt.Bot.Client.Impl.Droid.Utilities.Constants;
using Debug = System.Diagnostics.Debug;

namespace BuildIt.Bot.Client.Impl.Droid
{
    /// <summary>
    /// All of the activities MUST derive from this class
    /// </summary>
    public abstract class BotClientActivityBase : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity, IPushRegistrationService
    {
        private const string SuccessSubscriptionMsg = "success";
        private const string FailureSubscriptionMsg = "success";

        /// <summary>
        /// 
        /// </summary>
        public Func<string> RetrieveCurrentRegistrationId { private get; set; }

        /// <summary>
        /// 
        /// </summary>
        public Action<string> RegistrationSuccessful { private get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Action<Exception> RegistrationFailure { private get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="bundle"></param>
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            TryCleaningToastNotificationHistory();
        }

        /// <summary>
        /// 
        /// </summary>
        protected override void OnResume()
        {
            base.OnResume();

            MessagingCenter.Subscribe<GcmService, string>(this, SuccessSubscriptionMsg, (service, s) => { RegistrationSuccessful?.Invoke(s); });
            MessagingCenter.Subscribe<GcmService, Exception>(this, FailureSubscriptionMsg, (service, e) => { RegistrationFailure?.Invoke(e); });

            Settings.Instance.IsAppInForeground = true;
        }

        /// <summary>
        /// 
        /// </summary>
        protected override void OnPause()
        {
            base.OnPause();

            MessagingCenter.Unsubscribe<GcmService, string>(this, SuccessSubscriptionMsg);
            MessagingCenter.Unsubscribe<GcmService, Exception>(this, FailureSubscriptionMsg);

            Settings.Instance.IsAppInForeground = false;
        }

        /// <summary>
        /// 
        /// </summary>
        protected void InitNotifications(string googleApiConsoleAppProjectNumber)
        {
            try
            {
                Settings.Instance.RegistrationId = RetrieveCurrentRegistrationId?.Invoke();

                //Check to see that GCM is supported and that the manifest has the correct information
                GcmClient.CheckDevice(this);
                GcmClient.CheckManifest(this);

                //Call to Register the device for Push Notifications
                GcmClient.Register(this, googleApiConsoleAppProjectNumber);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        private bool IsLaunchedByPushNotification()
        {
            return Intent.GetBooleanExtra(Constants.PushNotificationExtra, false);
        }
{'fraction_non_alphanumeric': 0.10796264049390533, 'fraction_numerical': 0.0, 'mean_word_length': 1.9943127962085307, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 57, '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': '3957668', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1547, 'n_words': 336}