Skip to content

Fixes #3506: Image height remains zero for some time on bad network #3513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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