ConversationsActivity.java

  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.MenuDoubleTabUtil;
 76import eu.siacs.conversations.ui.util.PendingItem;
 77import eu.siacs.conversations.utils.ExceptionHelper;
 78import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
 79
 80import static eu.siacs.conversations.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
 81
 82public class ConversationsActivity extends XmppActivity implements OnConversationSelected, OnConversationArchived, OnConversationsListItemUpdated, OnConversationRead, XmppConnectionService.OnAccountUpdate, XmppConnectionService.OnConversationUpdate, XmppConnectionService.OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
 83
 84	public static final String ACTION_VIEW_CONVERSATION = "eu.siacs.conversations.action.VIEW";
 85	public static final String EXTRA_CONVERSATION = "conversationUuid";
 86	public static final String EXTRA_DOWNLOAD_UUID = "eu.siacs.conversations.download_uuid";
 87	public static final String EXTRA_TEXT = "text";
 88	public static final String EXTRA_NICK = "nick";
 89	public static final String EXTRA_IS_PRIVATE_MESSAGE = "pm";
 90
 91	public static final int REQUEST_OPEN_MESSAGE = 0x9876;
 92	public static final int REQUEST_PLAY_PAUSE = 0x5432;
 93
 94
 95	//secondary fragment (when holding the conversation, must be initialized before refreshing the overview fragment
 96	private static final @IdRes
 97	int[] FRAGMENT_ID_NOTIFICATION_ORDER = {R.id.secondary_fragment, R.id.main_fragment};
 98	private final PendingItem<Intent> pendingViewIntent = new PendingItem<>();
 99	private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
