private void setupDrawer() { View headerLayout = mNavigationView.getHeaderView(0); TextView userName = (TextView) headerLayout.findViewById(R.id.user_name_txt); TextView userEmail = (TextView) headerLayout.findViewById(R.id.user_email_txt); userName.setText(mDataManager.getPreferencesManager().getUserName()); userEmail.setText(mDataManager.getPreferencesManager().getEmail()); setRoundedAvatar(); mNavigationView.setNavigationItemSelectedListener( new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.team_menu: mNavigationDrawer.closeDrawer(GravityCompat.START); break; case R.id.user_profile_menu: Intent profileIntent = new Intent(UserListActivity.this, MainActivity.class); startActivity(profileIntent); mNavigationDrawer.closeDrawer(GravityCompat.START); break; case R.id.exit_menu: mDataManager.getPreferencesManager().saveAuthToken(""); Intent exitIntent = new Intent(UserListActivity.this, AuthActivity.class); startActivity(exitIntent); } return true; } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user_list); ButterKnife.bind(this); mConnector = new ChronosConnector(); mConnector.onCreate(this, savedInstanceState); mDataManager = DataManager.getInstance(); setupToolbar(); setupDrawer(); loadUsersFromDb(); }
@Override public void onBindViewHolder(final UserViewHolder holder, int position) { final User user = mUsers.get(position); final String userPhoto; if (user.getPhoto().isEmpty()) { userPhoto = "null"; Log.e(TAG, "onBindViewHolder: user with name " + user.getFullName() + " has empty name"); } else { userPhoto = user.getPhoto(); } try { DataManager.getInstance() .getPicasso() .load(userPhoto) .error(holder.mDummy) .placeholder(holder.mDummy) .fit() .centerCrop() .networkPolicy(NetworkPolicy.OFFLINE) .into( holder.mUserPhoto, new Callback() { @Override public void onSuccess() { Log.d(TAG, "load from cache"); } @Override public void onError() { DataManager.getInstance() .getPicasso() .load(userPhoto) .error(holder.mDummy) .placeholder(holder.mDummy) .fit() .centerCrop() .into( holder.mUserPhoto, new Callback() { @Override public void onSuccess() { Log.d(TAG, "load from cache"); } @Override public void onError() { Log.d(TAG, "Could not fetch image"); } }); } }); } catch (IllegalArgumentException e) { e.printStackTrace(); } holder.mFullName.setText(user.getFullName()); holder.mRating.setText(String.valueOf(user.getRating())); holder.mCodeLines.setText(String.valueOf(user.getCodeLines())); holder.mProjects.setText(String.valueOf(user.getProjects())); if (user.getBio() == null || user.getBio().isEmpty()) { holder.mBio.setVisibility(View.GONE); } else { holder.mBio.setText(user.getBio()); holder.mBio.setVisibility(View.VISIBLE); } }