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);
}
}
}
}
}
Aggregations