Search in sources :

Example 1 with ProfileImage

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();
            }
        });
    }
}
Also used : Context(android.content.Context) ProfileImage(org.edx.mobile.user.ProfileImage) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ProfileModel(org.edx.mobile.model.api.ProfileModel)

Example 2 with ProfileImage

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)));
}
Also used : Account(org.edx.mobile.user.Account) ProfileImage(org.edx.mobile.user.ProfileImage) BaseTest(org.edx.mobile.test.BaseTest) Test(org.junit.Test)

Example 3 with ProfileImage

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;
}
Also used : Account(org.edx.mobile.user.Account) ProfileImage(org.edx.mobile.user.ProfileImage) NonNull(android.support.annotation.NonNull)

Aggregations

ProfileImage (org.edx.mobile.user.ProfileImage)3 Account (org.edx.mobile.user.Account)2 Context (android.content.Context)1 NonNull (android.support.annotation.NonNull)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ProfileModel (org.edx.mobile.model.api.ProfileModel)1 BaseTest (org.edx.mobile.test.BaseTest)1 Test (org.junit.Test)1