BatchedAnalyticsService.java 2.31 KB
package com.bitstrips.imoji.analytics;

import android.app.Activity;
import android.os.Handler;
import android.support.annotation.NonNull;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;

public abstract class BatchedAnalyticsService
  implements BaseAnalyticsService
{
  final LinkedHashSet<AnalyticsEventBuilder.AnalyticsEvent> a = new LinkedHashSet();
  final LinkedHashSet<AnalyticsEventBuilder.AnalyticsEvent> b = new LinkedHashSet();
  boolean c = false;
  private final Handler d = new Handler();
  private final Runnable e = new Runnable()
  {
    public final void run()
    {
      BatchedAnalyticsService.this.reportAllEvents();
    }
  };
  
  private List<AnalyticsEventBuilder.AnalyticsEvent> b()
  {
    if (this.a.isEmpty()) {
      return null;
    }
    synchronized (this.a)
    {
      Iterator localIterator = this.a.iterator();
      if (localIterator.hasNext()) {
        ((AnalyticsEventBuilder.AnalyticsEvent)localIterator.next()).incrementRetryCount();
      }
    }
    ArrayList localArrayList = new ArrayList(this.a);
    this.a.clear();
    this.b.addAll(localArrayList);
    a();
    return localArrayList;
  }
  
  final void a()
  {
    ArrayList localArrayList = new ArrayList(this.a);
    localArrayList.addAll(this.b);
    b(localArrayList);
  }
  
  abstract void a(List<AnalyticsEventBuilder.AnalyticsEvent> paramList);
  
  abstract void b(List<AnalyticsEventBuilder.AnalyticsEvent> paramList);
  
  public void logEvent(@NonNull AnalyticsEventBuilder.AnalyticsEvent paramAnalyticsEvent)
  {
    if (paramAnalyticsEvent.hasBeenLogged()) {
      return;
    }
    synchronized (this.a)
    {
      this.a.add(paramAnalyticsEvent);
      a();
      if (this.a.size() >= 5) {
        reportAllEvents();
      }
      return;
    }
  }
  
  public void reportAllEvents()
  {
    a(b());
  }
  
  public void reportStart(@NonNull Activity paramActivity)
  {
    this.d.removeCallbacks(this.e);
    this.d.postDelayed(this.e, 30000L);
  }
  
  public void reportStop(@NonNull Activity paramActivity)
  {
    reportAllEvents();
    this.d.removeCallbacks(this.e);
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/bitstrips/imoji/analytics/BatchedAnalyticsService.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */