SnapchatManager.java 8.99 KB
package com.bitstrips.imoji.manager;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.util.Log;
import com.bitstrips.imoji.api.BitmojiApi;
import com.bitstrips.imoji.experiments.Experiments;
import com.bitstrips.imoji.identity.AvatarManager;
import com.bitstrips.imoji.identity.AvatarManager.UpdateAvatarInfoCallback;
import com.bitstrips.imoji.injection.ForApplication;
import com.bitstrips.imoji.models.SCUser;
import com.bitstrips.imoji.monouser.oauth2.OAuth2Manager;
import com.bitstrips.imoji.ui.BitmojiBaseActivity;
import com.bitstrips.imoji.ui.IntentCreatorService;
import com.bitstrips.imoji.util.PreferenceUtils;
import java.lang.ref.WeakReference;
import java.util.List;
import javax.inject.Inject;
import retrofit.Callback;
import retrofit.RetrofitError;

public class SnapchatManager
{
  private Intent a = null;
  private String b = "snapchat://";
  private final AvatarManager c;
  private final BitmojiApi d;
  private final PreferenceUtils e;
  private final IntentCreatorService f;
  private final Context g;
  private final OAuth2Manager h;
  private final Experiments i;
  
  @Inject
  public SnapchatManager(AvatarManager paramAvatarManager, BitmojiApi paramBitmojiApi, PreferenceUtils paramPreferenceUtils, IntentCreatorService paramIntentCreatorService, @ForApplication Context paramContext, OAuth2Manager paramOAuth2Manager, Experiments paramExperiments)
  {
    this.c = paramAvatarManager;
    this.d = paramBitmojiApi;
    this.e = paramPreferenceUtils;
    this.f = paramIntentCreatorService;
    this.g = paramContext;
    this.h = paramOAuth2Manager;
    this.i = paramExperiments;
  }
  
  private Uri a(String paramString)
  {
    if (("debug".equalsIgnoreCase("release")) && (!this.b.equals("snapchat://")) && (!hasActivityToHandleUri(this.b))) {
      this.b = "snapchat://";
    }
    return Uri.parse(this.b + paramString);
  }
  
  private String a(Intent paramIntent)
  {
    if (paramIntent == null) {
      return null;
    }
    String str;
    int j;
    if (paramIntent != null)
    {
      str = paramIntent.getStringExtra("build_type");
      if (str != null)
      {
        j = -1;
        switch (str.hashCode())
        {
        default: 
          switch (j)
          {
          default: 
            label60:
            this.b = "snapchat://";
          }
          break;
        }
      }
    }
    for (;;)
    {
      paramIntent = paramIntent.getStringExtra("snapchat_action");
      if (TextUtils.isEmpty(paramIntent)) {
        break;
      }
      return paramIntent;
      if (!str.equals("alpha")) {
        break label60;
      }
      j = 0;
      break label60;
      if (!str.equals("debug")) {
        break label60;
      }
      j = 1;
      break label60;
      if (!str.equals("master")) {
        break label60;
      }
      j = 2;
      break label60;
      this.b = "snapchatalpha://";
      continue;
      this.b = "snapchatdebug://";
      continue;
      this.b = "snapchatmaster://";
    }
  }
  
  private static void a(Uri paramUri, Context paramContext)
  {
    try
    {
      Intent localIntent = new Intent("android.intent.action.VIEW");
      localIntent.addFlags(268435456);
      localIntent.setData(paramUri);
      paramContext.startActivity(localIntent);
      return;
    }
    catch (Exception paramUri) {}
  }
  
  private void a(OnSnapchatResponseListener paramOnSnapchatResponseListener, Intent paramIntent, int paramInt)
  {
    if (paramIntent == null) {
      return;
    }
    paramIntent = paramIntent.getStringExtra("bitmask_request_token");
    if (paramIntent == null)
    {
      paramOnSnapchatResponseListener.onSnapchatResponseError();
      return;
    }
    handleSnapchatActionLogin(paramOnSnapchatResponseListener, paramIntent, paramInt);
  }
  
  public Intent getCurrentLinkingIntent()
  {
    return this.a;
  }
  
  public String getSnapchatRequestTokenForLinkage(Intent paramIntent)
  {
    if (paramIntent == null) {}
    String str;
    do
    {
      return null;
      str = paramIntent.getStringExtra("snapchat_action");
    } while ((TextUtils.isEmpty(str)) || (!str.equals("auth")));
    return paramIntent.getStringExtra("bitmask_request_token");
  }
  
  public String getSnapchatRequestTokenForLogin(Intent paramIntent)
  {
    if (paramIntent == null) {}
    String str;
    do
    {
      return null;
      str = paramIntent.getStringExtra("snapchat_action");
    } while ((TextUtils.isEmpty(str)) || ((!str.equals("create")) && (!str.equals("login"))));
    return paramIntent.getStringExtra("bitmask_request_token");
  }
  
