Refactoring

This commit is contained in:
M66B
2022-07-23 09:27:04 +02:00
parent 73f7b4a9a4
commit dbc8dc5266
5 changed files with 163 additions and 157 deletions

View File

@@ -215,7 +215,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
else if (id == R.id.ibSave)
onSave(attachment);
else if (id == R.id.ibScan)
Check.virus(context, owner, parentFragment.getParentFragmentManager(), attachment.id);
onScan(attachment);
else {
if (attachment.available)
onShare(attachment);
@@ -310,6 +310,36 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
.putExtra("type", attachment.getMimeType()));
}
private void onScan(EntityAttachment attachment) {
Bundle args = new Bundle();
args.putLong("id", attachment.id);
new SimpleTask<Bundle>() {
@Override
protected Bundle onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityAttachment attachment = db.attachment().getAttachment(id);
if (attachment == null)
return null;
return VirusTotal.scan(context, attachment.getFile(context));
}
@Override
protected void onExecuted(Bundle args, Bundle result) {
String uri = result.getString("uri");
Helper.view(context, Uri.parse(uri), true);
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "attachment:scan");
}
private void onShare(EntityAttachment attachment) {
String title = (attachment.name == null ? attachment.cid : attachment.name);
Helper.share(context, attachment.getFile(context), attachment.getMimeType(), title);

View File

@@ -655,7 +655,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
tvVirusTotalPrivacy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.view(v.getContext(), Uri.parse(Check.URI_VT_PRIVACY), true);
Helper.view(v.getContext(), Uri.parse(VirusTotal.URI_PRIVACY), true);
}
});