1package eu.siacs.conversations.ui;
2
3import android.annotation.SuppressLint;
4import android.app.ActionBar;
5import android.app.AlertDialog;
6import android.app.FragmentTransaction;
7import android.app.PendingIntent;
8import android.content.ClipData;
9import android.content.DialogInterface;
10import android.content.DialogInterface.OnClickListener;
11import android.content.Intent;
12import android.content.IntentSender.SendIntentException;
13import android.net.Uri;
14import android.os.Build;
15import android.os.Bundle;
16import android.provider.MediaStore;
17import android.support.v4.widget.SlidingPaneLayout;
18import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
19import android.util.Log;
20import android.view.Menu;
21import android.view.MenuItem;
22import android.view.View;
23import android.widget.AdapterView;
24import android.widget.AdapterView.OnItemClickListener;
25import android.widget.ArrayAdapter;
26import android.widget.CheckBox;
27import android.widget.PopupMenu;
28import android.widget.PopupMenu.OnMenuItemClickListener;
29import android.widget.Toast;
30
31import net.java.otr4j.session.SessionStatus;
32
33import java.util.ArrayList;
34import java.util.Iterator;
35import java.util.List;
36
37import de.timroes.android.listview.EnhancedListView;
38import eu.siacs.conversations.Config;
39import eu.siacs.conversations.R;
40import eu.siacs.conversations.crypto.axolotl.AxolotlService;
41import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
42import eu.siacs.conversations.entities.Account;
43import eu.siacs.conversations.entities.Blockable;
44import eu.siacs.conversations.entities.Contact;
45import eu.siacs.conversations.entities.Conversation;
46import eu.siacs.conversations.entities.Message;
47import eu.siacs.conversations.services.XmppConnectionService;
48import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
49import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
50import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
51import eu.siacs.conversations.ui.adapter.ConversationAdapter;
52import eu.siacs.conversations.utils.ExceptionHelper;
53import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
54import eu.siacs.conversations.xmpp.jid.InvalidJidException;
55import eu.siacs.conversations.xmpp.jid.Jid;
56
57public class ConversationActivity extends XmppActivity
58 implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
59
60 public static final String ACTION_DOWNLOAD = "eu.siacs.conversations.action.DOWNLOAD";
61
62 public static final String VIEW_CONVERSATION = "viewConversation";
63 public static final String CONVERSATION = "conversationUuid";
64 public static final String MESSAGE = "messageUuid";
65 public static final String TEXT = "text";
66 public static final String NICK = "nick";
67 public static final String PRIVATE_MESSAGE = "pm";
68
69 public static final int REQUEST_SEND_MESSAGE = 0x0201;
70 public static final int REQUEST_DECRYPT_PGP = 0x0202;
71 public static final int REQUEST_ENCRYPT_MESSAGE = 0x0207;
72 public static final int REQUEST_TRUST_KEYS_TEXT = 0x0208;
73 public static final int REQUEST_TRUST_KEYS_MENU = 0x0209;
74 public static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301;
75 public static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302;
76 public static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303;
77 public static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0304;
78 public static final int ATTACHMENT_CHOICE_LOCATION = 0x0305;
79 public static final int ATTACHMENT_CHOICE_INVALID = 0x0306;
80 private static final String STATE_OPEN_CONVERSATION = "state_open_conversation";
81 private static final String STATE_PANEL_OPEN = "state_panel_open";
82 private static final String STATE_PENDING_URI = "state_pending_uri";
83
84 private String mOpenConverstaion = null;
85 private boolean mPanelOpen = true;
86 final private List<Uri> mPendingImageUris = new ArrayList<>();
87 final private List<Uri> mPendingFileUris = new ArrayList<>();
88 private Uri mPendingGeoUri = null;
89 private boolean forbidProcessingPendings = false;
90
91 private View mContentView;
92
93 private List<Conversation> conversationList = new ArrayList<>();
94 private Conversation swipedConversation = null;
95 private Conversation mSelectedConversation = null;
96 private EnhancedListView listView;
97 private ConversationFragment mConversationFragment;
98
99 private ArrayAdapter<Conversation> listAdapter;
100
101 private Toast prepareFileToast;
102
103 private boolean mActivityPaused = false;
104 private boolean mRedirected = true;
105
106 public Conversation getSelectedConversation() {
107 return this.mSelectedConversation;
108 }
109
110 public void setSelectedConversation(Conversation conversation) {
111 this.mSelectedConversation = conversation;
112 }
113
114 public void showConversationsOverview() {
115 if (mContentView instanceof SlidingPaneLayout) {
116 SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
117 mSlidingPaneLayout.openPane();
118 }
119 }
120
121 @Override
122 protected String getShareableUri() {
123 Conversation conversation = getSelectedConversation();
124 if (conversation != null) {
125 return conversation.getAccount().getShareableUri();
126 } else {
127 return "";
128 }
129 }
130
131 public void hideConversationsOverview() {
132 if (mContentView instanceof SlidingPaneLayout) {
133 SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
134 mSlidingPaneLayout.closePane();
135 }
136 }
137
138 public boolean isConversationsOverviewHideable() {
139 if (mContentView instanceof SlidingPaneLayout) {
140 SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
141 return mSlidingPaneLayout.isSlideable();
142 } else {
143 return false;
144 }
145 }
146
147 public boolean isConversationsOverviewVisable() {
148 if (mContentView instanceof SlidingPaneLayout) {
149 SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
150 return mSlidingPaneLayout.isOpen();
151 } else {
152 return true;
153 }
154 }
155
156 @Override
157 protected void onCreate(final Bundle savedInstanceState) {
158 super.onCreate(savedInstanceState);
159 if (savedInstanceState != null) {
160 mOpenConverstaion = savedInstanceState.getString(STATE_OPEN_CONVERSATION, null);
161 mPanelOpen = savedInstanceState.getBoolean(STATE_PANEL_OPEN, true);
162 String pending = savedInstanceState.getString(STATE_PENDING_URI, null);
163 if (pending != null) {
164 mPendingImageUris.clear();
165 mPendingImageUris.add(Uri.parse(pending));
166 }
167 }
168
169 setContentView(R.layout.fragment_conversations_overview);
170
171 this.mConversationFragment = new ConversationFragment();
172 FragmentTransaction transaction = getFragmentManager().beginTransaction();
173 transaction.replace(R.id.selected_conversation, this.mConversationFragment, "conversation");
174 transaction.commit();
175
176 listView = (EnhancedListView) findViewById(R.id.list);
177 this.listAdapter = new ConversationAdapter(this, conversationList);
178 listView.setAdapter(this.listAdapter);
179
180 if (getActionBar() != null) {
181 getActionBar().setDisplayHomeAsUpEnabled(false);
182 getActionBar().setHomeButtonEnabled(false);
183 }
184
185 listView.setOnItemClickListener(new OnItemClickListener() {
186
187 @Override
188 public void onItemClick(AdapterView<?> arg0, View clickedView,
189 int position, long arg3) {
190 if (getSelectedConversation() != conversationList.get(position)) {
191 setSelectedConversation(conversationList.get(position));
192 ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation());
193 }
194 hideConversationsOverview();
195 openConversation();
196 }
197 });
198
199 listView.setDismissCallback(new EnhancedListView.OnDismissCallback() {
200
201 @Override
202 public EnhancedListView.Undoable onDismiss(final EnhancedListView enhancedListView, final int position) {
203
204 final int index = listView.getFirstVisiblePosition();
205 View v = listView.getChildAt(0);
206 final int top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop());
207
208 swipedConversation = listAdapter.getItem(position);
209 listAdapter.remove(swipedConversation);
210 swipedConversation.markRead();
211 xmppConnectionService.getNotificationService().clear(swipedConversation);
212
213 final boolean formerlySelected = (getSelectedConversation() == swipedConversation);
214 if (position == 0 && listAdapter.getCount() == 0) {
215 endConversation(swipedConversation, false, true);
216 return null;
217 } else if (formerlySelected) {
218 setSelectedConversation(listAdapter.getItem(0));
219 ConversationActivity.this.mConversationFragment
220 .reInit(getSelectedConversation());
221 }
222
223 return new EnhancedListView.Undoable() {
224
225 @Override
226 public void undo() {
227 listAdapter.insert(swipedConversation, position);
228 if (formerlySelected) {
229 setSelectedConversation(swipedConversation);
230 ConversationActivity.this.mConversationFragment
231 .reInit(getSelectedConversation());
232 }
233 swipedConversation = null;
234 listView.setSelectionFromTop(index + (listView.getChildCount() < position ? 1 : 0), top);
235 }
236
237 @Override
238 public void discard() {
239 if (!swipedConversation.isRead()
240 && swipedConversation.getMode() == Conversation.MODE_SINGLE) {
241 swipedConversation = null;
242 return;
243 }
244 endConversation(swipedConversation, false, false);
245 swipedConversation = null;
246 }
247
248 @Override
249 public String getTitle() {
250 if (swipedConversation.getMode() == Conversation.MODE_MULTI) {
251 return getResources().getString(R.string.title_undo_swipe_out_muc);
252 } else {
253 return getResources().getString(R.string.title_undo_swipe_out_conversation);
254 }
255 }
256 };
257 }
258 });
259 listView.enableSwipeToDismiss();
260 listView.setSwipingLayout(R.id.swipeable_item);
261 listView.setUndoStyle(EnhancedListView.UndoStyle.SINGLE_POPUP);
262 listView.setUndoHideDelay(5000);
263 listView.setRequireTouchBeforeDismiss(false);
264
265 mContentView = findViewById(R.id.content_view_spl);
266 if (mContentView == null) {
267 mContentView = findViewById(R.id.content_view_ll);
268 }
269 if (mContentView instanceof SlidingPaneLayout) {
270 SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
271 mSlidingPaneLayout.setParallaxDistance(150);
272 mSlidingPaneLayout
273 .setShadowResource(R.drawable.es_slidingpane_shadow);
274 mSlidingPaneLayout.setSliderFadeColor(0);
275 mSlidingPaneLayout.setPanelSlideListener(new PanelSlideListener() {
276
277 @Override
278 public void onPanelOpened(View arg0) {
279 updateActionBarTitle();
280 invalidateOptionsMenu();
281 hideKeyboard();
282 if (xmppConnectionServiceBound) {
283 xmppConnectionService.getNotificationService()
284 .setOpenConversation(null);
285 }
286 closeContextMenu();
287 }
288
289 @Override
290 public void onPanelClosed(View arg0) {
291 listView.discardUndo();
292 openConversation();
293 }
294
295 @Override
296 public void onPanelSlide(View arg0, float arg1) {
297 // TODO Auto-generated method stub
298
299 }
300 });
301 }
302 }
303
304 @Override
305 public void switchToConversation(Conversation conversation) {
306 setSelectedConversation(conversation);
307 runOnUiThread(new Runnable() {
308 @Override
309 public void run() {
310 ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation());
311 openConversation();
312 }
313 });
314 }
315
316 private void updateActionBarTitle() {
317 updateActionBarTitle(isConversationsOverviewHideable() && !isConversationsOverviewVisable());
318 }
319
320 private void updateActionBarTitle(boolean titleShouldBeName) {
321 final ActionBar ab = getActionBar();
322 final Conversation conversation = getSelectedConversation();
323 if (ab != null) {
324 if (titleShouldBeName && conversation != null) {
325 ab.setDisplayHomeAsUpEnabled(true);
326 ab.setHomeButtonEnabled(true);
327 if (conversation.getMode() == Conversation.MODE_SINGLE || useSubjectToIdentifyConference()) {
328 ab.setTitle(conversation.getName());
329 } else {
330 ab.setTitle(conversation.getJid().toBareJid().toString());
331 }
332 } else {
333 ab.setDisplayHomeAsUpEnabled(false);
334 ab.setHomeButtonEnabled(false);
335 ab.setTitle(R.string.app_name);
336 }
337 }
338 }
339
340 private void openConversation() {
341 this.updateActionBarTitle();
342 this.invalidateOptionsMenu();
343 if (xmppConnectionServiceBound) {
344 final Conversation conversation = getSelectedConversation();
345 xmppConnectionService.getNotificationService().setOpenConversation(conversation);
346 sendReadMarkerIfNecessary(conversation);
347 }
348 listAdapter.notifyDataSetChanged();
349 }
350
351 public void sendReadMarkerIfNecessary(final Conversation conversation) {
352 if (!mActivityPaused && conversation != null) {
353 if (!conversation.isRead()) {
354 xmppConnectionService.sendReadMarker(conversation);
355 } else {
356 xmppConnectionService.markRead(conversation);
357 }
358 }
359 }
360
361 @Override
362 public boolean onCreateOptionsMenu(Menu menu) {
363 getMenuInflater().inflate(R.menu.conversations, menu);
364 final MenuItem menuSecure = menu.findItem(R.id.action_security);
365 final MenuItem menuArchive = menu.findItem(R.id.action_archive);
366 final MenuItem menuMucDetails = menu.findItem(R.id.action_muc_details);
367 final MenuItem menuContactDetails = menu.findItem(R.id.action_contact_details);
368 final MenuItem menuAttach = menu.findItem(R.id.action_attach_file);
369 final MenuItem menuClearHistory = menu.findItem(R.id.action_clear_history);
370 final MenuItem menuAdd = menu.findItem(R.id.action_add);
371 final MenuItem menuInviteContact = menu.findItem(R.id.action_invite);
372 final MenuItem menuMute = menu.findItem(R.id.action_mute);
373 final MenuItem menuUnmute = menu.findItem(R.id.action_unmute);
374
375 if (isConversationsOverviewVisable() && isConversationsOverviewHideable()) {
376 menuArchive.setVisible(false);
377 menuMucDetails.setVisible(false);
378 menuContactDetails.setVisible(false);
379 menuSecure.setVisible(false);
380 menuInviteContact.setVisible(false);
381 menuAttach.setVisible(false);
382 menuClearHistory.setVisible(false);
383 menuMute.setVisible(false);
384 menuUnmute.setVisible(false);
385 } else {
386 menuAdd.setVisible(!isConversationsOverviewHideable());
387 if (this.getSelectedConversation() != null) {
388 if (this.getSelectedConversation().getNextEncryption() != Message.ENCRYPTION_NONE) {
389 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
390 menuSecure.setIcon(R.drawable.ic_lock_white_24dp);
391 } else {
392 menuSecure.setIcon(R.drawable.ic_action_secure);
393 }
394 }
395 if (this.getSelectedConversation().getMode() == Conversation.MODE_MULTI) {
396 menuContactDetails.setVisible(false);
397 menuAttach.setVisible(getSelectedConversation().getAccount().httpUploadAvailable());
398 menuInviteContact.setVisible(getSelectedConversation().getMucOptions().canInvite());
399 menuSecure.setVisible(!Config.HIDE_PGP_IN_UI); //if pgp is hidden conferences have no choice of encryption
400 } else {
401 menuMucDetails.setVisible(false);
402 }
403 if (this.getSelectedConversation().isMuted()) {
404 menuMute.setVisible(false);
405 } else {
406 menuUnmute.setVisible(false);
407 }
408 }
409 }
410 return true;
411 }
412
413 protected void selectPresenceToAttachFile(final int attachmentChoice, final int encryption) {
414 final Conversation conversation = getSelectedConversation();
415 final Account account = conversation.getAccount();
416 final OnPresenceSelected callback = new OnPresenceSelected() {
417
418 @Override
419 public void onPresenceSelected() {
420 Intent intent = new Intent();
421 boolean chooser = false;
422 String fallbackPackageId = null;
423 switch (attachmentChoice) {
424 case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
425 intent.setAction(Intent.ACTION_GET_CONTENT);
426 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
427 intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,true);
428 }
429 intent.setType("image/*");
430 chooser = true;
431 break;
432 case ATTACHMENT_CHOICE_TAKE_PHOTO:
433 Uri uri = xmppConnectionService.getFileBackend().getTakePhotoUri();
434 intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
435 intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
436 mPendingImageUris.clear();
437 mPendingImageUris.add(uri);
438 break;
439 case ATTACHMENT_CHOICE_CHOOSE_FILE:
440 chooser = true;
441 intent.setType("*/*");
442 intent.addCategory(Intent.CATEGORY_OPENABLE);
443 intent.setAction(Intent.ACTION_GET_CONTENT);
444 break;
445 case ATTACHMENT_CHOICE_RECORD_VOICE:
446 intent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
447 fallbackPackageId = "eu.siacs.conversations.voicerecorder";
448 break;
449 case ATTACHMENT_CHOICE_LOCATION:
450 intent.setAction("eu.siacs.conversations.location.request");
451 fallbackPackageId = "eu.siacs.conversations.sharelocation";
452 break;
453 }
454 if (intent.resolveActivity(getPackageManager()) != null) {
455 if (chooser) {
456 startActivityForResult(
457 Intent.createChooser(intent, getString(R.string.perform_action_with)),
458 attachmentChoice);
459 } else {
460 startActivityForResult(intent, attachmentChoice);
461 }
462 } else if (fallbackPackageId != null) {
463 startActivity(getInstallApkIntent(fallbackPackageId));
464 }
465 }
466 };
467 if ((account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) && encryption != Message.ENCRYPTION_OTR) {
468 conversation.setNextCounterpart(null);
469 callback.onPresenceSelected();
470 } else {
471 selectPresence(conversation, callback);
472 }
473 }
474
475 private Intent getInstallApkIntent(final String packageId) {
476 Intent intent = new Intent(Intent.ACTION_VIEW);
477 intent.setData(Uri.parse("market://details?id="+packageId));
478 if (intent.resolveActivity(getPackageManager()) != null) {
479 return intent;
480 } else {
481 intent.setData(Uri.parse("http://play.google.com/store/apps/details?id=" + packageId));
482 return intent;
483 }
484 }
485
486 public void attachFile(final int attachmentChoice) {
487 switch (attachmentChoice) {
488 case ATTACHMENT_CHOICE_LOCATION:
489 getPreferences().edit().putString("recently_used_quick_action","location").apply();
490 break;
491 case ATTACHMENT_CHOICE_RECORD_VOICE:
492 getPreferences().edit().putString("recently_used_quick_action","voice").apply();
493 break;
494 case ATTACHMENT_CHOICE_TAKE_PHOTO:
495 getPreferences().edit().putString("recently_used_quick_action","photo").apply();
496 break;
497 case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
498 getPreferences().edit().putString("recently_used_quick_action","picture").apply();
499 break;
500 }
501 final Conversation conversation = getSelectedConversation();
502 final int encryption = conversation.getNextEncryption();
503 if (encryption == Message.ENCRYPTION_PGP) {
504 if (hasPgp()) {
505 if (conversation.getContact().getPgpKeyId() != 0) {
506 xmppConnectionService.getPgpEngine().hasKey(
507 conversation.getContact(),
508 new UiCallback<Contact>() {
509
510 @Override
511 public void userInputRequried(PendingIntent pi,
512 Contact contact) {
513 ConversationActivity.this.runIntent(pi,attachmentChoice);
514 }
515
516 @Override
517 public void success(Contact contact) {
518 selectPresenceToAttachFile(attachmentChoice,encryption);
519 }
520
521 @Override
522 public void error(int error, Contact contact) {
523 displayErrorDialog(error);
524 }
525 });
526 } else {
527 final ConversationFragment fragment = (ConversationFragment) getFragmentManager()
528 .findFragmentByTag("conversation");
529 if (fragment != null) {
530 fragment.showNoPGPKeyDialog(false,
531 new OnClickListener() {
532
533 @Override
534 public void onClick(DialogInterface dialog,
535 int which) {
536 conversation
537 .setNextEncryption(Message.ENCRYPTION_NONE);
538 xmppConnectionService.databaseBackend
539 .updateConversation(conversation);
540 selectPresenceToAttachFile(attachmentChoice,Message.ENCRYPTION_NONE);
541 }
542 });
543 }
544 }
545 } else {
546 showInstallPgpDialog();
547 }
548 } else {
549 if (encryption != Message.ENCRYPTION_AXOLOTL || !trustKeysIfNeeded(REQUEST_TRUST_KEYS_MENU, attachmentChoice)) {
550 selectPresenceToAttachFile(attachmentChoice, encryption);
551 }
552 }
553 }
554
555 @Override
556 public boolean onOptionsItemSelected(final MenuItem item) {
557 if (item.getItemId() == android.R.id.home) {
558 showConversationsOverview();
559 return true;
560 } else if (item.getItemId() == R.id.action_add) {
561 startActivity(new Intent(this, StartConversationActivity.class));
562 return true;
563 } else if (getSelectedConversation() != null) {
564 switch (item.getItemId()) {
565 case R.id.action_attach_file:
566 attachFileDialog();
567 break;
568 case R.id.action_archive:
569 this.endConversation(getSelectedConversation());
570 break;
571 case R.id.action_contact_details:
572 switchToContactDetails(getSelectedConversation().getContact());
573 break;
574 case R.id.action_muc_details:
575 Intent intent = new Intent(this,
576 ConferenceDetailsActivity.class);
577 intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
578 intent.putExtra("uuid", getSelectedConversation().getUuid());
579 startActivity(intent);
580 break;
581 case R.id.action_invite:
582 inviteToConversation(getSelectedConversation());
583 break;
584 case R.id.action_security:
585 selectEncryptionDialog(getSelectedConversation());
586 break;
587 case R.id.action_clear_history:
588 clearHistoryDialog(getSelectedConversation());
589 break;
590 case R.id.action_mute:
591 muteConversationDialog(getSelectedConversation());
592 break;
593 case R.id.action_unmute:
594 unmuteConversation(getSelectedConversation());
595 break;
596 case R.id.action_block:
597 BlockContactDialog.show(this, xmppConnectionService, getSelectedConversation());
598 break;
599 case R.id.action_unblock:
600 BlockContactDialog.show(this, xmppConnectionService, getSelectedConversation());
601 break;
602 default:
603 break;
604 }
605 return super.onOptionsItemSelected(item);
606 } else {
607 return super.onOptionsItemSelected(item);
608 }
609 }
610
611 public void endConversation(Conversation conversation) {
612 endConversation(conversation, true, true);
613 }
614
615 public void endConversation(Conversation conversation, boolean showOverview, boolean reinit) {
616 if (showOverview) {
617 showConversationsOverview();
618 }
619 xmppConnectionService.archiveConversation(conversation);
620 if (reinit) {
621 if (conversationList.size() > 0) {
622 setSelectedConversation(conversationList.get(0));
623 this.mConversationFragment.reInit(getSelectedConversation());
624 } else {
625 setSelectedConversation(null);
626 }
627 }
628 }
629
630 @SuppressLint("InflateParams")
631 protected void clearHistoryDialog(final Conversation conversation) {
632 AlertDialog.Builder builder = new AlertDialog.Builder(this);
633 builder.setTitle(getString(R.string.clear_conversation_history));
634 View dialogView = getLayoutInflater().inflate(
635 R.layout.dialog_clear_history, null);
636 final CheckBox endConversationCheckBox = (CheckBox) dialogView
637 .findViewById(R.id.end_conversation_checkbox);
638 builder.setView(dialogView);
639 builder.setNegativeButton(getString(R.string.cancel), null);
640 builder.setPositiveButton(getString(R.string.delete_messages),
641 new OnClickListener() {
642
643 @Override
644 public void onClick(DialogInterface dialog, int which) {
645 ConversationActivity.this.xmppConnectionService.clearConversationHistory(conversation);
646 if (endConversationCheckBox.isChecked()) {
647 endConversation(conversation);
648 } else {
649 updateConversationList();
650 ConversationActivity.this.mConversationFragment.updateMessages();
651 }
652 }
653 });
654 builder.create().show();
655 }
656
657 protected void attachFileDialog() {
658 View menuAttachFile = findViewById(R.id.action_attach_file);
659 if (menuAttachFile == null) {
660 return;
661 }
662 PopupMenu attachFilePopup = new PopupMenu(this, menuAttachFile);
663 attachFilePopup.inflate(R.menu.attachment_choices);
664 if (new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION).resolveActivity(getPackageManager()) == null) {
665 attachFilePopup.getMenu().findItem(R.id.attach_record_voice).setVisible(false);
666 }
667 if (new Intent("eu.siacs.conversations.location.request").resolveActivity(getPackageManager()) == null) {
668 attachFilePopup.getMenu().findItem(R.id.attach_location).setVisible(false);
669 }
670 attachFilePopup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
671
672 @Override
673 public boolean onMenuItemClick(MenuItem item) {
674 switch (item.getItemId()) {
675 case R.id.attach_choose_picture:
676 attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE);
677 break;
678 case R.id.attach_take_picture:
679 attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
680 break;
681 case R.id.attach_choose_file:
682 attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE);
683 break;
684 case R.id.attach_record_voice:
685 attachFile(ATTACHMENT_CHOICE_RECORD_VOICE);
686 break;
687 case R.id.attach_location:
688 attachFile(ATTACHMENT_CHOICE_LOCATION);
689 break;
690 }
691 return false;
692 }
693 });
694 attachFilePopup.show();
695 }
696
697 public void verifyOtrSessionDialog(final Conversation conversation, View view) {
698 if (!conversation.hasValidOtrSession() || conversation.getOtrSession().getSessionStatus() != SessionStatus.ENCRYPTED) {
699 Toast.makeText(this, R.string.otr_session_not_started, Toast.LENGTH_LONG).show();
700 return;
701 }
702 if (view == null) {
703 return;
704 }
705 PopupMenu popup = new PopupMenu(this, view);
706 popup.inflate(R.menu.verification_choices);
707 popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
708 @Override
709 public boolean onMenuItemClick(MenuItem menuItem) {
710 Intent intent = new Intent(ConversationActivity.this, VerifyOTRActivity.class);
711 intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT);
712 intent.putExtra("contact", conversation.getContact().getJid().toBareJid().toString());
713 intent.putExtra("account", conversation.getAccount().getJid().toBareJid().toString());
714 switch (menuItem.getItemId()) {
715 case R.id.scan_fingerprint:
716 intent.putExtra("mode",VerifyOTRActivity.MODE_SCAN_FINGERPRINT);
717 break;
718 case R.id.ask_question:
719 intent.putExtra("mode",VerifyOTRActivity.MODE_ASK_QUESTION);
720 break;
721 case R.id.manual_verification:
722 intent.putExtra("mode",VerifyOTRActivity.MODE_MANUAL_VERIFICATION);
723 break;
724 }
725 startActivity(intent);
726 return true;
727 }
728 });
729 popup.show();
730 }
731
732 protected void selectEncryptionDialog(final Conversation conversation) {
733 View menuItemView = findViewById(R.id.action_security);
734 if (menuItemView == null) {
735 return;
736 }
737 PopupMenu popup = new PopupMenu(this, menuItemView);
738 final ConversationFragment fragment = (ConversationFragment) getFragmentManager()
739 .findFragmentByTag("conversation");
740 if (fragment != null) {
741 popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
742
743 @Override
744 public boolean onMenuItemClick(MenuItem item) {
745 switch (item.getItemId()) {
746 case R.id.encryption_choice_none:
747 conversation.setNextEncryption(Message.ENCRYPTION_NONE);
748 item.setChecked(true);
749 break;
750 case R.id.encryption_choice_otr:
751 conversation.setNextEncryption(Message.ENCRYPTION_OTR);
752 item.setChecked(true);
753 break;
754 case R.id.encryption_choice_pgp:
755 if (hasPgp()) {
756 if (conversation.getAccount().getKeys().has("pgp_signature")) {
757 conversation.setNextEncryption(Message.ENCRYPTION_PGP);
758 item.setChecked(true);
759 } else {
760 announcePgp(conversation.getAccount(),conversation);
761 }
762 } else {
763 showInstallPgpDialog();
764 }
765 break;
766 case R.id.encryption_choice_axolotl:
767 Log.d(Config.LOGTAG, AxolotlService.getLogprefix(conversation.getAccount())
768 + "Enabled axolotl for Contact " + conversation.getContact().getJid());
769 conversation.setNextEncryption(Message.ENCRYPTION_AXOLOTL);
770 item.setChecked(true);
771 break;
772 default:
773 conversation.setNextEncryption(Message.ENCRYPTION_NONE);
774 break;
775 }
776 xmppConnectionService.databaseBackend.updateConversation(conversation);
777 fragment.updateChatMsgHint();
778 invalidateOptionsMenu();
779 refreshUi();
780 return true;
781 }
782 });
783 popup.inflate(R.menu.encryption_choices);
784 MenuItem otr = popup.getMenu().findItem(R.id.encryption_choice_otr);
785 MenuItem none = popup.getMenu().findItem(R.id.encryption_choice_none);
786 MenuItem pgp = popup.getMenu().findItem(R.id.encryption_choice_pgp);
787 MenuItem axolotl = popup.getMenu().findItem(R.id.encryption_choice_axolotl);
788 pgp.setVisible(!Config.HIDE_PGP_IN_UI);
789 if (conversation.getMode() == Conversation.MODE_MULTI) {
790 otr.setVisible(false);
791 axolotl.setVisible(false);
792 } else if (!conversation.getAccount().getAxolotlService().isContactAxolotlCapable(conversation.getContact())) {
793 axolotl.setEnabled(false);
794 }
795 switch (conversation.getNextEncryption()) {
796 case Message.ENCRYPTION_NONE:
797 none.setChecked(true);
798 break;
799 case Message.ENCRYPTION_OTR:
800 otr.setChecked(true);
801 break;
802 case Message.ENCRYPTION_PGP:
803 pgp.setChecked(true);
804 break;
805 case Message.ENCRYPTION_AXOLOTL:
806 axolotl.setChecked(true);
807 break;
808 default:
809 none.setChecked(true);
810 break;
811 }
812 popup.show();
813 }
814 }
815
816 protected void muteConversationDialog(final Conversation conversation) {
817 AlertDialog.Builder builder = new AlertDialog.Builder(this);
818 builder.setTitle(R.string.disable_notifications);
819 final int[] durations = getResources().getIntArray(R.array.mute_options_durations);
820 builder.setItems(R.array.mute_options_descriptions,
821 new OnClickListener() {
822
823 @Override
824 public void onClick(final DialogInterface dialog, final int which) {
825 final long till;
826 if (durations[which] == -1) {
827 till = Long.MAX_VALUE;
828 } else {
829 till = System.currentTimeMillis() + (durations[which] * 1000);
830 }
831 conversation.setMutedTill(till);
832 ConversationActivity.this.xmppConnectionService.databaseBackend
833 .updateConversation(conversation);
834 updateConversationList();
835 ConversationActivity.this.mConversationFragment.updateMessages();
836 invalidateOptionsMenu();
837 }
838 });
839 builder.create().show();
840 }
841
842 public void unmuteConversation(final Conversation conversation) {
843 conversation.setMutedTill(0);
844 this.xmppConnectionService.databaseBackend.updateConversation(conversation);
845 updateConversationList();
846 ConversationActivity.this.mConversationFragment.updateMessages();
847 invalidateOptionsMenu();
848 }
849
850 @Override
851 public void onBackPressed() {
852 if (!isConversationsOverviewVisable()) {
853 showConversationsOverview();
854 } else {
855 moveTaskToBack(true);
856 }
857 }
858
859 @Override
860 protected void onNewIntent(final Intent intent) {
861 if (xmppConnectionServiceBound) {
862 if (intent != null && VIEW_CONVERSATION.equals(intent.getType())) {
863 handleViewConversationIntent(intent);
864 }
865 } else {
866 setIntent(intent);
867 }
868 }
869
870 @Override
871 public void onStart() {
872 super.onStart();
873 this.mRedirected = false;
874 if (this.xmppConnectionServiceBound) {
875 this.onBackendConnected();
876 }
877 if (conversationList.size() >= 1) {
878 this.onConversationUpdate();
879 }
880 }
881
882 @Override
883 public void onPause() {
884 listView.discardUndo();
885 super.onPause();
886 this.mActivityPaused = true;
887 if (this.xmppConnectionServiceBound) {
888 this.xmppConnectionService.getNotificationService().setIsInForeground(false);
889 }
890 }
891
892 @Override
893 public void onResume() {
894 super.onResume();
895 final int theme = findTheme();
896 final boolean usingEnterKey = usingEnterKey();
897 if (this.mTheme != theme || usingEnterKey != mUsingEnterKey) {
898 recreate();
899 }
900 this.mActivityPaused = false;
901 if (this.xmppConnectionServiceBound) {
902 this.xmppConnectionService.getNotificationService().setIsInForeground(true);
903 }
904
905 if (!isConversationsOverviewVisable() || !isConversationsOverviewHideable()) {
906 sendReadMarkerIfNecessary(getSelectedConversation());
907 }
908
909 }
910
911 @Override
912 public void onSaveInstanceState(final Bundle savedInstanceState) {
913 Conversation conversation = getSelectedConversation();
914 if (conversation != null) {
915 savedInstanceState.putString(STATE_OPEN_CONVERSATION,
916 conversation.getUuid());
917 }
918 savedInstanceState.putBoolean(STATE_PANEL_OPEN,
919 isConversationsOverviewVisable());
920 if (this.mPendingImageUris.size() >= 1) {
921 savedInstanceState.putString(STATE_PENDING_URI, this.mPendingImageUris.get(0).toString());
922 }
923 super.onSaveInstanceState(savedInstanceState);
924 }
925
926 @Override
927 void onBackendConnected() {
928 this.xmppConnectionService.getNotificationService().setIsInForeground(true);
929 updateConversationList();
930
931 if (mPendingConferenceInvite != null) {
932 mPendingConferenceInvite.execute(this);
933 mPendingConferenceInvite = null;
934 }
935
936 if (xmppConnectionService.getAccounts().size() == 0) {
937 if (!mRedirected) {
938 this.mRedirected = true;
939 startActivity(new Intent(this, EditAccountActivity.class));
940 finish();
941 }
942 } else if (conversationList.size() <= 0) {
943 if (!mRedirected) {
944 this.mRedirected = true;
945 Intent intent = new Intent(this, StartConversationActivity.class);
946 intent.putExtra("init",true);
947 startActivity(intent);
948 finish();
949 }
950 } else if (getIntent() != null && VIEW_CONVERSATION.equals(getIntent().getType())) {
951 handleViewConversationIntent(getIntent());
952 } else if (selectConversationByUuid(mOpenConverstaion)) {
953 if (mPanelOpen) {
954 showConversationsOverview();
955 } else {
956 if (isConversationsOverviewHideable()) {
957 openConversation();
958 }
959 }
960 this.mConversationFragment.reInit(getSelectedConversation());
961 mOpenConverstaion = null;
962 } else if (getSelectedConversation() == null) {
963 showConversationsOverview();
964 mPendingImageUris.clear();
965 mPendingFileUris.clear();
966 mPendingGeoUri = null;
967 setSelectedConversation(conversationList.get(0));
968 this.mConversationFragment.reInit(getSelectedConversation());
969 } else {
970 this.mConversationFragment.messageListAdapter.updatePreferences();
971 this.mConversationFragment.messagesView.invalidateViews();
972 }
973
974 if(!forbidProcessingPendings) {
975 for (Iterator<Uri> i = mPendingImageUris.iterator(); i.hasNext(); i.remove()) {
976 Uri foo = i.next();
977 attachImageToConversation(getSelectedConversation(), foo);
978 }
979
980 for (Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) {
981 attachFileToConversation(getSelectedConversation(), i.next());
982 }
983
984 if (mPendingGeoUri != null) {
985 attachLocationToConversation(getSelectedConversation(), mPendingGeoUri);
986 mPendingGeoUri = null;
987 }
988 }
989 forbidProcessingPendings = false;
990
991 ExceptionHelper.checkForCrash(this, this.xmppConnectionService);
992 setIntent(new Intent());
993 }
994
995 private void handleViewConversationIntent(final Intent intent) {
996 final String uuid = intent.getStringExtra(CONVERSATION);
997 final String downloadUuid = intent.getStringExtra(MESSAGE);
998 final String text = intent.getStringExtra(TEXT);
999 final String nick = intent.getStringExtra(NICK);
1000 final boolean pm = intent.getBooleanExtra(PRIVATE_MESSAGE,false);
1001 if (selectConversationByUuid(uuid)) {
1002 this.mConversationFragment.reInit(getSelectedConversation());
1003 if (nick != null) {
1004 if (pm) {
1005 Jid jid = getSelectedConversation().getJid();
1006 try {
1007 Jid next = Jid.fromParts(jid.getLocalpart(),jid.getDomainpart(),nick);
1008 this.mConversationFragment.privateMessageWith(next);
1009 } catch (final InvalidJidException ignored) {
1010 //do nothing
1011 }
1012 } else {
1013 this.mConversationFragment.highlightInConference(nick);
1014 }
1015 } else {
1016 this.mConversationFragment.appendText(text);
1017 }
1018 hideConversationsOverview();
1019 openConversation();
1020 if (mContentView instanceof SlidingPaneLayout) {
1021 updateActionBarTitle(true); //fixes bug where slp isn't properly closed yet
1022 }
1023 if (downloadUuid != null) {
1024 final Message message = mSelectedConversation.findMessageWithFileAndUuid(downloadUuid);
1025 if (message != null) {
1026 mConversationFragment.messageListAdapter.startDownloadable(message);
1027 }
1028 }
1029 }
1030 }
1031
1032 private boolean selectConversationByUuid(String uuid) {
1033 if (uuid == null) {
1034 return false;
1035 }
1036 for (Conversation aConversationList : conversationList) {
1037 if (aConversationList.getUuid().equals(uuid)) {
1038 setSelectedConversation(aConversationList);
1039 return true;
1040 }
1041 }
1042 return false;
1043 }
1044
1045 @Override
1046 protected void unregisterListeners() {
1047 super.unregisterListeners();
1048 xmppConnectionService.getNotificationService().setOpenConversation(null);
1049 }
1050
1051 @SuppressLint("NewApi")
1052 private static List<Uri> extractUriFromIntent(final Intent intent) {
1053 List<Uri> uris = new ArrayList<>();
1054 Uri uri = intent.getData();
1055 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && uri == null) {
1056 ClipData clipData = intent.getClipData();
1057 for(int i = 0; i < clipData.getItemCount(); ++i) {
1058 uris.add(clipData.getItemAt(i).getUri());
1059 }
1060 } else {
1061 uris.add(uri);
1062 }
1063 return uris;
1064 }
1065
1066 @Override
1067 protected void onActivityResult(int requestCode, int resultCode,
1068 final Intent data) {
1069 super.onActivityResult(requestCode, resultCode, data);
1070 if (resultCode == RESULT_OK) {
1071 if (requestCode == REQUEST_DECRYPT_PGP) {
1072 mConversationFragment.hideSnackbar();
1073 mConversationFragment.updateMessages();
1074 } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
1075 mPendingImageUris.clear();
1076 mPendingImageUris.addAll(extractUriFromIntent(data));
1077 if (xmppConnectionServiceBound) {
1078 for(Iterator<Uri> i = mPendingImageUris.iterator(); i.hasNext(); i.remove()) {
1079 attachImageToConversation(getSelectedConversation(),i.next());
1080 }
1081 }
1082 } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_FILE || requestCode == ATTACHMENT_CHOICE_RECORD_VOICE) {
1083 mPendingFileUris.clear();
1084 mPendingFileUris.addAll(extractUriFromIntent(data));
1085 if (xmppConnectionServiceBound) {
1086 for(Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) {
1087 attachFileToConversation(getSelectedConversation(), i.next());
1088 }
1089 }
1090 } else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) {
1091 if (mPendingImageUris.size() == 1) {
1092 Uri uri = mPendingImageUris.get(0);
1093 if (xmppConnectionServiceBound) {
1094 attachImageToConversation(getSelectedConversation(), uri);
1095 mPendingImageUris.clear();
1096 }
1097 Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
1098 intent.setData(uri);
1099 sendBroadcast(intent);
1100 } else {
1101 mPendingImageUris.clear();
1102 }
1103 } else if (requestCode == ATTACHMENT_CHOICE_LOCATION) {
1104 double latitude = data.getDoubleExtra("latitude",0);
1105 double longitude = data.getDoubleExtra("longitude",0);
1106 this.mPendingGeoUri = Uri.parse("geo:"+String.valueOf(latitude)+","+String.valueOf(longitude));
1107 if (xmppConnectionServiceBound) {
1108 attachLocationToConversation(getSelectedConversation(), mPendingGeoUri);
1109 this.mPendingGeoUri = null;
1110 }
1111 } else if (requestCode == REQUEST_TRUST_KEYS_TEXT || requestCode == REQUEST_TRUST_KEYS_MENU) {
1112 this.forbidProcessingPendings = !xmppConnectionServiceBound;
1113 mConversationFragment.onActivityResult(requestCode, resultCode, data);
1114 }
1115 } else {
1116 mPendingImageUris.clear();
1117 mPendingFileUris.clear();
1118 }
1119 }
1120
1121 private void attachLocationToConversation(Conversation conversation, Uri uri) {
1122 if (conversation == null) {
1123 return;
1124 }
1125 xmppConnectionService.attachLocationToConversation(conversation,uri, new UiCallback<Message>() {
1126
1127 @Override
1128 public void success(Message message) {
1129 xmppConnectionService.sendMessage(message);
1130 }
1131
1132 @Override
1133 public void error(int errorCode, Message object) {
1134
1135 }
1136
1137 @Override
1138 public void userInputRequried(PendingIntent pi, Message object) {
1139
1140 }
1141 });
1142 }
1143
1144 private void attachFileToConversation(Conversation conversation, Uri uri) {
1145 if (conversation == null) {
1146 return;
1147 }
1148 prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_file), Toast.LENGTH_LONG);
1149 prepareFileToast.show();
1150 xmppConnectionService.attachFileToConversation(conversation, uri, new UiCallback<Message>() {
1151 @Override
1152 public void success(Message message) {
1153 hidePrepareFileToast();
1154 xmppConnectionService.sendMessage(message);
1155 }
1156
1157 @Override
1158 public void error(int errorCode, Message message) {
1159 displayErrorDialog(errorCode);
1160 }
1161
1162 @Override
1163 public void userInputRequried(PendingIntent pi, Message message) {
1164
1165 }
1166 });
1167 }
1168
1169 private void attachImageToConversation(Conversation conversation, Uri uri) {
1170 if (conversation == null) {
1171 return;
1172 }
1173 prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_image), Toast.LENGTH_LONG);
1174 prepareFileToast.show();
1175 xmppConnectionService.attachImageToConversation(conversation, uri,
1176 new UiCallback<Message>() {
1177
1178 @Override
1179 public void userInputRequried(PendingIntent pi,
1180 Message object) {
1181 hidePrepareFileToast();
1182 }
1183
1184 @Override
1185 public void success(Message message) {
1186 xmppConnectionService.sendMessage(message);
1187 }
1188
1189 @Override
1190 public void error(int error, Message message) {
1191 hidePrepareFileToast();
1192 displayErrorDialog(error);
1193 }
1194 });
1195 }
1196
1197 private void hidePrepareFileToast() {
1198 if (prepareFileToast != null) {
1199 runOnUiThread(new Runnable() {
1200
1201 @Override
1202 public void run() {
1203 prepareFileToast.cancel();
1204 }
1205 });
1206 }
1207 }
1208
1209 public void updateConversationList() {
1210 xmppConnectionService
1211 .populateWithOrderedConversations(conversationList);
1212 if (swipedConversation != null) {
1213 if (swipedConversation.isRead()) {
1214 conversationList.remove(swipedConversation);
1215 } else {
1216 listView.discardUndo();
1217 }
1218 }
1219 listAdapter.notifyDataSetChanged();
1220 }
1221
1222 public void runIntent(PendingIntent pi, int requestCode) {
1223 try {
1224 this.startIntentSenderForResult(pi.getIntentSender(), requestCode,
1225 null, 0, 0, 0);
1226 } catch (final SendIntentException ignored) {
1227 }
1228 }
1229
1230 public void encryptTextMessage(Message message) {
1231 xmppConnectionService.getPgpEngine().encrypt(message,
1232 new UiCallback<Message>() {
1233
1234 @Override
1235 public void userInputRequried(PendingIntent pi,
1236 Message message) {
1237 ConversationActivity.this.runIntent(pi,
1238 ConversationActivity.REQUEST_SEND_MESSAGE);
1239 }
1240
1241 @Override
1242 public void success(Message message) {
1243 message.setEncryption(Message.ENCRYPTION_DECRYPTED);
1244 xmppConnectionService.sendMessage(message);
1245 }
1246
1247 @Override
1248 public void error(int error, Message message) {
1249
1250 }
1251 });
1252 }
1253
1254 public boolean useSendButtonToIndicateStatus() {
1255 return getPreferences().getBoolean("send_button_status", false);
1256 }
1257
1258 public boolean indicateReceived() {
1259 return getPreferences().getBoolean("indicate_received", false);
1260 }
1261
1262 public boolean useWhiteBackground() {
1263 return getPreferences().getBoolean("use_white_background",false);
1264 }
1265
1266 protected boolean trustKeysIfNeeded(int requestCode) {
1267 return trustKeysIfNeeded(requestCode, ATTACHMENT_CHOICE_INVALID);
1268 }
1269
1270 protected boolean trustKeysIfNeeded(int requestCode, int attachmentChoice) {
1271 AxolotlService axolotlService = mSelectedConversation.getAccount().getAxolotlService();
1272 boolean hasPendingKeys = !axolotlService.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED,
1273 mSelectedConversation.getContact()).isEmpty()
1274 || !axolotlService.findDevicesWithoutSession(mSelectedConversation).isEmpty();
1275 boolean hasNoTrustedKeys = axolotlService.getNumTrustedKeys(mSelectedConversation.getContact()) == 0;
1276 if( hasPendingKeys || hasNoTrustedKeys) {
1277 axolotlService.createSessionsIfNeeded(mSelectedConversation);
1278 Intent intent = new Intent(getApplicationContext(), TrustKeysActivity.class);
1279 intent.putExtra("contact", mSelectedConversation.getContact().getJid().toBareJid().toString());
1280 intent.putExtra("account", mSelectedConversation.getAccount().getJid().toBareJid().toString());
1281 intent.putExtra("choice", attachmentChoice);
1282 intent.putExtra("has_no_trusted", hasNoTrustedKeys);
1283 startActivityForResult(intent, requestCode);
1284 return true;
1285 } else {
1286 return false;
1287 }
1288 }
1289
1290 @Override
1291 protected void refreshUiReal() {
1292 updateConversationList();
1293 if (xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 0) {
1294 if (!mRedirected) {
1295 this.mRedirected = true;
1296 startActivity(new Intent(this, EditAccountActivity.class));
1297 finish();
1298 }
1299 } else if (conversationList.size() == 0) {
1300 if (!mRedirected) {
1301 this.mRedirected = true;
1302 Intent intent = new Intent(this, StartConversationActivity.class);
1303 intent.putExtra("init",true);
1304 startActivity(intent);
1305 finish();
1306 }
1307 } else {
1308 ConversationActivity.this.mConversationFragment.updateMessages();
1309 updateActionBarTitle();
1310 }
1311 invalidateOptionsMenu();
1312 }
1313
1314 @Override
1315 public void onAccountUpdate() {
1316 this.refreshUi();
1317 }
1318
1319 @Override
1320 public void onConversationUpdate() {
1321 this.refreshUi();
1322 }
1323
1324 @Override
1325 public void onRosterUpdate() {
1326 this.refreshUi();
1327 }
1328
1329 @Override
1330 public void OnUpdateBlocklist(Status status) {
1331 this.refreshUi();
1332 }
1333
1334 public void unblockConversation(final Blockable conversation) {
1335 xmppConnectionService.sendUnblockRequest(conversation);
1336 }
1337
1338 public boolean enterIsSend() {
1339 return getPreferences().getBoolean("enter_is_send",false);
1340 }
1341
1342 @Override
1343 public void onShowErrorToast(final int resId) {
1344 runOnUiThread(new Runnable() {
1345 @Override
1346 public void run() {
1347 Toast.makeText(ConversationActivity.this,resId,Toast.LENGTH_SHORT).show();
1348 }
1349 });
1350 }
1351}