AppIndexingManager.java 4.92 KB
package com.bitstrips.imoji.manager;

import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.bitstrips.imoji.behaviour.BehaviourHelper;
import com.bitstrips.imoji.firebase.AppIndexingLegacyScheduler;
import com.bitstrips.imoji.firebase.AppIndexingParams;
import com.bitstrips.imoji.firebase.AppIndexingParams.Builder;
import com.bitstrips.imoji.firebase.AppIndexingService;
import com.bitstrips.imoji.injection.ForApplication;
import com.bitstrips.imoji.models.StickerPacks;
import com.bitstrips.imoji.util.PreferenceUtils;
import com.google.firebase.appindexing.FirebaseAppIndex;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class AppIndexingManager
  implements StickerPacksManager.OnStickerPacksChangedListener
{
  private static final long a = TimeUnit.MINUTES.toMillis(5L);
  private static final long b = TimeUnit.MINUTES.toMillis(5L);
  private final Context c;
  private final PreferenceUtils d;
  private final AppIndexingLegacyScheduler e;
  private final BehaviourHelper f;
  private boolean g = false;
  private AtomicBoolean h = new AtomicBoolean(false);
  private WeakHashMap<OnFirebaseIndexCompleteListener, Void> i = new WeakHashMap();
  
  @Inject
  public AppIndexingManager(@ForApplication Context paramContext, PreferenceUtils paramPreferenceUtils, AppIndexingLegacyScheduler paramAppIndexingLegacyScheduler, BehaviourHelper paramBehaviourHelper, StickerPacksManager paramStickerPacksManager)
  {
    this.c = paramContext;
    this.d = paramPreferenceUtils;
    this.e = paramAppIndexingLegacyScheduler;
    this.f = paramBehaviourHelper;
    paramStickerPacksManager.addOnStickerPacksChangedListener(this);
  }
  
  public void addOnFirebaseIndexCompleteListener(OnFirebaseIndexCompleteListener paramOnFirebaseIndexCompleteListener)
  {
    this.i.put(paramOnFirebaseIndexCompleteListener, null);
  }
  
  public void clearIndex()
  {
    this.g = false;
    FirebaseAppIndex.getInstance().removeAll();
  }
  
  public boolean hasCompletedIndex()
  {
    return (this.g) || (this.d.getLong(2131231266, 0L).longValue() != 0L);
  }
  
  public void notifyFirebaseIndexCompleteOnMainThread()
  {
    this.g = true;
    Runnable local1 = new Runnable()
    {
      public final void run()
      {
        AppIndexingManager.a(AppIndexingManager.this);
      }
    };
    new Handler(Looper.getMainLooper()).post(local1);
  }
  
  public void onStickerPacksChanged(StickerPacks paramStickerPacks)
  {
    if (paramStickerPacks == null)
    {
      clearIndex();
      return;
    }
    Log.i("AppIndexingManager", "Updating Firebase index due to avatar change..");
    updateIndex(new AppIndexingParams.Builder().setIndexingReason("stickers_changed").build());
  }
  
  public void removeOnFirebaseIndexCompleteListener(OnFirebaseIndexCompleteListener paramOnFirebaseIndexCompleteListener)
  {
    this.i.remove(paramOnFirebaseIndexCompleteListener);
  }
  
  public void setIsUpdatingIndex(boolean paramBoolean)
  {
    this.h.set(paramBoolean);
  }
  
  public void updateIndex(AppIndexingParams paramAppIndexingParams)
  {
    int k = 1;
    Object localObject = paramAppIndexingParams.getIndexingReason();
    int j = k;
    if (this.h.getAndSet(true))
    {
      j = k;
      if (!"stickers_changed".equals(localObject)) {
        if (!"locale_changed".equals(localObject)) {
          break label58;
        }
      }
    }
    label58:
    for (j = k; j == 0; j = 0)
    {
      Log.v("AppIndexingManager", "Ignoring app indexing request: already indexing");
      return;
    }
    localObject = new Intent(this.c, AppIndexingService.class);
    ((Intent)localObject).putExtra("forceRequestAvatarInfo", paramAppIndexingParams.isForceRequestAvatarInfo());
    ((Intent)localObject).putExtra("forceRequestStickerPacks", paramAppIndexingParams.isForceRequestStickerPacks());
    ((Intent)localObject).putExtra("forceFlushFirebase", paramAppIndexingParams.isForceFlushFirebase());
    ((Intent)localObject).putExtra("reason", paramAppIndexingParams.getIndexingReason());
    if ((Build.VERSION.SDK_INT >= 21) && (paramAppIndexingParams.getMessenger() != null) && (paramAppIndexingParams.getJobParameters() != null))
    {
      ((Intent)localObject).putExtra("messenger", paramAppIndexingParams.getMessenger());
      ((Intent)localObject).putExtra("jobParams", paramAppIndexingParams.getJobParameters());
    }
    this.c.startService((Intent)localObject);
  }
  
  public static abstract interface OnFirebaseIndexCompleteListener
  {
    public abstract void onFirebaseIndexComplete(AppIndexingManager paramAppIndexingManager);
  }
}


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