  public void goBackToSnapchat(Context paramContext)
  {
    a(a(""), paramContext);
  }
  
  public void goBackToSnapchatWithAvatarChange(Context paramContext)
  {
    a(a("bitmoji/avatar_change"), paramContext);
  }
  
  public void goToPlayStoreSnapchat()
  {
    try
    {
      Intent localIntent = new Intent("android.intent.action.VIEW");
      localIntent.addFlags(268435456);
      localIntent.setData(Uri.parse("market://details?id=com.snapchat.android"));
      this.g.startActivity(localIntent);
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }
  
  public void goToSnapchatOrPlayStore(BitmojiBaseActivity paramBitmojiBaseActivity)
  {
    if (hasActivityToHandleUri(this.b))
    {
      sendIntentForRequestToken(paramBitmojiBaseActivity);
      return;
    }
    paramBitmojiBaseActivity.showAlertDialog(this.g.getString(2131230959), this.g.getString(2131230958), new Runnable()new Runnable
    {
      public final void run()
      {
        SnapchatManager.this.goToPlayStoreSnapchat();
      }
    }, new Runnable()
    {
      public final void run() {}
    });
  }
  
  public void goToSnapchatWithSuccess(Context paramContext)
  {
    this.a = null;
    a(a("bitmoji/auth_success"), paramContext);
  }
  
  public void handleSnapchatActionLogin(OnSnapchatResponseListener paramOnSnapchatResponseListener, String paramString)
  {
    handleSnapchatActionLogin(paramOnSnapchatResponseListener, paramString, 0);
  }
  
  public void handleSnapchatActionLogin(final OnSnapchatResponseListener paramOnSnapchatResponseListener, String paramString, final int paramInt)
  {
    final WeakReference localWeakReference = new WeakReference(paramOnSnapchatResponseListener);
    this.d.loginToSnapchat(paramString, new Callback()
    {
      public final void failure(RetrofitError paramAnonymousRetrofitError)
      {
        paramAnonymousRetrofitError = (SnapchatManager.OnSnapchatResponseListener)localWeakReference.get();
        if (paramAnonymousRetrofitError != null) {
          paramAnonymousRetrofitError.onSnapchatResponseError();
        }
      }
    });
  }
  
  @VisibleForTesting
  public boolean hasActivityToHandleUri(String paramString)
  {
    Intent localIntent = new Intent("android.intent.action.VIEW");
    localIntent.setData(Uri.parse(paramString));
    paramString = this.g.getPackageManager();
    if (paramString == null) {}
    while (paramString.queryIntentActivities(localIntent, 0).size() <= 0) {
      return false;
    }
    return true;
  }
  
  public boolean isSnapchatChangeOutfit(Intent paramIntent)
  {
    paramIntent = a(paramIntent);
    if (paramIntent == null) {
      return false;
    }
    return paramIntent.equals("change_outfit");
  }
  
  public boolean isSnapchatCreating(Intent paramIntent)
  {
    paramIntent = a(paramIntent);
    if (paramIntent == null) {
      return false;
    }
    return paramIntent.equals("create");
  }
  
  public boolean isSnapchatEditAvatar(Intent paramIntent)
  {
    paramIntent = a(paramIntent);
    if (paramIntent == null) {
      return false;
    }
    return paramIntent.equals("edit");
  }
  
  public boolean isSnapchatLinking(Intent paramIntent)
  {
    paramIntent = a(paramIntent);
    if (paramIntent == null) {
      return false;
    }
    return paramIntent.equals("auth");
  }
  
  public void logInWithRequestTokenAndOpenAvatarBuilder(OnSnapchatResponseListener paramOnSnapchatResponseListener, Intent paramIntent)
  {
    a(paramOnSnapchatResponseListener, paramIntent, 1);
  }
  
  public void logInWithRequestTokenAndOpenOutfitBuilder(OnSnapchatResponseListener paramOnSnapchatResponseListener, Intent paramIntent)
  {
    a(paramOnSnapchatResponseListener, paramIntent, 2);
  }
  
  public void saveCurrentIntentData(Intent paramIntent)
  {
    if (isSnapchatLinking(paramIntent)) {
      this.a = paramIntent;
    }
  }
  
  public void sendIntentForRequestToken(Context paramContext)
  {
    a(a("bitmoji/auth"), paramContext);
    ((Activity)paramContext).finish();
  }
  
  public static abstract interface OnSnapchatResponseListener
  {
    public abstract void onSnapchatResponseError();
    
    public abstract void onSnapchatResponseSuccess();
  }
}


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