-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
There was a problem hiding this 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.
/** | ||
* 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(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done
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. |
There was a problem hiding this 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
Fixed the bug by setting a default profile picture from the web to be set for any users that did not choose one.