StickerPacksManager.java 11.9 KB
package com.bitstrips.imoji.manager;

import android.content.Context;
import android.content.res.Resources;
import android.os.Build.VERSION;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import com.bitstrips.imoji.api.BitmojiApi;
import com.bitstrips.imoji.behaviour.BehaviourHelper;
import com.bitstrips.imoji.experiments.Experiments;
import com.bitstrips.imoji.injection.ForApplication;
import com.bitstrips.imoji.models.StickerPacks;
import com.bitstrips.imoji.util.PreferenceTimer;
import com.bitstrips.imoji.util.PreferenceUtils;
import com.bitstrips.imoji.util.StickerPacksValidator;
import com.google.gson.Gson;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
import java.util.WeakHashMap;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.lang3.time.FastDateFormat;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
import retrofit.converter.GsonConverter;

@Singleton
public class StickerPacksManager
{
  private static final FastDateFormat a = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ssZZ", Calendar.getInstance().getTimeZone());
  private final BitmojiApi b;
  private final Context c;
  private final PreferenceUtils d;
  private final PreferenceTimer e;
  private final GsonConverter f;
  private final BehaviourHelper g;
  private final Experiments h;
  private final Gson i;
  private final Handler j;
  private final WeakHashMap<OnStickerPacksChangedListener, Void> k = new WeakHashMap();
  private StickerPacks l;
  
  @Inject
  public StickerPacksManager(@ForApplication Context paramContext, BitmojiApi paramBitmojiApi, GsonConverter paramGsonConverter, PreferenceUtils paramPreferenceUtils, BehaviourHelper paramBehaviourHelper, Experiments paramExperiments, Gson paramGson) {}
  
  @VisibleForTesting
  private StickerPacksManager(Context paramContext, BitmojiApi paramBitmojiApi, GsonConverter paramGsonConverter, PreferenceUtils paramPreferenceUtils, BehaviourHelper paramBehaviourHelper, PreferenceTimer paramPreferenceTimer, Experiments paramExperiments, Gson paramGson, StickerPacks paramStickerPacks, Handler paramHandler)
  {
    this.c = paramContext;
    this.b = paramBitmojiApi;
    this.f = paramGsonConverter;
    this.d = paramPreferenceUtils;
    this.g = paramBehaviourHelper;
    this.e = paramPreferenceTimer;
    this.h = paramExperiments;
    this.l = paramStickerPacks;
    this.i = paramGson;
    this.j = paramHandler;
  }
  
