Confirmation dialog added before sending delete command for remote file

This commit is contained in:
steckbrief 2016-08-23 11:23:40 +02:00
parent e91e8a30b1
commit ad096f4bfd
6 changed files with 84 additions and 23 deletions

View file

@ -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
}
}

View file

@ -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();

View file

@ -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();
}
}
}

View file

@ -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);
}
}
}

View file

@ -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();
}

View file

@ -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);
}