예제 #1
0
 //Válido para Lollipop en Adelante, no KitKat.
 public override void OnListenerConnected()
 {
     base.OnListenerConnected();
     catcherInstance     = this;
     listaNotificaciones = GetActiveNotifications().ToList();
     adapter             = new NotificationAdapter(listaNotificaciones);
     RegisterReceiver(new ScreenOnOffReceiver(), new IntentFilter(Intent.ActionScreenOn));
     Log.Info("Listener connected, list: ", listaNotificaciones.Count.ToString());
 }
예제 #2
0
        public override void OnNotificationPosted(StatusBarNotification sbn)
        {
            //Kitkat Dirty ListenerConnected.
            //No funciona si no hay una notificación nueva
            if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop && isConnected == false)
            {
                catcherInstance     = this;
                listaNotificaciones = GetActiveNotifications().ToList();
                adapter             = new NotificationAdapter(listaNotificaciones);
                isConnected         = true;
                Log.Info("Kitkat Listener connected, list: ", listaNotificaciones.Count.ToString());
            }

            int id     = sbn.Id;
            int indice = listaNotificaciones.IndexOf(listaNotificaciones.FirstOrDefault(o => o.Id == sbn.Id));

            //Condicional debido a que Play Store causa que algun item se pierda #wontfix ?
            if (indice >= 0)
            {
                listaNotificaciones.RemoveAt(indice);
                listaNotificaciones.Add(sbn);
                if (LockScreenActivity.lockScreenInstance != null)
                {
                    LockScreenActivity.lockScreenInstance.RunOnUiThread(() => adapter.NotifyItemChanged(indice));
                }

                Log.Info("Elemento actualizado", "Tamaño lista: " + listaNotificaciones.Count);
            }
            else
            {
                listaNotificaciones.Add(sbn);
                if (LockScreenActivity.lockScreenInstance != null)
                {
                    LockScreenActivity.lockScreenInstance.RunOnUiThread(() => adapter.NotifyItemInserted(listaNotificaciones.Count));
                }
                Log.Info("Elemento insertado", "Tamaño lista: " + listaNotificaciones.Count);
            }
        }