Esempio n. 1
0
  @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();
  }
Esempio n. 2
0
  @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);
    }
  }