diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/ConversationActivity.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/ConversationActivity.java | 139 |
1 files changed, 79 insertions, 60 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index d02a7c7b6..5dccde184 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -52,13 +52,14 @@ public class ConversationActivity extends XmppActivity implements public static final int REQUEST_SEND_MESSAGE = 0x0201; public static final int REQUEST_DECRYPT_PGP = 0x0202; public static final int REQUEST_ENCRYPT_MESSAGE = 0x0207; - private static final int REQUEST_ATTACH_FILE_DIALOG = 0x0203; + private static final int REQUEST_ATTACH_IMAGE_DIALOG = 0x0203; private static final int REQUEST_IMAGE_CAPTURE = 0x0204; private static final int REQUEST_RECORD_AUDIO = 0x0205; private static final int REQUEST_SEND_PGP_IMAGE = 0x0206; + private static final int REQUEST_ATTACH_FILE_DIALOG = 0x0208; private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301; private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302; - private static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0303; + private static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303; 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_URI = "state_pending_uri"; @@ -66,17 +67,18 @@ public class ConversationActivity extends XmppActivity implements private String mOpenConverstaion = null; private boolean mPanelOpen = true; private Uri mPendingImageUri = null; + private Uri mPendingFileUri = null; private View mContentView; - private List<Conversation> conversationList = new ArrayList<Conversation>(); + private List<Conversation> conversationList = new ArrayList<>(); private Conversation selectedConversation = null; private ListView listView; private ConversationFragment mConversationFragment; private ArrayAdapter<Conversation> listAdapter; - private Toast prepareImageToast; + private Toast prepareFileToast; public List<Conversation> getConversationList() { @@ -106,7 +108,7 @@ public class ConversationActivity extends XmppActivity implements protected String getShareableUri() { Conversation conversation = getSelectedConversation(); if (conversation != null) { - return "xmpp:" + conversation.getAccount().getJid(); + return conversation.getAccount().getShareableUri(); } else { return ""; } @@ -160,8 +162,10 @@ public class ConversationActivity extends XmppActivity implements this.listAdapter = new ConversationAdapter(this, conversationList); listView.setAdapter(this.listAdapter); - getActionBar().setDisplayHomeAsUpEnabled(false); - getActionBar().setHomeButtonEnabled(false); + if (getActionBar() != null) { + getActionBar().setDisplayHomeAsUpEnabled(false); + getActionBar().setHomeButtonEnabled(false); + } listView.setOnItemClickListener(new OnItemClickListener() { @@ -228,8 +232,7 @@ public class ConversationActivity extends XmppActivity implements .useSubjectToIdentifyConference()) { ab.setTitle(getSelectedConversation().getName()); } else { - ab.setTitle(getSelectedConversation().getContactJid() - .split("/")[0]); + ab.setTitle(getSelectedConversation().getContactJid().toBareJid().toString()); } } invalidateOptionsMenu(); @@ -307,11 +310,16 @@ public class ConversationActivity extends XmppActivity implements attachFileIntent.setAction(Intent.ACTION_GET_CONTENT); Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file)); + startActivityForResult(chooser, REQUEST_ATTACH_IMAGE_DIALOG); + } else if (attachmentChoice == ATTACHMENT_CHOICE_CHOOSE_FILE) { + Intent attachFileIntent = new Intent(); + //attachFileIntent.setType("file/*"); + attachFileIntent.setType("*/*"); + attachFileIntent.addCategory(Intent.CATEGORY_OPENABLE); + attachFileIntent.setAction(Intent.ACTION_GET_CONTENT); + Intent chooser = Intent.createChooser(attachFileIntent, + getString(R.string.attach_file)); startActivityForResult(chooser, REQUEST_ATTACH_FILE_DIALOG); - } else if (attachmentChoice == ATTACHMENT_CHOICE_RECORD_VOICE) { - Intent intent = new Intent( - MediaStore.Audio.Media.RECORD_SOUND_ACTION); - startActivityForResult(intent, REQUEST_RECORD_AUDIO); } } }); @@ -482,7 +490,7 @@ public class ConversationActivity extends XmppActivity implements attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO); break; case R.id.attach_record_voice: - attachFile(ATTACHMENT_CHOICE_RECORD_VOICE); + attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE); break; } return false; @@ -600,7 +608,7 @@ public class ConversationActivity extends XmppActivity implements } @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { + public boolean onKeyDown(final int keyCode, final KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (!isConversationsOverviewVisable()) { showConversationsOverview(); @@ -611,7 +619,7 @@ public class ConversationActivity extends XmppActivity implements } @Override - protected void onNewIntent(Intent intent) { + protected void onNewIntent(final Intent intent) { if (xmppConnectionServiceBound) { if (intent != null && VIEW_CONVERSATION.equals(intent.getType())) { handleViewConversationIntent(intent); @@ -633,19 +641,7 @@ public class ConversationActivity extends XmppActivity implements } @Override - protected void onStop() { - if (xmppConnectionServiceBound) { - xmppConnectionService.removeOnConversationListChangedListener(); - xmppConnectionService.removeOnAccountListChangedListener(); - xmppConnectionService.removeOnRosterUpdateListener(); - xmppConnectionService.getNotificationService().setOpenConversation( - null); - } - super.onStop(); - } - - @Override - public void onSaveInstanceState(Bundle savedInstanceState) { + public void onSaveInstanceState(final Bundle savedInstanceState) { Conversation conversation = getSelectedConversation(); if (conversation != null) { savedInstanceState.putString(STATE_OPEN_CONVERSATION, @@ -661,9 +657,7 @@ public class ConversationActivity extends XmppActivity implements @Override void onBackendConnected() { - this.registerListener(); updateConversationList(); - if (xmppConnectionService.getAccounts().size() == 0) { startActivity(new Intent(this, EditAccountActivity.class)); } else if (conversationList.size() <= 0) { @@ -688,14 +682,17 @@ public class ConversationActivity extends XmppActivity implements } else { showConversationsOverview(); mPendingImageUri = null; + mPendingFileUri = null; setSelectedConversation(conversationList.get(0)); this.mConversationFragment.reInit(getSelectedConversation()); } if (mPendingImageUri != null) { - attachImageToConversation(getSelectedConversation(), - mPendingImageUri); + attachImageToConversation(getSelectedConversation(),mPendingImageUri); mPendingImageUri = null; + } else if (mPendingFileUri != null) { + attachFileToConversation(getSelectedConversation(),mPendingFileUri); + mPendingFileUri = null; } ExceptionHelper.checkForCrash(this, this.xmppConnectionService); setIntent(new Intent()); @@ -714,17 +711,17 @@ public class ConversationActivity extends XmppActivity implements } private void selectConversationByUuid(String uuid) { - for (int i = 0; i < conversationList.size(); ++i) { - if (conversationList.get(i).getUuid().equals(uuid)) { - setSelectedConversation(conversationList.get(i)); - } - } + for (Conversation aConversationList : conversationList) { + if (aConversationList.getUuid().equals(uuid)) { + setSelectedConversation(aConversationList); + } + } } - public void registerListener() { - xmppConnectionService.setOnConversationListChangedListener(this); - xmppConnectionService.setOnAccountListChangedListener(this); - xmppConnectionService.setOnRosterUpdateListener(this); + @Override + protected void unregisterListeners() { + super.unregisterListeners(); + xmppConnectionService.getNotificationService().setOpenConversation(null); } @Override @@ -739,13 +736,20 @@ public class ConversationActivity extends XmppActivity implements selectedFragment.hideSnackbar(); selectedFragment.updateMessages(); } - } else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) { + } else if (requestCode == REQUEST_ATTACH_IMAGE_DIALOG) { mPendingImageUri = data.getData(); if (xmppConnectionServiceBound) { attachImageToConversation(getSelectedConversation(), mPendingImageUri); mPendingImageUri = null; } + } else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) { + mPendingFileUri = data.getData(); + if (xmppConnectionServiceBound) { + attachFileToConversation(getSelectedConversation(), + mPendingFileUri); + mPendingFileUri = null; + } } else if (requestCode == REQUEST_SEND_PGP_IMAGE) { } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) { @@ -767,9 +771,6 @@ public class ConversationActivity extends XmppActivity implements Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); intent.setData(mPendingImageUri); sendBroadcast(intent); - } else if (requestCode == REQUEST_RECORD_AUDIO) { - attachAudioToConversation(getSelectedConversation(), - data.getData()); } } else { if (requestCode == REQUEST_IMAGE_CAPTURE) { @@ -778,21 +779,40 @@ public class ConversationActivity extends XmppActivity implements } } - private void attachAudioToConversation(Conversation conversation, Uri uri) { + private void attachFileToConversation(Conversation conversation, Uri uri) { + prepareFileToast = Toast.makeText(getApplicationContext(), + getText(R.string.preparing_file), Toast.LENGTH_LONG); + prepareFileToast.show(); + xmppConnectionService.attachFileToConversation(conversation,uri, new UiCallback<Message>() { + @Override + public void success(Message message) { + hidePrepareFileToast(); + xmppConnectionService.sendMessage(message); + } + + @Override + public void error(int errorCode, Message message) { + displayErrorDialog(errorCode); + } + + @Override + public void userInputRequried(PendingIntent pi, Message message) { + } + }); } private void attachImageToConversation(Conversation conversation, Uri uri) { - prepareImageToast = Toast.makeText(getApplicationContext(), + prepareFileToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG); - prepareImageToast.show(); + prepareFileToast.show(); xmppConnectionService.attachImageToConversation(conversation, uri, new UiCallback<Message>() { @Override public void userInputRequried(PendingIntent pi, Message object) { - hidePrepareImageToast(); + hidePrepareFileToast(); ConversationActivity.this.runIntent(pi, ConversationActivity.REQUEST_SEND_PGP_IMAGE); } @@ -804,19 +824,19 @@ public class ConversationActivity extends XmppActivity implements @Override public void error(int error, Message message) { - hidePrepareImageToast(); + hidePrepareFileToast(); displayErrorDialog(error); } }); } - private void hidePrepareImageToast() { - if (prepareImageToast != null) { + private void hidePrepareFileToast() { + if (prepareFileToast != null) { runOnUiThread(new Runnable() { @Override public void run() { - prepareImageToast.cancel(); + prepareFileToast.cancel(); } }); } @@ -832,7 +852,7 @@ public class ConversationActivity extends XmppActivity implements try { this.startIntentSenderForResult(pi.getIntentSender(), requestCode, null, 0, 0, 0); - } catch (SendIntentException e1) { + } catch (final SendIntentException ignored) { } } @@ -895,12 +915,11 @@ public class ConversationActivity extends XmppActivity implements public void run() { updateConversationList(); if (conversationList.size() == 0) { - startActivity(new Intent(getApplicationContext(), - StartConversationActivity.class)); - finish(); - } else { - ConversationActivity.this.mConversationFragment.updateMessages(); + startActivity(new Intent(getApplicationContext(), + StartConversationActivity.class)); + finish(); } + ConversationActivity.this.mConversationFragment.updateMessages(); } }); } |