Auto download+share last attachment

pull/209/head
M66B 2 years ago
parent 455c6e3dd7
commit 234cf641bd

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

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

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

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

Loading…
Cancel
Save