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.Bundle;
 45import android.provider.Settings;
 46import android.support.annotation.IdRes;
 47import android.support.annotation.NonNull;
 48import android.support.v7.app.ActionBar;
 49import android.support.v7.app.AlertDialog;
 50import android.support.v7.widget.Toolbar;
 51import android.util.Log;
 52import android.view.Menu;
 53import android.view.MenuItem;
 54import android.widget.Toast;
 55
 56import org.openintents.openpgp.util.OpenPgpApi;
 57
 58import java.util.concurrent.atomic.AtomicBoolean;
 59
 60import eu.siacs.conversations.Config;
 61import eu.siacs.conversations.R;
 62import eu.siacs.conversations.crypto.OmemoSetting;
 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.ConversationMenuConfigurator;
 75import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
 76import eu.siacs.conversations.ui.util.PendingItem;
 77import eu.siacs.conversations.utils.EmojiWrapper;
 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					try {
472						fm.popBackStack();
473					} catch (IllegalStateException e) {
474						Log.w(Config.LOGTAG,"Unable to pop back stack after pressing home button");
475					}
476					return true;
477				}
478				break;
479			case R.id.action_scan_qr_code:
480				UriHandlerActivity.scan(this);
481				return true;
482		}
483		return super.onOptionsItemSelected(item);
484	}
485
486	@Override
487	public void onSaveInstanceState(Bundle savedInstanceState) {
488		Intent pendingIntent = pendingViewIntent.peek();
489		savedInstanceState.putParcelable("intent", pendingIntent != null ? pendingIntent : getIntent());
490		super.onSaveInstanceState(savedInstanceState);
491	}
492
493	@Override
494	protected void onStart() {
495		final int theme = findTheme();
496		if (this.mTheme != theme) {
497			this.mSkipBackgroundBinding = true;
498			recreate();
499		} else {
500			this.mSkipBackgroundBinding = false;
501		}
502		mRedirectInProcess.set(false);
503		super.onStart();
504	}
505
506	@Override
507	protected void onNewIntent(final Intent intent) {
508		if (isViewIntent(intent)) {
509			if (xmppConnectionService != null) {
510				processViewIntent(intent);
511			} else {
512				pendingViewIntent.push(intent);
513			}
514		}
515		setIntent(createLauncherIntent(this));
516	}
517
518	@Override
519	public void onPause() {
520		this.mActivityPaused = true;
521		super.onPause();
522	}
523
524	@Override
525	public void onResume() {
526		super.onResume();
527		this.mActivityPaused = false;
528	}
529
530	private void initializeFragments() {
531		FragmentTransaction transaction = getFragmentManager().beginTransaction();
532		Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
533		Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
534		if (mainFragment != null) {
535			if (binding.secondaryFragment != null) {
536				if (mainFragment instanceof ConversationFragment) {
537					getFragmentManager().popBackStack();
538					transaction.remove(mainFragment);
539					transaction.commit();
540					getFragmentManager().executePendingTransactions();
541					transaction = getFragmentManager().beginTransaction();
542					transaction.replace(R.id.secondary_fragment, mainFragment);
543					transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
544					transaction.commit();
545					return;
546				}
547			} else {
548				if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
549					transaction.remove(secondaryFragment);
550					transaction.commit();
551					getFragmentManager().executePendingTransactions();
552					transaction = getFragmentManager().beginTransaction();
553					transaction.replace(R.id.main_fragment, secondaryFragment);
554					transaction.addToBackStack(null);
555					transaction.commit();
556					return;
557				}
558			}
559		} else {
560			transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
561		}
562		if (binding.secondaryFragment != null && secondaryFragment == null) {
563			transaction.replace(R.id.secondary_fragment, new ConversationFragment());
564		}
565		transaction.commit();
566	}
567
568	private void invalidateActionBarTitle() {
569		final ActionBar actionBar = getSupportActionBar();
570		if (actionBar != null) {
571			Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
572			if (mainFragment != null && mainFragment instanceof ConversationFragment) {
573				final Conversation conversation = ((ConversationFragment) mainFragment).getConversation();
574				if (conversation != null) {
575					actionBar.setTitle(EmojiWrapper.transform(conversation.getName()));
576					actionBar.setDisplayHomeAsUpEnabled(true);
577					return;
578				}
579			}
580			actionBar.setTitle(R.string.app_name);
581			actionBar.setDisplayHomeAsUpEnabled(false);
582		}
583	}
584
585	@Override
586	public void onConversationArchived(Conversation conversation) {
587		if (performRedirectIfNecessary(conversation, false)) {
588			return;
589		}
590		Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
591		if (mainFragment != null && mainFragment instanceof ConversationFragment) {
592			try {
593				getFragmentManager().popBackStack();
594			} catch (IllegalStateException e) {
595				Log.w(Config.LOGTAG,"state loss while popping back state after archiving conversation",e);
596				//this usually means activity is no longer active; meaning on the next open we will run through this again
597			}
598			return;
599		}
600		Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
601		if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
602			if (((ConversationFragment) secondaryFragment).getConversation() == conversation) {
603				Conversation suggestion = ConversationsOverviewFragment.getSuggestion(this, conversation);
604				if (suggestion != null) {
605					openConversation(suggestion, null);
606				}
607			}
608		}
609	}
610
611	@Override
612	public void onConversationsListItemUpdated() {
613		Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
614		if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
615			((ConversationsOverviewFragment) fragment).refresh();
616		}
617	}
618
619	@Override
620	public void switchToConversation(Conversation conversation) {
621		Log.d(Config.LOGTAG, "override");
622		openConversation(conversation, null);
623	}
624
625	@Override
626	public void onConversationRead(Conversation conversation, String upToUuid) {
627		if (!mActivityPaused && pendingViewIntent.peek() == null) {
628			xmppConnectionService.sendReadMarker(conversation, upToUuid);
629		} else {
630			Log.d(Config.LOGTAG, "ignoring read callback. mActivityPaused=" + Boolean.toString(mActivityPaused));
631		}
632	}
633
634	@Override
635	public void onAccountUpdate() {
636		this.refreshUi();
637	}
638
639	@Override
640	public void onConversationUpdate() {
641		if (performRedirectIfNecessary(false)) {
642			return;
643		}
644		this.refreshUi();
645	}
646
647	@Override
648	public void onRosterUpdate() {
649		this.refreshUi();
650	}
651
652	@Override
653	public void OnUpdateBlocklist(OnUpdateBlocklist.Status status) {
654		this.refreshUi();
655	}
656
657	@Override
658	public void onShowErrorToast(int resId) {
659		runOnUiThread(() -> Toast.makeText(this, resId, Toast.LENGTH_SHORT).show());
660	}
661}