Search in sources :

Example 1 with CapabilityBooleanType

use of com.owncloud.android.lib.resources.status.CapabilityBooleanType in project android by nextcloud.

the class DrawerActivity method updateHeaderBackground.

public void updateHeaderBackground() {
    if (getAccount() != null && getStorageManager().getCapability(getAccount().name).getServerBackground() != null) {
        final ViewGroup navigationHeader = (ViewGroup) findNavigationViewChildById(R.id.drawer_header_view);
        if (navigationHeader != null) {
            OCCapability capability = getStorageManager().getCapability(getAccount().name);
            String background = capability.getServerBackground();
            CapabilityBooleanType backgroundDefault = capability.getServerBackgroundDefault();
            CapabilityBooleanType backgroundPlain = capability.getServerBackgroundPlain();
            int primaryColor = ThemeUtils.primaryColor(getAccount());
            if (backgroundDefault.isTrue() && backgroundPlain.isTrue()) {
                // use only solid color
                setNavigationHeaderBackground(new ColorDrawable(primaryColor), navigationHeader);
            } else if (backgroundDefault.isTrue() && backgroundPlain.isFalse()) {
                // use nc13 background image with themed color
                Drawable[] drawables = { new ColorDrawable(primaryColor), getResources().getDrawable(R.drawable.background_nc13) };
                LayerDrawable layerDrawable = new LayerDrawable(drawables);
                setNavigationHeaderBackground(layerDrawable, navigationHeader);
            } else {
                // use url
                if (URLUtil.isValidUrl(background) || background.isEmpty()) {
                    // background image
                    SimpleTarget target = new SimpleTarget<Drawable>() {

                        @Override
                        public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
                            Drawable[] drawables = { new ColorDrawable(primaryColor), resource };
                            LayerDrawable layerDrawable = new LayerDrawable(drawables);
                            setNavigationHeaderBackground(layerDrawable, navigationHeader);
                        }

                        @Override
                        public void onLoadFailed(Exception e, Drawable errorDrawable) {
                            Drawable[] drawables = { new ColorDrawable(primaryColor), errorDrawable };
                            LayerDrawable layerDrawable = new LayerDrawable(drawables);
                            setNavigationHeaderBackground(layerDrawable, navigationHeader);
                        }
                    };
                    int backgroundResource;
                    OwnCloudVersion ownCloudVersion = AccountUtils.getServerVersion(getAccount());
                    if (ownCloudVersion.compareTo(OwnCloudVersion.nextcloud_13) >= 0) {
                        backgroundResource = R.drawable.background_nc13;
                    } else {
                        backgroundResource = R.drawable.background;
                    }
                    Glide.with(this).load(background).centerCrop().placeholder(backgroundResource).error(backgroundResource).crossFade().into(target);
                } else {
                    // plain color
                    setNavigationHeaderBackground(new ColorDrawable(primaryColor), navigationHeader);
                }
            }
        }
    }
}
Also used : OCCapability(com.owncloud.android.lib.resources.status.OCCapability) ViewGroup(android.view.ViewGroup) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) TextDrawable(com.owncloud.android.ui.TextDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) MenuSimpleTarget(com.owncloud.android.utils.svg.MenuSimpleTarget) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) CapabilityBooleanType(com.owncloud.android.lib.resources.status.CapabilityBooleanType) OwnCloudVersion(com.owncloud.android.lib.resources.status.OwnCloudVersion)

Aggregations

ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 LayerDrawable (android.graphics.drawable.LayerDrawable)1 ViewGroup (android.view.ViewGroup)1 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)1 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)1 CapabilityBooleanType (com.owncloud.android.lib.resources.status.CapabilityBooleanType)1 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)1 OwnCloudVersion (com.owncloud.android.lib.resources.status.OwnCloudVersion)1 TextDrawable (com.owncloud.android.ui.TextDrawable)1 MenuSimpleTarget (com.owncloud.android.utils.svg.MenuSimpleTarget)1