aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFileService.java33
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java5
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/dialogs/SimpleConfirmDialog.java36
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java18
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/SimpleUserDecisionCallback.java9
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/UserDecisionListener.java6
6 files changed, 84 insertions, 23 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFileService.java b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFileService.java
index 42410ed4..2b26fd85 100644
--- a/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFileService.java
+++ b/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/delete/DeleteRemoteFileService.java
@@ -2,6 +2,7 @@ package de.thedevstack.conversationsplus.services.filetransfer.http.delete;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Message;
+import de.thedevstack.conversationsplus.ui.listeners.SimpleUserDecisionCallback;
import de.thedevstack.conversationsplus.utils.XmppSendUtil;
import de.thedevstack.conversationsplus.xmpp.filetransfer.http.FileTransferHttp;
import de.thedevstack.conversationsplus.xmpp.filetransfer.http.delete.FileTransferHttpDeleteSlotRequestPacketGenerator;
@@ -11,20 +12,36 @@ import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;
/**
* Created by steckbrief on 21.08.2016.
*/
-public class DeleteRemoteFileService {
- public void deleteRemoteFile(Message message) {
- if (message.isHttpUploaded()) {
- String path = message.getBody();
- if (message.hasFileOnRemoteHost()) {
- path = message.getFileParams().url.toString();
+public class DeleteRemoteFileService implements SimpleUserDecisionCallback {
+ private Message message;
+
+ public DeleteRemoteFileService(Message message) {
+ this.message = message;
+ }
+
+ public void deleteRemoteFile() {
+ if (this.message.isHttpUploaded()) {
+ String path = this.message.getBody();
+ if (this.message.hasFileOnRemoteHost()) {
+ path = this.message.getFileParams().url.toString();
}
- DeleteRemoteFile remoteFile = new DeleteRemoteFile(path, message);
- Account account = message.getConversation().getAccount();
+ DeleteRemoteFile remoteFile = new DeleteRemoteFile(path, this.message);
+ Account account = this.message.getConversation().getAccount();
Jid host = account.getXmppConnection().findDiscoItemByFeature(FileTransferHttp.NAMESPACE);
IqPacket request = FileTransferHttpDeleteSlotRequestPacketGenerator.generate(host, path);
XmppSendUtil.sendIqPacket(account, request, new DeleteTokenReceived(remoteFile));
}
}
+
+ @Override
+ public void onYes() {
+ this.deleteRemoteFile();
+ }
+
+ @Override
+ public void onNo() {
+ // Nothing to do
+ }
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
index c3d7c962..397de0b3 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
@@ -46,6 +46,7 @@ import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.http.HttpConnectionManager;
import de.thedevstack.conversationsplus.http.HttpDownloadConnection;
import de.thedevstack.conversationsplus.services.filetransfer.http.delete.DeleteRemoteFileService;
+import de.thedevstack.conversationsplus.ui.dialogs.SimpleConfirmDialog;
import de.thedevstack.conversationsplus.ui.dialogs.MessageDetailsDialog;
import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
@@ -67,6 +68,8 @@ 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.SimpleUserDecisionCallback;
+import de.thedevstack.conversationsplus.ui.listeners.UserDecisionListener;
import de.thedevstack.conversationsplus.utils.GeoHelper;
import de.thedevstack.conversationsplus.utils.MessageUtil;
import de.thedevstack.conversationsplus.utils.UIHelper;
@@ -585,7 +588,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 DeleteRemoteFileService().deleteRemoteFile(selectedMessage);
+ new SimpleConfirmDialog(getActivity(), "Are you sure?", new DeleteRemoteFileService(selectedMessage)).show();
return true;
case R.id.msg_ctx_mnu_details:
new MessageDetailsDialog(getActivity(), selectedMessage).show();
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/SimpleConfirmDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/SimpleConfirmDialog.java
new file mode 100644
index 00000000..04e60caa
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/SimpleConfirmDialog.java
@@ -0,0 +1,36 @@
+package de.thedevstack.conversationsplus.ui.dialogs;
+
+import android.content.Context;
+import android.content.DialogInterface;
+
+import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.ui.listeners.SimpleUserDecisionCallback;
+
+/**
+ * A dialog to give the user the choice to decide whether to do something or not.
+ * A UserDecisionListener is used to provide the functionality to be performed by clicking on yes, or no.
+ */
+public class SimpleConfirmDialog extends AbstractAlertDialog {
+ protected final SimpleUserDecisionCallback callback;
+
+ public SimpleConfirmDialog(Context context, String title, SimpleUserDecisionCallback userDecisionCallback) {
+ super(context, title);
+ this.callback = userDecisionCallback;
+ this.setPositiveButton(R.string.cplus_ok, new ConfirmOnClickListener());
+ this.setNegativeButton(R.string.cancel, null);
+ }
+
+ public SimpleConfirmDialog(Context context, int titleTextId, SimpleUserDecisionCallback userDecisionCallback) {
+ super(context, titleTextId);
+ this.callback = userDecisionCallback;
+ this.setPositiveButton(R.string.cplus_ok, new ConfirmOnClickListener());
+ this.setNegativeButton(R.string.cancel, null);
+ }
+
+ private class ConfirmOnClickListener implements DialogInterface.OnClickListener {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ callback.onYes();
+ }
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java
index 25349b2d..e0834390 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java
@@ -15,13 +15,11 @@ import de.thedevstack.conversationsplus.R;
* The user also has the choice to save his answer for the future.
* A UserDecisionListener is used to provide the functionality to be performed by clicking on yes, or no.
*/
-public class UserDecisionDialog extends AbstractAlertDialog {
- protected final UserDecisionListener listener;
+public class UserDecisionDialog extends SimpleConfirmDialog {
protected final CheckBox rememberCheckBox;
public UserDecisionDialog(Activity context, int questionResourceId, UserDecisionListener userDecisionListener) {
- super(context, questionResourceId);
- this.listener = userDecisionListener;
+ super(context, questionResourceId, userDecisionListener);
int viewId = R.layout.dialog_userdecision;
View view = context.getLayoutInflater().inflate(viewId, null);
@@ -36,10 +34,10 @@ public class UserDecisionDialog extends AbstractAlertDialog {
public void decide(UserDecision baseDecision) {
switch (baseDecision) {
case ALWAYS:
- this.listener.onYes();
+ this.callback.onYes();
break;
case NEVER:
- this.listener.onNo();
+ this.callback.onNo();
break;
case ASK:
this.show();
@@ -51,9 +49,9 @@ public class UserDecisionDialog extends AbstractAlertDialog {
@Override
public void onClick(DialogInterface dialog, int which) {
- listener.onYes();
+ callback.onYes();
if (rememberCheckBox.isChecked()) {
- listener.onRemember(UserDecision.ALWAYS);
+ ((UserDecisionListener)callback).onRemember(UserDecision.ALWAYS);
}
}
}
@@ -62,9 +60,9 @@ public class UserDecisionDialog extends AbstractAlertDialog {
@Override
public void onClick(DialogInterface dialog, int which) {
- listener.onNo();
+ callback.onNo();
if (rememberCheckBox.isChecked()) {
- listener.onRemember(UserDecision.NEVER);
+ ((UserDecisionListener)callback).onRemember(UserDecision.NEVER);
}
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/SimpleUserDecisionCallback.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/SimpleUserDecisionCallback.java
new file mode 100644
index 00000000..3ed49c2d
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/SimpleUserDecisionCallback.java
@@ -0,0 +1,9 @@
+package de.thedevstack.conversationsplus.ui.listeners;
+
+/**
+ * Callback to be executed on a user decision.
+ */
+public interface SimpleUserDecisionCallback {
+ void onYes();
+ void onNo();
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/UserDecisionListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/UserDecisionListener.java
index fbee6290..45576225 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/UserDecisionListener.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/UserDecisionListener.java
@@ -3,10 +3,8 @@ package de.thedevstack.conversationsplus.ui.listeners;
import de.thedevstack.conversationsplus.enums.UserDecision;
/**
- * Created by tzur on 31.10.2015.
+ * Callback to be executed on a user decision with the possibility to remember the decision.
*/
-public interface UserDecisionListener {
- void onYes();
- void onNo();
+public interface UserDecisionListener extends SimpleUserDecisionCallback {
void onRemember(UserDecision decision);
}