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