Maybe fix Canvas: drawing too large bitmap again.

This commit is contained in:
Alex Ning 2021-01-18 00:24:52 +08:00
parent 6c3a8c9340
commit c2abe90ba2
3 changed files with 18 additions and 16 deletions

View File

@ -934,8 +934,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
Post.Preview preview = getSuitablePreview(mPost.getPreviews());
if (preview != null) {
if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) {
int height = (int) (400 * mScale);
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.getLayoutParams().height = (int) (400 * mScale);
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.getLayoutParams().height = height;
preview.setPreviewWidth(mImageViewWidth);
preview.setPreviewHeight(height);
} else {
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setRatio((float) preview.getPreviewHeight() / (float) preview.getPreviewWidth());
}
@ -1475,29 +1478,29 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
previewIndex = 0;
}
preview = previews.get(previewIndex);
if (preview.getPreviewWidth() * preview.getPreviewHeight() > 35_000_000) {
if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) {
for (int i = previews.size() - 1; i >= 1; i--) {
preview = previews.get(i);
if (mImageViewWidth >= preview.getPreviewWidth()) {
if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 35_000_000) {
if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 10_000_000) {
return preview;
}
} else {
int height = mImageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight();
if (mImageViewWidth * height <= 35_000_000) {
if (mImageViewWidth * height <= 10_000_000) {
return preview;
}
}
}
}
if (preview.getPreviewWidth() * preview.getPreviewHeight() > 35_000_000) {
if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) {
int divisor = 2;
do {
preview.setPreviewWidth(preview.getPreviewWidth() / divisor);
preview.setPreviewHeight(preview.getPreviewHeight() / divisor);
divisor *= 2;
} while (preview.getPreviewWidth() * preview.getPreviewHeight() / divisor / divisor > 35_000_000);
} while (preview.getPreviewWidth() * preview.getPreviewHeight() / divisor / divisor > 10_000_000);
}
return preview;

View File

@ -696,8 +696,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
if (preview != null) {
((PostWithPreviewTypeViewHolder) holder).imageWrapperRelativeLayout.setVisibility(View.VISIBLE);
if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) {
int height = (int) (400 * mScale);
((PostWithPreviewTypeViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
((PostWithPreviewTypeViewHolder) holder).imageView.getLayoutParams().height = (int) (400 * mScale);
((PostWithPreviewTypeViewHolder) holder).imageView.getLayoutParams().height = height;
preview.setPreviewWidth(mImageViewWidth);
preview.setPreviewHeight(height);
} else {
((PostWithPreviewTypeViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
@ -1047,29 +1050,29 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
previewIndex = 0;
}
preview = previews.get(previewIndex);
if (preview.getPreviewWidth() * preview.getPreviewHeight() > 35_000_000) {
if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) {
for (int i = previews.size() - 1; i >= 1; i--) {
preview = previews.get(i);
if (mImageViewWidth >= preview.getPreviewWidth()) {
if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 35_000_000) {
if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 10_000_000) {
return preview;
}
} else {
int height = mImageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight();
if (mImageViewWidth * height <= 35_000_000) {
if (mImageViewWidth * height <= 10_000_000) {
return preview;
}
}
}
}
if (preview.getPreviewWidth() * preview.getPreviewHeight() > 35_000_000) {
if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) {
int divisor = 2;
do {
preview.setPreviewWidth(preview.getPreviewWidth() / divisor);
preview.setPreviewHeight(preview.getPreviewHeight() / divisor);
divisor *= 2;
} while (preview.getPreviewWidth() * preview.getPreviewHeight() / divisor / divisor > 35_000_000);
} while (preview.getPreviewWidth() * preview.getPreviewHeight() / divisor / divisor > 10_000_000);
}
return preview;

View File

@ -3,7 +3,6 @@ package ml.docilealligator.infinityforreddit.post;
import android.net.Uri;
import android.os.AsyncTask;
import android.text.Html;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
@ -242,9 +241,6 @@ public class ParsePost {
//Video post
JSONObject redditVideoObject = data.getJSONObject(JSONUtils.MEDIA_KEY).getJSONObject(JSONUtils.REDDIT_VIDEO_KEY);
int postType = Post.VIDEO_TYPE;
if (!redditVideoObject.has(JSONUtils.HLS_URL_KEY)) {
Log.i("afasd", "s " + redditVideoObject);
}
String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.HLS_URL_KEY)).toString();
String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY);