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.utils.XmppUri;
80import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
81
82import static eu.siacs.conversations.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
83
84public class ConversationsActivity extends XmppActivity implements OnConversationSelected, OnConversationArchived, OnConversationsListItemUpdated, OnConversationRead, XmppConnectionService.OnAccountUpdate, XmppConnectionService.OnConversationUpdate, XmppConnectionService.OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
85
86 public static final String ACTION_VIEW_CONVERSATION = "eu.siacs.conversations.action.VIEW";
87 public static final String EXTRA_CONVERSATION = "conversationUuid";
88 public static final String EXTRA_DOWNLOAD_UUID = "eu.siacs.conversations.download_uuid";
89 public static final String EXTRA_TEXT = "text";
90 public static final String EXTRA_AS_QUOTE = "as_quote";
91 public static final String EXTRA_NICK = "nick";
92 public static final String EXTRA_IS_PRIVATE_MESSAGE = "pm";
93
94 public static final int REQUEST_OPEN_MESSAGE = 0x9876;
95 public static final int REQUEST_PLAY_PAUSE = 0x5432;
96
97
98 //secondary fragment (when holding the conversation, must be initialized before refreshing the overview fragment
99 private static final @IdRes
100 int[] FRAGMENT_ID_NOTIFICATION_ORDER = {R.id.secondary_fragment, R.id.main_fragment};
101 private final PendingItem<Intent> pendingViewIntent = new PendingItem<>();
102 private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
103 private ActivityConversationsBinding binding;
104 private boolean mActivityPaused = true;
105 private AtomicBoolean mRedirectInProcess = new AtomicBoolean(false);
106
107 private static boolean isViewIntent(Intent i) {
108 return i != null && ACTION_VIEW_CONVERSATION.equals(i.getAction()) && i.hasExtra(EXTRA_CONVERSATION);
109 }
110
111 private static Intent createLauncherIntent(Context context) {
112 final Intent intent = new Intent(context, ConversationsActivity.class);
113 intent.setAction(Intent.ACTION_MAIN);
114 intent.addCategory(Intent.CATEGORY_LAUNCHER);
115 return intent;
116 }
117
118 @Override
119 protected void refreshUiReal() {
120 for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
121 refreshFragment(id);
122 }
123 }
124
125 @Override
126 void onBackendConnected() {
127 if (performRedirectIfNecessary(true)) {
128 return;
129 }
130 xmppConnectionService.getNotificationService().setIsInForeground(true);
131 Intent intent = pendingViewIntent.pop();
132 if (intent != null) {
133 if (processViewIntent(intent)) {
134 if (binding.secondaryFragment != null) {
135 notifyFragmentOfBackendConnected(R.id.main_fragment);
136 }
137 invalidateActionBarTitle();
138 return;
139 }
140 }
141 for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
142 notifyFragmentOfBackendConnected(id);
143 }
144
145 ActivityResult activityResult = postponedActivityResult.pop();
146 if (activityResult != null) {
147 handleActivityResult(activityResult);
148 }
149
150 invalidateActionBarTitle();
151 if (binding.secondaryFragment != null && ConversationFragment.getConversation(this) == null) {
152 Conversation conversation = ConversationsOverviewFragment.getSuggestion(this);
153 if (conversation != null) {
154 openConversation(conversation, null);
155 }
156 }
157 showDialogsIfMainIsOverview();
158 }
159
160 private boolean performRedirectIfNecessary(boolean noAnimation) {
161 return performRedirectIfNecessary(null, noAnimation);
162 }
163
164 private boolean performRedirectIfNecessary(final Conversation ignore, final boolean noAnimation) {
165 if (xmppConnectionService == null) {
166 return false;
167 }
168 boolean isConversationsListEmpty = xmppConnectionService.isConversationsListEmpty(ignore);
169 if (isConversationsListEmpty && mRedirectInProcess.compareAndSet(false, true)) {
170 final Intent intent = getRedirectionIntent(noAnimation);
171 runOnUiThread(() -> {
172 startActivity(intent);
173 if (noAnimation) {
174 overridePendingTransition(0, 0);
175 }
176 });
177 }
178 return mRedirectInProcess.get();
179 }
180
181 private Intent getRedirectionIntent(boolean noAnimation) {
182 Account pendingAccount = xmppConnectionService.getPendingAccount();
183 Intent intent;
184 if (pendingAccount != null) {
185 intent = new Intent(this, EditAccountActivity.class);
186 intent.putExtra("jid", pendingAccount.getJid().asBareJid().toString());
187 } else {
188 if (xmppConnectionService.getAccounts().size() == 0) {
189 if (Config.X509_VERIFICATION) {
190 intent = new Intent(this, ManageAccountActivity.class);
191 } else if (Config.MAGIC_CREATE_DOMAIN != null) {
192 intent = new Intent(this, WelcomeActivity.class);
193 WelcomeActivity.addInviteUri(intent, getIntent());
194 } else {
195 intent = new Intent(this, EditAccountActivity.class);
196 }
197 } else {
198 intent = new Intent(this, StartConversationActivity.class);
199 }
200 }
201 intent.putExtra("init", true);
202 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
203 if (noAnimation) {
204 intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
205 }
206 return intent;
207 }
208
209 private void showDialogsIfMainIsOverview() {
210 if (xmppConnectionService == null) {
211 return;
212 }
213 final Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
214 if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
215 if (ExceptionHelper.checkForCrash(this)) {
216 return;
217 }
218 openBatteryOptimizationDialogIfNeeded();
219 }
220 }
221
222 private String getBatteryOptimizationPreferenceKey() {
223 @SuppressLint("HardwareIds") String device = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
224 return "show_battery_optimization" + (device == null ? "" : device);
225 }
226
227 private void setNeverAskForBatteryOptimizationsAgain() {
228 getPreferences().edit().putBoolean(getBatteryOptimizationPreferenceKey(), false).apply();
229 }
230
231 private void openBatteryOptimizationDialogIfNeeded() {
232 if (hasAccountWithoutPush()
233 && isOptimizingBattery()
234 && getPreferences().getBoolean(getBatteryOptimizationPreferenceKey(), true)) {
235 AlertDialog.Builder builder = new AlertDialog.Builder(this);
236 builder.setTitle(R.string.battery_optimizations_enabled);
237 builder.setMessage(R.string.battery_optimizations_enabled_dialog);
238 builder.setPositiveButton(R.string.next, (dialog, which) -> {
239 Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
240 Uri uri = Uri.parse("package:" + getPackageName());
241 intent.setData(uri);
242 try {
243 startActivityForResult(intent, REQUEST_BATTERY_OP);
244 } catch (ActivityNotFoundException e) {
245 Toast.makeText(this, R.string.device_does_not_support_battery_op, Toast.LENGTH_SHORT).show();
246 }
247 });
248 builder.setOnDismissListener(dialog -> setNeverAskForBatteryOptimizationsAgain());
249 final AlertDialog dialog = builder.create();
250 dialog.setCanceledOnTouchOutside(false);
251 dialog.show();
252 }
253 }
254
255 private boolean hasAccountWithoutPush() {
256 for (Account account : xmppConnectionService.getAccounts()) {
257 if (account.getStatus() == Account.State.ONLINE && !xmppConnectionService.getPushManagementService().available(account)) {
258 return true;
259 }
260 }
261 return false;
262 }
263
264 private void notifyFragmentOfBackendConnected(@IdRes int id) {
265 final Fragment fragment = getFragmentManager().findFragmentById(id);
266 if (fragment != null && fragment instanceof OnBackendConnected) {
267 ((OnBackendConnected) fragment).onBackendConnected();
268 }
269 }
270
271 private void refreshFragment(@IdRes int id) {
272 final Fragment fragment = getFragmentManager().findFragmentById(id);
273 if (fragment != null && fragment instanceof XmppFragment) {
274 ((XmppFragment) fragment).refresh();
275 }
276 }
277
278 private boolean processViewIntent(Intent intent) {
279 String uuid = intent.getStringExtra(EXTRA_CONVERSATION);
280 Conversation conversation = uuid != null ? xmppConnectionService.findConversationByUuid(uuid) : null;
281 if (conversation == null) {
282 Log.d(Config.LOGTAG, "unable to view conversation with uuid:" + uuid);
283 return false;
284 }
285 openConversation(conversation, intent.getExtras());
286 return true;
287 }
288
289 @Override
290 public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
291 UriHandlerActivity.onRequestPermissionResult(this, requestCode, grantResults);
292 if (grantResults.length > 0) {
293 if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
294 switch (requestCode) {
295 case REQUEST_OPEN_MESSAGE:
296 refreshUiReal();
297 ConversationFragment.openPendingMessage(this);
298 break;
299 case REQUEST_PLAY_PAUSE:
300 ConversationFragment.startStopPending(this);
301 break;
302 }
303 }
304 }
305 }
306
307 @Override
308 public void onActivityResult(int requestCode, int resultCode, final Intent data) {
309 super.onActivityResult(requestCode, resultCode, data);
310 ActivityResult activityResult = ActivityResult.of(requestCode, resultCode, data);
311 if (xmppConnectionService != null) {
312 handleActivityResult(activityResult);
313 } else {
314 this.postponedActivityResult.push(activityResult);
315 }
316 }
317
318 private void handleActivityResult(ActivityResult activityResult) {
319 if (activityResult.resultCode == Activity.RESULT_OK) {
320 handlePositiveActivityResult(activityResult.requestCode, activityResult.data);
321 } else {
322 handleNegativeActivityResult(activityResult.requestCode);
323 }
324 }
325
326 private void handleNegativeActivityResult(int requestCode) {
327 Conversation conversation = ConversationFragment.getConversationReliable(this);
328 switch (requestCode) {
329 case REQUEST_DECRYPT_PGP:
330 if (conversation == null) {
331 break;
332 }
333 conversation.getAccount().getPgpDecryptionService().giveUpCurrentDecryption();
334 break;
335 case REQUEST_BATTERY_OP:
336 setNeverAskForBatteryOptimizationsAgain();
337 break;
338 }
339 }
340
341 private void handlePositiveActivityResult(int requestCode, final Intent data) {
342 Conversation conversation = ConversationFragment.getConversationReliable(this);
343 if (conversation == null) {
344 Log.d(Config.LOGTAG, "conversation not found");
345 return;
346 }
347 switch (requestCode) {
348 case REQUEST_DECRYPT_PGP:
349 conversation.getAccount().getPgpDecryptionService().continueDecryption(data);
350 break;
351 case REQUEST_CHOOSE_PGP_ID:
352 long id = data.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, 0);
353 if (id != 0) {
354 conversation.getAccount().setPgpSignId(id);
355 announcePgp(conversation.getAccount(), null, null, onOpenPGPKeyPublished);
356 } else {
357 choosePgpSignId(conversation.getAccount());
358 }
359 break;
360 case REQUEST_ANNOUNCE_PGP:
361 announcePgp(conversation.getAccount(), conversation, data, onOpenPGPKeyPublished);
362 break;
363 }
364 }
365
366 @Override
367 protected void onCreate(final Bundle savedInstanceState) {
368 super.onCreate(savedInstanceState);
369 ConversationMenuConfigurator.reloadFeatures(this);
370 OmemoSetting.load(this);
371 new EmojiService(this).init();
372 this.binding = DataBindingUtil.setContentView(this, R.layout.activity_conversations);
373 setSupportActionBar((Toolbar) binding.toolbar);
374 configureActionBar(getSupportActionBar());
375 this.getFragmentManager().addOnBackStackChangedListener(this::invalidateActionBarTitle);
376 this.getFragmentManager().addOnBackStackChangedListener(this::showDialogsIfMainIsOverview);
377 this.initializeFragments();
378 this.invalidateActionBarTitle();
379 final Intent intent;
380 if (savedInstanceState == null) {
381 intent = getIntent();
382 } else {
383 intent = savedInstanceState.getParcelable("intent");
384 }
385 if (isViewIntent(intent)) {
386 pendingViewIntent.push(intent);
387 setIntent(createLauncherIntent(this));
388 }
389 }
390
391 @Override
392 public boolean onCreateOptionsMenu(Menu menu) {
393 getMenuInflater().inflate(R.menu.activity_conversations, menu);
394 MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
395 if (qrCodeScanMenuItem != null) {
396 if (isCameraFeatureAvailable()) {
397 Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
398 boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan)
399 && fragment != null
400 && fragment instanceof ConversationsOverviewFragment;
401 qrCodeScanMenuItem.setVisible(visible);
402 } else {
403 qrCodeScanMenuItem.setVisible(false);
404 }
405 }
406 return super.onCreateOptionsMenu(menu);
407 }
408
409 @Override
410 public void onConversationSelected(Conversation conversation) {
411 if (ConversationFragment.getConversation(this) == conversation) {
412 Log.d(Config.LOGTAG, "ignore onConversationSelected() because conversation is already open");
413 return;
414 }
415 openConversation(conversation, null);
416 }
417
418 private void openConversation(Conversation conversation, Bundle extras) {
419 ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
420 final boolean mainNeedsRefresh;
421 if (conversationFragment == null) {
422 mainNeedsRefresh = false;
423 Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
424 if (mainFragment != null && mainFragment instanceof ConversationFragment) {
425 conversationFragment = (ConversationFragment) mainFragment;
426 } else {
427 conversationFragment = new ConversationFragment();
428 FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
429 fragmentTransaction.replace(R.id.main_fragment, conversationFragment);
430 fragmentTransaction.addToBackStack(null);
431 try {
432 fragmentTransaction.commit();
433 } catch (IllegalStateException e) {
434 Log.w(Config.LOGTAG,"sate loss while opening conversation",e);
435 //allowing state loss is probably fine since view intents et all are already stored and a click can probably be 'ignored'
436 return;
437 }
438 }
439 } else {
440 mainNeedsRefresh = true;
441 }
442 conversationFragment.reInit(conversation, extras == null ? new Bundle() : extras);
443 if (mainNeedsRefresh) {
444 refreshFragment(R.id.main_fragment);
445 } else {
446 invalidateActionBarTitle();
447 }
448 }
449
450 public boolean onXmppUriClicked(Uri uri) {
451 XmppUri xmppUri = new XmppUri(uri);
452 if (xmppUri.isJidValid() && !xmppUri.hasFingerprints()) {
453 final Conversation conversation = xmppConnectionService.findUniqueConversationByJid(xmppUri);
454 if (conversation != null) {
455 openConversation(conversation, null);
456 return true;
457 }
458 }
459 return false;
460 }
461
462 @Override
463 public boolean onOptionsItemSelected(MenuItem item) {
464 if (MenuDoubleTabUtil.shouldIgnoreTap()) {
465 return false;
466 }
467 switch (item.getItemId()) {
468 case android.R.id.home:
469 FragmentManager fm = getFragmentManager();
470 if (fm.getBackStackEntryCount() > 0) {
471 fm.popBackStack();
472 return true;
473 }
474 break;
475 case R.id.action_scan_qr_code:
476 UriHandlerActivity.scan(this);
477 return true;
478 }
479 return super.onOptionsItemSelected(item);
480 }
481
482 @Override
483 public void onSaveInstanceState(Bundle savedInstanceState) {
484 Intent pendingIntent = pendingViewIntent.peek();
485 savedInstanceState.putParcelable("intent", pendingIntent != null ? pendingIntent : getIntent());
486 super.onSaveInstanceState(savedInstanceState);
487 }
488
489 @Override
490 protected void onStart() {
491 final int theme = findTheme();
492 if (this.mTheme != theme) {
493 this.mSkipBackgroundBinding = true;
494 recreate();
495 } else {
496 this.mSkipBackgroundBinding = false;
497 }
498 mRedirectInProcess.set(false);
499 super.onStart();
500 }
501
502 @Override
503 protected void onNewIntent(final Intent intent) {
504 if (isViewIntent(intent)) {
505 if (xmppConnectionService != null) {
506 processViewIntent(intent);
507 } else {
508 pendingViewIntent.push(intent);
509 }
510 }
511 setIntent(createLauncherIntent(this));
512 }
513
514 @Override
515 public void onPause() {
516 this.mActivityPaused = true;
517 super.onPause();
518 }
519
520 @Override
521 public void onResume() {
522 super.onResume();
523 this.mActivityPaused = false;
524 }
525
526 private void initializeFragments() {
527 FragmentTransaction transaction = getFragmentManager().beginTransaction();
528 Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
529 Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
530 if (mainFragment != null) {
531 if (binding.secondaryFragment != null) {
532 if (mainFragment instanceof ConversationFragment) {
533 getFragmentManager().popBackStack();
534 transaction.remove(mainFragment);
535 transaction.commit();
536 getFragmentManager().executePendingTransactions();
537 transaction = getFragmentManager().beginTransaction();
538 transaction.replace(R.id.secondary_fragment, mainFragment);
539 transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
540 transaction.commit();
541 return;
542 }
543 } else {
544 if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
545 transaction.remove(secondaryFragment);
546 transaction.commit();
547 getFragmentManager().executePendingTransactions();
548 transaction = getFragmentManager().beginTransaction();
549 transaction.replace(R.id.main_fragment, secondaryFragment);
550 transaction.addToBackStack(null);
551 transaction.commit();
552 return;
553 }
554 }
555 } else {
556 transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
557 }
558 if (binding.secondaryFragment != null && secondaryFragment == null) {
559 transaction.replace(R.id.secondary_fragment, new ConversationFragment());
560 }
561 transaction.commit();
562 }
563
564 private void invalidateActionBarTitle() {
565 final ActionBar actionBar = getSupportActionBar();
566 if (actionBar != null) {
567 Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
568 if (mainFragment != null && mainFragment instanceof ConversationFragment) {
569 final Conversation conversation = ((ConversationFragment) mainFragment).getConversation();
570 if (conversation != null) {
571 actionBar.setTitle(conversation.getName());
572 actionBar.setDisplayHomeAsUpEnabled(true);
573 return;
574 }
575 }
576 actionBar.setTitle(R.string.app_name);
577 actionBar.setDisplayHomeAsUpEnabled(false);
578 }
579 }
580
581 @Override
582 public void onConversationArchived(Conversation conversation) {
583 if (performRedirectIfNecessary(conversation, false)) {
584 return;
585 }
586 Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
587 if (mainFragment != null && mainFragment instanceof ConversationFragment) {
588 try {
589 getFragmentManager().popBackStack();
590 } catch (IllegalStateException e) {
591 Log.w(Config.LOGTAG,"state loss while popping back state after archiving conversation",e);
592 //this usually means activity is no longer active; meaning on the next open we will run through this again
593 }
594 return;
595 }
596 Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
597 if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
598 if (((ConversationFragment) secondaryFragment).getConversation() == conversation) {
599 Conversation suggestion = ConversationsOverviewFragment.getSuggestion(this, conversation);
600 if (suggestion != null) {
601 openConversation(suggestion, null);
602 }
603 }
604 }
605 }
606
607 @Override
608 public void onConversationsListItemUpdated() {
609 Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
610 if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
611 ((ConversationsOverviewFragment) fragment).refresh();
612 }
613 }
614
615 @Override
616 public void switchToConversation(Conversation conversation) {
617 Log.d(Config.LOGTAG, "override");
618 openConversation(conversation, null);
619 }
620
621 @Override
622 public void onConversationRead(Conversation conversation, String upToUuid) {
623 if (!mActivityPaused && pendingViewIntent.peek() == null) {
624 xmppConnectionService.sendReadMarker(conversation, upToUuid);
625 } else {
626 Log.d(Config.LOGTAG, "ignoring read callback. mActivityPaused=" + Boolean.toString(mActivityPaused));
627 }
628 }
629
630 @Override
631 public void onAccountUpdate() {
632 this.refreshUi();
633 }
634
635 @Override
636 public void onConversationUpdate() {
637 if (performRedirectIfNecessary(false)) {
638 return;
639 }
640 this.refreshUi();
641 }
642
643 @Override
644 public void onRosterUpdate() {
645 this.refreshUi();
646 }
647
648 @Override
649 public void OnUpdateBlocklist(OnUpdateBlocklist.Status status) {
650 this.refreshUi();
651 }
652
653 @Override
654 public void onShowErrorToast(int resId) {
655 runOnUiThread(() -> Toast.makeText(this, resId, Toast.LENGTH_SHORT).show());
656 }
657}