public class Config {
public static final String FILE = "config";
public static final String USER_ID = "user_id";
public static final String TOKEN = "token";
public static void logout(Context context) {
SharedPreferences sharedPref = context.getSharedPreferences(Config.FILE, Context.MODE_PRIVATE);
Editor editor = sharedPref.edit();
editor.remove(Config.USER_ID);
editor.remove(Config.TOKEN);
editor.commit();
}
public static boolean isLogined(Context context){
SharedPreferences sharedPref = context.getSharedPreferences(Config.FILE, Context.MODE_PRIVATE);
String userId = sharedPref.getString(Config.USER_ID, "");
if(!TextUtils.isEmpty(userId)){
return true;
}
return false;
}
public static String getUserId(Context context){
SharedPreferences sharedPref = context.getSharedPreferences(Config.FILE, Context.MODE_PRIVATE);
return sharedPref.getString(USER_ID, "");
}
public static void setUserId(Context context, String userId){
SharedPreferences sharedPref = context.getSharedPreferences(Config.FILE, Context.MODE_PRIVATE);
Editor editor = sharedPref.edit();
editor.putString(Config.USER_ID, userId);
editor.commit();
}
public static String getToken(Context context){
SharedPreferences sharedPref = context.getSharedPreferences(Config.FILE, Context.MODE_PRIVATE);
return sharedPref.getString(TOKEN, "");
}
public static void setToken(Context context, String token){
SharedPreferences sharedPref = context.getSharedPreferences(Config.FILE, Context.MODE_PRIVATE);
Editor editor = sharedPref.edit();
editor.putString(Config.TOKEN, token);
editor.commit();
}
}



