bumptech/glide

API suggestion - RequestOptions

Open

#2.875 aberto em 5 de fev. de 2018

Ver no GitHub
 (2 comments) (0 reactions) (0 assignees)Java (6.176 forks)batch import
enhancementhelp wanted

Métricas do repositório

Stars
 (35.023 stars)
Métricas de merge de PR
 (Mesclagem média 4d 10h) (11 fundiu PRs em 30d)

Description

Glide Version: 4.5

Integration libraries: -

Device/Android Version: LL

Issue details / Repro steps / Use case background:

Current RequestOptions differentiate between one and multiple transformations. Why? I see that internally the transformations are handled by a MultiTransformation if multiple transformations are used, but this could be totally hidden from the user I think. Additional, currently a unnecessary MultiTransformation object is created if only one transformation is passed to the transforms function

Suggestion

Why not change the API to look like following (combine transform and transforms):

public RequestOptions transform(@NonNull Transformation<Bitmap>... transformations) {
	if (transformations.lengh > 1) {
		return transform(new MultiTransformation<>(transformations), /*isRequired=*/ true);
	} else if (transformations.lengh == 1) {
		return transform(transformation, /*isRequired=*/ true);
	} else {
		return this;
	}
}

Usage before

This way as a user using an array (potentially empty) I could change following:

RequestOptions ro = new RequestOptions();
if (transformations != null && transformations.size() > 0) {
	if (transformations .size() == 1) {
		ro = ro.transform(transformations .get(0));
	} else {
		ro = ro.transforms(transformations .toArray(new Transformation[transformations .size()]));
	}
}

Usage after

RequestOptions ro = new RequestOptions();
if (transformations != null) {
	ro = ro.transform(transformations .toArray(new Transformation[transformations .size()]));
}

Guia do colaborador