package com.kickstarter.models;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.google.gson.Gson;

import timber.log.Timber;

public class CurrentUser {
  private static final String USER_KEY = "user";
  private static final String ACCESS_TOKEN_KEY = "access_token";

  private static final Gson gson = new Gson();

  private CurrentUser() {}

  public static User getUser(final Context context) {
    return gson.fromJson(sharedPreferences(context).getString(USER_KEY, null), User.class);
  }

  public static String getToken(final Context context) {
    return sharedPreferences(context).getString(ACCESS_TOKEN_KEY, null);
  }

  public static void set(final Context context, final User user, final String access_token) {
    Timber.d("Set current user to %s", user.name());

    SharedPreferences.Editor editor = sharedPreferencesEditor(context);
    editor.putString(USER_KEY, gson.toJson(user, User.class));
    editor.putString(ACCESS_TOKEN_KEY, access_token);
    editor.apply();
  }

  public static void unset(final Context context) {
    Timber.d("Unset current user");

    SharedPreferences.Editor editor = sharedPreferencesEditor(context);
    editor.remove(USER_KEY);
    editor.remove(ACCESS_TOKEN_KEY);
    editor.apply();
  }

  private static SharedPreferences sharedPreferences(final Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context);
  }

  private static SharedPreferences.Editor sharedPreferencesEditor(final Context context) {
    return sharedPreferences(context).edit();
  }
}

/*
  public static void setCurrent(final User user) {
    currentUser = user;
  }

  public static void unsetCurrent() {
    currentUser = null;
  }

  public static User current() {
    return currentUser;
  }

  public static boolean haveCurrent() {
    return currentUser != null;
  }

  public boolean isCurrent() {
    return this.id == User.current().id();
  }
*/

@@ -1618,375 +1618,4 @@
 %7D%0A%7D%0A
-%0A/*%0A  public static void setCurrent(final User user) %7B%0A    currentUser = user;%0A  %7D%0A%0A  public static void unsetCurrent() %7B%0A    currentUser = null;%0A  %7D%0A%0A  public static User current() %7B%0A    return currentUser;%0A  %7D%0A%0A  public static boolean haveCurrent() %7B%0A    return currentUser != null;%0A  %7D%0A%0A  public boolean isCurrent() %7B%0A    return this.id == User.current().id();%0A  %7D%0A*/%0A

Clean up commented code