bumptech/glide

API suggestion - RequestOptions

Open

#2 875 ouverte le 5 févr. 2018

Voir sur GitHub
 (2 commentaires) (0 réactions) (0 assignés)Java (6 176 forks)batch import
enhancementhelp wanted

Métriques du dépôt

Stars
 (35 023 stars)
Métriques de merge PR
 (Merge moyen 4j 10h) (11 PRs mergées en 30 j)

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()]));
}

Guide contributeur