bumptech/glide

API suggestion - RequestOptions

Open

#2.875 geöffnet am 5. Feb. 2018

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Java (6.176 Forks)batch import
enhancementhelp wanted

Repository-Metriken

Stars
 (35.023 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 4T 10h) (11 gemergte PRs in 30 T)

Beschreibung

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

Contributor Guide