I can't add the image from firebase to the navigation drawer I'm getting the url of the image after the navigation drawer has been created because of the async method of getting url from firebase the method to get the url is called after the navigation drawer has been created hence can't update it.
I'm getting the url of the image after the navigation drawer has been created because of the async method of getting url from firebase the method to get the url is called after the navigation drawer has been created hence can't update it. I have tried to create a class and method that does that but then they are called after the onCreate method has executed of which thats where im trying to get the image url
if (profileImageUrlRef != null)
{
profileImageUrlRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri)
{
urlImage=uri.toString();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
}
DrawerImageLoader.init(new AbstractDrawerImageLoader() {
@Override
public void set(ImageView imageView, Uri uri, Drawable placeholder, String tag) {
Glide.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
}
@Override
public void cancel(ImageView imageView) {
Glide.with(Client_Services.this).clear(imageView);
}
@Override
public Drawable placeholder(Context ctx, String tag) {
//define different placeholders for different imageView targets
//default tags are accessible via the DrawerImageLoader.Tags
//custom ones can be checked via string. see the CustomUrlBasePrimaryDrawerItem LINE 111
if (DrawerImageLoader.Tags.PROFILE.name().equals(tag)) {
return DrawerUIUtils.getPlaceHolder(ctx);
} else if (DrawerImageLoader.Tags.ACCOUNT_HEADER.name().equals(tag)) {
return new IconicsDrawable(ctx).iconText(" ").backgroundColorRes(com.mikepenz.materialdrawer.R.color.primary).sizeDp(56);
} else if ("customUrlItem".equals(tag)) {
return new IconicsDrawable(ctx).iconText(" ").backgroundColorRes(R.color.md_red_500).sizeDp(56);
}
//we use the default one for
//DrawerImageLoader.Tags.PROFILE_DRAWER_ITEM.name()
return super.placeholder(ctx, tag);
}
});
final AccountHeader headerResult = new AccountHeaderBuilder()
.withActivity(this)
.withHeaderBackground(R.drawable.background)
.addProfiles(
new ProfileDrawerItem().withName("Ceo AtRalk").withEmail("[email protected]").withIcon(urlImage)
)
.withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
@Override
public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
return false;
}
})
.build();
Im expecting the urlImage variable to be populated with the url when its passed to withIcon method
I've once wrote an
AsyncTaskwhich caches the profile image to SD card:Usage example:
This is the callback
interface, which sets the image when the task is done:And it's implementation: