Skip to content
This repository has been archived by the owner on Feb 1, 2025. It is now read-only.

Profile fetching bug #118

Merged
merged 5 commits into from
Mar 31, 2023
Merged

Profile fetching bug #118

merged 5 commits into from
Mar 31, 2023

Conversation

PH-14
Copy link
Contributor

@PH-14 PH-14 commented Mar 31, 2023

Fixed the bug by setting a default profile picture from the web to be set for any users that did not choose one.

Copy link
Contributor

@sgueissa sgueissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it is great, I would just like if you could also change the default picture shown on the profile creation page to be the same as you are using.

Comment on lines +137 to +175
/**
* Adds the default profile image to the user
* @param username: the user's username
*/
private void addDefaultProfilePic(String username) {
// we need to create a new thread to download the default profile pic, otherwise it will make the app lag
new Thread(() -> {
try {
// the url of the default profile picture
URL url = new URL(getString(R.string.default_profile_pic));

// connect via html to download
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(input);

// store the file as a temporary image in the cache
File cacheDir = requireContext().getCacheDir();
File imageFile = File.createTempFile("profile_pic", ".jpg", cacheDir);
FileOutputStream outputStream = new FileOutputStream(imageFile);

// get the bitmap out of it, and convert to uri
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
outputStream.close();
Uri uri = Uri.fromFile(imageFile);

// we can now store it in the database, and then switch to main activity
Database.setProfilePic(username, uri).addOnCompleteListener(v -> {
switchToMainActivity(username);
makeToast(getString(R.string.profile_creation_success));
});;
} catch (IOException e) {
throw new RuntimeException("Failed to download and save the default profile pic", e);
}
}).start();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done

@codeclimate
Copy link

codeclimate bot commented Mar 31, 2023

Code Climate has analyzed commit 25cdc5b and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 0.0% (70% is the threshold).

This pull request will bring the total coverage in the repository to 76.9% (-2.2% change).

View more on Code Climate.

Copy link
Contributor

@sgueissa sgueissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took too much time to try to change the picture and it is not an important detail

@sgueissa sgueissa merged commit d65d41d into main Mar 31, 2023
@sgueissa sgueissa deleted the profile_fetching_bug branch March 31, 2023 14:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants