use of org.edx.mobile.user.ProfileImage in project edx-app-android by edx.
the class AuthorLayoutViewHolder method populateViewHolder.
public void populateViewHolder(@NonNull Config config, @NonNull IAuthorData authorData, @NonNull ProfileImageProvider provider, long initialTimeStampMs, @NonNull final Runnable listener) {
final Context context = profileImageView.getContext();
final ProfileImage profileImage;
{
if (provider.getProfileImage() != null && provider.getProfileImage().hasImage()) {
profileImage = provider.getProfileImage();
} else {
/**
* Background: Currently the POST & PATCH APIs aren't configured to return a user's
* {@link ProfileImage} in their response. Since, the currently logged-in user is
* the only one that can POST using the app, so, we use the locally stored
* {@link ProfileImage} in {@link LoginPrefs} instead.
* Incase of PATCH we just use the image that we got in the initial GET call.
*/
ProfileModel profileModel = loginPrefs.getCurrentUserProfile();
if (profileModel != null && authorData.getAuthor().equals(profileModel.username)) {
profileImage = loginPrefs.getProfileImage();
} else {
profileImage = null;
}
}
if (profileImage != null && profileImage.hasImage()) {
Glide.with(context).load(profileImage.getImageUrlMedium()).into(profileImageView);
} else {
profileImageView.setImageResource(R.drawable.profile_photo_placeholder);
}
}
DiscussionTextUtils.setAuthorText(authorTextView, authorData);
if (authorData.getCreatedAt() != null) {
CharSequence relativeTime = DiscussionTextUtils.getRelativeTimeSpanString(context, initialTimeStampMs, authorData.getCreatedAt().getTime());
dateTextView.setText(relativeTime);
} else {
dateTextView.setVisibility(View.GONE);
}
if (config.isUserProfilesEnabled() && !authorData.isAuthorAnonymous()) {
profileRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.run();
}
});
}
}
use of org.edx.mobile.user.ProfileImage in project edx-app-android by edx.
the class UserProfileInteractorTest method whenProfileImageObserved_withProfileImage_emitsFullImageUrl.
@Test
public void whenProfileImageObserved_withProfileImage_emitsFullImageUrl() {
final Account account = configureBareMockAccount();
final ProfileImage profileImage = account.getProfileImage();
when(profileImage.hasImage()).thenReturn(true);
when(profileImage.getImageUrlFull()).thenReturn(ProfileValues.ABSOLUTE_URL);
createAndObserveInteractor();
verify(imageObserver).onData(refEq(new UserProfileImageViewModel(Uri.parse(ProfileValues.ABSOLUTE_URL), true)));
}
use of org.edx.mobile.user.ProfileImage in project edx-app-android by edx.
the class NavigationFragmentTest method configureMockAccount.
@NonNull
private Account configureMockAccount(String username) {
final ProfileImage profileImage = mock(ProfileImage.class);
when(profileImage.hasImage()).thenReturn(true);
when(profileImage.getImageUrlLarge()).thenReturn("file:///mnt/sdcard/dummy.jpg");
final Account account = mock(Account.class);
when(account.getUsername()).thenReturn(username);
when(account.getProfileImage()).thenReturn(profileImage);
return account;
}
Aggregations