100	private ActivityConversationsBinding binding;
101	private boolean mActivityPaused = true;
102	private AtomicBoolean mRedirectInProcess = new AtomicBoolean(false);
103
104	private static boolean isViewIntent(Intent i) {
105		return i != null && ACTION_VIEW_CONVERSATION.equals(i.getAction()) && i.hasExtra(EXTRA_CONVERSATION);
106	}
107
108	private static Intent createLauncherIntent(Context context) {
109		final Intent intent = new Intent(context, ConversationsActivity.class);
110		intent.setAction(Intent.ACTION_MAIN);
111		intent.addCategory(Intent.CATEGORY_LAUNCHER);
112		return intent;
113	}
114
115	@Override
116	protected void refreshUiReal() {
117		for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
118			refreshFragment(id);
119		}
120	}
121
122	@Override
123	void onBackendConnected() {
124		if (performRedirectIfNecessary(true)) {
125			return;
126		}
127		xmppConnectionService.getNotificationService().setIsInForeground(true);
128		Intent intent = pendingViewIntent.pop();
129		if (intent != null) {
130			if (processViewIntent(intent)) {
131				if (binding.secondaryFragment != null) {
132					notifyFragmentOfBackendConnected(R.id.main_fragment);
133				}
134				invalidateActionBarTitle();
135				return;
136			}
137		}
138		for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
139			notifyFragmentOfBackendConnected(id);
140		}
141
142		ActivityResult activityResult = postponedActivityResult.pop();
143		if (activityResult != null) {
144			handleActivityResult(activityResult);
145		}
146
147		invalidateActionBarTitle();
148		if (binding.secondaryFragment != null && ConversationFragment.getConversation(this) == null) {
149			Conversation conversation = ConversationsOverviewFragment.getSuggestion(this);
150			if (conversation != null) {
151				openConversation(conversation, null);
152			}
153		}
154		showDialogsIfMainIsOverview();
155	}
156
157	private boolean performRedirectIfNecessary(boolean noAnimation) {
158		return performRedirectIfNecessary(null, noAnimation);
159	}
160
161	private boolean performRedirectIfNecessary(final Conversation ignore, final boolean noAnimation) {
162		if (xmppConnectionService == null) {
163			return false;
164		}
165		boolean isConversationsListEmpty = xmppConnectionService.isConversationsListEmpty(ignore);
166		if (isConversationsListEmpty && mRedirectInProcess.compareAndSet(false, true)) {
167			final Intent intent = getRedirectionIntent(noAnimation);
168			runOnUiThread(() -> {
169				startActivity(intent);
170				if (noAnimation) {
171					overridePendingTransition(0, 0);
172				}
173			});
174		}
175		return mRedirectInProcess.get();
176	}
177
178	private Intent getRedirectionIntent(boolean noAnimation) {
179		Account pendingAccount = xmppConnectionService.getPendingAccount();
180		Intent intent;
181		if (pendingAccount != null) {
182			intent = new Intent(this, EditAccountActivity.class);
183			intent.putExtra("jid", pendingAccount.getJid().asBareJid().toString());
184		} else {
185			if (xmppConnectionService.getAccounts().size() == 0) {
186				if (Config.X509_VERIFICATION) {
187					intent = new Intent(this, ManageAccountActivity.class);
188				} else if (Config.MAGIC_CREATE_DOMAIN != null) {
189					intent = new Intent(this, WelcomeActivity.class);
190					WelcomeActivity.addInviteUri(intent, getIntent());
191				} else {
192					intent = new Intent(this, EditAccountActivity.class);
193				}
194			} else {
195				intent = new Intent(this, StartConversationActivity.class);
196			}
197		}
198		intent.putExtra("init", true);
199		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
200		if (noAnimation) {
201			intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
202		}
203		return intent;
204	}
205
206	private void showDialogsIfMainIsOverview() {
207		if (xmppConnectionService == null) {
208			return;
209		}
210		final Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
211		if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
212			if (ExceptionHelper.checkForCrash(this)) {
213				return;
214			}
215			openBatteryOptimizationDialogIfNeeded();
216		}
217	}
218
219	private String getBatteryOptimizationPreferenceKey() {
220		@SuppressLint("HardwareIds") String device = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
221		return "show_battery_optimization" + (device == null ? "" : device);
222	}
223
224	private void setNeverAskForBatteryOptimizationsAgain() {
225		getPreferences().edit().putBoolean(getBatteryOptimizationPreferenceKey(), false).apply();
226	}
227
228	private void openBatteryOptimizationDialogIfNeeded() {
229		if (hasAccountWithoutPush()
230				&& isOptimizingBattery()
231				&& getPreferences().getBoolean(getBatteryOptimizationPreferenceKey(), true)) {
232			AlertDialog.Builder builder = new AlertDialog.Builder(this);
233			builder.setTitle(R.string.battery_optimizations_enabled);
234			builder.setMessage(R.string.battery_optimizations_enabled_dialog);
235			builder.setPositiveButton(R.string.next, (dialog, which) -> {
236				Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
237				Uri uri = Uri.parse("package:" + getPackageName());
238				intent.setData(uri);
239				try {
240					startActivityForResult(intent, REQUEST_BATTERY_OP);
241				} catch (ActivityNotFoundException e) {
242					Toast.makeText(this, R.string.device_does_not_support_battery_op, Toast.LENGTH_SHORT).show();
243				}
244			});
245			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
246				builder.setOnDismissListener(dialog -> setNeverAskForBatteryOptimizationsAgain());
247			}
248			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		OmemoSetting.load(this);
369		new EmojiService(this).init();
370		this.binding = DataBindingUtil.setContentView(this, R.layout.activity_conversations);
371		setSupportActionBar((Toolbar) binding.toolbar);
372		configureActionBar(getSupportActionBar());
373		this.getFragmentManager().addOnBackStackChangedListener(this::invalidateActionBarTitle);
374		this.getFragmentManager().addOnBackStackChangedListener(this::showDialogsIfMainIsOverview);
375		this.initializeFragments();
376		this.invalidateActionBarTitle();
377		final Intent intent;
378		if (savedInstanceState == null) {
379			intent = getIntent();
380		} else {
381			intent = savedInstanceState.getParcelable("intent");
382		}
383		if (isViewIntent(intent)) {
384			pendingViewIntent.push(intent);
385			setIntent(createLauncherIntent(this));
386		}
387	}
388
389	@Override
390	public boolean onCreateOptionsMenu(Menu menu) {
391		getMenuInflater().inflate(R.menu.activity_conversations, menu);
392		MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
393		if (qrCodeScanMenuItem != null) {
394			if (isCameraFeatureAvailable()) {
395				Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
396				boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan)
397						&& fragment != null
398						&& fragment instanceof ConversationsOverviewFragment;
399				qrCodeScanMenuItem.setVisible(visible);
400			} else {
401				qrCodeScanMenuItem.setVisible(false);
402			}
403		}
404		return super.onCreateOptionsMenu(menu);
405	}
406
407	@Override
408	public void onConversationSelected(Conversation conversation) {
409		if (ConversationFragment.getConversation(this) == conversation) {
410			Log.d(Config.LOGTAG, "ignore onConversationSelected() because conversation is already open");
411			return;
412		}
413		openConversation(conversation, null);
414	}
415
416	private void openConversation(Conversation conversation, Bundle extras) {
417		ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
418		final boolean mainNeedsRefresh;
419		if (conversationFragment == null) {
420			mainNeedsRefresh = false;
421			Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
422			if (mainFragment != null && mainFragment instanceof ConversationFragment) {
423				conversationFragment = (ConversationFragment) mainFragment;
424			} else {
425				conversationFragment = new ConversationFragment();
426				FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
427				fragmentTransaction.replace(R.id.main_fragment, conversationFragment);
428				fragmentTransaction.addToBackStack(null);
429				fragmentTransaction.commitAllowingStateLoss(); //allowing state loss is probably fine since view intents et all are already stored and a click can probably be 'ignored'
430			}
431		} else {
432			mainNeedsRefresh = true;
433		}
434		conversationFragment.reInit(conversation, extras == null ? new Bundle() : extras);
435		if (mainNeedsRefresh) {
436			refreshFragment(R.id.main_fragment);
437		} else {
438			invalidateActionBarTitle();
439		}
440	}
441
442	@Override
443	public boolean onOptionsItemSelected(MenuItem item) {
444		if (MenuDoubleTabUtil.shouldIgnoreTap()) {
445			return false;
446		}
447		switch (item.getItemId()) {
448			case android.R.id.home:
449				FragmentManager fm = getFragmentManager();
450				if (fm.getBackStackEntryCount() > 0) {
451					fm.popBackStack();
452					return true;
453				}
454				break;
455			case R.id.action_scan_qr_code:
456				UriHandlerActivity.scan(this);
457				return true;
458		}
459		return super.onOptionsItemSelected(item);
460	}
461
462	@Override
463	public void onSaveInstanceState(Bundle savedInstanceState) {
464		Intent pendingIntent = pendingViewIntent.peek();
465		savedInstanceState.putParcelable("intent", pendingIntent != null ? pendingIntent : getIntent());
466		super.onSaveInstanceState(savedInstanceState);
467	}
468
469	@Override
470	protected void onStart() {
471		final int theme = findTheme();
472		if (this.mTheme != theme) {
473			this.mSkipBackgroundBinding = true;
474			recreate();
475		} else {
476			this.mSkipBackgroundBinding = false;
477		}
478		mRedirectInProcess.set(false);
479		super.onStart();
480	}
481
482	@Override
483	protected void onNewIntent(final Intent intent) {
484		if (isViewIntent(intent)) {
485			if (xmppConnectionService != null) {
486				processViewIntent(intent);
487			} else {
488				pendingViewIntent.push(intent);
489			}
490		}
491		setIntent(createLauncherIntent(this));
492	}
493
494	@Override
495	public void onPause() {
496		this.mActivityPaused = true;
497		super.onPause();
498	}
499
500	@Override
501	public void onResume() {
502		super.onResume();
503		this.mActivityPaused = false;
504	}
505
506	private void initializeFragments() {
507		FragmentTransaction transaction = getFragmentManager().beginTransaction();
508		Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
509		Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
510		if (mainFragment != null) {
511			if (binding.secondaryFragment != null) {
512				if (mainFragment instanceof ConversationFragment) {
513					getFragmentManager().popBackStack();
514					transaction.remove(mainFragment);
515					transaction.commit();
516					getFragmentManager().executePendingTransactions();
517					transaction = getFragmentManager().beginTransaction();
518					transaction.replace(R.id.secondary_fragment, mainFragment);
519					transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
520					transaction.commit();
521					return;
522				}
523			} else {
524				if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
525					transaction.remove(secondaryFragment);
526					transaction.commit();
527					getFragmentManager().executePendingTransactions();
528					transaction = getFragmentManager().beginTransaction();
529					transaction.replace(R.id.main_fragment, secondaryFragment);
530					transaction.addToBackStack(null);
531					transaction.commit();
532					return;
533				}
534			}
535		} else {
536			transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
537		}
538		if (binding.secondaryFragment != null && secondaryFragment == null) {
539			transaction.replace(R.id.secondary_fragment, new ConversationFragment());
540		}
541		transaction.commit();
542	}
543
544	private void invalidateActionBarTitle() {
545		final ActionBar actionBar = getSupportActionBar();
546		if (actionBar != null) {
547			Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
548			if (mainFragment != null && mainFragment instanceof ConversationFragment) {
549				final Conversation conversation = ((ConversationFragment) mainFragment).getConversation();
550				if (conversation != null) {
551					actionBar.setTitle(conversation.getName());
552					actionBar.setDisplayHomeAsUpEnabled(true);
553					return;
554				}
555			}
556			actionBar.setTitle(R.string.app_name);
557			actionBar.setDisplayHomeAsUpEnabled(false);
558		}
559	}
560
561	@Override
562	public void onConversationArchived(Conversation conversation) {
563		if (performRedirectIfNecessary(conversation, false)) {
564			return;
565		}
566		Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
567		if (mainFragment != null && mainFragment instanceof ConversationFragment) {
568			getFragmentManager().popBackStack();
569			return;
570		}
571		Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
572		if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
573			if (((ConversationFragment) secondaryFragment).getConversation() == conversation) {
574				Conversation suggestion = ConversationsOverviewFragment.getSuggestion(this, conversation);
575				if (suggestion != null) {
576					openConversation(suggestion, null);
577				}
578			}
579		}
580	}
581
582	@Override
583	public void onConversationsListItemUpdated() {
584		Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
585		if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
586			((ConversationsOverviewFragment) fragment).refresh();
587		}
588	}
589
590	@Override
591	public void switchToConversation(Conversation conversation) {
592		Log.d(Config.LOGTAG, "override");
593		openConversation(conversation, null);
594	}
595
596	@Override
597	public void onConversationRead(Conversation conversation) {
598		if (!mActivityPaused && pendingViewIntent.peek() == null) {
599			xmppConnectionService.sendReadMarker(conversation);
600		} else {
601			Log.d(Config.LOGTAG, "ignoring read callback. mActivityPaused=" + Boolean.toString(mActivityPaused));
602		}
603	}
604
605	@Override
606	public void onAccountUpdate() {
607		this.refreshUi();
608	}
609
610	@Override
611	public void onConversationUpdate() {
612		if (performRedirectIfNecessary(false)) {
613			return;
614		}
615		this.refreshUi();
616	}
617
618	@Override
619	public void onRosterUpdate() {
620		this.refreshUi();
621	}
622
623	@Override
624	public void OnUpdateBlocklist(OnUpdateBlocklist.Status status) {
625		this.refreshUi();
626	}
627
628	@Override
629	public void onShowErrorToast(int resId) {
630		runOnUiThread(() -> Toast.makeText(this, resId, Toast.LENGTH_SHORT).show());
631	}
632}