2020-08-24 15:05:54 +00:00
|
|
|
package awais.instagrabber.customviews.helpers;
|
|
|
|
|
|
|
|
import android.graphics.drawable.Animatable;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
import com.facebook.drawee.controller.BaseControllerListener;
|
|
|
|
import com.facebook.drawee.generic.GenericDraweeHierarchy;
|
|
|
|
import com.facebook.drawee.view.DraweeView;
|
|
|
|
import com.facebook.imagepipeline.image.ImageInfo;
|
|
|
|
|
2020-09-10 11:44:25 +00:00
|
|
|
import awais.instagrabber.utils.NumberUtils;
|
2020-08-24 15:05:54 +00:00
|
|
|
|
|
|
|
public class ImageResizingControllerListener<T extends DraweeView<GenericDraweeHierarchy>> extends BaseControllerListener<ImageInfo> {
|
|
|
|
private static final String TAG = "ImageResizingController";
|
|
|
|
|
|
|
|
private T imageView;
|
|
|
|
private final int requiredWidth;
|
|
|
|
|
|
|
|
public ImageResizingControllerListener(final T imageView, final int requiredWidth) {
|
|
|
|
this.imageView = imageView;
|
|
|
|
this.requiredWidth = requiredWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onIntermediateImageSet(final String id, final ImageInfo imageInfo) {
|
|
|
|
super.onIntermediateImageSet(id, imageInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
|
|
|
|
if (imageInfo != null) {
|
|
|
|
// updateViewSize(imageInfo);
|
|
|
|
final int height = imageInfo.getHeight();
|
|
|
|
final int width = imageInfo.getWidth();
|
|
|
|
// final float aspectRatio = ((float) width) / height;
|
|
|
|
final ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
|
|
|
|
// final int deviceWidth = Utils.displayMetrics.widthPixels;
|
2020-09-10 11:44:25 +00:00
|
|
|
final int resultingHeight = NumberUtils.getResultingHeight(requiredWidth, height, width);
|
2020-08-24 15:05:54 +00:00
|
|
|
layoutParams.width = requiredWidth;
|
|
|
|
layoutParams.height = resultingHeight;
|
|
|
|
imageView.requestLayout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|