bumptech/glide

API suggestion - RequestOptions

Open

#2875 aperta il 5 feb 2018

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)Java (6176 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (35.023 star)
Metriche merge PR
 (Merge medio 4g 10h) (11 PR mergiate in 30 g)

Descrizione

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

Guida contributor