1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-25 01:06:04 +00:00

Auto download+share last attachment

This commit is contained in:
M66B 2022-08-09 09:35:49 +02:00
parent 455c6e3dd7
commit 234cf641bd
4 changed files with 30 additions and 4 deletions

View file

@ -71,6 +71,8 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
private LayoutInflater inflater;
private boolean readonly;
private AdapterMessage.IProperties properties;
private boolean vt_enabled;
private String vt_apikey;
private boolean debug;
@ -207,6 +209,16 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
tvError.setText(attachment.error);
tvError.setVisibility(attachment.error == null ? View.GONE : View.VISIBLE);
if (properties != null) {
String aid = properties.getValue("attachment");
if (aid != null) {
if (attachment.id.equals(Long.parseLong(aid)) && attachment.available) {
properties.setValue("attachment", null);
onShare(attachment);
}
}
}
}
@Override
@ -337,6 +349,9 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
}
private void onDownload(EntityAttachment attachment) {
if (properties != null)
properties.setValue("attachment", Long.toString(attachment.id));
Bundle args = new Bundle();
args.putLong("id", attachment.id);
args.putLong("message", attachment.message);
@ -392,9 +407,10 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
}
}
AdapterAttachment(Fragment parentFragment, boolean readonly) {
AdapterAttachment(Fragment parentFragment, boolean readonly, final AdapterMessage.IProperties properties) {
this.parentFragment = parentFragment;
this.readonly = readonly;
this.properties = properties;
this.context = parentFragment.getContext();
this.owner = parentFragment.getViewLifecycleOwner();

View file

@ -841,7 +841,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
rvAttachment.setLayoutManager(llm);
rvAttachment.setItemAnimator(null);
adapterAttachment = new AdapterAttachment(parentFragment, true);
adapterAttachment = new AdapterAttachment(parentFragment, true, properties);
rvAttachment.setAdapter(adapterAttachment);
cbInline = attachments.findViewById(R.id.cbInline);
@ -7999,6 +7999,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
void setValue(String name, long id, boolean enabled);
String getValue(String key);
boolean getValue(String name, long id);
void setExpanded(TupleMessageEx message, boolean expanded, boolean scroll);

View file

@ -1367,7 +1367,7 @@ public class FragmentCompose extends FragmentBase {
rvAttachment.setLayoutManager(llm);
rvAttachment.setItemAnimator(null);
adapter = new AdapterAttachment(this, false);
adapter = new AdapterAttachment(this, false, null);
rvAttachment.setAdapter(adapter);
tvNoInternetAttachments.setVisibility(View.GONE);

View file

@ -2125,7 +2125,10 @@ public class FragmentMessages extends FragmentBase
private AdapterMessage.IProperties iProperties = new AdapterMessage.IProperties() {
@Override
public void setValue(String key, String value) {
kv.put(key, value);
if (value == null)
kv.remove(key);
else
kv.put(key, value);
}
@Override
@ -2174,6 +2177,11 @@ public class FragmentMessages extends FragmentBase
}
}
@Override
public String getValue(String key) {
return kv.get(key);
}
@Override
public boolean getValue(String name, long id) {
if (values.containsKey(name))