mikepenz / MaterialDrawer

The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
https://mikepenz.dev
Apache License 2.0
11.67k stars 2.05k forks source link

AccountHeaderBackground and ProfileDrawerItem icon as URL not working #2257

Closed Zulqurnain closed 6 years ago

Zulqurnain commented 6 years ago

i am trying to load my account header background and header item icon as url but it doesn't work instead it will keep placeholders.

code

private void setUpDrawer() {

        //initialize and create the image loader logic
        DrawerImageLoader.init(new AbstractDrawerImageLoader() {
            @Override
            public void set(ImageView imageView, Uri uri, Drawable placeholder) {
                Glide.with(imageView.getContext())
                        .load(uri)
                        .apply(new RequestOptions().placeholder(placeholder))
                        .into(imageView);
            }

            @Override
            public void cancel(ImageView imageView) {
                Glide.with(imageView.getContext()).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(R.color.primaryColor).sizeDp(56);
                } else if ("customUrlItem".equals(tag)) {
                    return new IconicsDrawable(ctx).iconText(" ").backgroundColorRes(R.color.colorAccent).sizeDp(56);
                }

                //we use the default one for
                //DrawerImageLoader.Tags.PROFILE_DRAWER_ITEM.name()

                return super.placeholder(ctx, tag);
            }

            /*
            @Override
            public Drawable placeholder(Context ctx) {
                return super.placeholder(ctx);
            }

            */
        });

        // Create the AccountHeader
        headerResult = new AccountHeaderBuilder()
                .withActivity(this)
                .withHeaderBackground(new ImageHolder(header_img_url))
                .addProfiles(
                        new ProfileDrawerItem()
                                .withName("Zulqurnain Haider")
                                .withEmail("zulqurnainjutt@gmail.com")
                                .withIcon(my_profile_pic_url)
                )
                .withOnAccountHeaderListener((view, profile, currentProfile) -> false)
                .build();

        //if you want to update the items at a later time it is recommended to keep it in a variable
        PrimaryDrawerItem item1 =
                new PrimaryDrawerItem()
                        .withIdentifier(1)
                        .withName("Something 1");
        SecondaryDrawerItem item2 =
                new SecondaryDrawerItem()
                        .withIdentifier(2)
                        .withName("Something 2");

        //create the drawer and remember the `Drawer` result object
        drawerResult = new DrawerBuilder()
                .withActivity(this)
                .withToolbar(toolbar)
                .withAccountHeader(headerResult)
                .addDrawerItems(
                        item1,
                        new DividerDrawerItem(),
                        item2,
                        new SecondaryDrawerItem().withName("Settings")
                )
                .withOnDrawerItemClickListener((view, position, drawerItem) -> {
                    // do something with the clicked item :D
                    ToastUtils.showShort("item" + drawerItem.toString());
                    return true;
                })
                .build();

        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        drawerResult.getActionBarDrawerToggle().setDrawerIndicatorEnabled(true);

    }

Details

Zulqurnain commented 6 years ago

Apparently i was dumb enough to miss Internet permission, sorry for wasting your time , close this issue