code clean up
This commit is contained in:
parent
65e7294802
commit
1f600be4dd
|
@ -67,9 +67,11 @@ public class ConversationActivity extends XmppActivity {
|
||||||
private static final int REQUEST_ATTACH_FILE_DIALOG = 0x48502;
|
private static final int REQUEST_ATTACH_FILE_DIALOG = 0x48502;
|
||||||
private static final int REQUEST_IMAGE_CAPTURE = 0x33788;
|
private static final int REQUEST_IMAGE_CAPTURE = 0x33788;
|
||||||
private static final int REQUEST_SEND_PGP_IMAGE = 0x53883;
|
private static final int REQUEST_SEND_PGP_IMAGE = 0x53883;
|
||||||
private static final int REQUEST_ATTACH_FILE = 0x73824;
|
|
||||||
public static final int REQUEST_ENCRYPT_MESSAGE = 0x378018;
|
public static final int REQUEST_ENCRYPT_MESSAGE = 0x378018;
|
||||||
|
|
||||||
|
private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x92734;
|
||||||
|
private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x84123;
|
||||||
|
|
||||||
protected SlidingPaneLayout spl;
|
protected SlidingPaneLayout spl;
|
||||||
|
|
||||||
private List<Conversation> conversationList = new ArrayList<Conversation>();
|
private List<Conversation> conversationList = new ArrayList<Conversation>();
|
||||||
|
@ -332,12 +334,19 @@ public class ConversationActivity extends XmppActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attachFileDialog() {
|
private void selectPresenceToAttachFile(final int attachmentChoice) {
|
||||||
selectPresence(getSelectedConversation(), new OnPresenceSelected() {
|
selectPresence(getSelectedConversation(), new OnPresenceSelected() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPresenceSelected(boolean success, String presence) {
|
public void onPresenceSelected(boolean success, String presence) {
|
||||||
if (success) {
|
if (success) {
|
||||||
|
if (attachmentChoice==ATTACHMENT_CHOICE_TAKE_PHOTO) {
|
||||||
|
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
|
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, ImageProvider.getIncomingContentUri());
|
||||||
|
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
|
||||||
|
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
|
||||||
|
}
|
||||||
|
} else if (attachmentChoice==ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
|
||||||
Intent attachFileIntent = new Intent();
|
Intent attachFileIntent = new Intent();
|
||||||
attachFileIntent.setType("image/*");
|
attachFileIntent.setType("image/*");
|
||||||
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
|
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
|
||||||
|
@ -345,26 +354,6 @@ public class ConversationActivity extends XmppActivity {
|
||||||
startActivityForResult(chooser, REQUEST_ATTACH_FILE_DIALOG);
|
startActivityForResult(chooser, REQUEST_ATTACH_FILE_DIALOG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSendPlainTextInstead() {
|
|
||||||
|
|
||||||
}
|
|
||||||
},"file");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void takePicture() {
|
|
||||||
selectPresence(getSelectedConversation(), new OnPresenceSelected() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPresenceSelected(boolean success, String presence) {
|
|
||||||
if (success) {
|
|
||||||
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
||||||
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, ImageProvider.getIncomingContentUri());
|
|
||||||
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
|
|
||||||
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -373,10 +362,9 @@ public class ConversationActivity extends XmppActivity {
|
||||||
|
|
||||||
}
|
}
|
||||||
},"file");
|
},"file");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attachFile() {
|
private void attachFile(final int attachmentChoice) {
|
||||||
final Conversation conversation = getSelectedConversation();
|
final Conversation conversation = getSelectedConversation();
|
||||||
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
|
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
|
||||||
if (hasPgp()) {
|
if (hasPgp()) {
|
||||||
|
@ -385,12 +373,12 @@ public class ConversationActivity extends XmppActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void userInputRequried(PendingIntent pi) {
|
public void userInputRequried(PendingIntent pi) {
|
||||||
ConversationActivity.this.runIntent(pi, REQUEST_ATTACH_FILE);
|
ConversationActivity.this.runIntent(pi, attachmentChoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void success() {
|
public void success() {
|
||||||
attachFileDialog();
|
selectPresenceToAttachFile(attachmentChoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -408,14 +396,14 @@ public class ConversationActivity extends XmppActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
||||||
attachFileDialog();
|
selectPresenceToAttachFile(attachmentChoice);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (getSelectedConversation().getNextEncryption() == Message.ENCRYPTION_NONE) {
|
} else if (getSelectedConversation().getNextEncryption() == Message.ENCRYPTION_NONE) {
|
||||||
attachFileDialog();
|
selectPresenceToAttachFile(attachmentChoice);
|
||||||
} else {
|
} else {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setTitle(getString(R.string.otr_file_transfer));
|
builder.setTitle(getString(R.string.otr_file_transfer));
|
||||||
|
@ -427,7 +415,7 @@ public class ConversationActivity extends XmppActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
||||||
attachFile();
|
attachFile(attachmentChoice);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -436,7 +424,7 @@ public class ConversationActivity extends XmppActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
conversation.setNextEncryption(Message.ENCRYPTION_PGP);
|
conversation.setNextEncryption(Message.ENCRYPTION_PGP);
|
||||||
attachFile();
|
attachFile(attachmentChoice);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -460,10 +448,10 @@ public class ConversationActivity extends XmppActivity {
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.attach_choose_picture:
|
case R.id.attach_choose_picture:
|
||||||
attachFile();
|
attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE);
|
||||||
break;
|
break;
|
||||||
case R.id.attach_take_picture:
|
case R.id.attach_take_picture:
|
||||||
takePicture();
|
attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -714,69 +702,28 @@ public class ConversationActivity extends XmppActivity {
|
||||||
selectedFragment.hidePgpPassphraseBox();
|
selectedFragment.hidePgpPassphraseBox();
|
||||||
}
|
}
|
||||||
} else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) {
|
} else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) {
|
||||||
prepareImageToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG);
|
attachImageToConversation(getSelectedConversation(),data.getData());
|
||||||
final Conversation conversation = getSelectedConversation();
|
|
||||||
if (conversation.getNextEncryption() == Message.ENCRYPTION_NONE) {
|
|
||||||
prepareImageToast.show();
|
|
||||||
this.pendingMessage = xmppConnectionService.attachImageToConversation(conversation, data.getData(),new UiCallback() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void userInputRequried(PendingIntent pi) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void success() {
|
|
||||||
sendPendingImageMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void error(int error) {
|
|
||||||
pendingMessage = null;
|
|
||||||
displayErrorDialog(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
|
|
||||||
prepareImageToast.show();
|
|
||||||
attachPgpFile(conversation,data.getData());
|
|
||||||
} else {
|
|
||||||
Log.d(LOGTAG,"unknown next message encryption: "+conversation.getNextEncryption());
|
|
||||||
}
|
|
||||||
} else if (requestCode == REQUEST_SEND_PGP_IMAGE) {
|
} else if (requestCode == REQUEST_SEND_PGP_IMAGE) {
|
||||||
|
|
||||||
} else if (requestCode == REQUEST_ATTACH_FILE) {
|
} else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
|
||||||
attachFile();
|
attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE);
|
||||||
|
} else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) {
|
||||||
|
attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
|
||||||
} else if (requestCode == REQUEST_ANNOUNCE_PGP) {
|
} else if (requestCode == REQUEST_ANNOUNCE_PGP) {
|
||||||
announcePgp(getSelectedConversation().getAccount(),getSelectedConversation());
|
announcePgp(getSelectedConversation().getAccount(),getSelectedConversation());
|
||||||
} else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
|
} else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
|
||||||
encryptTextMessage();
|
encryptTextMessage();
|
||||||
} else if (requestCode == REQUEST_IMAGE_CAPTURE) {
|
} else if (requestCode == REQUEST_IMAGE_CAPTURE) {
|
||||||
this.pendingMessage = xmppConnectionService.attachImageToConversation(getSelectedConversation(), null, new UiCallback() {
|
attachImageToConversation(getSelectedConversation(), null);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void userInputRequried(PendingIntent pi) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void success() {
|
|
||||||
sendPendingImageMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void error(int errorCode) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
Log.d(LOGTAG,"unknown result code:"+requestCode);
|
Log.d(LOGTAG,"unknown result code:"+requestCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attachPgpFile(Conversation conversation, Uri uri) {
|
private void attachImageToConversation(Conversation conversation, Uri uri) {
|
||||||
|
prepareImageToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG);
|
||||||
|
prepareImageToast.show();
|
||||||
pendingMessage = xmppConnectionService.attachImageToConversation(conversation, uri, new UiCallback() {
|
pendingMessage = xmppConnectionService.attachImageToConversation(conversation, uri, new UiCallback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue