diff options
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ConversationActivity.java | 1023 |
1 files changed, 11 insertions, 1012 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index bf049fe70..2f43461fe 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -4,32 +4,24 @@ import android.annotation.SuppressLint; import android.app.FragmentTransaction; import android.app.PendingIntent; import android.content.ActivityNotFoundException; -import android.content.ClipData; import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Typeface; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; -import android.provider.MediaStore; import android.provider.Settings; -import android.support.media.ExifInterface; import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; import android.support.v7.app.ActionBar; import android.support.v7.app.AlertDialog; import android.util.Log; import android.util.Pair; -import android.view.Gravity; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; @@ -38,9 +30,6 @@ import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; -import android.widget.CheckBox; -import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.ListView; import android.widget.PopupMenu; import android.widget.PopupMenu.OnMenuItemClickListener; @@ -49,28 +38,17 @@ import android.widget.Toast; import net.java.otr4j.session.SessionStatus; -import org.openintents.openpgp.util.OpenPgpApi; - -import java.io.File; -import java.io.IOException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import de.pixart.messenger.Config; import de.pixart.messenger.R; -import de.pixart.messenger.crypto.axolotl.AxolotlService; -import de.pixart.messenger.crypto.axolotl.FingerprintStatus; import de.pixart.messenger.entities.Account; -import de.pixart.messenger.entities.Blockable; -import de.pixart.messenger.entities.Contact; import de.pixart.messenger.entities.Conversation; import de.pixart.messenger.entities.Message; import de.pixart.messenger.entities.MucOptions; import de.pixart.messenger.entities.Presence; -import de.pixart.messenger.entities.Transferable; -import de.pixart.messenger.persistance.FileBackend; import de.pixart.messenger.services.EmojiService; import de.pixart.messenger.services.UpdateService; import de.pixart.messenger.services.XmppConnectionService; @@ -79,8 +57,6 @@ import de.pixart.messenger.services.XmppConnectionService.OnConversationUpdate; import de.pixart.messenger.services.XmppConnectionService.OnRosterUpdate; import de.pixart.messenger.ui.adapter.ConversationAdapter; import de.pixart.messenger.utils.ExceptionHelper; -import de.pixart.messenger.utils.FileUtils; -import de.pixart.messenger.utils.SendButtonAction; import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.xmpp.OnUpdateBlocklist; import de.pixart.messenger.xmpp.XmppConnection; @@ -89,7 +65,6 @@ import de.pixart.messenger.xmpp.jid.InvalidJidException; import de.pixart.messenger.xmpp.jid.Jid; import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS; -import static de.pixart.messenger.ui.ShowFullscreenMessageActivity.getMimeType; public class ConversationActivity extends XmppActivity implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast, View.OnClickListener { @@ -98,41 +73,22 @@ public class ConversationActivity extends XmppActivity public static final String ACTION_DESTROY_MUC = "de.pixart.messenger.DESTROY_MUC"; public static final String CONVERSATION = "conversationUuid"; public static final String EXTRA_DOWNLOAD_UUID = "de.pixart.messenger.download_uuid"; - public static final String RECENTLY_USED_QUICK_ACTION = "recently_used_quick_action"; public static final String TEXT = "text"; public static final String NICK = "nick"; public static final String PRIVATE_MESSAGE = "pm"; - public static final int REQUEST_SEND_MESSAGE = 0x0201; - public static final int REQUEST_DECRYPT_PGP = 0x0202; - public static final int REQUEST_ENCRYPT_MESSAGE = 0x0207; - public static final int REQUEST_TRUST_KEYS_TEXT = 0x0208; - public static final int REQUEST_TRUST_KEYS_MENU = 0x0209; - public static final int REQUEST_START_DOWNLOAD = 0x0210; - public static final int REQUEST_ADD_EDITOR_CONTENT = 0x0211; - public static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301; - public static final int ATTACHMENT_CHOICE_TAKE_FROM_CAMERA = 0x0302; - public static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303; - public static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0304; - public static final int ATTACHMENT_CHOICE_LOCATION = 0x0305; - public static final int ATTACHMENT_CHOICE_CHOOSE_VIDEO = 0x0306; - public static final int ATTACHMENT_CHOICE_INVALID = 0x0399; private static final String STATE_OPEN_CONVERSATION = "state_open_conversation"; private static final String STATE_PANEL_OPEN = "state_panel_open"; private static final String STATE_PENDING_IMAGE_URI = "state_pending_image_uri"; private static final String STATE_PENDING_PHOTO_URI = "state_pending_photo_uri"; private static final String STATE_FIRST_VISIBLE = "first_visible"; private static final String STATE_OFFSET_FROM_TOP = "offset_from_top"; - final private List<Uri> mPendingImageUris = new ArrayList<>(); - final private List<Uri> mPendingPhotoUris = new ArrayList<>(); - final private List<Uri> mPendingFileUris = new ArrayList<>(); + private String mOpenConversation = null; private boolean mPanelOpen = true; private AtomicBoolean mShouldPanelBeOpen = new AtomicBoolean(false); private Pair<Integer, Integer> mScrollPosition = null; - private Uri mPendingGeoUri = null; private boolean forbidProcessingPendings = false; - private Message mPendingDownloadableMessage = null; private boolean conversationWasSelectedByKeyboard = false; @@ -148,9 +104,7 @@ public class ConversationActivity extends XmppActivity private boolean mActivityPaused = false; private AtomicBoolean mRedirected = new AtomicBoolean(false); - private Pair<Integer, Intent> mPostponedActivityResult; private boolean mUnprocessedNewIntent = false; - public Uri mPendingEditorContent = null; private boolean showLastSeen = false; long FirstStartTime = -1; @@ -226,18 +180,6 @@ public class ConversationActivity extends XmppActivity } else { mScrollPosition = null; } - String pending_image = savedInstanceState.getString(STATE_PENDING_IMAGE_URI, null); - if (pending_image != null) { - Log.d(Config.LOGTAG, "ConversationActivity.onCreate() - restoring pending image uri"); - mPendingImageUris.clear(); - mPendingImageUris.add(Uri.parse(pending_image)); - } - String pending_photo = savedInstanceState.getString(STATE_PENDING_PHOTO_URI, null); - if (pending_photo != null) { - Log.d(Config.LOGTAG, "ConversationActivity.onCreate() - restoring pending photo uri"); - mPendingPhotoUris.clear(); - mPendingPhotoUris.add(Uri.parse(pending_photo)); - } } setContentView(R.layout.fragment_conversations_overview); @@ -471,319 +413,9 @@ public class ConversationActivity extends XmppActivity @Override public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.conversations, menu); - final MenuItem menuSecure = menu.findItem(R.id.action_security); - final MenuItem menuArchiveChat = menu.findItem(R.id.action_archive_chat); - final MenuItem menuArchiveMuc = menu.findItem(R.id.action_archive_muc); - final MenuItem menuAttach = menu.findItem(R.id.action_attach_file); - final MenuItem menuClearHistory = menu.findItem(R.id.action_clear_history); - final MenuItem menuAdd = menu.findItem(R.id.action_add); - final MenuItem menuInviteContact = menu.findItem(R.id.action_invite); - final MenuItem menuAttachSoundRecorder = menu.findItem(R.id.attach_record_voice); - final MenuItem menuAttachLocation = menu.findItem(R.id.attach_location); - final MenuItem menuUpdater = menu.findItem(R.id.action_check_updates); - final MenuItem menuInviteUser = menu.findItem(R.id.action_invite_user); - final MenuItem menuSearchHistory = menu.findItem(R.id.action_search_history); - final MenuItem menuActionAccounts = menu.findItem(R.id.action_accounts); - if (xmppConnectionServiceBound) { - if (xmppConnectionService.getAccounts().size() == 1 && !xmppConnectionService.multipleAccounts()) { - menuActionAccounts.setTitle(R.string.mgmt_account_edit); - } else { - menuActionAccounts.setTitle(R.string.action_accounts); - } - } - if (isConversationsOverviewVisable() && isConversationsOverviewHideable()) { - menuArchiveChat.setVisible(false); - menuArchiveMuc.setVisible(false); - menuSecure.setVisible(false); - menuInviteContact.setVisible(false); - menuAttach.setVisible(false); - menuAttachLocation.setVisible(false); - menuAttachSoundRecorder.setVisible(false); - menuClearHistory.setVisible(false); - menuSearchHistory.setVisible(false); - if (xmppConnectionService.installedFromFDroid()) { - menuUpdater.setVisible(false); - } else { - menuUpdater.setVisible(true); - } - } else { - menuAdd.setVisible(!isConversationsOverviewHideable()); - //hide settings, accounts and updater in all menus except in main window - menuUpdater.setVisible(false); - menuInviteUser.setVisible(false); - - if (this.getSelectedConversation() != null) { - if (this.getSelectedConversation().getMode() == Conversation.MODE_SINGLE) { - menuArchiveMuc.setVisible(false); - } else { - menuArchiveChat.setVisible(false); - } - if (this.getSelectedConversation().getNextEncryption() != Message.ENCRYPTION_NONE) { - menuSecure.setIcon(R.drawable.ic_lock_white_24dp); - } - if (this.getSelectedConversation().getMode() == Conversation.MODE_MULTI) { - menuAttach.setVisible(getSelectedConversation().getAccount().httpUploadAvailable() && getSelectedConversation().getMucOptions().participating()); - menuInviteContact.setVisible(getSelectedConversation().getMucOptions().canInvite()); - menuSecure.setVisible((Config.supportOpenPgp() || Config.supportOmemo()) && Config.multipleEncryptionChoices()); //only if pgp is supported we have a choice - } else { - menuSecure.setVisible(Config.multipleEncryptionChoices()); - menuInviteContact.setVisible(xmppConnectionService != null && xmppConnectionService.findConferenceServer(getSelectedConversation().getAccount()) != null); - } - menuAttachLocation.setVisible(true); - menuAttachSoundRecorder.setVisible(true); - configureEncryptionMenu(getSelectedConversation(), menu); - } - } return super.onCreateOptionsMenu(menu); } - private static void configureEncryptionMenu(Conversation conversation, Menu menu) { - MenuItem otr = menu.findItem(R.id.encryption_choice_otr); - MenuItem none = menu.findItem(R.id.encryption_choice_none); - MenuItem pgp = menu.findItem(R.id.encryption_choice_pgp); - MenuItem axolotl = menu.findItem(R.id.encryption_choice_axolotl); - pgp.setVisible(Config.supportOpenPgp()); - none.setVisible(Config.supportUnencrypted() || conversation.getMode() == Conversation.MODE_MULTI); - otr.setVisible(Config.supportOtr()); - axolotl.setVisible(Config.supportOmemo()); - if (conversation.getMode() == Conversation.MODE_MULTI) { - otr.setVisible(false); - } - if (!conversation.getAccount().getAxolotlService().isConversationAxolotlCapable(conversation)) { - axolotl.setEnabled(false); - } - switch (conversation.getNextEncryption()) { - case Message.ENCRYPTION_NONE: - none.setChecked(true); - break; - case Message.ENCRYPTION_OTR: - otr.setChecked(true); - break; - case Message.ENCRYPTION_PGP: - pgp.setChecked(true); - break; - case Message.ENCRYPTION_AXOLOTL: - axolotl.setChecked(true); - break; - default: - none.setChecked(true); - break; - } - } - - protected void selectPresenceToAttachFile(final int attachmentChoice, final int encryption) { - final Conversation conversation = getSelectedConversation(); - final Account account = conversation.getAccount(); - final OnPresenceSelected callback = () -> { - final Intent intent = new Intent(); - boolean chooser = false; - String fallbackPackageId = null; - switch (attachmentChoice) { - case ATTACHMENT_CHOICE_CHOOSE_IMAGE: - intent.setAction(Intent.ACTION_GET_CONTENT); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); - } - intent.setType("image/*"); - chooser = true; - break; - case ATTACHMENT_CHOICE_CHOOSE_VIDEO: - chooser = true; - intent.setType("video/*"); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setAction(Intent.ACTION_GET_CONTENT); - break; - case ATTACHMENT_CHOICE_TAKE_FROM_CAMERA: - AlertDialog.Builder builder = new AlertDialog.Builder(ConversationActivity.this); - builder.setTitle(getString(R.string.attach_take_from_camera)); - builder.setNegativeButton(getString(R.string.action_take_photo), - (dialog, which) -> { - Uri uri = xmppConnectionService.getFileBackend().getTakePhotoUri(); - intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); - intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); - intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); - mPendingPhotoUris.clear(); - mPendingPhotoUris.add(uri); - startActivityForResult(intent, attachmentChoice); - }); - builder.setPositiveButton(getString(R.string.action_take_video), - (dialog, which) -> { - Uri uri = xmppConnectionService.getFileBackend().getTakeVideoUri(); - intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE); - mPendingFileUris.clear(); - mPendingFileUris.add(uri); - startActivityForResult(intent, attachmentChoice); - }); - builder.create().show(); - break; - case ATTACHMENT_CHOICE_CHOOSE_FILE: - chooser = true; - intent.setType("*/*"); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setAction(Intent.ACTION_GET_CONTENT); - break; - case ATTACHMENT_CHOICE_RECORD_VOICE: - startActivityForResult(new Intent(getApplicationContext(), RecordingActivity.class), attachmentChoice); - break; - case ATTACHMENT_CHOICE_LOCATION: - startActivityForResult(new Intent(getApplicationContext(), ShareLocationActivity.class), attachmentChoice); - break; - } - if (intent.resolveActivity(getPackageManager()) != null) { - Log.d(Config.LOGTAG, "Attachment: " + attachmentChoice); - if (chooser) { - startActivityForResult( - Intent.createChooser(intent, getString(R.string.perform_action_with)), - attachmentChoice); - } else { - startActivityForResult(intent, attachmentChoice); - } - } else if (fallbackPackageId != null) { - startActivity(getInstallApkIntent(fallbackPackageId)); - } - }; - if ((account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) && encryption != Message.ENCRYPTION_OTR) { - conversation.setNextCounterpart(null); - callback.onPresenceSelected(); - } else { - selectPresence(conversation, callback); - } - } - - private Intent getInstallApkIntent(final String packageId) { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("market://details?id=" + packageId)); - if (intent.resolveActivity(getPackageManager()) != null) { - return intent; - } else { - intent.setData(Uri.parse("http://play.google.com/store/apps/details?id=" + packageId)); - return intent; - } - } - - public void attachFile(final int attachmentChoice) { - if (attachmentChoice != ATTACHMENT_CHOICE_LOCATION) { - if (!hasStoragePermission(attachmentChoice)) { - return; - } - } - if (attachmentChoice == ATTACHMENT_CHOICE_RECORD_VOICE) { - if (!hasMicPermission(attachmentChoice)) { - return; - } - } - if (attachmentChoice == ATTACHMENT_CHOICE_LOCATION) { - if (!hasLocationPermission(attachmentChoice)) { - return; - } - } - try { - getPreferences().edit() - .putString(RECENTLY_USED_QUICK_ACTION, SendButtonAction.of(attachmentChoice).toString()) - .apply(); - } catch (IllegalArgumentException e) { - //just do not save - } - final Conversation conversation = getSelectedConversation(); - final int encryption = conversation.getNextEncryption(); - final int mode = conversation.getMode(); - if (encryption == Message.ENCRYPTION_PGP) { - if (hasPgp()) { - if (mode == Conversation.MODE_SINGLE && conversation.getContact().getPgpKeyId() != 0) { - xmppConnectionService.getPgpEngine().hasKey( - conversation.getContact(), - new UiCallback<Contact>() { - - @Override - public void userInputRequried(PendingIntent pi, Contact contact) { - ConversationActivity.this.runIntent(pi, attachmentChoice); - } - - @Override - public void success(Contact contact) { - selectPresenceToAttachFile(attachmentChoice, encryption); - } - - @Override - public void error(int error, Contact contact) { - replaceToast(getString(error)); - } - }); - } else if (mode == Conversation.MODE_MULTI && conversation.getMucOptions().pgpKeysInUse()) { - if (!conversation.getMucOptions().everybodyHasKeys()) { - Toast warning = Toast - .makeText(this, - R.string.missing_public_keys, - Toast.LENGTH_LONG); - warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0); - warning.show(); - } - selectPresenceToAttachFile(attachmentChoice, encryption); - } else { - final ConversationFragment fragment = (ConversationFragment) getFragmentManager() - .findFragmentByTag("conversation"); - if (fragment != null) { - fragment.showNoPGPKeyDialog(false, - new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, - int which) { - conversation.setNextEncryption(Message.ENCRYPTION_NONE); - xmppConnectionService.updateConversation(conversation); - selectPresenceToAttachFile(attachmentChoice, Message.ENCRYPTION_NONE); - } - }); - } - } - } else { - showInstallPgpDialog(); - } - } else { - if (encryption != Message.ENCRYPTION_AXOLOTL || !trustKeysIfNeeded(REQUEST_TRUST_KEYS_MENU, attachmentChoice)) { - selectPresenceToAttachFile(attachmentChoice, encryption); - } - } - } - - @Override - public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { - if (grantResults.length > 0) - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - if (requestCode == REQUEST_START_DOWNLOAD) { - if (this.mPendingDownloadableMessage != null) { - startDownloadable(this.mPendingDownloadableMessage); - } - } else if (requestCode == REQUEST_ADD_EDITOR_CONTENT) { - if (this.mPendingEditorContent != null) { - attachImageToConversation(this.mPendingEditorContent); - } - } else { - attachFile(requestCode); - } - } else { - Toast.makeText(this, R.string.no_permission, Toast.LENGTH_SHORT).show(); - } - } - - public void startDownloadable(Message message) { - if (!hasStoragePermission(ConversationActivity.REQUEST_START_DOWNLOAD)) { - this.mPendingDownloadableMessage = message; - return; - } - Transferable transferable = message.getTransferable(); - if (transferable != null) { - if (!transferable.start()) { - Toast.makeText(this, R.string.not_connected_try_again, Toast.LENGTH_SHORT).show(); - } - } else if (message.treatAsDownloadable()) { - xmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message, true); - } - } - @Override public boolean onOptionsItemSelected(final MenuItem item) { if (item.getItemId() == android.R.id.home) { @@ -792,57 +424,6 @@ public class ConversationActivity extends XmppActivity } else if (item.getItemId() == R.id.action_add) { startActivity(new Intent(this, StartConversationActivity.class)); return true; - } else if (getSelectedConversation() != null) { - switch (item.getItemId()) { - case R.id.encryption_choice_axolotl: - case R.id.encryption_choice_otr: - case R.id.encryption_choice_pgp: - case R.id.encryption_choice_none: - handleEncryptionSelection(item); - break; - case R.id.attach_choose_picture: - case R.id.attach_take_picture: - case R.id.attach_choose_file: - case R.id.attach_record_voice: - case R.id.attach_location: - handleAttachmentSelection(item); - break; - case R.id.action_archive_chat: - this.endConversation(getSelectedConversation()); - break; - case R.id.action_archive_muc: - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(getString(R.string.action_end_conversation_muc)); - builder.setMessage(getString(R.string.leave_conference_warning)); - builder.setNegativeButton(getString(R.string.cancel), null); - builder.setPositiveButton(getString(R.string.action_end_conversation_muc), - new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - endConversation(getSelectedConversation()); - } - }); - builder.create().show(); - break; - case R.id.action_invite: - inviteToConversation(getSelectedConversation()); - break; - case R.id.action_clear_history: - clearHistoryDialog(getSelectedConversation()); - break; - case R.id.action_block: - BlockContactDialog.show(this, getSelectedConversation()); - break; - case R.id.action_unblock: - BlockContactDialog.show(this, getSelectedConversation()); - break; - case R.id.action_search_history: - mConversationFragment.showSearchField(); - break; - default: - break; - } - return super.onOptionsItemSelected(item); } else { return super.onOptionsItemSelected(item); } @@ -873,50 +454,6 @@ public class ConversationActivity extends XmppActivity } } - @SuppressLint("InflateParams") - protected void clearHistoryDialog(final Conversation conversation) { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(getString(R.string.clear_conversation_history)); - final View dialogView = getLayoutInflater().inflate(R.layout.dialog_clear_history, null); - final CheckBox endConversationCheckBox = dialogView.findViewById(R.id.end_conversation_checkbox); - if (conversation.getMode() == Conversation.MODE_SINGLE) { - endConversationCheckBox.setVisibility(View.VISIBLE); - endConversationCheckBox.setChecked(true); - } - builder.setView(dialogView); - builder.setNegativeButton(getString(R.string.cancel), null); - builder.setPositiveButton(getString(R.string.delete_messages), (dialog, which) -> { - ConversationActivity.this.xmppConnectionService.clearConversationHistory(conversation); - if (endConversationCheckBox.isChecked()) { - endConversation(conversation); - } else { - updateConversationList(); - ConversationActivity.this.mConversationFragment.updateMessages(); - } - }); - builder.create().show(); - } - - private void handleAttachmentSelection(MenuItem item) { - switch (item.getItemId()) { - case R.id.attach_choose_picture: - attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE); - break; - case R.id.attach_take_picture: - attachFile(ATTACHMENT_CHOICE_TAKE_FROM_CAMERA); - break; - case R.id.attach_choose_file: - attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE); - break; - case R.id.attach_record_voice: - attachFile(ATTACHMENT_CHOICE_RECORD_VOICE); - break; - case R.id.attach_location: - attachFile(ATTACHMENT_CHOICE_LOCATION); - break; - } - } - public void verifyOtrSessionDialog(final Conversation conversation, View view) { if (!conversation.hasValidOtrSession() || conversation.getOtrSession().getSessionStatus() != SessionStatus.ENCRYPTED) { Toast.makeText(this, R.string.otr_session_not_started, Toast.LENGTH_LONG).show(); @@ -952,49 +489,6 @@ public class ConversationActivity extends XmppActivity popup.show(); } - private void handleEncryptionSelection(MenuItem item) { - Conversation conversation = getSelectedConversation(); - if (conversation == null) { - return; - } - final ConversationFragment fragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation"); - switch (item.getItemId()) { - case R.id.encryption_choice_none: - conversation.setNextEncryption(Message.ENCRYPTION_NONE); - item.setChecked(true); - break; - case R.id.encryption_choice_otr: - conversation.setNextEncryption(Message.ENCRYPTION_OTR); - item.setChecked(true); - break; - case R.id.encryption_choice_pgp: - if (hasPgp()) { - if (conversation.getAccount().getPgpSignature() != null) { - conversation.setNextEncryption(Message.ENCRYPTION_PGP); - item.setChecked(true); - } else { - announcePgp(conversation.getAccount(), conversation, null, onOpenPGPKeyPublished); - } - } else { - showInstallPgpDialog(); - } - break; - case R.id.encryption_choice_axolotl: - Log.d(Config.LOGTAG, AxolotlService.getLogprefix(conversation.getAccount()) - + "Enabled axolotl for Contact " + conversation.getContact().getJid()); - conversation.setNextEncryption(Message.ENCRYPTION_AXOLOTL); - item.setChecked(true); - break; - default: - conversation.setNextEncryption(Message.ENCRYPTION_NONE); - break; - } - xmppConnectionService.updateConversation(conversation); - fragment.updateChatMsgHint(); - invalidateOptionsMenu(); - refreshUi(); - } - @Override public void onBackPressed() { if (!isConversationsOverviewVisable() && mConversationFragment.isSearchFieldVisible()) { @@ -1189,7 +683,7 @@ public class ConversationActivity extends XmppActivity savedInstanceState.remove(STATE_OPEN_CONVERSATION); } savedInstanceState.putBoolean(STATE_PANEL_OPEN, isConversationsOverviewVisable()); - if (this.mPendingImageUris.size() >= 1) { + /*if (this.mPendingImageUris.size() >= 1) { Log.d(Config.LOGTAG, "ConversationActivity.onSaveInstanceState() - saving pending image uri"); savedInstanceState.putString(STATE_PENDING_IMAGE_URI, this.mPendingImageUris.get(0).toString()); } else if (this.mPendingPhotoUris.size() >= 1) { @@ -1197,16 +691,12 @@ public class ConversationActivity extends XmppActivity } else { savedInstanceState.remove(STATE_PENDING_IMAGE_URI); savedInstanceState.remove(STATE_PENDING_PHOTO_URI); - } + }*/ super.onSaveInstanceState(savedInstanceState); } private void clearPending() { - mPendingImageUris.clear(); - mPendingFileUris.clear(); - mPendingPhotoUris.clear(); - mPendingGeoUri = null; - mPostponedActivityResult = null; + mConversationFragment.clearPending(); } private void redirectToStartConversationActivity(boolean noAnimation) { @@ -1325,42 +815,7 @@ public class ConversationActivity extends XmppActivity } } - if (this.mPostponedActivityResult != null) { - this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second); - } - - final boolean stopping = isStopping(); - - if (!forbidProcessingPendings) { - int ImageUrisCount = mPendingImageUris.size(); - if (ImageUrisCount == 1) { - Uri uri = mPendingImageUris.get(0); - Log.d(Config.LOGTAG, "ConversationActivity.onBackendConnected() - attaching image to conversations. stopping=" + Boolean.toString(stopping)); - attachImageToConversation(getSelectedConversation(), uri, false); - } else { - for (Iterator<Uri> i = mPendingImageUris.iterator(); i.hasNext(); i.remove()) { - Uri foo = i.next(); - Log.d(Config.LOGTAG, "ConversationActivity.onBackendConnected() - attaching images to conversations. stopping=" + Boolean.toString(stopping)); - attachImagesToConversation(getSelectedConversation(), foo); - } - } - - for (Iterator<Uri> i = mPendingPhotoUris.iterator(); i.hasNext(); i.remove()) { - Log.d(Config.LOGTAG, "ConversationActivity.onBackendConnected() - attaching photo to conversations. stopping=" + Boolean.toString(stopping)); - attachPhotoToConversation(getSelectedConversation(), i.next()); - } - - for (Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) { - Log.d(Config.LOGTAG, "ConversationActivity.onBackendConnected() - attaching file to conversations. stopping=" + Boolean.toString(stopping)); - attachFileToConversation(getSelectedConversation(), i.next()); - } - - if (mPendingGeoUri != null) { - attachLocationToConversation(getSelectedConversation(), mPendingGeoUri); - mPendingGeoUri = null; - } - } - forbidProcessingPendings = false; + mConversationFragment.onBackendConnected(); if (!ExceptionHelper.checkForCrash(this, this.xmppConnectionService) && !mRedirected.get()) { openBatteryOptimizationDialogIfNeeded(); @@ -1421,11 +876,12 @@ public class ConversationActivity extends XmppActivity if (downloadUuid != null) { final Message message = mSelectedConversation.findMessageWithFileAndUuid(downloadUuid); if (message != null) { - startDownloadable(message); + //startDownloadable(message); } - } else { - mUnprocessedNewIntent = false; } + } else { + mUnprocessedNewIntent = false; + } } @@ -1448,146 +904,17 @@ public class ConversationActivity extends XmppActivity xmppConnectionService.getNotificationService().setOpenConversation(null); } - @SuppressLint("NewApi") - private static List<Uri> extractUriFromIntent(final Intent intent) { - List<Uri> uris = new ArrayList<>(); - if (intent == null) { - return uris; - } - Uri uri = intent.getData(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && uri == null) { - final ClipData clipData = intent.getClipData(); - if (clipData != null) { - for (int i = 0; i < clipData.getItemCount(); ++i) { - uris.add(clipData.getItemAt(i).getUri()); - } - } - } else { - uris.add(uri); - } - return uris; - } - @Override protected void onActivityResult(final int requestCode, int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (resultCode == RESULT_OK) { - if (requestCode == REQUEST_DECRYPT_PGP) { - mConversationFragment.onActivityResult(requestCode, resultCode, data); - } else if (requestCode == REQUEST_CHOOSE_PGP_ID) { - // the user chose OpenPGP for encryption and selected his key in the PGP provider - if (xmppConnectionServiceBound) { - if (data.getExtras().containsKey(OpenPgpApi.EXTRA_SIGN_KEY_ID)) { - // associate selected PGP keyId with the account - mSelectedConversation.getAccount().setPgpSignId(data.getExtras().getLong(OpenPgpApi.EXTRA_SIGN_KEY_ID)); - // we need to announce the key as described in XEP-027 - announcePgp(mSelectedConversation.getAccount(), null, null, onOpenPGPKeyPublished); - } else { - choosePgpSignId(mSelectedConversation.getAccount()); - } - this.mPostponedActivityResult = null; - } else { - this.mPostponedActivityResult = new Pair<>(requestCode, data); - } - } else if (requestCode == REQUEST_ANNOUNCE_PGP) { - if (xmppConnectionServiceBound) { - announcePgp(mSelectedConversation.getAccount(), mSelectedConversation, data, onOpenPGPKeyPublished); - this.mPostponedActivityResult = null; - } else { - this.mPostponedActivityResult = new Pair<>(requestCode, data); - } - } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) { - mPendingImageUris.clear(); - mPendingImageUris.addAll(extractUriFromIntent(data)); - int ImageUrisCount = mPendingImageUris.size(); - if (xmppConnectionServiceBound) { - if (ImageUrisCount == 1) { - Uri uri = mPendingImageUris.get(0); - Log.d(Config.LOGTAG, "ConversationActivity.onActivityResult() - attaching image to conversations. CHOOSE_IMAGE"); - attachImageToConversation(getSelectedConversation(), uri, false); - } else { - for (Iterator<Uri> i = mPendingImageUris.iterator(); i.hasNext(); i.remove()) { - Log.d(Config.LOGTAG, "ConversationActivity.onActivityResult() - attaching images to conversations. CHOOSE_IMAGES"); - attachImagesToConversation(getSelectedConversation(), i.next()); - } - } - } - } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_FILE - || requestCode == ATTACHMENT_CHOICE_RECORD_VOICE - || requestCode == ATTACHMENT_CHOICE_CHOOSE_VIDEO - || requestCode == ATTACHMENT_CHOICE_TAKE_FROM_CAMERA) { - final List<Uri> uris = extractUriFromIntent(data); - final Conversation c = getSelectedConversation(); - final OnPresenceSelected callback = new OnPresenceSelected() { - @Override - public void onPresenceSelected() { - mPendingFileUris.clear(); - mPendingFileUris.addAll(uris); - if (xmppConnectionServiceBound) { - for (Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) { - if (requestCode == ATTACHMENT_CHOICE_TAKE_FROM_CAMERA && getMimeType(i.next().toString()).contains("image")) { - return; - } - Log.d(Config.LOGTAG, "ConversationActivity.onActivityResult() - attaching file to conversations. CHOOSE_FILE/RECORD_VOICE"); - attachFileToConversation(c, i.next()); - } - } - } - }; - if (c == null || c.getMode() == Conversation.MODE_MULTI - || FileBackend.allFilesUnderSize(this, uris, getMaxHttpUploadSize(c)) - || c.getNextEncryption() == Message.ENCRYPTION_OTR) { - callback.onPresenceSelected(); - } else { - selectPresence(c, callback); - } - } else if (requestCode == ATTACHMENT_CHOICE_TAKE_FROM_CAMERA) { - if (mPendingPhotoUris.size() == 1) { - Uri uri = FileBackend.getIndexableTakePhotoUri(mPendingPhotoUris.get(0)); - mPendingPhotoUris.set(0, uri); - if (xmppConnectionServiceBound) { - Log.d(Config.LOGTAG, "ConversationActivity.onActivityResult() - attaching photo to conversations. TAKE_FROM_CAMERA"); - attachPhotoToConversation(getSelectedConversation(), uri); - mPendingPhotoUris.clear(); - } - Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); - intent.setData(uri); - sendBroadcast(intent); - } else { - mPendingPhotoUris.clear(); - } - } else if (requestCode == ATTACHMENT_CHOICE_LOCATION) { - double latitude = data.getDoubleExtra("latitude", 0); - double longitude = data.getDoubleExtra("longitude", 0); - this.mPendingGeoUri = Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude)); - if (xmppConnectionServiceBound) { - attachLocationToConversation(getSelectedConversation(), mPendingGeoUri); - this.mPendingGeoUri = null; - } - } else if (requestCode == REQUEST_TRUST_KEYS_TEXT || requestCode == REQUEST_TRUST_KEYS_MENU) { - this.forbidProcessingPendings = true; - if (xmppConnectionServiceBound) { - mConversationFragment.onActivityResult(requestCode, resultCode, data); - this.mPostponedActivityResult = null; - } else { - this.mPostponedActivityResult = new Pair<>(requestCode, data); - } - - } - } else { - mPendingImageUris.clear(); - mPendingFileUris.clear(); - mPendingPhotoUris.clear(); - if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) { - mConversationFragment.onActivityResult(requestCode, resultCode, data); - } + if (resultCode != RESULT_OK) { if (requestCode == REQUEST_BATTERY_OP) { setNeverAskForBatteryOptimizationsAgain(); } } } - private long getMaxHttpUploadSize(Conversation conversation) { + public long getMaxHttpUploadSize(Conversation conversation) { final XmppConnection connection = conversation.getAccount().getXmppConnection(); return connection == null ? -1 : connection.getFeatures().getMaxHttpUploadSize(); } @@ -1634,263 +961,6 @@ public class ConversationActivity extends XmppActivity return false; } - private void attachLocationToConversation(Conversation conversation, Uri uri) { - if (conversation == null) { - return; - } - xmppConnectionService.attachLocationToConversation(conversation, uri, new UiCallback<Message>() { - - @Override - public void success(Message message) { - xmppConnectionService.sendMessage(message); - } - - @Override - public void error(int errorCode, Message object) { - - } - - @Override - public void userInputRequried(PendingIntent pi, Message object) { - - } - }); - } - - private void attachFileToConversation(Conversation conversation, Uri uri) { - if (conversation == null) { - return; - } - final Toast prepareFileToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_file), Toast.LENGTH_LONG); - prepareFileToast.show(); - delegateUriPermissionsToService(uri); - xmppConnectionService.attachFileToConversation(conversation, uri, new UiInformableCallback<Message>() { - @Override - public void inform(final String text) { - hidePrepareFileToast(prepareFileToast); - runOnUiThread(() -> replaceToast(text)); - } - - @Override - public void success(Message message) { - runOnUiThread(() -> hideToast()); - hidePrepareFileToast(prepareFileToast); - xmppConnectionService.sendMessage(message); - } - - @Override - public void error(final int errorCode, Message message) { - hidePrepareFileToast(prepareFileToast); - runOnUiThread(() -> replaceToast(getString(errorCode))); - - } - - @Override - public void userInputRequried(PendingIntent pi, Message message) { - hidePrepareFileToast(prepareFileToast); - } - }); - } - - private void attachPhotoToConversation(Conversation conversation, Uri uri) { - if (conversation == null) { - return; - } - final Toast prepareFileToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG); - prepareFileToast.show(); - delegateUriPermissionsToService(uri); - xmppConnectionService.attachImageToConversation(conversation, uri, - new UiCallback<Message>() { - - @Override - public void userInputRequried(PendingIntent pi, Message object) { - hidePrepareFileToast(prepareFileToast); - } - - @Override - public void success(Message message) { - hidePrepareFileToast(prepareFileToast); - xmppConnectionService.sendMessage(message); - } - - @Override - public void error(final int error, Message message) { - hidePrepareFileToast(prepareFileToast); - runOnUiThread(new Runnable() { - @Override - public void run() { - replaceToast(getString(error)); - } - }); - } - }); - } - - private void attachImagesToConversation(Conversation conversation, Uri uri) { - if (conversation == null) { - return; - } - final Toast prepareFileToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG); - prepareFileToast.show(); - delegateUriPermissionsToService(uri); - xmppConnectionService.attachImageToConversation(conversation, uri, - new UiCallback<Message>() { - - @Override - public void userInputRequried(PendingIntent pi, Message object) { - hidePrepareFileToast(prepareFileToast); - } - - @Override - public void success(Message message) { - hidePrepareFileToast(prepareFileToast); - xmppConnectionService.sendMessage(message); - } - - @Override - public void error(final int error, Message message) { - hidePrepareFileToast(prepareFileToast); - runOnUiThread(new Runnable() { - @Override - public void run() { - replaceToast(getString(error)); - } - }); - } - }); - } - - public void attachImageToConversation(Uri uri) { - this.attachImageToConversation(getSelectedConversation(), uri, true); - } - - private void attachImageToConversation(Conversation conversation, Uri uri, boolean sendAsIs) { - if (conversation == null) { - return; - } - if (sendAsIs) { - sendImage(conversation, uri); - return; - } - final Conversation conversation_preview = conversation; - final Uri uri_preview = uri; - Bitmap bitmap = BitmapFactory.decodeFile(FileUtils.getPath(this, uri)); - File file = null; - ExifInterface exif = null; - int orientation = 0; - try { - file = new File(FileUtils.getPath(this, uri)); - } catch (Exception e) { - e.printStackTrace(); - } - if (file != null) { - try { - exif = new ExifInterface(file.toString()); - } catch (IOException e) { - e.printStackTrace(); - } - orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); - } - Log.d(Config.LOGTAG, "EXIF: " + orientation); - Bitmap rotated_image = null; - Log.d(Config.LOGTAG, "Rotate image"); - rotated_image = FileBackend.rotateBitmap(file, bitmap, orientation); - if (rotated_image != null) { - int scaleSize = 600; - int originalWidth = rotated_image.getWidth(); - int originalHeight = rotated_image.getHeight(); - int newWidth = -1; - int newHeight = -1; - float multFactor; - if (originalHeight > originalWidth) { - newHeight = scaleSize; - multFactor = (float) originalWidth / (float) originalHeight; - newWidth = (int) (newHeight * multFactor); - } else if (originalWidth > originalHeight) { - newWidth = scaleSize; - multFactor = (float) originalHeight / (float) originalWidth; - newHeight = (int) (newWidth * multFactor); - } else if (originalHeight == originalWidth) { - newHeight = scaleSize; - newWidth = scaleSize; - } - Log.d(Config.LOGTAG, "Scaling preview image from " + originalHeight + "px x " + originalWidth + "px to " + newHeight + "px x " + newWidth + "px"); - Bitmap preview = Bitmap.createScaledBitmap(rotated_image, newWidth, newHeight, false); - ImageView ImagePreview = new ImageView(this); - LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); - ImagePreview.setLayoutParams(vp); - ImagePreview.setMaxWidth(newWidth); - ImagePreview.setMaxHeight(newHeight); - //ImagePreview.setScaleType(ImageView.ScaleType.FIT_XY); - //ImagePreview.setAdjustViewBounds(true); - ImagePreview.setPadding(5, 5, 5, 5); - ImagePreview.setImageBitmap(preview); - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setView(ImagePreview); - builder.setTitle(R.string.send_image); - builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(final DialogInterface dialog, final int which) { - sendImage(conversation_preview, uri_preview); - } - }); - builder.setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - mPendingImageUris.clear(); - } - }); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - builder.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - mPendingImageUris.clear(); - } - }); - } - AlertDialog alertDialog = builder.create(); - alertDialog.show(); - } else { - Toast.makeText(getApplicationContext(), getText(R.string.error_file_not_found), Toast.LENGTH_LONG).show(); - } - } - - private void sendImage(Conversation conversation, Uri uri) { - final Toast prepareFileToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG); - prepareFileToast.show(); - xmppConnectionService.attachImageToConversation(conversation, uri, - new UiCallback<Message>() { - - @Override - public void userInputRequried(PendingIntent pi, Message object) { - hidePrepareFileToast(prepareFileToast); - } - - @Override - public void success(Message message) { - hidePrepareFileToast(prepareFileToast); - xmppConnectionService.sendMessage(message); - } - - @Override - public void error(final int error, Message message) { - hidePrepareFileToast(prepareFileToast); - runOnUiThread(new Runnable() { - @Override - public void run() { - replaceToast(getString(error)); - } - }); - } - }); - } - - private void hidePrepareFileToast(final Toast prepareFileToast) { - if (prepareFileToast != null) { - runOnUiThread(() -> prepareFileToast.cancel()); - } - } - public void updateConversationList() { xmppConnectionService.populateWithOrderedConversations(conversationList); if (!conversationList.contains(mSelectedConversation)) { @@ -1912,43 +982,6 @@ public class ConversationActivity extends XmppActivity } } - public void encryptTextMessage(Message message) { - xmppConnectionService.getPgpEngine().encrypt(message, - new UiCallback<Message>() { - - @Override - public void userInputRequried(PendingIntent pi, Message message) { - ConversationActivity.this.runIntent(pi, ConversationActivity.REQUEST_SEND_MESSAGE); - } - - @Override - public void success(Message message) { - message.setEncryption(Message.ENCRYPTION_DECRYPTED); - xmppConnectionService.sendMessage(message); - runOnUiThread(new Runnable() { - @Override - public void run() { - mConversationFragment.messageSent(); - } - }); - } - - @Override - public void error(final int error, Message message) { - runOnUiThread(new Runnable() { - @Override - public void run() { - mConversationFragment.doneSendingPgpMessage(); - Toast.makeText(ConversationActivity.this, - R.string.unable_to_connect_to_keychain, - Toast.LENGTH_SHORT - ).show(); - } - }); - } - }); - } - public boolean useSendButtonToIndicateStatus() { return getPreferences().getBoolean("send_button_status", getResources().getBoolean(R.bool.send_button_status)); } @@ -1965,36 +998,6 @@ public class ConversationActivity extends XmppActivity return getPreferences().getBoolean(USE_BUNDLED_EMOJIS, getResources().getBoolean(R.bool.use_bundled_emoji)); } - protected boolean trustKeysIfNeeded(int requestCode) { - return trustKeysIfNeeded(requestCode, ATTACHMENT_CHOICE_INVALID); - } - - protected boolean trustKeysIfNeeded(int requestCode, int attachmentChoice) { - AxolotlService axolotlService = mSelectedConversation.getAccount().getAxolotlService(); - final List<Jid> targets = axolotlService.getCryptoTargets(mSelectedConversation); - boolean hasUnaccepted = !mSelectedConversation.getAcceptedCryptoTargets().containsAll(targets); - boolean hasUndecidedOwn = !axolotlService.getKeysWithTrust(FingerprintStatus.createActiveUndecided()).isEmpty(); - boolean hasUndecidedContacts = !axolotlService.getKeysWithTrust(FingerprintStatus.createActiveUndecided(), targets).isEmpty(); - boolean hasPendingKeys = !axolotlService.findDevicesWithoutSession(mSelectedConversation).isEmpty(); - boolean hasNoTrustedKeys = axolotlService.anyTargetHasNoTrustedKeys(targets); - if (hasUndecidedOwn || hasUndecidedContacts || hasPendingKeys || hasNoTrustedKeys || hasUnaccepted) { - axolotlService.createSessionsIfNeeded(mSelectedConversation); - Intent intent = new Intent(getApplicationContext(), TrustKeysActivity.class); - String[] contacts = new String[targets.size()]; - for (int i = 0; i < contacts.length; ++i) { - contacts[i] = targets.get(i).toString(); - } - intent.putExtra("contacts", contacts); - intent.putExtra(EXTRA_ACCOUNT, mSelectedConversation.getAccount().getJid().toBareJid().toString()); - intent.putExtra("choice", attachmentChoice); - intent.putExtra("conversation", mSelectedConversation.getUuid()); - startActivityForResult(intent, requestCode); - return true; - } else { - return false; - } - } - @Override protected void refreshUiReal() { updateConversationList(); @@ -2037,10 +1040,6 @@ public class ConversationActivity extends XmppActivity this.refreshUi(); } - public void unblockConversation(final Blockable conversation) { - xmppConnectionService.sendUnblockRequest(conversation); - } - public boolean enterIsSend() { return getPreferences().getBoolean("enter_is_send", getResources().getBoolean(R.bool.enter_is_send)); } |