Blur sensitive media for Pixelfed
This commit is contained in:
parent
7a98ce45ac
commit
cc1668c9e7
|
@ -0,0 +1,8 @@
|
|||
Added:
|
||||
- Watermarks for pictures (default: disabled)
|
||||
- Blur sensitive media for Pixelfed
|
||||
- Put messages into drafts when replying to a deleted message
|
||||
|
||||
|
||||
|
||||
|
|
@ -22,9 +22,9 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.text.Html;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
|
@ -111,6 +111,7 @@ import app.fedilab.android.sqlite.StatusCacheDAO;
|
|||
import app.fedilab.android.sqlite.StatusStoredDAO;
|
||||
import app.fedilab.android.sqlite.TempMuteDAO;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
import static app.fedilab.android.activities.BaseMainActivity.mutedAccount;
|
||||
|
@ -393,23 +394,7 @@ public class PixelfedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
.into(holder.pf_pp);
|
||||
|
||||
|
||||
holder.art_media.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(context, SlideMediaActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
intent.putParcelableArrayListExtra("mediaArray", status.getMedia_attachments());
|
||||
b.putInt("position", 1);
|
||||
b.putInt("bgcolor", context.getResources().getColor(R.color.cyanea_primary_dark));
|
||||
intent.putExtras(b);
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
||||
ActivityOptionsCompat options = ActivityOptionsCompat
|
||||
.makeSceneTransitionAnimation((Activity) context, holder.art_media, status.getMedia_attachments().get(0).getUrl());
|
||||
// start the new activity
|
||||
context.startActivity(intent, options.toBundle());
|
||||
} else {
|
||||
// start the new activity
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
int iconColor = prefs.getInt("theme_icons_color", -1);
|
||||
|
@ -547,9 +532,47 @@ public class PixelfedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
|
||||
|
||||
holder.art_media_play.setVisibility(View.GONE);
|
||||
boolean expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false);
|
||||
|
||||
|
||||
holder.art_media.setOnClickListener(v -> {
|
||||
if( expand_media || !status.isSensitive() || status.isAttachmentShown() ) {
|
||||
Intent intent = new Intent(context, SlideMediaActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
intent.putParcelableArrayListExtra("mediaArray", status.getMedia_attachments());
|
||||
b.putInt("position", 1);
|
||||
b.putInt("bgcolor", context.getResources().getColor(R.color.cyanea_primary_dark));
|
||||
intent.putExtras(b);
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
||||
ActivityOptionsCompat options = ActivityOptionsCompat
|
||||
.makeSceneTransitionAnimation((Activity) context, holder.art_media, status.getMedia_attachments().get(0).getUrl());
|
||||
// start the new activity
|
||||
context.startActivity(intent, options.toBundle());
|
||||
} else {
|
||||
// start the new activity
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}else{
|
||||
status.setAttachmentShown(true);
|
||||
notifyItemChanged(i);
|
||||
final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5);
|
||||
if (timeout > 0) {
|
||||
new CountDownTimer((timeout * 1000), 1000) {
|
||||
public void onTick(long millisUntilFinished) {
|
||||
}
|
||||
|
||||
public void onFinish() {
|
||||
status.setAttachmentShown(false);
|
||||
notifyItemChanged(i);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if (status.getMedia_attachments() != null && status.getMedia_attachments().size() > 1) {
|
||||
SliderAdapter sliderAdapter = new SliderAdapter(new WeakReference<>((Activity) context), false, status.getMedia_attachments());
|
||||
SliderAdapter sliderAdapter = new SliderAdapter(new WeakReference<>((Activity) context), false, status);
|
||||
holder.imageSlider.setSliderAdapter(sliderAdapter);
|
||||
holder.imageSlider.setIndicatorAnimation(IndicatorAnimations.WORM);
|
||||
holder.imageSlider.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
|
||||
|
@ -567,11 +590,20 @@ public class PixelfedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
} else {
|
||||
url = status.getMedia_attachments().get(0).getPreview_url();
|
||||
}
|
||||
Glide.with(holder.itemView.getContext())
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.thumbnail(0.1f)
|
||||
.into(holder.art_media);
|
||||
if( expand_media || !status.isSensitive() || status.isAttachmentShown()) {
|
||||
Glide.with(holder.itemView.getContext())
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.thumbnail(0.1f)
|
||||
.into(holder.art_media);
|
||||
}else {
|
||||
Glide.with(holder.itemView.getContext())
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.apply(new RequestOptions().transform(new BlurTransformation(50, 3)))
|
||||
.thumbnail(0.1f)
|
||||
.into(holder.art_media);
|
||||
}
|
||||
}
|
||||
|
||||
holder.pf_likes.setText(context.getResources().getQuantityString(R.plurals.likes, status.getFavourites_count(), status.getFavourites_count()));
|
||||
|
|
|
@ -23,6 +23,7 @@ import android.graphics.drawable.Drawable;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.text.InputFilter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -39,6 +40,7 @@ import androidx.appcompat.app.AlertDialog;
|
|||
import androidx.core.app.ActivityOptionsCompat;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.smarteist.autoimageslider.SliderViewAdapter;
|
||||
|
@ -52,8 +54,10 @@ import app.fedilab.android.activities.SlideMediaActivity;
|
|||
import app.fedilab.android.asynctasks.UpdateDescriptionAttachmentAsyncTask;
|
||||
import app.fedilab.android.client.Entities.Attachment;
|
||||
import app.fedilab.android.client.Entities.Error;
|
||||
import app.fedilab.android.client.Entities.Status;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.interfaces.OnRetrieveAttachmentInterface;
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
|
@ -61,10 +65,12 @@ import static android.content.Context.MODE_PRIVATE;
|
|||
public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapterVH> implements OnRetrieveAttachmentInterface {
|
||||
|
||||
private ArrayList<Attachment> attachments;
|
||||
private Status status;
|
||||
private WeakReference<Activity> contextWeakReference;
|
||||
private boolean canDelete;
|
||||
private SliderAdapter sliderAdapter;
|
||||
|
||||
|
||||
public SliderAdapter(WeakReference<Activity> contextWeakReference, boolean delete, ArrayList<Attachment> attachments) {
|
||||
this.attachments = attachments;
|
||||
this.contextWeakReference = contextWeakReference;
|
||||
|
@ -72,6 +78,14 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
|
|||
this.sliderAdapter = this;
|
||||
}
|
||||
|
||||
public SliderAdapter(WeakReference<Activity> contextWeakReference, boolean delete, Status status) {
|
||||
this.status = status;
|
||||
this.contextWeakReference = contextWeakReference;
|
||||
this.canDelete = delete;
|
||||
this.sliderAdapter = this;
|
||||
this.attachments = status.getMedia_attachments();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SliderAdapterVH onCreateViewHolder(ViewGroup parent) {
|
||||
View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.image_slider_layout_item, parent, false);
|
||||
|
@ -81,6 +95,12 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
|
|||
@Override
|
||||
public void onBindViewHolder(SliderAdapterVH viewHolder, int position) {
|
||||
|
||||
SharedPreferences sharedpreferences = contextWeakReference.get().getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||
boolean isSensitive = false;
|
||||
boolean expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false);
|
||||
if( status != null) {
|
||||
isSensitive = status.isSensitive();
|
||||
}
|
||||
if (attachments.size() > 1) {
|
||||
viewHolder.textViewDescription.setText(String.format("%s/%s", (position + 1), attachments.size()));
|
||||
}
|
||||
|
@ -96,28 +116,55 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
|
|||
} else {
|
||||
url = attachments.get(position).getPreview_url();
|
||||
}
|
||||
Glide.with(viewHolder.imageViewBackground.getContext())
|
||||
.load(url)
|
||||
.thumbnail(0.1f)
|
||||
.into(viewHolder.imageViewBackground);
|
||||
|
||||
if( expand_media || !isSensitive || (status != null && status.isAttachmentShown()) ) {
|
||||
Glide.with(viewHolder.imageViewBackground.getContext())
|
||||
.load(url)
|
||||
.thumbnail(0.1f)
|
||||
.into(viewHolder.imageViewBackground);
|
||||
}else{
|
||||
Glide.with(viewHolder.imageViewBackground.getContext())
|
||||
.load(url)
|
||||
.thumbnail(0.1f)
|
||||
.apply(new RequestOptions().transform(new BlurTransformation(50, 3)))
|
||||
.into(viewHolder.imageViewBackground);
|
||||
}
|
||||
viewHolder.imageViewBackground.setContentDescription(attachments.get(position).getDescription());
|
||||
if (!this.canDelete) {
|
||||
boolean finalIsSensitive = isSensitive;
|
||||
viewHolder.imageViewBackground.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(contextWeakReference.get(), SlideMediaActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
if( status == null || expand_media || !finalIsSensitive || status.isAttachmentShown() ) {
|
||||
Intent intent = new Intent(contextWeakReference.get(), SlideMediaActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
|
||||
intent.putParcelableArrayListExtra("mediaArray", attachments);
|
||||
b.putInt("position", (position + 1));
|
||||
b.putInt("bgcolor", contextWeakReference.get().getResources().getColor(R.color.cyanea_primary_dark));
|
||||
intent.putExtras(b);
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
||||
ActivityOptionsCompat options = ActivityOptionsCompat
|
||||
.makeSceneTransitionAnimation(contextWeakReference.get(), viewHolder.imageViewBackground, attachments.get((position)).getUrl());
|
||||
// start the new activity
|
||||
contextWeakReference.get().startActivity(intent, options.toBundle());
|
||||
} else {
|
||||
// start the new activity
|
||||
contextWeakReference.get().startActivity(intent);
|
||||
intent.putParcelableArrayListExtra("mediaArray", attachments);
|
||||
b.putInt("position", (position + 1));
|
||||
b.putInt("bgcolor", contextWeakReference.get().getResources().getColor(R.color.cyanea_primary_dark));
|
||||
intent.putExtras(b);
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
||||
ActivityOptionsCompat options = ActivityOptionsCompat
|
||||
.makeSceneTransitionAnimation(contextWeakReference.get(), viewHolder.imageViewBackground, attachments.get((position)).getUrl());
|
||||
// start the new activity
|
||||
contextWeakReference.get().startActivity(intent, options.toBundle());
|
||||
} else {
|
||||
// start the new activity
|
||||
contextWeakReference.get().startActivity(intent);
|
||||
}
|
||||
}else{
|
||||
status.setAttachmentShown(true);
|
||||
notifyDataSetChanged();
|
||||
final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5);
|
||||
if (timeout > 0) {
|
||||
new CountDownTimer((timeout * 1000), 1000) {
|
||||
public void onTick(long millisUntilFinished) {
|
||||
}
|
||||
|
||||
public void onFinish() {
|
||||
status.setAttachmentShown(false);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue