mirror of https://github.com/M66B/FairEmail.git
Added renaming of attachments
This commit is contained in:
parent
f64961b224
commit
f162304427
|
@ -273,15 +273,20 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
||||||
else {
|
else {
|
||||||
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, view);
|
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, view);
|
||||||
|
|
||||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_share, 1, R.string.title_share);
|
if (parentFragment instanceof FragmentCompose)
|
||||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_zip, 2, R.string.title_zip)
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_rename, 1, R.string.title_rename);
|
||||||
|
|
||||||
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_share, 2, R.string.title_share);
|
||||||
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_zip, 3, R.string.title_zip)
|
||||||
.setEnabled(!attachment.isInline() && !attachment.isCompressed());
|
.setEnabled(!attachment.isInline() && !attachment.isCompressed());
|
||||||
|
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
int itemId = item.getItemId();
|
int itemId = item.getItemId();
|
||||||
if (itemId == R.string.title_share)
|
if (itemId == R.string.title_rename)
|
||||||
|
return onRename(attachment);
|
||||||
|
else if (itemId == R.string.title_share)
|
||||||
return onShare(attachment);
|
return onShare(attachment);
|
||||||
else if (itemId == R.string.title_zip)
|
else if (itemId == R.string.title_zip)
|
||||||
return onZip(attachment);
|
return onZip(attachment);
|
||||||
|
@ -295,6 +300,20 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean onRename(EntityAttachment attachment) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putLong("id", attachment.id);
|
||||||
|
args.putString("prev", attachment.name);
|
||||||
|
args.putString("name", attachment.name);
|
||||||
|
|
||||||
|
FragmentDialogEditName fragment = new FragmentDialogEditName();
|
||||||
|
fragment.setArguments(args);
|
||||||
|
fragment.setTargetFragment(parentFragment, FragmentCompose.REQUEST_EDIT_ATTACHMENT);
|
||||||
|
fragment.show(parentFragment.getParentFragmentManager(), "attachment:name");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean onShare(final EntityAttachment attachment) {
|
private boolean onShare(final EntityAttachment attachment) {
|
||||||
try {
|
try {
|
||||||
new ShareCompat.IntentBuilder(context)
|
new ShareCompat.IntentBuilder(context)
|
||||||
|
|
|
@ -116,6 +116,12 @@ public interface DaoAttachment {
|
||||||
" AND NOT (name IS name AND type IS :type AND size IS :size)")
|
" AND NOT (name IS name AND type IS :type AND size IS :size)")
|
||||||
void setName(long id, String name, String type, Long size);
|
void setName(long id, String name, String type, Long size);
|
||||||
|
|
||||||
|
@Query("UPDATE attachment" +
|
||||||
|
" SET name = :name" +
|
||||||
|
" WHERE id = :id" +
|
||||||
|
" AND NOT (name IS :name)")
|
||||||
|
void setName(long id, String name);
|
||||||
|
|
||||||
@Query("UPDATE attachment" +
|
@Query("UPDATE attachment" +
|
||||||
" SET type = :type" +
|
" SET type = :type" +
|
||||||
" WHERE id = :id" +
|
" WHERE id = :id" +
|
||||||
|
|
|
@ -348,7 +348,8 @@ public class FragmentCompose extends FragmentBase {
|
||||||
private static final int REQUEST_LINK = 14;
|
private static final int REQUEST_LINK = 14;
|
||||||
private static final int REQUEST_DISCARD = 15;
|
private static final int REQUEST_DISCARD = 15;
|
||||||
private static final int REQUEST_SEND = 16;
|
private static final int REQUEST_SEND = 16;
|
||||||
private static final int REQUEST_REMOVE_ATTACHMENTS = 17;
|
static final int REQUEST_EDIT_ATTACHMENT = 17;
|
||||||
|
private static final int REQUEST_REMOVE_ATTACHMENTS = 18;
|
||||||
|
|
||||||
ActivityResultLauncher<PickVisualMediaRequest> pickImages;
|
ActivityResultLauncher<PickVisualMediaRequest> pickImages;
|
||||||
|
|
||||||
|
@ -3373,6 +3374,10 @@ public class FragmentCompose extends FragmentBase {
|
||||||
onAction(R.id.action_send, extras, "sendnow");
|
onAction(R.id.action_send, extras, "sendnow");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case REQUEST_EDIT_ATTACHMENT:
|
||||||
|
if (resultCode == RESULT_OK && data != null)
|
||||||
|
onEditAttachment(data.getBundleExtra("args"));
|
||||||
|
break;
|
||||||
case REQUEST_REMOVE_ATTACHMENTS:
|
case REQUEST_REMOVE_ATTACHMENTS:
|
||||||
if (resultCode == RESULT_OK)
|
if (resultCode == RESULT_OK)
|
||||||
onRemoveAttachments();
|
onRemoveAttachments();
|
||||||
|
@ -4965,6 +4970,45 @@ public class FragmentCompose extends FragmentBase {
|
||||||
onAction(R.id.action_delete, "delete");
|
onAction(R.id.action_delete, "delete");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onEditAttachment(Bundle args) {
|
||||||
|
new SimpleTask<Void>() {
|
||||||
|
@Override
|
||||||
|
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
||||||
|
long id = args.getLong("id");
|
||||||
|
String prev = args.getString("prev");
|
||||||
|
String name = args.getString("name");
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(name))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
name = Helper.sanitizeFilename(name);
|
||||||
|
|
||||||
|
File source = EntityAttachment.getFile(context, id, prev);
|
||||||
|
File target = EntityAttachment.getFile(context, id, name);
|
||||||
|
if (!source.renameTo(target))
|
||||||
|
throw new IllegalArgumentException("Could not rename " + source.getName() + " into " + target.getName());
|
||||||
|
|
||||||
|
DB db = DB.getInstance(context);
|
||||||
|
try {
|
||||||
|
db.beginTransaction();
|
||||||
|
|
||||||
|
db.attachment().setName(id, name);
|
||||||
|
|
||||||
|
db.setTransactionSuccessful();
|
||||||
|
} finally {
|
||||||
|
db.endTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onException(Bundle args, Throwable ex) {
|
||||||
|
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||||
|
}
|
||||||
|
}.execute(this, args, "attachment:edit");
|
||||||
|
}
|
||||||
|
|
||||||
private void onRemoveAttachments() {
|
private void onRemoveAttachments() {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putLong("id", working);
|
args.putLong("id", working);
|
||||||
|
|
|
@ -1508,6 +1508,7 @@
|
||||||
<string name="title_create_rule">Create rule …</string>
|
<string name="title_create_rule">Create rule …</string>
|
||||||
<string name="title_full_screen">Full screen</string>
|
<string name="title_full_screen">Full screen</string>
|
||||||
<string name="title_force_light">Force light theme</string>
|
<string name="title_force_light">Force light theme</string>
|
||||||
|
<string name="title_rename">Rename</string>
|
||||||
<string name="title_share">Share</string>
|
<string name="title_share">Share</string>
|
||||||
<string name="title_share_link" translatable="false">Share link</string>
|
<string name="title_share_link" translatable="false">Share link</string>
|
||||||
<string name="title_share_link_open" translatable="false">Open message</string>
|
<string name="title_share_link_open" translatable="false">Open message</string>
|
||||||
|
|
Loading…
Reference in New Issue