Allow to delete media

This commit is contained in:
tom79 2019-09-29 17:41:23 +02:00
parent 22a2e82e9d
commit fe2d1081fd
4 changed files with 53 additions and 5 deletions

View File

@ -182,7 +182,6 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
private ImageView pp_actionBar;
private ProgressBar pp_progress;
private Toast mToast;
private LinearLayout drawer_layout;
private TextView toot_space_left;
private String initialContent;
public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 754;
@ -323,7 +322,6 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
imageSlider.setIndicatorAnimation(IndicatorAnimations.WORM);
imageSlider.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
imageSlider.setSliderAdapter(sliderAdapter);
upload_media = findViewById(R.id.upload_media);
toot_space_left = findViewById(R.id.toot_space_left);
toot_visibility = findViewById(R.id.toot_visibility);
@ -335,7 +333,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
//There is no media the button is hidden
upload_media.setVisibility(View.INVISIBLE);
toot_sensitive = findViewById(R.id.toot_sensitive);
drawer_layout = findViewById(R.id.drawer_layout);
LinearLayout drawer_layout = findViewById(R.id.drawer_layout);
ImageButton toot_emoji = findViewById(R.id.toot_emoji);
isScheduled = false;
@ -815,6 +813,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
if (account.isSensitive()) {
toot_sensitive.setChecked(true);
}
imageSlider.setCurrentPagePosition(imageSlider.getChildCount());
} else {
if (attachments.size() > index && attachment.getDescription() != null) {
attachments.get(index).setDescription(attachment.getDescription());
@ -1906,6 +1905,18 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
}
public void redraw(){
int position = imageSlider.getCurrentPagePosition();
if( position > attachments.size()){
position = attachments.size();
}
sliderAdapter = new SliderAdapter(new WeakReference<>(PixelfedComposeActivity.this), true, attachments);
imageSlider.setIndicatorAnimation(IndicatorAnimations.WORM);
imageSlider.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
imageSlider.setSliderAdapter(sliderAdapter);
imageSlider.setCurrentPagePosition(position);
}
private void restoreServerSchedule(Status status) {
attachments = status.getMedia_attachments();
@ -2082,6 +2093,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
}
@Override
public void onStart() {
super.onStart();

View File

@ -85,6 +85,12 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
viewHolder.textViewDescription.setText(String.format("%s/%s", (position + 1), attachments.size()));
}
if( canDelete){
viewHolder.delete_media.setVisibility(View.VISIBLE);
}else{
viewHolder.delete_media.setVisibility(View.GONE);
}
Glide.with(viewHolder.imageViewBackground.getContext())
.load(attachments.get(position).getPreview_url())
.into(viewHolder.imageViewBackground);
@ -109,6 +115,10 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
showAddDescription(attachments.get(position));
}
});
viewHolder.delete_media.setOnClickListener(view ->{
showRemove(position);
});
}
}
@ -205,6 +215,9 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
public void onClick(DialogInterface dialog, int which) {
attachments.remove(attachments.get(position));
sliderAdapter.notifyDataSetChanged();
if( contextWeakReference.get() instanceof PixelfedComposeActivity){
((PixelfedComposeActivity) contextWeakReference.get()).redraw();
}
dialog.dismiss();
}
});
@ -229,13 +242,14 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
class SliderAdapterVH extends SliderViewAdapter.ViewHolder {
ImageView imageViewBackground;
ImageView imageViewBackground, delete_media;
TextView textViewDescription;
SliderAdapterVH(View itemView) {
super(itemView);
imageViewBackground = itemView.findViewById(R.id.iv_auto_image_slider);
textViewDescription = itemView.findViewById(R.id.tv_auto_image_slider);
delete_media = itemView.findViewById(R.id.delete_media);
}
}
}

View File

@ -0,0 +1,5 @@
<vector android:alpha="0.67" android:height="30dp"
android:tint="#FF0000" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="30dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector>

View File

@ -20,12 +20,28 @@
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/iv_auto_image_slider"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:adjustViewBounds="true" />
<ImageView
android:visibility="gone"
android:id="@+id/delete_media"
android:layout_margin="20dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_delete_media_pixelfed"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:contentDescription="@string/toot_delete_media"
/>
</RelativeLayout>
<ImageView
@ -33,7 +49,8 @@
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="bottom|start"
android:layout_margin="50dp" />
android:layout_marginStart="5dp"
android:layout_marginBottom="50dp" />
<FrameLayout