diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/CommentActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/CommentActivity.java index dff66129..88f14992 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/CommentActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/CommentActivity.java @@ -205,7 +205,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA } }; Markwon postBodyMarkwon = MarkdownUtils.createFullRedditMarkwon(this, - miscPlugin, parentTextColor, parentSpoilerBackgroundColor, null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false)); + miscPlugin, parentTextColor, parentSpoilerBackgroundColor, mGlide, null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false)); MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter(); binding.commentContentMarkdownView.setLayoutManager(new LinearLayoutManagerBugFixed(this)); binding.commentContentMarkdownView.setAdapter(markwonAdapter); diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/FullMarkdownActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/FullMarkdownActivity.java index 8a0e99a3..aacc26b8 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/FullMarkdownActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/FullMarkdownActivity.java @@ -18,6 +18,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.RecyclerView; +import com.bumptech.glide.Glide; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; @@ -139,7 +140,7 @@ public class FullMarkdownActivity extends BaseActivity { } }; Markwon markwon = MarkdownUtils.createFullRedditMarkwon(this, - miscPlugin, markdownColor, spoilerBackgroundColor, null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false)); + miscPlugin, markdownColor, spoilerBackgroundColor, Glide.with(getApplication()), null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false)); MarkwonAdapter markwonAdapter = MarkdownUtils.createTablesAdapter(); LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() { diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/InstanceInfoActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/InstanceInfoActivity.java index 03055bd7..d206d5ea 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/InstanceInfoActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/InstanceInfoActivity.java @@ -23,6 +23,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.bumptech.glide.Glide; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.card.MaterialCardView; import com.google.android.material.snackbar.Snackbar; @@ -190,7 +191,7 @@ public class InstanceInfoActivity extends BaseActivity { }; mPostDetailMarkwon = MarkdownUtils.createFullRedditMarkwon(this, - miscPlugin, markdownColor, postSpoilerBackgroundColor, null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false)); + miscPlugin, markdownColor, postSpoilerBackgroundColor, Glide.with(getApplication()), null, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false)); mMarkwonAdapter = MarkdownUtils.createTablesAdapter(); mContentMarkdownView.setAdapter(mMarkwonAdapter); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/WikiActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/WikiActivity.java index d856b7b5..a236bce4 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/WikiActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/WikiActivity.java @@ -176,7 +176,7 @@ public class WikiActivity extends BaseActivity { return true; }; markwon = MarkdownUtils.createFullRedditMarkwon(this, - miscPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false)); + miscPlugin, markdownColor, spoilerBackgroundColor, mGlide, onLinkLongClickListener, mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false)); markwonAdapter = MarkdownUtils.createTablesAdapter(); LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() { diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/CommentsListingRecyclerViewAdapter.java index 125e9e1e..0b1d8e89 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/CommentsListingRecyclerViewAdapter.java @@ -24,6 +24,7 @@ import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; +import com.bumptech.glide.Glide; import com.google.android.material.button.MaterialButton; import java.util.Locale; @@ -170,7 +171,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter() { + mGlide.load(preview.getPreviewUrl()).centerInside().thumbnail(0.1f).downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(new CustomTarget() { @Override public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { int width = resource.getIntrinsicWidth(); @@ -896,7 +896,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter() { + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).thumbnail(0.1f).into(new CustomTarget() { @Override public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { int width = resource.getIntrinsicWidth(); @@ -916,7 +916,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter() { + imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).thumbnail(0.1f).into(new CustomTarget() { @Override public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { int width = resource.getIntrinsicWidth(); diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/PostGalleryTypeImageRecyclerViewAdapter.java b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/PostGalleryTypeImageRecyclerViewAdapter.java index 87a39ca4..fe588884 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/PostGalleryTypeImageRecyclerViewAdapter.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/PostGalleryTypeImageRecyclerViewAdapter.java @@ -18,17 +18,18 @@ import com.bumptech.glide.RequestBuilder; import com.bumptech.glide.RequestManager; import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.engine.GlideException; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.Target; import java.util.ArrayList; -import io.noties.markwon.Markwon; -import jp.wasabeef.glide.transformations.BlurTransformation; import eu.toldi.infinityforlemmy.SaveMemoryCenterInisdeDownsampleStrategy; import eu.toldi.infinityforlemmy.databinding.ItemGalleryImageInPostFeedBinding; import eu.toldi.infinityforlemmy.post.Post; +import io.noties.markwon.Markwon; +import jp.wasabeef.glide.transformations.BlurTransformation; public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapter { private RequestManager glide; @@ -128,7 +129,7 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte return; } - RequestBuilder imageRequestBuilder = glide.load(galleryImages.get(index).url).listener(new RequestListener<>() { + RequestBuilder imageRequestBuilder = glide.load(galleryImages.get(index).url).override(1024).listener(new RequestListener<>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { holder.binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.GONE); @@ -144,10 +145,10 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte } }); if (blurImage) { - imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).thumbnail(0.1f).downsample(DownsampleStrategy.CENTER_INSIDE).override(1024) .into(holder.binding.imageViewItemGalleryImageInPostFeed); } else { - imageRequestBuilder.centerInside().downsample(saveMemoryCenterInisdeDownsampleStrategy).into(holder.binding.imageViewItemGalleryImageInPostFeed); + imageRequestBuilder.centerInside().downsample(saveMemoryCenterInisdeDownsampleStrategy).override(1024).thumbnail(0.1f).downsample(DownsampleStrategy.CENTER_INSIDE).into(holder.binding.imageViewItemGalleryImageInPostFeed); } } diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/RulesRecyclerViewAdapter.java b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/RulesRecyclerViewAdapter.java index d4cfd6b8..0d27a074 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/RulesRecyclerViewAdapter.java @@ -12,6 +12,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; +import com.bumptech.glide.Glide; + import java.util.ArrayList; import butterknife.BindView; @@ -84,7 +86,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); })) diff --git a/app/src/main/kotlin/eu/toldi/infinityforlemmy/markdown/GlideMarkdownLoader.kt b/app/src/main/kotlin/eu/toldi/infinityforlemmy/markdown/GlideMarkdownLoader.kt new file mode 100644 index 00000000..fcac41e7 --- /dev/null +++ b/app/src/main/kotlin/eu/toldi/infinityforlemmy/markdown/GlideMarkdownLoader.kt @@ -0,0 +1,20 @@ +package eu.toldi.infinityforlemmy.markdown + +import android.graphics.drawable.Drawable +import com.bumptech.glide.RequestBuilder +import com.bumptech.glide.RequestManager +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy +import com.bumptech.glide.request.target.Target +import io.noties.markwon.image.AsyncDrawable +import io.noties.markwon.image.glide.GlideImagesPlugin.GlideStore + +class GlideMarkdownLoader(val requestManager: RequestManager) : GlideStore { + override fun load(drawable: AsyncDrawable): RequestBuilder { + return requestManager.load(drawable.destination).override(2048) + .downsample(DownsampleStrategy.CENTER_INSIDE) + } + + override fun cancel(target: Target<*>) { + requestManager.clear(target); + } +} \ No newline at end of file