  /* Error */
  @VisibleForTesting
  private StickerPacks a(int paramInt, String paramString)
  {
    // Byte code:
    //   0: aload_0
    //   1: monitorenter
    //   2: aload_0
    //   3: getfield 112	com/bitstrips/imoji/manager/StickerPacksManager:c	Landroid/content/Context;
    //   6: ldc -119
    //   8: invokevirtual 142	android/content/Context:getString	(I)Ljava/lang/String;
    //   11: astore_3
    //   12: aload_0
    //   13: getfield 112	com/bitstrips/imoji/manager/StickerPacksManager:c	Landroid/content/Context;
    //   16: ldc -113
    //   18: invokevirtual 142	android/content/Context:getString	(I)Ljava/lang/String;
    //   21: astore 4
    //   23: aload_0
    //   24: getfield 114	com/bitstrips/imoji/manager/StickerPacksManager:b	Lcom/bitstrips/imoji/api/BitmojiApi;
    //   27: aload_2
    //   28: ldc -111
    //   30: ldc -109
    //   32: getstatic 61	com/bitstrips/imoji/manager/StickerPacksManager:a	Lorg/apache/commons/lang3/time/FastDateFormat;
    //   35: invokestatic 153	java/lang/System:currentTimeMillis	()J
    //   38: invokevirtual 157	org/apache/commons/lang3/time/FastDateFormat:format	(J)Ljava/lang/String;
    //   41: invokestatic 163	java/util/Locale:getDefault	()Ljava/util/Locale;
    //   44: invokevirtual 167	java/util/Locale:getLanguage	()Ljava/lang/String;
    //   47: aload_0
    //   48: invokespecial 169	com/bitstrips/imoji/manager/StickerPacksManager:a	()Ljava/lang/String;
    //   51: aload_0
    //   52: getfield 120	com/bitstrips/imoji/manager/StickerPacksManager:g	Lcom/bitstrips/imoji/behaviour/BehaviourHelper;
    //   55: aload_0
    //   56: getfield 124	com/bitstrips/imoji/manager/StickerPacksManager:h	Lcom/bitstrips/imoji/experiments/Experiments;
    //   59: invokevirtual 175	com/bitstrips/imoji/behaviour/BehaviourHelper:getChillvibesContentGroup	(Lcom/bitstrips/imoji/experiments/Experiments;)Ljava/lang/String;
    //   62: iconst_1
    //   63: aload_0
    //   64: getfield 120	com/bitstrips/imoji/manager/StickerPacksManager:g	Lcom/bitstrips/imoji/behaviour/BehaviourHelper;
    //   67: aload_0
    //   68: getfield 124	com/bitstrips/imoji/manager/StickerPacksManager:h	Lcom/bitstrips/imoji/experiments/Experiments;
    //   71: invokevirtual 179	com/bitstrips/imoji/behaviour/BehaviourHelper:getSmartvibesSuggestContentEnabled	(Lcom/bitstrips/imoji/experiments/Experiments;)Z
    //   74: aload_0
    //   75: getfield 120	com/bitstrips/imoji/manager/StickerPacksManager:g	Lcom/bitstrips/imoji/behaviour/BehaviourHelper;
    //   78: aload_0
    //   79: getfield 124	com/bitstrips/imoji/manager/StickerPacksManager:h	Lcom/bitstrips/imoji/experiments/Experiments;
    //   82: invokevirtual 182	com/bitstrips/imoji/behaviour/BehaviourHelper:getSmartvibesReorderContentEnabled	(Lcom/bitstrips/imoji/experiments/Experiments;)Z
    //   85: iload_1
    //   86: aload_3
    //   87: aload 4
    //   89: invokeinterface 188 14 0
    //   94: astore_3
    //   95: aload_0
    //   96: getfield 116	com/bitstrips/imoji/manager/StickerPacksManager:f	Lretrofit/converter/GsonConverter;
    //   99: aload_3
    //   100: invokevirtual 194	retrofit/client/Response:getBody	()Lretrofit/mime/TypedInput;
    //   103: ldc 94
    //   105: invokevirtual 200	retrofit/converter/GsonConverter:fromBody	(Lretrofit/mime/TypedInput;Ljava/lang/reflect/Type;)Ljava/lang/Object;
    //   108: checkcast 94	com/bitstrips/imoji/models/StickerPacks
    //   111: astore_2
    //   112: aload_0
    //   113: aload_2
    //   114: aload_3
    //   115: invokestatic 206	com/bitstrips/imoji/util/WebUtils:getETag	(Lretrofit/client/Response;)Ljava/lang/String;
    //   118: invokevirtual 209	com/bitstrips/imoji/manager/StickerPacksManager:a	(Lcom/bitstrips/imoji/models/StickerPacks;Ljava/lang/String;)V
    //   121: aload_0
    //   122: monitorexit
    //   123: aload_2
    //   124: areturn
    //   125: astore_2
    //   126: aload_2
    //   127: invokevirtual 213	retrofit/RetrofitError:getKind	()Lretrofit/RetrofitError$Kind;
    //   130: getstatic 219	retrofit/RetrofitError$Kind:NETWORK	Lretrofit/RetrofitError$Kind;
    //   133: if_acmpeq +18 -> 151
    //   136: aload_2
    //   137: invokevirtual 223	retrofit/RetrofitError:getResponse	()Lretrofit/client/Response;
    //   140: ifnull +11 -> 151
    //   143: aload_2
    //   144: invokevirtual 223	retrofit/RetrofitError:getResponse	()Lretrofit/client/Response;
    //   147: invokevirtual 227	retrofit/client/Response:getStatus	()I
    //   150: pop
    //   151: aload_0
    //   152: invokevirtual 230	com/bitstrips/imoji/manager/StickerPacksManager:getStickerPacks	()Lcom/bitstrips/imoji/models/StickerPacks;
    //   155: astore_3
    //   156: aload_3
    //   157: astore_2
    //   158: aload_3
    //   159: invokestatic 236	com/bitstrips/imoji/util/StickerPacksValidator:validate	(Lcom/bitstrips/imoji/models/StickerPacks;)Z
    //   162: ifne -41 -> 121
    //   165: aconst_null
    //   166: astore_2
    //   167: goto -46 -> 121
    //   170: astore_2
    //   171: new 238	java/lang/IllegalStateException
    //   174: dup
    //   175: ldc -16
    //   177: aload_2
    //   178: invokespecial 243	java/lang/IllegalStateException:<init>	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   181: athrow
    //   182: astore_2
    //   183: aload_0
    //   184: monitorexit
    //   185: aload_2
    //   186: athrow
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	187	0	this	StickerPacksManager
    //   0	187	1	paramInt	int
    //   0	187	2	paramString	String
    //   11	148	3	localObject	Object
    //   21	67	4	str	String
    // Exception table:
    //   from	to	target	type
    //   23	95	125	retrofit/RetrofitError
    //   95	112	170	retrofit/converter/ConversionException
    //   2	23	182	finally
    //   23	95	182	finally
    //   95	112	182	finally
    //   112	121	182	finally
    //   126	151	182	finally
    //   151	156	182	finally
    //   158	165	182	finally
    //   171	182	182	finally
  }
  
