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);
}
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);
}
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();
}
});
}
}
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);
}
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;
}
Aggregations