InstabugFeaturesManager.java 6.39 KB
package com.instabug.library;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import com.instabug.library.util.InstabugSDKLogger;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

public class InstabugFeaturesManager
{
  private static final String AVAILABILITY_PREFIX = "AVAIL";
  private static final boolean DEFAULT_FEATURE_AVAILABILITY = true;
  public static final Feature.State DEFAULT_FEATURE_STATE = Feature.State.ENABLED;
  private static InstabugFeaturesManager INSTANCE;
  private static final String STATE_PREFIX = "STATE";
  private HashMap<Feature, Boolean> featuresAvailability = new HashMap();
  private HashMap<Feature, Feature.State> featuresState = new HashMap();
  
  public static InstabugFeaturesManager getInstance()
  {
    if (INSTANCE == null) {
      INSTANCE = new InstabugFeaturesManager();
    }
    return INSTANCE;
  }
  
  public Feature.State getFeatureState(Feature paramFeature)
  {
    if ((isFeatureAvailable(paramFeature)) && (isFeatureAvailable(Feature.INSTABUG))) {}
    for (boolean bool = true;; bool = false)
    {
      InstabugSDKLogger.d(this, "Feature " + paramFeature + " isAvailable = " + bool + ", and it's state is " + this.featuresState.get(paramFeature));
      if (bool) {
        break;
      }
      InstabugSDKLogger.d(this, "Feature " + paramFeature + " isn't available, returning " + Feature.State.DISABLED);
      return Feature.State.DISABLED;
    }
    if (this.featuresState.containsKey(paramFeature)) {
      return (Feature.State)this.featuresState.get(paramFeature);
    }
    InstabugSDKLogger.d(this, "Feature " + paramFeature + " is available, but no specific state is set. Returning " + DEFAULT_FEATURE_STATE);
    return DEFAULT_FEATURE_STATE;
  }
  
  public boolean isFeatureAvailable(Feature paramFeature)
  {
    if (this.featuresAvailability.containsKey(paramFeature))
    {
      InstabugSDKLogger.d(this, "Feature " + paramFeature + " availability is " + this.featuresAvailability.get(paramFeature));
      return ((Boolean)this.featuresAvailability.get(paramFeature)).booleanValue();
    }
    InstabugSDKLogger.d(this, "Feature " + paramFeature + " availability not found, returning true");
    return true;
  }
  
  public void restoreFeaturesFromSharedPreferences(Context paramContext)
  {
    int i = 0;
    paramContext = paramContext.getSharedPreferences("instabug", 0);
    Feature[] arrayOfFeature = Feature.values();
    int j = arrayOfFeature.length;
    if (i < j)
    {
      Feature localFeature = arrayOfFeature[i];
      Object localObject = localFeature.name() + "AVAIL";
      boolean bool = paramContext.getBoolean(localFeature.name() + "AVAIL", true);
      if (paramContext.contains((String)localObject))
      {
        this.featuresAvailability.put(localFeature, Boolean.valueOf(bool));
        InstabugSDKLogger.d(this, "Feature " + localFeature + " saved availability " + bool + " restored from shared preferences");
        label149:
        if (this.featuresState.containsKey(localFeature)) {
          break label363;
        }
        localObject = Feature.State.valueOf(paramContext.getString(localFeature.name() + "STATE", DEFAULT_FEATURE_STATE.name()));
        this.featuresState.put(localFeature, localObject);
        InstabugSDKLogger.d(this, "Restored feature " + localFeature + " state " + localObject + " from shared preferences");
      }
      for (;;)
      {
        i += 1;
        break;
        if (!this.featuresAvailability.containsKey(localFeature))
        {
          this.featuresAvailability.put(localFeature, Boolean.valueOf(bool));
          InstabugSDKLogger.d(this, "Restored feature " + localFeature + " availability " + bool + " from shared preferences");
          break label149;
        }
        InstabugSDKLogger.d(this, "Not restoring feature " + localFeature + " availability as it's already set to " + this.featuresAvailability.get(localFeature));
        break label149;
        label363:
        InstabugSDKLogger.d(this, "Not restoring feature " + localFeature + " state as it's already set to " + this.featuresState.get(localFeature));
      }
    }
  }
  
  void saveFeaturesToSharedPreferences(Context paramContext)
  {
    paramContext = paramContext.getSharedPreferences("instabug", 0).edit();
    Iterator localIterator = this.featuresAvailability.keySet().iterator();
    Feature localFeature;
    while (localIterator.hasNext())
    {
      localFeature = (Feature)localIterator.next();
      paramContext.putBoolean(localFeature.name() + "AVAIL", ((Boolean)this.featuresAvailability.get(localFeature)).booleanValue());
      InstabugSDKLogger.d(this, "Saved feature " + localFeature + " availability " + this.featuresAvailability.get(localFeature) + " to shared preferences");
    }
    localIterator = this.featuresState.keySet().iterator();
    while (localIterator.hasNext())
    {
      localFeature = (Feature)localIterator.next();
      paramContext.putString(localFeature.name() + "STATE", ((Feature.State)this.featuresState.get(localFeature)).name());
      InstabugSDKLogger.d(this, "Saved feature " + localFeature + " state " + this.featuresState.get(localFeature) + " to shared preferences");
    }
    paramContext.apply();
  }
  
  public void setFeatureState(Feature paramFeature, Feature.State paramState)
  {
    if ((this.featuresState.containsKey(paramFeature)) && (this.featuresState.get(paramFeature) == paramState))
    {
      InstabugSDKLogger.d(this, "Feature " + paramFeature + " state is already " + paramState + " ignoring");
      return;
    }
    InstabugSDKLogger.d(this, "Setting " + paramFeature + " state to " + paramState);
    this.featuresState.put(paramFeature, paramState);
  }
  
  void updateFeatureAvailability(Feature paramFeature, boolean paramBoolean)
  {
    if ((this.featuresAvailability.containsKey(paramFeature)) && (((Boolean)this.featuresAvailability.get(paramFeature)).booleanValue() == paramBoolean))
    {
      InstabugSDKLogger.d(this, "Feature " + paramFeature + " availability is already " + paramBoolean + " ignoring");
      return;
    }
    InstabugSDKLogger.d(this, "Setting feature " + paramFeature + " availability to " + paramBoolean);
    this.featuresAvailability.put(paramFeature, Boolean.valueOf(paramBoolean));
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/instabug/library/InstabugFeaturesManager.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */