@Subscribe
  public void onUserRetrieved(UserRetrievedEvent event) {
    CWUser u = event.getUser();

    if (event.isTaskOver()) UserFragment.this.setRefresh(false);

    if (event.getError() != null) {
      Toast.makeText(getSherlockActivity(), event.getError().getMessage(), Toast.LENGTH_LONG)
          .show();
      return;
    } else if (u == null) return;

    if (UserFragment.this.username == null) {
      UserFragment.this.username = u.getUsername();
      SharedPreferences prefs =
          PreferenceManager.getDefaultSharedPreferences(getSherlockActivity());
      prefs.edit().putString(Constants.PREF_USERNAME, u.getUsername()).commit();
    }

    UserFragment.this.u = u;
    refreshNavigationListAdapter();

    if (pagerAdapter == null || viewPager.getAdapter() == null) {
      viewPager.setAdapter(pagerAdapter = new PagerUserAdapter(getFragmentManager(), u));
      pageIndicator.setViewPager(viewPager);
      pageIndicator.setOnPageChangeListener(UserFragment.this);
      pageIndicator.setBackgroundColor(getResources().getColor(R.color.coderwall_blue));
      pageIndicator.setFooterColor(Color.WHITE);
      pageIndicator.setFooterIndicatorStyle(IndicatorStyle.Triangle);
      pageIndicator.setFooterLineHeight(0);
    } else pagerAdapter.refreshUser(u);
  }
  public void refreshNavigationListAdapter() {
    List<User> users = new ArrayList<User>();
    File dir = new File(Utils.getAPICacheFolderPath());
    if (dir.exists()) {
      for (String s :
          dir.list(
              new FilenameFilter() {
                @Override
                public boolean accept(File dir, String filename) {
                  return filename.contains(CWManager.FILE_FORMAT);
                }
              })) {
        try {
          users.add(ApiCache.readUserJsonFromCache(s.replace(CWManager.FILE_FORMAT, "")));
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }

    if (listAdapter == null) listAdapter = new ListUserAdapter(getSherlockActivity(), users);
    else listAdapter.refreshItems(users);

    if (u != null) getActionBar().setSelectedNavigationItem(getUserIndex(u.getUsername()));
  }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.action_bar_refresh:
       if (u != null) createTask(u.getUsername(), true).execute();
       break;
     case R.id.action_bar_invite:
       createAlertDialog();
       break;
     case R.id.action_bar_about:
       new AlertDialog.Builder(getSherlockActivity())
           .setTitle("About")
           .setMessage(
               "When life gives you lemons, don't make lemonade. "
                   + "Make life take the lemons back! Get mad! I don't want your damn lemons! "
                   + "What am I supposed to do with these?! Demand to see life's manager! "
                   + "Make life rue the day it thought it could give Cave Johnson lemons! "
                   + "Do you know who I am? I'm the man who's gonna burn your house down! "
                   + "With the lemons! I'm gonna get my engineers to invent a combustible lemon that burns your house down! ")
           .setPositiveButton(
               "Dev profile",
               new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int whichButton) {
                   createTask("florianmski", true).execute();
                 }
               })
           .setNeutralButton(
               "Close",
               new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int whichButton) {}
               })
           .show();
       break;
     case R.id.action_bar_delete:
       new File(Utils.getAPICacheFolderPath() + u.getUsername() + ".html").delete();
       new File(Utils.getAPICacheFolderPath() + u.getUsername() + CWManager.FILE_FORMAT).delete();
       createTask(username, false).execute();
       break;
   }
   return super.onOptionsItemSelected(item);
 }
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    menu.add(Menu.NONE, R.id.action_bar_invite, 0, "Search")
        .setIcon(R.drawable.ic_menu_invite)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    MenuItem refreshItem = menu.add(Menu.NONE, R.id.action_bar_refresh, 1, "Refresh");
    refreshItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    if (refresh) refreshItem.setActionView(flProgress);
    else refreshItem.setIcon(R.drawable.ic_menu_refresh);

    if (username != null && u != null && !username.equals(u.getUsername())) {
      menu.add(Menu.NONE, R.id.action_bar_delete, Menu.NONE, "Delete")
          .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    menu.add(Menu.NONE, R.id.action_bar_about, Menu.NONE, "About")
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
  }