diff options
author | steckbrief <steckbrief@chefmail.de> | 2016-08-23 11:34:14 +0200 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2016-08-23 11:34:14 +0200 |
commit | 14e28d1e9afc058526eba4a6096d582f4810ea84 (patch) | |
tree | 2a788de4cdb34570fe4f64e142e974ff9ee12756 /src/main | |
parent | ad096f4bfd220a106aab670105275397bfcbfd0e (diff) |
Fixes FS#229: prompt for confirmation before deleting a file
Diffstat (limited to 'src/main')
4 files changed, 41 insertions, 9 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java index 397de0b3..56065ea4 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java @@ -68,6 +68,7 @@ import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter; import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter.OnContactPictureClicked; import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter.OnContactPictureLongClicked; import de.thedevstack.conversationsplus.ui.listeners.ConversationSwipeRefreshListener; +import de.thedevstack.conversationsplus.ui.listeners.DeleteFileCallback; import de.thedevstack.conversationsplus.ui.listeners.SimpleUserDecisionCallback; import de.thedevstack.conversationsplus.ui.listeners.UserDecisionListener; import de.thedevstack.conversationsplus.utils.GeoHelper; @@ -588,7 +589,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.msg_ctx_menu_delete_remote_file: - new SimpleConfirmDialog(getActivity(), "Are you sure?", new DeleteRemoteFileService(selectedMessage)).show(); + new SimpleConfirmDialog(getActivity(), R.string.cplus_are_you_sure, new DeleteRemoteFileService(selectedMessage)).show(); return true; case R.id.msg_ctx_mnu_details: new MessageDetailsDialog(getActivity(), selectedMessage).show(); @@ -615,7 +616,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa retryDecryption(selectedMessage); return true; case R.id.delete_file: - deleteFile(selectedMessage); + new SimpleConfirmDialog(getActivity(), R.string.cplus_are_you_sure, new DeleteFileCallback(selectedMessage)).show(); return true; default: return super.onContextItemSelected(item); @@ -654,13 +655,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } } - private void deleteFile(Message message) { - if (FileBackend.deleteFile(message, activity.xmppConnectionService)) { - message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED)); - activity.xmppConnectionService.updateConversationUi(); - } - } - private void resendMessage(Message message) { if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) { DownloadableFile file = FileBackend.getFile(message); diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/DeleteFileCallback.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/DeleteFileCallback.java new file mode 100644 index 00000000..3ff7f367 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/DeleteFileCallback.java @@ -0,0 +1,36 @@ +package de.thedevstack.conversationsplus.ui.listeners; + +import de.thedevstack.conversationsplus.entities.Message; +import de.thedevstack.conversationsplus.entities.Transferable; +import de.thedevstack.conversationsplus.entities.TransferablePlaceholder; +import de.thedevstack.conversationsplus.persistance.FileBackend; +import de.thedevstack.conversationsplus.utils.UiUpdateHelper; +import de.thedevstack.conversationsplus.utils.XmppConnectionServiceAccessor; + +/** + * Created by steckbrief on 23.08.2016. + */ +public class DeleteFileCallback implements SimpleUserDecisionCallback { + private final Message message; + + public DeleteFileCallback(Message message) { + this.message = message; + } + + private void deleteFile() { + if (FileBackend.deleteFile(this.message, XmppConnectionServiceAccessor.xmppConnectionService)) { + this.message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED)); + UiUpdateHelper.updateConversationUi(); + } + } + + @Override + public void onYes() { + this.deleteFile(); + } + + @Override + public void onNo() { + // Nothing to do + } +} diff --git a/src/main/res/values-de/strings.xml b/src/main/res/values-de/strings.xml index 0e3b388d..4cfbd67a 100644 --- a/src/main/res/values-de/strings.xml +++ b/src/main/res/values-de/strings.xml @@ -634,4 +634,5 @@ <string name="no_keys_just_confirm">Du vertraust diesem Kontakt bereits. Durch Auswählen von \"Fertig\" bestätigst du, dass %s Teil dieser Konferenz ist.</string> <string name="select_image_and_crop">Bild auswählen und zuschneiden</string> <string name="this_account_is_disabled">Du hast diesen Account deaktiviert</string> + <string name="cplus_are_you_sure">Bist du dir sicher?</string> </resources> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 22b6c490..8136a84f 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -675,4 +675,5 @@ <string name="no_application_to_share_uri">No application found to share URI</string> <string name="share_uri_with">Share URI with…</string> <string name="delete_remote_file_x">Delete remote file</string> + <string name="cplus_are_you_sure">Are you sure?</string> </resources> |