  private String a()
  {
    if ((this.g.isWebpEnabled()) && (Build.VERSION.SDK_INT >= 18)) {
      return "webp";
    }
    return null;
  }
  
  @VisibleForTesting
  final void a(final StickerPacks paramStickerPacks, String paramString)
  {
    try
    {
      this.l = paramStickerPacks;
      PreferenceUtils localPreferenceUtils = this.d;
      if (paramStickerPacks == null) {
        paramString = null;
      }
      localPreferenceUtils.putString(2131231327, paramString);
      this.d.putString(2131231328, this.i.toJson(paramStickerPacks));
      this.e.setTimestamp(System.currentTimeMillis());
      this.j.post(new Runnable()
      {
        public final void run()
        {
          Iterator localIterator = StickerPacksManager.a(StickerPacksManager.this).keySet().iterator();
          while (localIterator.hasNext()) {
            ((StickerPacksManager.OnStickerPacksChangedListener)localIterator.next()).onStickerPacksChanged(paramStickerPacks);
          }
        }
      });
      return;
    }
    finally {}
  }
  
  public void addOnStickerPacksChangedListener(OnStickerPacksChangedListener paramOnStickerPacksChangedListener)
  {
    this.k.put(paramOnStickerPacksChangedListener, null);
  }
  
  public void clear()
  {
    a(null, null);
  }
  
  public StickerPacks getStickerPacks()
  {
    return this.l;
  }
  
  public void updateStickerPacksAsync(int paramInt, @Nullable final OnStickerPacksLoadFailedCallback paramOnStickerPacksLoadFailedCallback)
  {
    String str1 = this.d.getString(2131231327, null);
    if (!StickerPacksValidator.validate(this.l)) {
      str1 = null;
    }
    String str2 = this.c.getString(2131231162);
    String str3 = this.c.getString(2131231303);
    this.b.getStickerPacks(str1, "application/content.stickers.v1+json;charset=utf-8", "bitmoji-app", a.format(System.currentTimeMillis()), Locale.getDefault().getLanguage(), a(), this.g.getChillvibesContentGroup(this.h), true, this.g.getSmartvibesSuggestContentEnabled(this.h), this.g.getSmartvibesReorderContentEnabled(this.h), paramInt, str2, str3, new Callback()
    {
      public final void failure(RetrofitError paramAnonymousRetrofitError)
      {
        if ((paramAnonymousRetrofitError.getResponse() != null) && (paramAnonymousRetrofitError.getResponse().getStatus() == 304)) {}
        while (paramOnStickerPacksLoadFailedCallback == null) {
          return;
        }
        paramOnStickerPacksLoadFailedCallback.onStickerPacksLoadFailed(paramAnonymousRetrofitError);
      }
    });
  }
  
  public StickerPacks updateStickerPacksIfNecessarySync(boolean paramBoolean, long paramLong)
  {
    StickerPacks localStickerPacks = getStickerPacks();
    int m = this.c.getResources().getInteger(2131558411);
    String str = this.d.getString(2131231327, null);
    boolean bool = StickerPacksValidator.validate(localStickerPacks);
    if ((this.e.timeSinceLastUpdateInMillisec() < paramLong) && (!paramBoolean) && (bool)) {
      return localStickerPacks;
    }
    if ((paramBoolean) || (!bool)) {
      str = null;
    }
    return a(m, str);
  }
  
  public static abstract interface OnStickerPacksChangedListener
  {
    public abstract void onStickerPacksChanged(StickerPacks paramStickerPacks);
  }
  
  public static abstract interface OnStickerPacksLoadFailedCallback
  {
    public abstract void onStickerPacksLoadFailed(RetrofitError paramRetrofitError);
  }
}


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