aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2018-08-30 13:18:21 +0000
committerAlex Ning <chineseperson5@gmail.com>2018-08-30 13:18:21 +0000
commit6637cefc051d44802f54e741ca2492cbd36ac405 (patch)
treed0d106c5a3a386782e340be768b12dd70d7549e7 /app/src/main/java/ml
parent4364e20e36aba6de96d25b237cac7c178a5e1980 (diff)
downloadinfinity-for-reddit-6637cefc051d44802f54e741ca2492cbd36ac405.tar
infinity-for-reddit-6637cefc051d44802f54e741ca2492cbd36ac405.tar.gz
infinity-for-reddit-6637cefc051d44802f54e741ca2492cbd36ac405.tar.bz2
infinity-for-reddit-6637cefc051d44802f54e741ca2492cbd36ac405.tar.lz
infinity-for-reddit-6637cefc051d44802f54e741ca2492cbd36ac405.tar.xz
infinity-for-reddit-6637cefc051d44802f54e741ca2492cbd36ac405.tar.zst
infinity-for-reddit-6637cefc051d44802f54e741ca2492cbd36ac405.zip
Blur the preview image if the post is NSFW. Tweak some layouts. Optimize some methods.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java87
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java95
2 files changed, 60 insertions, 122 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
index ac7a09b4..f2e5d200 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
@@ -24,15 +24,18 @@ import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
+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.request.RequestListener;
+import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import java.util.ArrayList;
import de.hdodenhof.circleimageview.CircleImageView;
+import jp.wasabeef.glide.transformations.BlurTransformation;
/**
* Created by alex on 2/25/18.
@@ -171,6 +174,27 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
((DataViewHolder) holder).relativeLayout.setVisibility(View.VISIBLE);
((DataViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
((DataViewHolder) holder).imageView.setVisibility(View.VISIBLE);
+
+ String previewUrl = mPostData.get(position).getPreviewUrl();
+ RequestBuilder imageRequestBuilder = glide.load(previewUrl).listener(new RequestListener<Drawable>() {
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+ return false;
+ }
+
+ @Override
+ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+ ((DataViewHolder) holder).progressBar.setVisibility(View.GONE);
+ return false;
+ }
+ });
+
+ if(mPostData.get(position).isNSFW()) {
+ imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3)))
+ .into(((DataViewHolder) holder).imageView);
+ } else {
+ imageRequestBuilder.into(((DataViewHolder) holder).imageView);
+ }
}
if(mPostData.get(position).isStickied()) {
@@ -181,20 +205,8 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
switch (mPostData.get(position).getPostType()) {
case PostData.IMAGE_TYPE:
((DataViewHolder) holder).typeTextView.setText("IMAGE");
- final String previewImageUrl = mPostData.get(position).getPreviewUrl();
- final String imageUrl = mPostData.get(position).getUrl();
- glide.load(previewImageUrl).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- return false;
- }
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- ((DataViewHolder) holder).progressBar.setVisibility(View.GONE);
- return false;
- }
- }).into(((DataViewHolder) holder).imageView);
+ final String imageUrl = mPostData.get(position).getUrl();
((DataViewHolder) holder).imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -209,20 +221,7 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
break;
case PostData.LINK_TYPE:
((DataViewHolder) holder).typeTextView.setText("LINK");
- String linkPreviewUrl = mPostData.get(position).getPreviewUrl();
- glide.load(linkPreviewUrl).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- return false;
- }
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- ((DataViewHolder) holder).progressBar.setVisibility(View.GONE);
- return false;
- }
- }).into(((DataViewHolder) holder).imageView);
- final String linkUrl = mPostData.get(position).getUrl();
((DataViewHolder) holder).imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -231,29 +230,14 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
builder.addDefaultShareMenuItem();
builder.setToolbarColor(mContext.getResources().getColor(R.color.colorPrimary));
CustomTabsIntent customTabsIntent = builder.build();
- customTabsIntent.launchUrl(mContext, Uri.parse(linkUrl));
+ customTabsIntent.launchUrl(mContext, Uri.parse(mPostData.get(position).getUrl()));
}
});
break;
case PostData.GIF_VIDEO_TYPE:
((DataViewHolder) holder).typeTextView.setText("GIF");
- String gifVideoPreviewUrl = mPostData.get(position).getPreviewUrl();
- glide.load(gifVideoPreviewUrl).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- return false;
- }
-
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- ((DataViewHolder) holder).progressBar.setVisibility(View.GONE);
- return false;
- }
- }).into(((DataViewHolder) holder).imageView);
-
- String gifVideoUrl = mPostData.get(position).getVideoUrl();
- final Uri gifVideoUri = Uri.parse(gifVideoUrl);
+ final Uri gifVideoUri = Uri.parse(mPostData.get(position).getVideoUrl());
((DataViewHolder) holder).imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -273,23 +257,8 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
break;
case PostData.VIDEO_TYPE:
((DataViewHolder) holder).typeTextView.setText("VIDEO");
- String videoPreviewUrl = mPostData.get(position).getPreviewUrl();
- glide.load(videoPreviewUrl).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- return false;
- }
-
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- ((DataViewHolder) holder).progressBar.setVisibility(View.GONE);
- return false;
- }
- }).into(((DataViewHolder) holder).imageView);
-
- String videoUrl = mPostData.get(position).getVideoUrl();
- final Uri videoUri = Uri.parse(videoUrl);
+ final Uri videoUri = Uri.parse(mPostData.get(position).getVideoUrl());
((DataViewHolder) holder).imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index 10591902..f922a0d6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -25,9 +25,11 @@ import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
+import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
+import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import org.sufficientlysecure.htmltextview.HtmlTextView;
@@ -35,6 +37,7 @@ import org.sufficientlysecure.htmltextview.HtmlTextView;
import java.util.ArrayList;
import de.hdodenhof.circleimageview.CircleImageView;
+import jp.wasabeef.glide.transformations.BlurTransformation;
public class ViewPostDetailActivity extends AppCompatActivity {
@@ -132,6 +135,32 @@ public class ViewPostDetailActivity extends AppCompatActivity {
break;
}
+ if(mPostData.getPostType() != PostData.TEXT_TYPE && mPostData.getPostType() != PostData.NO_PREVIEW_LINK_TYPE) {
+ relativeLayout.setVisibility(View.VISIBLE);
+ imageView.setVisibility(View.VISIBLE);
+
+ RequestBuilder imageRequestBuilder = Glide.with(this).load(mPostData.getPreviewUrl()).listener(new RequestListener<Drawable>() {
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+ //Need to be implemented
+ return false;
+ }
+
+ @Override
+ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+ progressBar.setVisibility(View.GONE);
+ return false;
+ }
+ });
+
+ if(mPostData.isNSFW()) {
+ imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 3)))
+ .into(imageView);
+ } else {
+ imageRequestBuilder.into(imageView);
+ }
+ }
+
mRecyclerView.setNestedScrollingEnabled(false);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
@@ -166,20 +195,6 @@ public class ViewPostDetailActivity extends AppCompatActivity {
switch (mPostData.getPostType()) {
case PostData.IMAGE_TYPE:
typeTextView.setText("IMAGE");
- relativeLayout.setVisibility(View.VISIBLE);
- Glide.with(this).load(mPostData.getPreviewUrl()).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- //Need to be implemented
- return false;
- }
-
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- progressBar.setVisibility(View.GONE);
- return false;
- }
- }).into(imageView);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -193,26 +208,12 @@ public class ViewPostDetailActivity extends AppCompatActivity {
});
break;
case PostData.LINK_TYPE:
- relativeLayout.setVisibility(View.VISIBLE);
typeTextView.setText("LINK");
if(!mPostData.getSelfText().equals("")) {
contentTextView.setVisibility(View.VISIBLE);
contentTextView.setHtml(mPostData.getSelfText());
}
- String linkPreviewUrl = mPostData.getPreviewUrl();
- Glide.with(this).load(linkPreviewUrl).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- return false;
- }
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- progressBar.setVisibility(View.GONE);
- return false;
- }
- }).into(imageView);
- final String linkUrl = mPostData.getUrl();
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -221,30 +222,14 @@ public class ViewPostDetailActivity extends AppCompatActivity {
builder.addDefaultShareMenuItem();
builder.setToolbarColor(getResources().getColor(R.color.colorPrimary));
CustomTabsIntent customTabsIntent = builder.build();
- customTabsIntent.launchUrl(ViewPostDetailActivity.this, Uri.parse(linkUrl));
+ customTabsIntent.launchUrl(ViewPostDetailActivity.this, Uri.parse(mPostData.getUrl()));
}
});
break;
case PostData.GIF_VIDEO_TYPE:
- relativeLayout.setVisibility(View.VISIBLE);
typeTextView.setText("VIDEO");
- String gifVideoPreviewUrl = mPostData.getPreviewUrl();
- Glide.with(this).load(gifVideoPreviewUrl).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- return false;
- }
-
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- progressBar.setVisibility(View.GONE);
- return false;
- }
- }).into(imageView);
-
- String gifVideoUrl = mPostData.getVideoUrl();
- final Uri gifVideoUri = Uri.parse(gifVideoUrl);
+ final Uri gifVideoUri = Uri.parse(mPostData.getVideoUrl());
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -263,25 +248,9 @@ public class ViewPostDetailActivity extends AppCompatActivity {
});
break;
case PostData.VIDEO_TYPE:
- relativeLayout.setVisibility(View.VISIBLE);
typeTextView.setText("VIDEO");
- String videoPreviewUrl = mPostData.getPreviewUrl();
- Glide.with(this).load(videoPreviewUrl).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- return false;
- }
-
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- progressBar.setVisibility(View.GONE);
- return false;
- }
- }).into(imageView);
-
- String videoUrl = mPostData.getVideoUrl();
- final Uri videoUri = Uri.parse(videoUrl);
+ final Uri videoUri = Uri.parse(mPostData.getVideoUrl());
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {