Browse Source

Added option to delete attachments

main
M66B 6 years ago
parent
commit
badbd134f5
5 changed files with 43 additions and 6 deletions
  1. +28
    -2
      app/src/main/java/eu/faircode/email/AdapterAttachment.java
  2. +3
    -0
      app/src/main/java/eu/faircode/email/DaoAttachment.java
  3. +1
    -1
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  4. +1
    -1
      app/src/main/java/eu/faircode/email/FragmentMessage.java
  5. +10
    -2
      app/src/main/res/layout/item_attachment.xml

+ 28
- 2
app/src/main/java/eu/faircode/email/AdapterAttachment.java View File

@ -51,6 +51,7 @@ import androidx.recyclerview.widget.RecyclerView;
public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.ViewHolder> { public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.ViewHolder> {
private Context context; private Context context;
private LifecycleOwner owner; private LifecycleOwner owner;
private boolean readonly;
private boolean debug; private boolean debug;
private List<EntityAttachment> all = new ArrayList<>(); private List<EntityAttachment> all = new ArrayList<>();
@ -58,6 +59,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
View itemView; View itemView;
ImageView ivDelete;
TextView tvName; TextView tvName;
TextView tvSize; TextView tvSize;
ImageView ivStatus; ImageView ivStatus;
@ -69,6 +71,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
super(itemView); super(itemView);
this.itemView = itemView; this.itemView = itemView;
ivDelete = itemView.findViewById(R.id.ivDelete);
tvName = itemView.findViewById(R.id.tvName); tvName = itemView.findViewById(R.id.tvName);
tvSize = itemView.findViewById(R.id.tvSize); tvSize = itemView.findViewById(R.id.tvSize);
ivStatus = itemView.findViewById(R.id.ivStatus); ivStatus = itemView.findViewById(R.id.ivStatus);
@ -79,10 +82,12 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
private void wire() { private void wire() {
itemView.setOnClickListener(this); itemView.setOnClickListener(this);
ivDelete.setOnClickListener(this);
} }
private void unwire() { private void unwire() {
itemView.setOnClickListener(null); itemView.setOnClickListener(null);
ivDelete.setOnClickListener(null);
} }
private void bindTo(EntityAttachment attachment) { private void bindTo(EntityAttachment attachment) {
@ -103,6 +108,8 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
ivStatus.setVisibility(View.VISIBLE); ivStatus.setVisibility(View.VISIBLE);
} }
ivDelete.setVisibility(readonly ? View.INVISIBLE : View.VISIBLE);
if (attachment.progress != null) if (attachment.progress != null)
progressbar.setProgress(attachment.progress); progressbar.setProgress(attachment.progress);
progressbar.setVisibility( progressbar.setVisibility(
@ -120,7 +127,24 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
if (pos == RecyclerView.NO_POSITION) if (pos == RecyclerView.NO_POSITION)
return; return;
final EntityAttachment attachment = filtered.get(pos); final EntityAttachment attachment = filtered.get(pos);
if (attachment != null)
if (view.getId() == R.id.ivDelete) {
Bundle args = new Bundle();
args.putLong("id", attachment.id);
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) {
DB.getInstance(context).attachment().deleteAttachment(attachment.id);
File dir = new File(context.getFilesDir(), "attachments");
File file = new File(dir, attachment.filename);
file.delete();
return null;
}
}.load(context, owner, args);
} else {
if (attachment.filename == null) { if (attachment.filename == null) {
if (attachment.progress == null) { if (attachment.progress == null) {
Bundle args = new Bundle(); Bundle args = new Bundle();
@ -183,12 +207,14 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
context.startActivity(intent); context.startActivity(intent);
} }
}
} }
} }
AdapterAttachment(Context context, LifecycleOwner owner) {
AdapterAttachment(Context context, LifecycleOwner owner, boolean readonly) {
this.context = context; this.context = context;
this.owner = owner; this.owner = owner;
this.readonly = readonly;
this.debug = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("debug", false); this.debug = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("debug", false);
setHasStableIds(true); setHasStableIds(true);
} }


+ 3
- 0
app/src/main/java/eu/faircode/email/DaoAttachment.java View File

@ -57,4 +57,7 @@ public interface DaoAttachment {
@Update @Update
void updateAttachment(EntityAttachment attachment); void updateAttachment(EntityAttachment attachment);
@Query("DELETE FROM attachment WHERE id = :id")
int deleteAttachment(long id);
} }

+ 1
- 1
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -247,7 +247,7 @@ public class FragmentCompose extends FragmentEx {
LinearLayoutManager llm = new LinearLayoutManager(getContext()); LinearLayoutManager llm = new LinearLayoutManager(getContext());
rvAttachment.setLayoutManager(llm); rvAttachment.setLayoutManager(llm);
adapter = new AdapterAttachment(getContext(), getViewLifecycleOwner());
adapter = new AdapterAttachment(getContext(), getViewLifecycleOwner(), false);
rvAttachment.setAdapter(adapter); rvAttachment.setAdapter(adapter);
return view; return view;


+ 1
- 1
app/src/main/java/eu/faircode/email/FragmentMessage.java View File

@ -227,7 +227,7 @@ public class FragmentMessage extends FragmentEx {
LinearLayoutManager llm = new LinearLayoutManager(getContext()); LinearLayoutManager llm = new LinearLayoutManager(getContext());
rvAttachment.setLayoutManager(llm); rvAttachment.setLayoutManager(llm);
adapter = new AdapterAttachment(getContext(), getViewLifecycleOwner());
adapter = new AdapterAttachment(getContext(), getViewLifecycleOwner(), true);
rvAttachment.setAdapter(adapter); rvAttachment.setAdapter(adapter);
return view; return view;


+ 10
- 2
app/src/main/res/layout/item_attachment.xml View File

@ -6,13 +6,21 @@
android:layout_marginBottom="6dp" android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"> android:layout_marginTop="6dp">
<ImageView
android:id="@+id/ivDelete"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/baseline_delete_24"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView <ImageView
android:id="@+id/ivAttachments" android:id="@+id/ivAttachments"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:src="@drawable/baseline_attachment_24" android:src="@drawable/baseline_attachment_24"
app:layout_constraintEnd_toStartOf="@+id/tvName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@id/ivDelete"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView


Loading…
Cancel
Save