UserLogoutController.java 4.59 KB
package com.bitstrips.imoji.monouser.controllers;

import android.content.Context;
import android.support.annotation.VisibleForTesting;
import com.bitstrips.imoji.abv3.camera.AvatarBuilderImageHelper;
import com.bitstrips.imoji.analytics.Action;
import com.bitstrips.imoji.analytics.BitstripsAnalyticsService;
import com.bitstrips.imoji.analytics.Category;
import com.bitstrips.imoji.api.BitmojiApi;
import com.bitstrips.imoji.experiments.Experiments;
import com.bitstrips.imoji.injection.ForApplication;
import com.bitstrips.imoji.manager.AppIndexingManager;
import com.bitstrips.imoji.manager.StickerPacksManager;
import com.bitstrips.imoji.monouser.oauth2.OAuth2Manager;
import com.bitstrips.imoji.persistence.MediaCache;
import com.bitstrips.imoji.util.PreferenceUtils;
import com.squareup.okhttp.Cache;
import java.io.File;
import javax.inject.Inject;
import javax.inject.Singleton;
import retrofit.Callback;
import retrofit.RetrofitError;

@Singleton
public class UserLogoutController
{
  private final BitstripsAnalyticsService a;
  private final StickerPacksManager b;
  private final PreferenceUtils c;
  private final BitmojiApi d;
  private final AppIndexingManager e;
  private final Cache f;
  private final MediaCache g;
  private final Context h;
  private final OAuth2Manager i;
  private final Experiments j;
  
  @Inject
  public UserLogoutController(BitstripsAnalyticsService paramBitstripsAnalyticsService, StickerPacksManager paramStickerPacksManager, PreferenceUtils paramPreferenceUtils, BitmojiApi paramBitmojiApi, AppIndexingManager paramAppIndexingManager, Cache paramCache, MediaCache paramMediaCache, @ForApplication Context paramContext, OAuth2Manager paramOAuth2Manager, Experiments paramExperiments)
  {
    this.a = paramBitstripsAnalyticsService;
    this.b = paramStickerPacksManager;
    this.c = paramPreferenceUtils;
    this.d = paramBitmojiApi;
    this.e = paramAppIndexingManager;
    this.f = paramCache;
    this.g = paramMediaCache;
    this.h = paramContext;
    this.i = paramOAuth2Manager;
    this.j = paramExperiments;
  }
  
  @VisibleForTesting
  protected void clearAvatarBuilderData()
  {
    AvatarBuilderImageHelper.deleteImage(this.h, "avatar_builder_bitmoji_user_image");
  }
  
  @VisibleForTesting
  protected void clearCachedData()
  {
    Object localObject = this.h.getCacheDir();
    if ((localObject != null) && (((File)localObject).exists()))
    {
      localObject = ((File)localObject).list();
      int m = localObject.length;
      int k = 0;
      while (k < m)
      {
        String str = localObject[k];
        if ((str != null) && (!str.equals("lib")) && (!str.contains(".dex"))) {
          deleteDir(str);
        }
        k += 1;
      }
    }
    try
    {
      clearSharedPrefFile();
      return;
    }
    catch (Exception localException) {}
  }
  
  @VisibleForTesting
  protected void clearHttpCache()
  {
    try
    {
      if (this.f != null) {
        this.f.evictAll();
      }
      return;
    }
    catch (Exception localException) {}
  }
  
  @VisibleForTesting
  protected void clearSharedPrefFile()
    throws Exception
  {
    new File(this.h.getCacheDir().getParent() + "/shared_prefs/" + this.h.getString(2131231305) + ".xml").delete();
  }
  
  @VisibleForTesting
  protected boolean deleteDir(File paramFile)
  {
    int k;
    if ((paramFile != null) && (paramFile.isDirectory()))
    {
      String[] arrayOfString = paramFile.list();
      int m = arrayOfString.length;
      k = 0;
      if (k < m) {
        if (deleteDir(new File(paramFile, arrayOfString[k]))) {}
      }
    }
    while ((paramFile == null) || (!paramFile.delete()))
    {
      return false;
      k += 1;
      break;
    }
    return true;
  }
  
  @VisibleForTesting
  protected boolean deleteDir(String paramString)
  {
    return deleteDir(new File(this.h.getCacheDir(), paramString));
  }
  
  @VisibleForTesting
  protected void invalidateServerSession()
  {
    if (this.i.isUserLoggedIn())
    {
      this.i.revokeToken();
      return;
    }
    this.d.logout("", new Callback()
    {
      public final void failure(RetrofitError paramAnonymousRetrofitError) {}
    });
  }
  
  public void logout()
  {
    this.a.sendEvent(Category.AUTH, Action.LOGOUT);
    this.a.resetSession();
    this.g.flush();
    this.b.clear();
    this.e.clearIndex();
    invalidateServerSession();
    clearHttpCache();
    clearCachedData();
    clearAvatarBuilderData();
    this.c.reset();
    this.j.reset();
  }
}


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