package fit;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import fit.internal.Utils;

/**
 * @auther Tu enum@foxmail.com
 * @date 16/8/27
 */
public final class Fit {

  private static MM instanceMM(Class clazz) {
    try {
      Class<? extends MM> mmClass = findMMForClass(clazz);
      return mmClass.newInstance();
    } catch (ClassNotFoundException e) {
      throw new RuntimeException("Miss SharedPreferenceAble", e);
    } catch (InstantiationException e) {
      throw new RuntimeException(clazz.getName() + " can't instance ", e);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(clazz.getName() + " can't instance ", e);
    }
  }

  private static Class<? extends MM> findMMForClass(Class clazz) throws ClassNotFoundException {
    return (Class<? extends MM>) Class.forName(clazz.getName() + "_Preference");
  }

  public static void save(@NonNull Context context, @NonNull Object o) {
    save(context, o.getClass().getName(), o);
  }

  public static void save(@NonNull Context context, String name, @NonNull Object o) {
    Utils.apply(saveEditor(context, name, o));
  }

  @NonNull
  public static SharedPreferences.Editor saveEditor(@NonNull Context context, @NonNull Object o) {
    return saveEditor(context, o.getClass().getName(), o);
  }

  @NonNull public static SharedPreferences.Editor saveEditor(@NonNull Context context, String name,
      @NonNull Object o) {
    Class clazz = o.getClass();
    return instanceMM(clazz).save(context, name, o);
  }

  public static <T> T get(@NonNull Context context, @NonNull Class<T> clazz) {
    return get(context, clazz.getName(), clazz);
  }

  public static <T> T get(@NonNull Context context, String name, @NonNull Class<T> clazz) {
    return (T) instanceMM(clazz).get(context, name);
  }

  public static void clear(@NonNull Context context, @NonNull Class clazz) {
    clear(context, clazz.getName());
  }

  public static void clear(@NonNull Context context, String name) {
    Utils.apply(clearEditor(context, name));
  }

  @NonNull public static SharedPreferences.Editor clearEditor(@NonNull Context context,
      @NonNull Class clazz) {
    return clearEditor(context, clazz.getName());
  }

  @NonNull
  public static SharedPreferences.Editor clearEditor(@NonNull Context context, String name) {
    return Utils.getSharedPreferenceEditor(context, name).clear();
  }

  /**
   * remove all values from the preferences for {@code name}.
   *
   * @deprecated use {@link #clear(Context, Class)} or {@link #clear(Context, String)}.
   */
  @Deprecated public static void clear(@NonNull Context context, String name, Class clazz) {
    Utils.apply(clearEditor(context, name));
  }

  /**
   * Mark in the {@link SharedPreferences.Editor} to remove all values from the {@code name}
   * preferences.
   *
   * @deprecated use {@link #clearEditor(Context, Class)} or {@link #clearEditor(Context, String)}.
   */
  @Deprecated public static SharedPreferences.Editor clearEditor(@NonNull Context context,
      String name, Class clazz) {
    return clearEditor(context, name);
  }

  public static SharedPreferences get(@NonNull Context context, String name) {
    return Utils.getSharedPreference(context, name);
  }

  public static SharedPreferences.Editor edit(@NonNull Context context, String name) {
    return Utils.getSharedPreferenceEditor(context, name);
  }
}

@@ -81,16 +81,61 @@
 rences;%0A
+import android.preference.PreferenceManager;%0A
 import a
@@ -3199,286 +3199,1251 @@
 %0A%0A  
-public static SharedPreferences get(@NonNull Context context, String name) %7B%0A    return Utils.getSharedPreference(context, name);%0A  %7D%0A%0A  public static SharedPreferences.Editor edit(@NonNull Context context, String name) %7B%0A    return Utils.getSharedPreferenceEditor(context, name
+/**%0A   * @param name Desired preferences file%0A   * @return The single SharedPreferences instance that can be used to retrieve and modify the%0A   * preference values.%0A   */%0A  public static SharedPreferences get(@NonNull Context context, String name) %7B%0A    return Utils.getSharedPreference(context, name);%0A  %7D%0A%0A  /**%0A   * @return The single SharedPreferences instance that can be used to retrieve and modify the%0A   * preference values.%0A   */%0A  public static SharedPreferences get(@NonNull Context context) %7B%0A    return PreferenceManager.getDefaultSharedPreferences(context);%0A  %7D%0A%0A  /**%0A   * @param name Desired preferences file%0A   * @return Returns a new instance of the SharedPreferences.Editor interface, allowing you to%0A   * modify the values in this SharedPreferences object.%0A   */%0A  public static SharedPreferences.Editor edit(@NonNull Context context, String name) %7B%0A    return Utils.getSharedPreferenceEditor(context, name);%0A  %7D%0A%0A  /**%0A   * @return Returns a new instance of the SharedPreferences.Editor interface, allowing you to%0A   * modify the values in this SharedPreferences object.%0A   */%0A  public static SharedPreferences.Editor edit(@NonNull Context context) %7B%0A    return PreferenceManager.getDefaultSharedPreferences(context).edit(
 );%0A 

add default sharedprefences file