zsmb13/MaterialDrawerKt

Loading URL for AccountHeaderBackground

travmichwill opened this issue · 2 comments

Hello,

I am looking for guidance and best practice in regards to using a URL based image as the Account Header Background photo.

Ultimate Goal: User will be able to update their profile photo AND the header background photo.

I am using Picasso as my image handling library, and was successful with the profile photo since it has the "iconURL" parameter.

I was hoping there would be a "backgroundURL" paramenter, but only found "background" and "backgroundDrawable" in the source.

The best method I have so far is as follows:

  1. Copy the existing header layout file, and reference the the new customViewRes in the header
    Example:
accountHeader {
                customViewRes = R.layout.header
                background = R.drawable.header

                selectionListEnabledForSingleProfile = false

                profile(userName, userEmail) {
                    iconUrl = profileURL
                }
            }
  1. Using picasso, set the target as the easily accessible ImageView called "material_drawer_account_header_background"
    The ImageView Reference above is thanks to Kotlin Extensions
Picasso.with(this@HomeActivity).load(headerURL).into(material_drawer_account_header_background)

My problem with this method is that I cannot reference the "material_drawer_account_header_background" imageview until the entire activity has loaded. Meaning that even after the drawer is built, the header layout seems to be null. The above Picasso code seems to only find the ImageView if I assign it to a button. With that said, I have also attempted to run the Picasso code in onResume to the same result.

Any advice and guidance would be appreciated!

Hey,

This is a question for the base library, and it seems to have been asked previously, for example, here. You should be able to easily translate the solution there to Kotlin. This issue is a bit old though, so if the solution doesn't work now, you should open a new issue for your problem on the base library's page.

Hope this helps you, let me know if you've managed to solve your problem!

Thank you for the quick response! I was able to fix the problem after reading the article you referenced.

Here was my solution:

Picasso.with(this@HomeActivity).load(headerURL).into(navDrawer.header.material_drawer_account_header_background)

That is using the default Header Layout resource, I just had to reference the ImageView through the Drawer Object!

Thanks again!