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