b.java 6.35 KB
package com.instabug.library;

import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build.VERSION;
import android.support.v4.app.NotificationCompat.Builder;
import com.instabug.library.model.g;
import com.instabug.library.model.g.a;
import com.instabug.library.model.h;
import com.instabug.library.util.InstabugSDKLogger;
import com.instabug.library.util.f;
import com.instabug.library.util.i;
import com.instabug.library.util.i.a;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class b
{
  private static b b;
  private f a;
  
  private static int a(List<g> paramList)
  {
    int k = 1;
    ArrayList localArrayList = new ArrayList();
    localArrayList.addAll(paramList);
    int j = Integer.parseInt(((g)paramList.get(0)).g());
    Collections.sort(localArrayList, new g.a(1));
    paramList = localArrayList.iterator();
    int i = 1;
    if (paramList.hasNext())
    {
      int m = Integer.parseInt(((g)paramList.next()).g());
      if (m == j) {
        break label113;
      }
      i += 1;
      j = m;
    }
    label113:
    for (;;)
    {
      break;
      j = k;
      if (i == 1) {
        j = 0;
      }
      return j;
    }
  }
  
  public static b a()
  {
    if (b == null) {
      b = new b();
    }
    return b;
  }
  
  private String a(Activity paramActivity, int paramInt, String paramString)
  {
    switch (paramInt)
    {
    default: 
      return "";
    case 0: 
      return paramString.substring(0, paramString.indexOf('<')) + "(" + this.a.a() + paramActivity.getString(R.string.instabug_str_notification_title) + ")";
    }
    return this.a.a() + paramActivity.getString(R.string.instabug_str_notification_title);
  }
  
  private static String a(Context paramContext, int paramInt, List<g> paramList)
  {
    switch (paramInt)
    {
    default: 
      return "";
    case 0: 
      return ((g)paramList.get(paramList.size() - 1)).c();
    }
    paramContext = paramContext.getResources();
    String[] arrayOfString = ((g)paramList.get(paramList.size() - 1)).f().split(" ");
    return String.format(paramContext.getString(R.string.instabug_str_notifications_body), new Object[] { Integer.valueOf(paramList.size()), arrayOfString[0] });
  }
  
  private void b(Context paramContext, List<g> paramList)
  {
    Object localObject2 = "";
    Object localObject1 = null;
    switch (a(paramList))
    {
    default: 
      paramList = (List<g>)localObject2;
    }
    for (;;)
    {
      int j = u.a().J();
      int i;
      if (j != -1)
      {
        i = j;
        if (j != 0) {}
      }
      else
      {
        i = this.a.b();
      }
      localObject1 = PendingIntent.getActivity(paramContext, 0, (Intent)localObject1, 134217728);
      localObject2 = RingtoneManager.getDefaultUri(2);
      paramList = new NotificationCompat.Builder(paramContext).setSmallIcon(i).setContentTitle(this.a.a()).setContentText(paramList).setAutoCancel(true).setSound((Uri)localObject2).setContentIntent((PendingIntent)localObject1);
      if ((!(paramContext instanceof Activity)) && (Build.VERSION.SDK_INT >= 16)) {
        paramList.setPriority(1);
      }
      ((NotificationManager)paramContext.getSystemService("notification")).notify(0, paramList.build());
      return;
      localObject1 = (g)paramList.get(paramList.size() - 1);
      paramList = a(paramContext, 0, paramList);
      localObject1 = j.a(paramContext, ((g)localObject1).f(), ((g)localObject1).g());
      continue;
      paramList = a(paramContext, 1, paramList);
      localObject1 = j.a(paramContext);
    }
  }
  
  public void a(final Activity paramActivity, final List<g> paramList)
  {
    if ((paramActivity == null) || (paramList == null))
    {
      InstabugSDKLogger.wtf(this, "Sending system notification using activity while application isn't running");
      return;
    }
    this.a = new f(paramActivity);
    if (u.a().t())
    {
      final int i = a(paramList);
      g localg = (g)paramList.get(paramList.size() - 1);
      h localh;
      switch (i)
      {
      default: 
        localh = null;
      }
      for (;;)
      {
        i.a().a(paramActivity, localh, new i.a()
        {
          public final void a(boolean paramAnonymousBoolean)
          {
            if (!paramAnonymousBoolean) {
              b.a(b.this, paramActivity, paramList);
            }
          }
          
          public final void onClick()
          {
            b.a(paramActivity, paramList, i);
          }
        });
        return;
        localh = new h();
        localh.a(a(paramActivity, 0, paramList));
        localh.b(a(paramActivity, 0, localg.f()));
        localh.c(localg.h());
        continue;
        localh = new h();
        localh.a(a(paramActivity, 1, paramList));
        localh.b(a(paramActivity, 1, localg.f()));
        localh.c(localg.h());
      }
    }
    b(paramActivity, paramList);
  }
  
  public void a(Context paramContext)
  {
    ((NotificationManager)paramContext.getSystemService("notification")).cancel(0);
  }
  
  public void a(Context paramContext, List<g> paramList)
  {
    if (paramContext == null) {
      throw new IllegalStateException("You forgot to set context for this notification");
    }
    if (paramList == null) {
      throw new IllegalStateException("No data for this notification");
    }
    this.a = new f(paramContext);
    b(paramContext, paramList);
  }
  
  public void b(final Context paramContext)
  {
    if (u.a().C())
    {
      paramContext = MediaPlayer.create(paramContext, R.raw.new_message);
      InstabugSDKLogger.v(this, "Created MediaPlayer to play notification sound");
      paramContext.start();
      paramContext.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
      {
        public final void onCompletion(MediaPlayer paramAnonymousMediaPlayer)
        {
          paramContext.release();
        }
      });
      return;
    }
    InstabugSDKLogger.v(this, "Notification sounds disabled, not playing sounds");
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/instabug/library/b.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */