Fix issue with image decoder.

Fixed issue where no max width/height would be given to
the image decoder, that resulted in lots of empty imageviews and
OOM errors.

Also add filesize to post info.
captchafix
Florens Douwes 11 years ago
parent 85321008a4
commit e8b5e863df
  1. 4
      Clover/src/org/floens/chan/core/manager/ThreadManager.java
  2. 1
      Clover/src/org/floens/chan/core/model/Post.java
  3. 2
      Clover/src/org/floens/chan/core/net/ChanReaderRequest.java
  4. 41
      Clover/src/org/floens/chan/ui/fragment/ImageViewFragment.java
  5. 24
      Clover/src/org/floens/chan/ui/view/ThumbnailImageView.java
  6. 12
      Clover/src/org/floens/chan/utils/Utils.java

@ -293,8 +293,8 @@ public class ThreadManager implements Loader.LoaderListener {
String text = ""; String text = "";
if (post.hasImage) { if (post.hasImage) {
text += "File: " + post.filename + "." + post.ext + " \nSize: " + post.imageWidth + "x" + post.imageHeight text += "File: " + post.filename + "." + post.ext + " \nDimensions: " + post.imageWidth + "x"
+ "\n\n"; + post.imageHeight + "\nSize: " + Utils.getReadableFileSize(post.fileSize, false) + "\n\n";
} }
text += "Time: " + post.date; text += "Time: " + post.date;

@ -70,6 +70,7 @@ public class Post {
public String email = ""; public String email = "";
public boolean isSavedReply = false; public boolean isSavedReply = false;
public String title = ""; public String title = "";
public int fileSize;
/** /**
* This post replies to the these ids * This post replies to the these ids

@ -271,6 +271,8 @@ public class ChanReaderRequest extends JsonReaderRequest<List<Post>> {
post.imageWidth = reader.nextInt(); post.imageWidth = reader.nextInt();
} else if (key.equals("h")) { } else if (key.equals("h")) {
post.imageHeight = reader.nextInt(); post.imageHeight = reader.nextInt();
} else if (key.equals("fsize")) {
post.fileSize = reader.nextInt();
} else if (key.equals("sub")) { } else if (key.equals("sub")) {
post.subject = reader.nextString(); post.subject = reader.nextString();
} else if (key.equals("replies")) { } else if (key.equals("replies")) {

@ -66,6 +66,7 @@ public class ImageViewFragment extends Fragment implements ThumbnailImageViewCal
imageView = new ThumbnailImageView(context); imageView = new ThumbnailImageView(context);
imageView.setCallback(this); imageView.setCallback(this);
imageView.setLayoutParams(Utils.MATCH_PARAMS);
int padding = (int) context.getResources().getDimension(R.dimen.image_view_padding); int padding = (int) context.getResources().getDimension(R.dimen.image_view_padding);
imageView.setPadding(padding, padding, padding, padding); imageView.setPadding(padding, padding, padding, padding);
@ -85,21 +86,33 @@ public class ImageViewFragment extends Fragment implements ThumbnailImageViewCal
throw new IllegalArgumentException("Post has no image"); throw new IllegalArgumentException("Post has no image");
} }
imageView.setThumbnail(post.thumbnailUrl); // After layout has been done so getWidth & getHeight don't return 0
imageView.post(new Runnable() {
if (post.ext.equals("gif")) { @Override
imageView.setGif(post.imageUrl); public void run() {
} else if (post.ext.equals("webm")) { // When the viewpager is created, it starts loading the first two views,
isVideo = true; // then we set a position to the viewpager and it loads three more views!
activity.invalidateActionBar(); // Check for these unused views here to avoid unnecessary loads
showProgressBar(false); if (imageView.getWidth() == 0 || imageView.getHeight() == 0)
return;
if (ChanPreferences.getVideoAutoPlay()) {
startVideo(); imageView.setThumbnail(post.thumbnailUrl);
if (post.ext.equals("gif")) {
imageView.setGif(post.imageUrl);
} else if (post.ext.equals("webm")) {
isVideo = true;
activity.invalidateActionBar();
showProgressBar(false);
if (ChanPreferences.getVideoAutoPlay()) {
startVideo();
}
} else {
imageView.setBigImage(post.imageUrl);
}
} }
} else { });
imageView.setBigImage(post.imageUrl);
}
} }
} }

@ -23,6 +23,7 @@ import org.floens.chan.ChanApplication;
import org.floens.chan.R; import org.floens.chan.R;
import org.floens.chan.core.net.FileRequest; import org.floens.chan.core.net.FileRequest;
import org.floens.chan.core.net.GIFRequest; import org.floens.chan.core.net.GIFRequest;
import org.floens.chan.utils.Logger;
import org.floens.chan.utils.Utils; import org.floens.chan.utils.Utils;
import uk.co.senab.photoview.PhotoViewAttacher; import uk.co.senab.photoview.PhotoViewAttacher;
@ -44,6 +45,8 @@ import com.android.volley.toolbox.ImageLoader.ImageContainer;
import com.android.volley.toolbox.ImageLoader.ImageListener; import com.android.volley.toolbox.ImageLoader.ImageListener;
public class ThumbnailImageView extends LoadView implements OnViewTapListener, View.OnClickListener { public class ThumbnailImageView extends LoadView implements OnViewTapListener, View.OnClickListener {
private static final String TAG = "ThumbnailImageView";
private ThumbnailImageViewCallback callback; private ThumbnailImageViewCallback callback;
/** /**
@ -82,6 +85,11 @@ public class ThumbnailImageView extends LoadView implements OnViewTapListener, V
} }
public void setThumbnail(String thumbnailUrl) { public void setThumbnail(String thumbnailUrl) {
if (getWidth() == 0 || getHeight() == 0) {
Logger.e(TAG, "getWidth() or getHeight() returned 0, not loading");
return;
}
ChanApplication.getImageLoader().get(thumbnailUrl, new ImageListener() { ChanApplication.getImageLoader().get(thumbnailUrl, new ImageListener() {
@Override @Override
public void onErrorResponse(VolleyError error) { public void onErrorResponse(VolleyError error) {
@ -101,8 +109,17 @@ public class ThumbnailImageView extends LoadView implements OnViewTapListener, V
} }
public void setBigImage(String imageUrl) { public void setBigImage(String imageUrl) {
if (getWidth() == 0 || getHeight() == 0) {
Logger.e(TAG, "getWidth() or getHeight() returned 0, not loading");
return;
}
callback.setProgress(true); callback.setProgress(true);
// 4096 is the max GPU upload size
int maxWidth = Math.min((int) (getWidth() * maxScale), 4096);
int maxHeight = Math.min((int) (getHeight() * maxScale), 4096);
imageContainerRequest = ChanApplication.getImageLoader().get(imageUrl, new ImageListener() { imageContainerRequest = ChanApplication.getImageLoader().get(imageUrl, new ImageListener() {
@Override @Override
public void onErrorResponse(VolleyError error) { public void onErrorResponse(VolleyError error) {
@ -127,10 +144,15 @@ public class ThumbnailImageView extends LoadView implements OnViewTapListener, V
tapDismiss = true; tapDismiss = true;
} }
} }
}, (int) (getWidth() * maxScale), (int) (getHeight() * maxScale)); }, maxWidth, maxHeight);
} }
public void setGif(String gifUrl) { public void setGif(String gifUrl) {
if (getWidth() == 0 || getHeight() == 0) {
Logger.e(TAG, "getWidth() or getHeight() returned 0, not loading");
return;
}
callback.setProgress(true); callback.setProgress(true);
imageRequest = ChanApplication.getVolleyRequestQueue().add( imageRequest = ChanApplication.getVolleyRequestQueue().add(

@ -95,7 +95,8 @@ public class Utils {
dialog.setOnShowListener(new OnShowListener() { dialog.setOnShowListener(new OnShowListener() {
@Override @Override
public void onShow(DialogInterface dialog) { public void onShow(DialogInterface dialog) {
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, 0); imm.showSoftInput(view, 0);
} }
}); });
@ -109,4 +110,13 @@ public class Utils {
Toast.makeText(context, R.string.open_link_failed, Toast.LENGTH_LONG).show(); Toast.makeText(context, R.string.open_link_failed, Toast.LENGTH_LONG).show();
} }
} }
public static String getReadableFileSize(int bytes, boolean si) {
int unit = si ? 1000 : 1024;
if (bytes < unit)
return bytes + " B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
} }

Loading…
Cancel
Save