Skip to content

Commit

Permalink
added default profile image
Browse files Browse the repository at this point in the history
  • Loading branch information
rrhzhang committed Apr 21, 2024
1 parent ae39dfe commit 279fa72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.spotify.sdk.android.auth.AuthorizationRequest;
import com.spotify.sdk.android.auth.AuthorizationResponse;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -182,19 +183,30 @@ public void updateProfileViews(String jsonData) {
JSONObject jsonObject = new JSONObject(jsonData);
String displayName = jsonObject.getString("display_name");
int followersCount = jsonObject.getJSONObject("followers").getInt("total");
String profileImageUrl = jsonObject.getJSONArray("images").getJSONObject(0).getString("url");
String profileImageUrl = null;

JSONArray imagesArray = jsonObject.getJSONArray("images");
if (imagesArray.length() > 0) {
profileImageUrl = imagesArray.getJSONObject(0).getString("url");
}

TextView displayNameTextView = findViewById(R.id.display_name_text);
TextView followersTextView = findViewById(R.id.followers_text);
ImageView profileImageView = findViewById(R.id.profile_image_view);

displayNameTextView.setText(displayName);
followersTextView.setText(followersCount + " Followers");
Glide.with(this).load(profileImageUrl).into(profileImageView); // Make sure you have Glide added to your project

if (profileImageUrl != null) {
Glide.with(this).load(profileImageUrl).into(profileImageView);
} else {
Glide.with(this).load(R.drawable.default_profile).into(profileImageView);
}
} catch (JSONException e) {
Toast.makeText(this, "Failed to parse user data", Toast.LENGTH_LONG).show();
}
}



}
Binary file added app/src/main/res/drawable/default_profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 279fa72

Please sign in to comment.