1/*
2 * Copyright (c) 2018, Daniel Gultsch All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
13 *
14 * 3. Neither the name of the copyright holder nor the names of its contributors
15 * may be used to endorse or promote products derived from this software without
16 * specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30package eu.siacs.conversations.ui;
31
32
33import android.annotation.SuppressLint;
34import android.app.Activity;
35import android.app.Fragment;
36import android.app.FragmentManager;
37import android.app.FragmentTransaction;
38import android.content.ActivityNotFoundException;
39import android.content.Context;
40import android.content.Intent;
41import android.content.pm.PackageManager;
42import android.databinding.DataBindingUtil;
43import android.net.Uri;
44import android.os.Build;
45import android.os.Bundle;
46import android.provider.Settings;
47import android.support.annotation.IdRes;
48import android.support.annotation.NonNull;
49import android.support.v7.app.ActionBar;
50import android.support.v7.app.AlertDialog;
51import android.support.v7.widget.Toolbar;
52import android.util.Log;
53import android.view.Menu;
54import android.view.MenuItem;
55import android.widget.Toast;
56
57import org.openintents.openpgp.util.OpenPgpApi;
58
59import java.util.concurrent.atomic.AtomicBoolean;
60
61import eu.siacs.conversations.Config;
62import eu.siacs.conversations.R;
63import eu.siacs.conversations.crypto.OmemoSetting;
64import eu.siacs.conversations.databinding.ActivityConversationsBinding;
65import eu.siacs.conversations.entities.Account;
66import eu.siacs.conversations.entities.Conversation;
67import eu.siacs.conversations.services.XmppConnectionService;
68import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
69import eu.siacs.conversations.ui.interfaces.OnConversationArchived;
70import eu.siacs.conversations.ui.interfaces.OnConversationRead;
71import eu.siacs.conversations.ui.interfaces.OnConversationSelected;
72import eu.siacs.conversations.ui.interfaces.OnConversationsListItemUpdated;
73import eu.siacs.conversations.ui.service.EmojiService;
74import eu.siacs.conversations.ui.util.ActivityResult;
75import eu.siacs.conversations.ui.util.ConversationMenuConfigurator;
76import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
77import eu.siacs.conversations.ui.util.PendingItem;
78import eu.siacs.conversations.utils.ExceptionHelper;
79import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
80
81import static eu.siacs.conversations.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
82
83public class ConversationsActivity extends XmppActivity implements OnConversationSelected, OnConversationArchived, OnConversationsListItemUpdated, OnConversationRead, XmppConnectionService.OnAccountUpdate, XmppConnectionService.OnConversationUpdate, XmppConnectionService.OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
84
85 public static final String ACTION_VIEW_CONVERSATION = "eu.siacs.conversations.action.VIEW";
86 public static final String EXTRA_CONVERSATION = "conversationUuid";
87 public static final String EXTRA_DOWNLOAD_UUID = "eu.siacs.conversations.download_uuid";
88 public static final String EXTRA_TEXT = "text";
89 public static final String EXTRA_AS_QUOTE = "as_quote";
90 public static final String EXTRA_NICK = "nick";
91 public static final String EXTRA_IS_PRIVATE_MESSAGE = "pm";
92
93 public static final int REQUEST_OPEN_MESSAGE = 0x9876;
94 public static final int REQUEST_PLAY_PAUSE = 0x5432;
95
96
97 //secondary fragment (when holding the conversation, must be initialized before refreshing the overview fragment
98 private static final @IdRes
99 int[] FRAGMENT_ID_NOTIFICATION_ORDER = {R.id.secondary_fragment, R.id.main_fragment};
100 private final PendingItem<Intent> pendingViewIntent = new PendingItem<>();
101 private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
102 private ActivityConversationsBinding binding;
103 private boolean mActivityPaused = true;
104 private AtomicBoolean mRedirectInProcess = new AtomicBoolean(false);
105
106 private static boolean isViewIntent(Intent i) {
107 return i != null && ACTION_VIEW_CONVERSATION.equals(i.getAction()) && i.hasExtra(EXTRA_CONVERSATION);
108 }
109
110 private static Intent createLauncherIntent(Context context) {
111 final Intent intent = new Intent(context, ConversationsActivity.class);
112 intent.setAction(Intent.ACTION_MAIN);
113 intent.addCategory(Intent.CATEGORY_LAUNCHER);
114 return intent;
115 }
116
117 @Override
118 protected void refreshUiReal() {
119 for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
120 refreshFragment(id);
121 }
122 }
123
124 @Override
125 void onBackendConnected() {
126 if (performRedirectIfNecessary(true)) {
127 return;
128 }
129 xmppConnectionService.getNotificationService().setIsInForeground(true);
130 Intent intent = pendingViewIntent.pop();
131 if (intent != null) {
132 if (processViewIntent(intent)) {
133 if (binding.secondaryFragment != null) {
134 notifyFragmentOfBackendConnected(R.id.main_fragment);
135 }
136 invalidateActionBarTitle();
137 return;
138 }
139 }
140 for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
141 notifyFragmentOfBackendConnected(id);
142 }
143
144 ActivityResult activityResult = postponedActivityResult.pop();
145 if (activityResult != null) {
146 handleActivityResult(activityResult);
147 }
148
149 invalidateActionBarTitle();
150 if (binding.secondaryFragment != null && ConversationFragment.getConversation(this) == null) {
151 Conversation conversation = ConversationsOverviewFragment.getSuggestion(this);
152 if (conversation != null) {
153 openConversation(conversation, null);
154 }
155 }
156 showDialogsIfMainIsOverview();
157 }
158
159 private boolean performRedirectIfNecessary(boolean noAnimation) {
160 return performRedirectIfNecessary(null, noAnimation);
161 }
162
163 private boolean performRedirectIfNecessary(final Conversation ignore, final boolean noAnimation) {
164 if (xmppConnectionService == null) {
165 return false;
166 }
167 boolean isConversationsListEmpty = xmppConnectionService.isConversationsListEmpty(ignore);
168 if (isConversationsListEmpty && mRedirectInProcess.compareAndSet(false, true)) {
169 final Intent intent = getRedirectionIntent(noAnimation);
170 runOnUiThread(() -> {
171 startActivity(intent);
172 if (noAnimation) {
173 overridePendingTransition(0, 0);
174 }
175 });
176 }
177 return mRedirectInProcess.get();
178 }
179
180 private Intent getRedirectionIntent(boolean noAnimation) {
181 Account pendingAccount = xmppConnectionService.getPendingAccount();
182 Intent intent;
183 if (pendingAccount != null) {
184 intent = new Intent(this, EditAccountActivity.class);
185 intent.putExtra("jid", pendingAccount.getJid().asBareJid().toString());
186 } else {
187 if (xmppConnectionService.getAccounts().size() == 0) {
188 if (Config.X509_VERIFICATION) {
189 intent = new Intent(this, ManageAccountActivity.class);
190 } else if (Config.MAGIC_CREATE_DOMAIN != null) {
191 intent = new Intent(this, WelcomeActivity.class);
192 WelcomeActivity.addInviteUri(intent, getIntent());
193 } else {
194 intent = new Intent(this, EditAccountActivity.class);
195 }
196 } else {
197 intent = new Intent(this, StartConversationActivity.class);
198 }
199 }
200 intent.putExtra("init", true);
201 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
202 if (noAnimation) {
203 intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
204 }
205 return intent;
206 }
207
208 private void showDialogsIfMainIsOverview() {
209 if (xmppConnectionService == null) {
210 return;
211 }
212 final Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
213 if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
214 if (ExceptionHelper.checkForCrash(this)) {
215 return;
216 }
217 openBatteryOptimizationDialogIfNeeded();
218 }
219 }
220
221 private String getBatteryOptimizationPreferenceKey() {
222 @SuppressLint("HardwareIds") String device = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
223 return "show_battery_optimization" + (device == null ? "" : device);
224 }
225
226 private void setNeverAskForBatteryOptimizationsAgain() {
227 getPreferences().edit().putBoolean(getBatteryOptimizationPreferenceKey(), false).apply();
228 }
229
230 private void openBatteryOptimizationDialogIfNeeded() {
231 if (hasAccountWithoutPush()
232 && isOptimizingBattery()
233 && getPreferences().getBoolean(getBatteryOptimizationPreferenceKey(), true)) {
234 AlertDialog.Builder builder = new AlertDialog.Builder(this);
235 builder.setTitle(R.string.battery_optimizations_enabled);
236 builder.setMessage(R.string.battery_optimizations_enabled_dialog);
237 builder.setPositiveButton(R.string.next, (dialog, which) -> {
238 Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
239 Uri uri = Uri.parse("package:" + getPackageName());
240 intent.setData(uri);
241 try {
242 startActivityForResult(intent, REQUEST_BATTERY_OP);
243 } catch (ActivityNotFoundException e) {
244 Toast.makeText(this, R.string.device_does_not_support_battery_op, Toast.LENGTH_SHORT).show();
245 }
246 });
247 builder.setOnDismissListener(dialog -> setNeverAskForBatteryOptimizationsAgain());
248 final AlertDialog dialog = builder.create();
249 dialog.setCanceledOnTouchOutside(false);
250 dialog.show();
251 }
252 }
253
254 private boolean hasAccountWithoutPush() {
255 for (Account account : xmppConnectionService.getAccounts()) {
256 if (account.getStatus() == Account.State.ONLINE && !xmppConnectionService.getPushManagementService().available(account)) {
257 return true;
258 }
259 }
260 return false;
261 }
262
263 private void notifyFragmentOfBackendConnected(@IdRes int id) {
264 final Fragment fragment = getFragmentManager().findFragmentById(id);
265 if (fragment != null && fragment instanceof OnBackendConnected) {
266 ((OnBackendConnected) fragment).onBackendConnected();
267 }
268 }
269
270 private void refreshFragment(@IdRes int id) {
271 final Fragment fragment = getFragmentManager().findFragmentById(id);
272 if (fragment != null && fragment instanceof XmppFragment) {
273 ((XmppFragment) fragment).refresh();
274 }
275 }
276
277 private boolean processViewIntent(Intent intent) {
278 String uuid = intent.getStringExtra(EXTRA_CONVERSATION);
279 Conversation conversation = uuid != null ? xmppConnectionService.findConversationByUuid(uuid) : null;
280 if (conversation == null) {
281 Log.d(Config.LOGTAG, "unable to view conversation with uuid:" + uuid);
282 return false;
283 }
284 openConversation(conversation, intent.getExtras());
285 return true;
286 }
287
288 @Override
289 public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
290 UriHandlerActivity.onRequestPermissionResult(this, requestCode, grantResults);
291 if (grantResults.length > 0) {
292 if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
293 switch (requestCode) {
294 case REQUEST_OPEN_MESSAGE:
295 refreshUiReal();
296 ConversationFragment.openPendingMessage(this);
297 break;
298 case REQUEST_PLAY_PAUSE:
299 ConversationFragment.startStopPending(this);
300 break;
301 }
302 }
303 }
304 }
305
306 @Override
307 public void onActivityResult(int requestCode, int resultCode, final Intent data) {
308 super.onActivityResult(requestCode, resultCode, data);
309 ActivityResult activityResult = ActivityResult.of(requestCode, resultCode, data);
310 if (xmppConnectionService != null) {
311 handleActivityResult(activityResult);
312 } else {
313 this.postponedActivityResult.push(activityResult);
314 }
315 }
316
317 private void handleActivityResult(ActivityResult activityResult) {
318 if (activityResult.resultCode == Activity.RESULT_OK) {
319 handlePositiveActivityResult(activityResult.requestCode, activityResult.data);
320 } else {
321 handleNegativeActivityResult(activityResult.requestCode);
322 }
323 }
324
325 private void handleNegativeActivityResult(int requestCode) {
326 Conversation conversation = ConversationFragment.getConversationReliable(this);
327 switch (requestCode) {
328 case REQUEST_DECRYPT_PGP:
329 if (conversation == null) {
330 break;
331 }
332 conversation.getAccount().getPgpDecryptionService().giveUpCurrentDecryption();
333 break;
334 case REQUEST_BATTERY_OP:
335 setNeverAskForBatteryOptimizationsAgain();
336 break;
337 }
338 }
339
340 private void handlePositiveActivityResult(int requestCode, final Intent data) {
341 Conversation conversation = ConversationFragment.getConversationReliable(this);
342 if (conversation == null) {
343 Log.d(Config.LOGTAG, "conversation not found");
344 return;
345 }
346 switch (requestCode) {
347 case REQUEST_DECRYPT_PGP:
348 conversation.getAccount().getPgpDecryptionService().continueDecryption(data);
349 break;
350 case REQUEST_CHOOSE_PGP_ID:
351 long id = data.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, 0);
352 if (id != 0) {
353 conversation.getAccount().setPgpSignId(id);
354 announcePgp(conversation.getAccount(), null, null, onOpenPGPKeyPublished);
355 } else {
356 choosePgpSignId(conversation.getAccount());
357 }
358 break;
359 case REQUEST_ANNOUNCE_PGP:
360 announcePgp(conversation.getAccount(), conversation, data, onOpenPGPKeyPublished);
361 break;
362 }
363 }
364
365 @Override
366 protected void onCreate(final Bundle savedInstanceState) {
367 super.onCreate(savedInstanceState);
368 ConversationMenuConfigurator.reloadFeatures(this);
369 OmemoSetting.load(this);
370 new EmojiService(this).init();
371 this.binding = DataBindingUtil.setContentView(this, R.layout.activity_conversations);
372 setSupportActionBar((Toolbar) binding.toolbar);
373 configureActionBar(getSupportActionBar());
374 this.getFragmentManager().addOnBackStackChangedListener(this::invalidateActionBarTitle);
375 this.getFragmentManager().addOnBackStackChangedListener(this::showDialogsIfMainIsOverview);
376 this.initializeFragments();
377 this.invalidateActionBarTitle();
378 final Intent intent;
379 if (savedInstanceState == null) {
380 intent = getIntent();
381 } else {
382 intent = savedInstanceState.getParcelable("intent");
383 }
384 if (isViewIntent(intent)) {
385 pendingViewIntent.push(intent);
386 setIntent(createLauncherIntent(this));
387 }
388 }
389
390 @Override
391 public boolean onCreateOptionsMenu(Menu menu) {
392 getMenuInflater().inflate(R.menu.activity_conversations, menu);
393 MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
394 if (qrCodeScanMenuItem != null) {
395 if (isCameraFeatureAvailable()) {
396 Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
397 boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan)
398 && fragment != null
399 && fragment instanceof ConversationsOverviewFragment;
400 qrCodeScanMenuItem.setVisible(visible);
401 } else {
402 qrCodeScanMenuItem.setVisible(false);
403 }
404 }
405 return super.onCreateOptionsMenu(menu);
406 }
407
408 @Override
409 public void onConversationSelected(Conversation conversation) {
410 if (ConversationFragment.getConversation(this) == conversation) {
411 Log.d(Config.LOGTAG, "ignore onConversationSelected() because conversation is already open");
412 return;
413 }
414 openConversation(conversation, null);
415 }
416
417 private void openConversation(Conversation conversation, Bundle extras) {
418 ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
419 final boolean mainNeedsRefresh;
420 if (conversationFragment == null) {
421 mainNeedsRefresh = false;
422 Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
423 if (mainFragment != null && mainFragment instanceof ConversationFragment) {
424 conversationFragment = (ConversationFragment) mainFragment;
425 } else {
426 conversationFragment = new ConversationFragment();
427 FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
428 fragmentTransaction.replace(R.id.main_fragment, conversationFragment);
429 fragmentTransaction.addToBackStack(null);
430 try {
431 fragmentTransaction.commit();
432 } catch (IllegalStateException e) {
433 Log.w(Config.LOGTAG,"sate loss while opening conversation",e);
434 //allowing state loss is probably fine since view intents et all are already stored and a click can probably be 'ignored'
435 return;
436 }
437 }
438 } else {
439 mainNeedsRefresh = true;
440 }
441 conversationFragment.reInit(conversation, extras == null ? new Bundle() : extras);
442 if (mainNeedsRefresh) {
443 refreshFragment(R.id.main_fragment);
444 } else {
445 invalidateActionBarTitle();
446 }
447 }
448
449 @Override
450 public boolean onOptionsItemSelected(MenuItem item) {
451 if (MenuDoubleTabUtil.shouldIgnoreTap()) {
452 return false;
453 }
454 switch (item.getItemId()) {
455 case android.R.id.home:
456 FragmentManager fm = getFragmentManager();
457 if (fm.getBackStackEntryCount() > 0) {
458 fm.popBackStack();
459 return true;
460 }
461 break;
462 case R.id.action_scan_qr_code:
463 UriHandlerActivity.scan(this);
464 return true;
465 }
466 return super.onOptionsItemSelected(item);
467 }
468
469 @Override
470 public void onSaveInstanceState(Bundle savedInstanceState) {
471 Intent pendingIntent = pendingViewIntent.peek();
472 savedInstanceState.putParcelable("intent", pendingIntent != null ? pendingIntent : getIntent());
473 super.onSaveInstanceState(savedInstanceState);
474 }
475
476 @Override
477 protected void onStart() {
478 final int theme = findTheme();
479 if (this.mTheme != theme) {
480 this.mSkipBackgroundBinding = true;
481 recreate();
482 } else {
483 this.mSkipBackgroundBinding = false;
484 }
485 mRedirectInProcess.set(false);
486 super.onStart();
487 }
488
489 @Override
490 protected void onNewIntent(final Intent intent) {
491 if (isViewIntent(intent)) {
492 if (xmppConnectionService != null) {
493 processViewIntent(intent);
494 } else {
495 pendingViewIntent.push(intent);
496 }
497 }
498 setIntent(createLauncherIntent(this));
499 }
500
501 @Override
502 public void onPause() {
503 this.mActivityPaused = true;
504 super.onPause();
505 }
506
507 @Override
508 public void onResume() {
509 super.onResume();
510 this.mActivityPaused = false;
511 }
512
513 private void initializeFragments() {
514 FragmentTransaction transaction = getFragmentManager().beginTransaction();
515 Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
516 Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
517 if (mainFragment != null) {
518 if (binding.secondaryFragment != null) {
519 if (mainFragment instanceof ConversationFragment) {
520 getFragmentManager().popBackStack();
521 transaction.remove(mainFragment);
522 transaction.commit();
523 getFragmentManager().executePendingTransactions();
524 transaction = getFragmentManager().beginTransaction();
525 transaction.replace(R.id.secondary_fragment, mainFragment);
526 transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
527 transaction.commit();
528 return;
529 }
530 } else {
531 if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
532 transaction.remove(secondaryFragment);
533 transaction.commit();
534 getFragmentManager().executePendingTransactions();
535 transaction = getFragmentManager().beginTransaction();
536 transaction.replace(R.id.main_fragment, secondaryFragment);
537 transaction.addToBackStack(null);
538 transaction.commit();
539 return;
540 }
541 }
542 } else {
543 transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
544 }
545 if (binding.secondaryFragment != null && secondaryFragment == null) {
546 transaction.replace(R.id.secondary_fragment, new ConversationFragment());
547 }
548 transaction.commit();
549 }
550
551 private void invalidateActionBarTitle() {
552 final ActionBar actionBar = getSupportActionBar();
553 if (actionBar != null) {
554 Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
555 if (mainFragment != null && mainFragment instanceof ConversationFragment) {
556 final Conversation conversation = ((ConversationFragment) mainFragment).getConversation();
557 if (conversation != null) {
558 actionBar.setTitle(conversation.getName());
559 actionBar.setDisplayHomeAsUpEnabled(true);
560 return;
561 }
562 }
563 actionBar.setTitle(R.string.app_name);
564 actionBar.setDisplayHomeAsUpEnabled(false);
565 }
566 }
567
568 @Override
569 public void onConversationArchived(Conversation conversation) {
570 if (performRedirectIfNecessary(conversation, false)) {
571 return;
572 }
573 Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
574 if (mainFragment != null && mainFragment instanceof ConversationFragment) {
575 try {
576 getFragmentManager().popBackStack();
577 } catch (IllegalStateException e) {
578 Log.w(Config.LOGTAG,"state loss while popping back state after archiving conversation",e);
579 //this usually means activity is no longer active; meaning on the next open we will run through this again
580 }
581 return;
582 }
583 Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
584 if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
585 if (((ConversationFragment) secondaryFragment).getConversation() == conversation) {
586 Conversation suggestion = ConversationsOverviewFragment.getSuggestion(this, conversation);
587 if (suggestion != null) {
588 openConversation(suggestion, null);
589 }
590 }
591 }
592 }
593
594 @Override
595 public void onConversationsListItemUpdated() {
596 Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
597 if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
598 ((ConversationsOverviewFragment) fragment).refresh();
599 }
600 }
601
602 @Override
603 public void switchToConversation(Conversation conversation) {
604 Log.d(Config.LOGTAG, "override");
605 openConversation(conversation, null);
606 }
607
608 @Override
609 public void onConversationRead(Conversation conversation, String upToUuid) {
610 if (!mActivityPaused && pendingViewIntent.peek() == null) {
611 xmppConnectionService.sendReadMarker(conversation, upToUuid);
612 } else {
613 Log.d(Config.LOGTAG, "ignoring read callback. mActivityPaused=" + Boolean.toString(mActivityPaused));
614 }
615 }
616
617 @Override
618 public void onAccountUpdate() {
619 this.refreshUi();
620 }
621
622 @Override
623 public void onConversationUpdate() {
624 if (performRedirectIfNecessary(false)) {
625 return;
626 }
627 this.refreshUi();
628 }
629
630 @Override
631 public void onRosterUpdate() {
632 this.refreshUi();
633 }
634
635 @Override
636 public void OnUpdateBlocklist(OnUpdateBlocklist.Status status) {
637 this.refreshUi();
638 }
639
640 @Override
641 public void onShowErrorToast(int resId) {
642 runOnUiThread(() -> Toast.makeText(this, resId, Toast.LENGTH_SHORT).show());
643 }
644}