Search in sources :

Example 1 with ProfileModel

use of org.edx.mobile.model.api.ProfileModel in project edx-app-android by edx.

the class DbTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    db = DatabaseFactory.getInstance(DatabaseFactory.TYPE_DATABASE_NATIVE, RuntimeEnvironment.application);
    // Our database makes use of the authenticated user's username, so we must mock it.
    final ProfileModel profileModel = new ProfileModel();
    profileModel.username = username;
    loginPrefs.storeUserProfile(profileModel);
}
Also used : ProfileModel(org.edx.mobile.model.api.ProfileModel)

Example 2 with ProfileModel

use of org.edx.mobile.model.api.ProfileModel in project edx-app-android by edx.

the class UserBasedPrefManager method getInstance.

public static final UserBasedPrefManager getInstance(UserPrefType userPrefType) {
    Context context = MainApplication.instance().getApplicationContext();
    ProfileModel profileModel = MainApplication.getEnvironment(MainApplication.instance()).getLoginPrefs().getCurrentUserProfile();
    String prefName = profileModel == null ? userPrefType.name() : profileModel.username + "_" + userPrefType.name();
    return new UserBasedPrefManager(context, prefName);
}
Also used : Context(android.content.Context) ProfileModel(org.edx.mobile.model.api.ProfileModel)

Example 3 with ProfileModel

use of org.edx.mobile.model.api.ProfileModel 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 4 with ProfileModel

use of org.edx.mobile.model.api.ProfileModel in project edx-app-android by edx.

the class UserProfileInteractorTest method setAuthenticatedUsername.

private void setAuthenticatedUsername(@NonNull String username) {
    final ProfileModel profileModel = new ProfileModel();
    profileModel.username = username;
    when(userPrefs.getProfile()).thenReturn(profileModel);
}
Also used : ProfileModel(org.edx.mobile.model.api.ProfileModel)

Example 5 with ProfileModel

use of org.edx.mobile.model.api.ProfileModel in project edx-app-android by edx.

the class UserPrefs method getDownloadDirectory.

/**
 * Returns user storage directory under /Android/data/ folder for the currently logged in user.
 * This is the folder where all video downloads should be kept.
 *
 * @return
 */
@Nullable
public File getDownloadDirectory() {
    final File externalAppDir = FileUtil.getExternalAppDir(context);
    final ProfileModel profile = getProfile();
    if (externalAppDir != null && profile != null) {
        File videosDir = new File(externalAppDir, AppConstants.Directories.VIDEOS);
        File usersVidsDir = new File(videosDir, Sha1Util.SHA1(profile.username));
        usersVidsDir.mkdirs();
        try {
            File noMediaFile = new File(usersVidsDir, ".nomedia");
            noMediaFile.createNewFile();
        } catch (IOException ioException) {
            logger.error(ioException);
        }
        return usersVidsDir;
    }
    return null;
}
Also used : IOException(java.io.IOException) File(java.io.File) ProfileModel(org.edx.mobile.model.api.ProfileModel) Nullable(android.support.annotation.Nullable)

Aggregations

ProfileModel (org.edx.mobile.model.api.ProfileModel)7 Context (android.content.Context)2 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 File (java.io.File)1 IOException (java.io.IOException)1 ProfileImage (org.edx.mobile.user.ProfileImage)1 Test (org.junit.Test)1