Skip to content

Commit

Permalink
Fixes #3506: Image height remains zero for some time on bad network (#…
Browse files Browse the repository at this point in the history
…3513)

* optimise width loading

* amending as per the reviews

* aspect ratio updates after layout completion

* MediaDetailFragment: update aspect ratio using onGlobalLayoutListener

* remove unnecessary imports
  • Loading branch information
kbhardwaj123 authored Apr 7, 2020
1 parent c53fcb5 commit c82283a
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
Expand All @@ -33,7 +33,6 @@

import org.apache.commons.lang3.StringUtils;
import org.wikipedia.util.DateUtil;
import org.wikipedia.util.StringUtil;

import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -224,7 +223,15 @@ public void onResume() {
.setVisibility(View.GONE);
}
media = detailProvider.getMediaAtPosition(index);
displayMediaDetails();
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
displayMediaDetails();
}
}
);
}

private void displayMediaDetails() {
Expand All @@ -243,7 +250,8 @@ private void displayMediaDetails() {

private void updateAspectRatio(ImageInfo imageInfo) {
if (imageInfo != null) {
int finalHeight = (scrollView.getWidth()*imageInfo.getHeight()) / imageInfo.getWidth();
int screenWidth = scrollView.getWidth();
int finalHeight = (screenWidth*imageInfo.getHeight()) / imageInfo.getWidth();
ViewGroup.LayoutParams params = image.getLayoutParams();
params.height = finalHeight;
image.setLayoutParams(params);
Expand Down

0 comments on commit c82283a

Please # to comment.