2018-03-07 18:05:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018, Daniel Gultsch All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
* other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
|
|
|
|
2021-08-25 18:04:47 +00:00
|
|
|
import static eu.siacs.conversations.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
|
|
|
|
|
2018-03-07 18:05:28 +00:00
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.ActivityNotFoundException;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.provider.Settings;
|
|
|
|
import android.util.Log;
|
2020-07-12 07:45:27 +00:00
|
|
|
import android.view.KeyEvent;
|
2018-03-07 18:05:28 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2021-01-23 08:25:34 +00:00
|
|
|
import androidx.annotation.IdRes;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.databinding.DataBindingUtil;
|
2021-09-20 06:22:55 +00:00
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
2021-01-23 08:25:34 +00:00
|
|
|
|
2018-03-07 18:05:28 +00:00
|
|
|
import org.openintents.openpgp.util.OpenPgpApi;
|
|
|
|
|
2018-09-12 15:21:32 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2018-03-07 18:05:28 +00:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.Config;
|
|
|
|
import eu.siacs.conversations.R;
|
2018-03-27 13:35:53 +00:00
|
|
|
import eu.siacs.conversations.crypto.OmemoSetting;
|
2018-03-07 18:05:28 +00:00
|
|
|
import eu.siacs.conversations.databinding.ActivityConversationsBinding;
|
|
|
|
import eu.siacs.conversations.entities.Account;
|
2021-08-25 18:04:47 +00:00
|
|
|
import eu.siacs.conversations.entities.Contact;
|
2018-03-07 18:05:28 +00:00
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
2021-08-25 18:04:47 +00:00
|
|
|
import eu.siacs.conversations.entities.Conversational;
|
2018-03-07 18:05:28 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
2018-03-13 21:44:08 +00:00
|
|
|
import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
|
2018-03-07 18:05:28 +00:00
|
|
|
import eu.siacs.conversations.ui.interfaces.OnConversationArchived;
|
|
|
|
import eu.siacs.conversations.ui.interfaces.OnConversationRead;
|
|
|
|
import eu.siacs.conversations.ui.interfaces.OnConversationSelected;
|
|
|
|
import eu.siacs.conversations.ui.interfaces.OnConversationsListItemUpdated;
|
2021-08-25 18:04:47 +00:00
|
|
|
import eu.siacs.conversations.ui.util.ActionBarUtil;
|
2018-03-07 18:05:28 +00:00
|
|
|
import eu.siacs.conversations.ui.util.ActivityResult;
|
2018-05-03 15:01:16 +00:00
|
|
|
import eu.siacs.conversations.ui.util.ConversationMenuConfigurator;
|
2018-03-18 22:32:30 +00:00
|
|
|
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
|
2018-03-07 18:05:28 +00:00
|
|
|
import eu.siacs.conversations.ui.util.PendingItem;
|
2018-06-25 07:25:55 +00:00
|
|
|
import eu.siacs.conversations.utils.EmojiWrapper;
|
2018-03-07 18:05:28 +00:00
|
|
|
import eu.siacs.conversations.utils.ExceptionHelper;
|
2018-10-09 17:35:33 +00:00
|
|
|
import eu.siacs.conversations.utils.SignupUtils;
|
2018-06-20 13:12:02 +00:00
|
|
|
import eu.siacs.conversations.utils.XmppUri;
|
2020-05-15 15:06:16 +00:00
|
|
|
import eu.siacs.conversations.xmpp.Jid;
|
2021-01-23 08:25:34 +00:00
|
|
|
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
|
2018-03-07 18:05:28 +00:00
|
|
|
|
2019-01-28 09:52:35 +00:00
|
|
|
public class ConversationsActivity extends XmppActivity implements OnConversationSelected, OnConversationArchived, OnConversationsListItemUpdated, OnConversationRead, XmppConnectionService.OnAccountUpdate, XmppConnectionService.OnConversationUpdate, XmppConnectionService.OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnAffiliationChanged {
|
2018-03-07 18:05:28 +00:00
|
|
|
|
2018-09-16 08:09:22 +00:00
|
|
|
public static final String ACTION_VIEW_CONVERSATION = "eu.siacs.conversations.action.VIEW";
|
|
|
|
public static final String EXTRA_CONVERSATION = "conversationUuid";
|
|
|
|
public static final String EXTRA_DOWNLOAD_UUID = "eu.siacs.conversations.download_uuid";
|
2019-08-26 11:40:47 +00:00
|
|
|
public static final String EXTRA_AS_QUOTE = "eu.siacs.conversations.as_quote";
|
2018-09-16 08:09:22 +00:00
|
|
|
public static final String EXTRA_NICK = "nick";
|
|
|
|
public static final String EXTRA_IS_PRIVATE_MESSAGE = "pm";
|
2018-10-19 13:39:31 +00:00
|
|
|
public static final String EXTRA_DO_NOT_APPEND = "do_not_append";
|
2020-05-30 08:30:57 +00:00
|
|
|
public static final String EXTRA_POST_INIT_ACTION = "post_init_action";
|
|
|
|
public static final String POST_ACTION_RECORD_VOICE = "record_voice";
|
2018-09-16 08:09:22 +00:00
|
|
|
|
2021-01-23 08:25:34 +00:00
|
|
|
private static final List<String> VIEW_AND_SHARE_ACTIONS = Arrays.asList(
|
2018-09-16 08:09:22 +00:00
|
|
|
ACTION_VIEW_CONVERSATION,
|
|
|
|
Intent.ACTION_SEND,
|
|
|
|
Intent.ACTION_SEND_MULTIPLE
|
|
|
|
);
|
|
|
|
|
|
|
|
public static final int REQUEST_OPEN_MESSAGE = 0x9876;
|
|
|
|
public static final int REQUEST_PLAY_PAUSE = 0x5432;
|
|
|
|
|
|
|
|
|
|
|
|
//secondary fragment (when holding the conversation, must be initialized before refreshing the overview fragment
|
|
|
|
private static final @IdRes
|
|
|
|
int[] FRAGMENT_ID_NOTIFICATION_ORDER = {R.id.secondary_fragment, R.id.main_fragment};
|
|
|
|
private final PendingItem<Intent> pendingViewIntent = new PendingItem<>();
|
|
|
|
private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
|
|
|
|
private ActivityConversationsBinding binding;
|
|
|
|
private boolean mActivityPaused = true;
|
2021-01-23 08:25:34 +00:00
|
|
|
private final AtomicBoolean mRedirectInProcess = new AtomicBoolean(false);
|
2018-09-16 08:09:22 +00:00
|
|
|
|
|
|
|
private static boolean isViewOrShareIntent(Intent i) {
|
|
|
|
Log.d(Config.LOGTAG, "action: " + (i == null ? null : i.getAction()));
|
|
|
|
return i != null && VIEW_AND_SHARE_ACTIONS.contains(i.getAction()) && i.hasExtra(EXTRA_CONVERSATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Intent createLauncherIntent(Context context) {
|
|
|
|
final Intent intent = new Intent(context, ConversationsActivity.class);
|
|
|
|
intent.setAction(Intent.ACTION_MAIN);
|
|
|
|
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void refreshUiReal() {
|
2020-12-01 19:31:30 +00:00
|
|
|
invalidateOptionsMenu();
|
2018-09-16 08:09:22 +00:00
|
|
|
for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
|
|
|
|
refreshFragment(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void onBackendConnected() {
|
|
|
|
if (performRedirectIfNecessary(true)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
xmppConnectionService.getNotificationService().setIsInForeground(true);
|
|
|
|
Intent intent = pendingViewIntent.pop();
|
|
|
|
if (intent != null) {
|
|
|
|
if (processViewIntent(intent)) {
|
|
|
|
if (binding.secondaryFragment != null) {
|
|
|
|
notifyFragmentOfBackendConnected(R.id.main_fragment);
|
|
|
|
}
|
|
|
|
invalidateActionBarTitle();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
|
|
|
|
notifyFragmentOfBackendConnected(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
ActivityResult activityResult = postponedActivityResult.pop();
|
|
|
|
if (activityResult != null) {
|
|
|
|
handleActivityResult(activityResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
invalidateActionBarTitle();
|
2021-09-20 06:22:55 +00:00
|
|
|
if (binding.secondaryFragment != null && ConversationFragment.getConversation(getSupportFragmentManager()) == null) {
|
|
|
|
Conversation conversation = ConversationsOverviewFragment.getSuggestion(getSupportFragmentManager());
|
2018-09-16 08:09:22 +00:00
|
|
|
if (conversation != null) {
|
|
|
|
openConversation(conversation, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
showDialogsIfMainIsOverview();
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean performRedirectIfNecessary(boolean noAnimation) {
|
|
|
|
return performRedirectIfNecessary(null, noAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean performRedirectIfNecessary(final Conversation ignore, final boolean noAnimation) {
|
|
|
|
if (xmppConnectionService == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
boolean isConversationsListEmpty = xmppConnectionService.isConversationsListEmpty(ignore);
|
|
|
|
if (isConversationsListEmpty && mRedirectInProcess.compareAndSet(false, true)) {
|
2018-10-09 17:35:33 +00:00
|
|
|
final Intent intent = SignupUtils.getRedirectionIntent(this);
|
|
|
|
if (noAnimation) {
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
|
|
|
}
|
2018-09-16 08:09:22 +00:00
|
|
|
runOnUiThread(() -> {
|
|
|
|
startActivity(intent);
|
|
|
|
if (noAnimation) {
|
|
|
|
overridePendingTransition(0, 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return mRedirectInProcess.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showDialogsIfMainIsOverview() {
|
|
|
|
if (xmppConnectionService == null) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-20 06:22:55 +00:00
|
|
|
final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.main_fragment);
|
2018-10-24 18:00:25 +00:00
|
|
|
if (fragment instanceof ConversationsOverviewFragment) {
|
2018-09-16 08:09:22 +00:00
|
|
|
if (ExceptionHelper.checkForCrash(this)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
openBatteryOptimizationDialogIfNeeded();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getBatteryOptimizationPreferenceKey() {
|
|
|
|
@SuppressLint("HardwareIds") String device = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
|
|
|
|
return "show_battery_optimization" + (device == null ? "" : device);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setNeverAskForBatteryOptimizationsAgain() {
|
|
|
|
getPreferences().edit().putBoolean(getBatteryOptimizationPreferenceKey(), false).apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openBatteryOptimizationDialogIfNeeded() {
|
|
|
|
if (hasAccountWithoutPush()
|
|
|
|
&& isOptimizingBattery()
|
2018-12-10 12:58:05 +00:00
|
|
|
&& android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M
|
2018-09-16 08:09:22 +00:00
|
|
|
&& getPreferences().getBoolean(getBatteryOptimizationPreferenceKey(), true)) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(R.string.battery_optimizations_enabled);
|
2021-02-08 15:03:30 +00:00
|
|
|
builder.setMessage(getString(R.string.battery_optimizations_enabled_dialog, getString(R.string.app_name)));
|
2018-09-16 08:09:22 +00:00
|
|
|
builder.setPositiveButton(R.string.next, (dialog, which) -> {
|
|
|
|
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
|
|
|
|
Uri uri = Uri.parse("package:" + getPackageName());
|
|
|
|
intent.setData(uri);
|
|
|
|
try {
|
|
|
|
startActivityForResult(intent, REQUEST_BATTERY_OP);
|
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
Toast.makeText(this, R.string.device_does_not_support_battery_op, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setOnDismissListener(dialog -> setNeverAskForBatteryOptimizationsAgain());
|
|
|
|
final AlertDialog dialog = builder.create();
|
|
|
|
dialog.setCanceledOnTouchOutside(false);
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean hasAccountWithoutPush() {
|
|
|
|
for (Account account : xmppConnectionService.getAccounts()) {
|
|
|
|
if (account.getStatus() == Account.State.ONLINE && !xmppConnectionService.getPushManagementService().available(account)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void notifyFragmentOfBackendConnected(@IdRes int id) {
|
2021-09-20 06:22:55 +00:00
|
|
|
final Fragment fragment = getSupportFragmentManager().findFragmentById(id);
|
2018-10-24 18:00:25 +00:00
|
|
|
if (fragment instanceof OnBackendConnected) {
|
2018-09-16 08:09:22 +00:00
|
|
|
((OnBackendConnected) fragment).onBackendConnected();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void refreshFragment(@IdRes int id) {
|
2021-09-20 06:22:55 +00:00
|
|
|
final Fragment fragment = getSupportFragmentManager().findFragmentById(id);
|
2018-10-24 18:00:25 +00:00
|
|
|
if (fragment instanceof XmppFragment) {
|
2018-09-16 08:09:22 +00:00
|
|
|
((XmppFragment) fragment).refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean processViewIntent(Intent intent) {
|
2020-08-05 19:31:54 +00:00
|
|
|
final String uuid = intent.getStringExtra(EXTRA_CONVERSATION);
|
|
|
|
final Conversation conversation = uuid != null ? xmppConnectionService.findConversationByUuid(uuid) : null;
|
2018-09-16 08:09:22 +00:00
|
|
|
if (conversation == null) {
|
|
|
|
Log.d(Config.LOGTAG, "unable to view conversation with uuid:" + uuid);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
openConversation(conversation, intent.getExtras());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-11 13:06:33 +00:00
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
2021-09-20 07:27:40 +00:00
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
2018-09-16 08:09:22 +00:00
|
|
|
UriHandlerActivity.onRequestPermissionResult(this, requestCode, grantResults);
|
|
|
|
if (grantResults.length > 0) {
|
|
|
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
switch (requestCode) {
|
|
|
|
case REQUEST_OPEN_MESSAGE:
|
|
|
|
refreshUiReal();
|
2021-09-20 06:22:55 +00:00
|
|
|
ConversationFragment.openPendingMessage(getSupportFragmentManager());
|
2018-09-16 08:09:22 +00:00
|
|
|
break;
|
|
|
|
case REQUEST_PLAY_PAUSE:
|
2021-09-20 06:22:55 +00:00
|
|
|
ConversationFragment.startStopPending(getSupportFragmentManager());
|
2018-09-16 08:09:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, final Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
ActivityResult activityResult = ActivityResult.of(requestCode, resultCode, data);
|
|
|
|
if (xmppConnectionService != null) {
|
|
|
|
handleActivityResult(activityResult);
|
|
|
|
} else {
|
|
|
|
this.postponedActivityResult.push(activityResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleActivityResult(ActivityResult activityResult) {
|
|
|
|
if (activityResult.resultCode == Activity.RESULT_OK) {
|
|
|
|
handlePositiveActivityResult(activityResult.requestCode, activityResult.data);
|
|
|
|
} else {
|
|
|
|
handleNegativeActivityResult(activityResult.requestCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleNegativeActivityResult(int requestCode) {
|
2021-09-20 06:22:55 +00:00
|
|
|
Conversation conversation = ConversationFragment.getConversationReliable(getSupportFragmentManager());
|
2018-09-16 08:09:22 +00:00
|
|
|
switch (requestCode) {
|
|
|
|
case REQUEST_DECRYPT_PGP:
|
|
|
|
if (conversation == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
conversation.getAccount().getPgpDecryptionService().giveUpCurrentDecryption();
|
|
|
|
break;
|
|
|
|
case REQUEST_BATTERY_OP:
|
|
|
|
setNeverAskForBatteryOptimizationsAgain();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handlePositiveActivityResult(int requestCode, final Intent data) {
|
2021-09-20 06:22:55 +00:00
|
|
|
Conversation conversation = ConversationFragment.getConversationReliable(getSupportFragmentManager());
|
2018-09-16 08:09:22 +00:00
|
|
|
if (conversation == null) {
|
|
|
|
Log.d(Config.LOGTAG, "conversation not found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (requestCode) {
|
|
|
|
case REQUEST_DECRYPT_PGP:
|
|
|
|
conversation.getAccount().getPgpDecryptionService().continueDecryption(data);
|
|
|
|
break;
|
|
|
|
case REQUEST_CHOOSE_PGP_ID:
|
|
|
|
long id = data.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, 0);
|
|
|
|
if (id != 0) {
|
|
|
|
conversation.getAccount().setPgpSignId(id);
|
|
|
|
announcePgp(conversation.getAccount(), null, null, onOpenPGPKeyPublished);
|
|
|
|
} else {
|
|
|
|
choosePgpSignId(conversation.getAccount());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case REQUEST_ANNOUNCE_PGP:
|
|
|
|
announcePgp(conversation.getAccount(), conversation, data, onOpenPGPKeyPublished);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
ConversationMenuConfigurator.reloadFeatures(this);
|
|
|
|
OmemoSetting.load(this);
|
|
|
|
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_conversations);
|
2021-01-23 08:25:34 +00:00
|
|
|
setSupportActionBar(binding.toolbar);
|
2018-09-16 08:09:22 +00:00
|
|
|
configureActionBar(getSupportActionBar());
|
2021-09-20 06:22:55 +00:00
|
|
|
this.getSupportFragmentManager().addOnBackStackChangedListener(this::invalidateActionBarTitle);
|
|
|
|
this.getSupportFragmentManager().addOnBackStackChangedListener(this::showDialogsIfMainIsOverview);
|
2018-09-16 08:09:22 +00:00
|
|
|
this.initializeFragments();
|
|
|
|
this.invalidateActionBarTitle();
|
|
|
|
final Intent intent;
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
intent = getIntent();
|
|
|
|
} else {
|
|
|
|
intent = savedInstanceState.getParcelable("intent");
|
|
|
|
}
|
|
|
|
if (isViewOrShareIntent(intent)) {
|
|
|
|
pendingViewIntent.push(intent);
|
|
|
|
setIntent(createLauncherIntent(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
getMenuInflater().inflate(R.menu.activity_conversations, menu);
|
2020-09-01 14:50:25 +00:00
|
|
|
final MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
|
2018-09-16 08:09:22 +00:00
|
|
|
if (qrCodeScanMenuItem != null) {
|
|
|
|
if (isCameraFeatureAvailable()) {
|
2021-09-20 06:22:55 +00:00
|
|
|
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.main_fragment);
|
2018-09-16 08:09:22 +00:00
|
|
|
boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan)
|
|
|
|
&& fragment instanceof ConversationsOverviewFragment;
|
|
|
|
qrCodeScanMenuItem.setVisible(visible);
|
|
|
|
} else {
|
|
|
|
qrCodeScanMenuItem.setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onCreateOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConversationSelected(Conversation conversation) {
|
|
|
|
clearPendingViewIntent();
|
2021-09-20 06:22:55 +00:00
|
|
|
if (ConversationFragment.getConversation(getSupportFragmentManager()) == conversation) {
|
2018-09-16 08:09:22 +00:00
|
|
|
Log.d(Config.LOGTAG, "ignore onConversationSelected() because conversation is already open");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
openConversation(conversation, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearPendingViewIntent() {
|
|
|
|
if (pendingViewIntent.clear()) {
|
|
|
|
Log.e(Config.LOGTAG, "cleared pending view intent");
|
|
|
|
}
|
|
|
|
}
|
2018-03-07 18:05:28 +00:00
|
|
|
|
2018-08-26 15:32:30 +00:00
|
|
|
private void displayToast(final String msg) {
|
|
|
|
runOnUiThread(() -> Toast.makeText(ConversationsActivity.this, msg, Toast.LENGTH_SHORT).show());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAffiliationChangedSuccessful(Jid jid) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAffiliationChangeFailed(Jid jid, int resId) {
|
|
|
|
displayToast(getString(resId, jid.asBareJid().toString()));
|
|
|
|
}
|
|
|
|
|
2018-09-16 08:09:22 +00:00
|
|
|
private void openConversation(Conversation conversation, Bundle extras) {
|
2021-09-20 06:22:55 +00:00
|
|
|
final FragmentManager fragmentManager = getSupportFragmentManager();
|
2021-09-20 08:07:38 +00:00
|
|
|
executePendingTransactions(fragmentManager);
|
2021-08-25 16:54:00 +00:00
|
|
|
ConversationFragment conversationFragment = (ConversationFragment) fragmentManager.findFragmentById(R.id.secondary_fragment);
|
2018-09-16 08:09:22 +00:00
|
|
|
final boolean mainNeedsRefresh;
|
|
|
|
if (conversationFragment == null) {
|
|
|
|
mainNeedsRefresh = false;
|
2021-08-25 16:54:00 +00:00
|
|
|
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
2018-10-24 18:00:25 +00:00
|
|
|
if (mainFragment instanceof ConversationFragment) {
|
2018-09-16 08:09:22 +00:00
|
|
|
conversationFragment = (ConversationFragment) mainFragment;
|
|
|
|
} else {
|
|
|
|
conversationFragment = new ConversationFragment();
|
2021-08-25 16:54:00 +00:00
|
|
|
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
2018-09-16 08:09:22 +00:00
|
|
|
fragmentTransaction.replace(R.id.main_fragment, conversationFragment);
|
|
|
|
fragmentTransaction.addToBackStack(null);
|
|
|
|
try {
|
|
|
|
fragmentTransaction.commit();
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
Log.w(Config.LOGTAG, "sate loss while opening conversation", e);
|
|
|
|
//allowing state loss is probably fine since view intents et all are already stored and a click can probably be 'ignored'
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mainNeedsRefresh = true;
|
|
|
|
}
|
|
|
|
conversationFragment.reInit(conversation, extras == null ? new Bundle() : extras);
|
|
|
|
if (mainNeedsRefresh) {
|
|
|
|
refreshFragment(R.id.main_fragment);
|
|
|
|
} else {
|
|
|
|
invalidateActionBarTitle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-20 08:07:38 +00:00
|
|
|
private static void executePendingTransactions(final FragmentManager fragmentManager) {
|
|
|
|
try {
|
|
|
|
fragmentManager.executePendingTransactions();
|
|
|
|
} catch (final Exception e) {
|
|
|
|
Log.e(Config.LOGTAG,"unable to execute pending fragment transactions");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-16 08:09:22 +00:00
|
|
|
public boolean onXmppUriClicked(Uri uri) {
|
|
|
|
XmppUri xmppUri = new XmppUri(uri);
|
2020-01-10 11:51:04 +00:00
|
|
|
if (xmppUri.isValidJid() && !xmppUri.hasFingerprints()) {
|
2018-09-16 08:09:22 +00:00
|
|
|
final Conversation conversation = xmppConnectionService.findUniqueConversationByJid(xmppUri);
|
|
|
|
if (conversation != null) {
|
|
|
|
openConversation(conversation, null);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
if (MenuDoubleTabUtil.shouldIgnoreTap()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
2021-09-20 06:22:55 +00:00
|
|
|
FragmentManager fm = getSupportFragmentManager();
|
2018-09-16 08:09:22 +00:00
|
|
|
if (fm.getBackStackEntryCount() > 0) {
|
|
|
|
try {
|
|
|
|
fm.popBackStack();
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
Log.w(Config.LOGTAG, "Unable to pop back stack after pressing home button");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R.id.action_scan_qr_code:
|
|
|
|
UriHandlerActivity.scan(this);
|
|
|
|
return true;
|
2020-08-29 06:16:08 +00:00
|
|
|
case R.id.action_search_all_conversations:
|
|
|
|
startActivity(new Intent(this, SearchActivity.class));
|
|
|
|
return true;
|
|
|
|
case R.id.action_search_this_conversation:
|
2021-09-20 06:22:55 +00:00
|
|
|
final Conversation conversation = ConversationFragment.getConversation(getSupportFragmentManager());
|
2020-08-29 06:16:08 +00:00
|
|
|
if (conversation == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
final Intent intent = new Intent(this, SearchActivity.class);
|
|
|
|
intent.putExtra(SearchActivity.EXTRA_CONVERSATION_UUID, conversation.getUuid());
|
|
|
|
startActivity(intent);
|
|
|
|
return true;
|
2018-09-16 08:09:22 +00:00
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-12 07:45:27 +00:00
|
|
|
public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_DPAD_UP && keyEvent.isCtrlPressed()) {
|
2021-09-20 06:22:55 +00:00
|
|
|
final ConversationFragment conversationFragment = ConversationFragment.get(getSupportFragmentManager());
|
2020-07-12 07:45:27 +00:00
|
|
|
if (conversationFragment != null && conversationFragment.onArrowUpCtrlPressed()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onKeyDown(keyCode, keyEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(final Bundle savedInstanceState) {
|
|
|
|
final Intent pendingIntent = pendingViewIntent.peek();
|
2018-09-16 08:09:22 +00:00
|
|
|
savedInstanceState.putParcelable("intent", pendingIntent != null ? pendingIntent : getIntent());
|
|
|
|
super.onSaveInstanceState(savedInstanceState);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart() {
|
|
|
|
final int theme = findTheme();
|
|
|
|
if (this.mTheme != theme) {
|
|
|
|
this.mSkipBackgroundBinding = true;
|
|
|
|
recreate();
|
|
|
|
} else {
|
|
|
|
this.mSkipBackgroundBinding = false;
|
|
|
|
}
|
|
|
|
mRedirectInProcess.set(false);
|
|
|
|
super.onStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onNewIntent(final Intent intent) {
|
2021-01-23 17:42:34 +00:00
|
|
|
super.onNewIntent(intent);
|
2018-09-16 08:09:22 +00:00
|
|
|
if (isViewOrShareIntent(intent)) {
|
|
|
|
if (xmppConnectionService != null) {
|
2019-01-02 08:32:22 +00:00
|
|
|
clearPendingViewIntent();
|
2018-09-16 08:09:22 +00:00
|
|
|
processViewIntent(intent);
|
|
|
|
} else {
|
|
|
|
pendingViewIntent.push(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setIntent(createLauncherIntent(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
this.mActivityPaused = true;
|
|
|
|
super.onPause();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
this.mActivityPaused = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeFragments() {
|
2021-09-20 06:22:55 +00:00
|
|
|
final FragmentManager fragmentManager = getSupportFragmentManager();
|
2021-08-25 16:54:00 +00:00
|
|
|
FragmentTransaction transaction = fragmentManager.beginTransaction();
|
|
|
|
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
|
|
|
final Fragment secondaryFragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
|
2018-09-16 08:09:22 +00:00
|
|
|
if (mainFragment != null) {
|
|
|
|
if (binding.secondaryFragment != null) {
|
|
|
|
if (mainFragment instanceof ConversationFragment) {
|
2021-09-20 06:22:55 +00:00
|
|
|
getSupportFragmentManager().popBackStack();
|
2018-09-16 08:09:22 +00:00
|
|
|
transaction.remove(mainFragment);
|
|
|
|
transaction.commit();
|
2021-08-25 16:54:00 +00:00
|
|
|
fragmentManager.executePendingTransactions();
|
|
|
|
transaction = fragmentManager.beginTransaction();
|
2018-09-16 08:09:22 +00:00
|
|
|
transaction.replace(R.id.secondary_fragment, mainFragment);
|
|
|
|
transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
|
|
|
|
transaction.commit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2018-10-24 18:00:25 +00:00
|
|
|
if (secondaryFragment instanceof ConversationFragment) {
|
2018-09-16 08:09:22 +00:00
|
|
|
transaction.remove(secondaryFragment);
|
|
|
|
transaction.commit();
|
2021-09-20 06:22:55 +00:00
|
|
|
getSupportFragmentManager().executePendingTransactions();
|
2021-08-25 16:54:00 +00:00
|
|
|
transaction = fragmentManager.beginTransaction();
|
2018-09-16 08:09:22 +00:00
|
|
|
transaction.replace(R.id.main_fragment, secondaryFragment);
|
|
|
|
transaction.addToBackStack(null);
|
|
|
|
transaction.commit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
|
|
|
|
}
|
|
|
|
if (binding.secondaryFragment != null && secondaryFragment == null) {
|
|
|
|
transaction.replace(R.id.secondary_fragment, new ConversationFragment());
|
|
|
|
}
|
|
|
|
transaction.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void invalidateActionBarTitle() {
|
|
|
|
final ActionBar actionBar = getSupportActionBar();
|
2021-08-25 18:04:47 +00:00
|
|
|
if (actionBar == null) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-20 06:22:55 +00:00
|
|
|
final FragmentManager fragmentManager = getSupportFragmentManager();
|
2021-08-25 18:04:47 +00:00
|
|
|
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
|
|
|
if (mainFragment instanceof ConversationFragment) {
|
|
|
|
final Conversation conversation = ((ConversationFragment) mainFragment).getConversation();
|
|
|
|
if (conversation != null) {
|
|
|
|
actionBar.setTitle(EmojiWrapper.transform(conversation.getName()));
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
ActionBarUtil.setActionBarOnClickListener(
|
|
|
|
binding.toolbar,
|
|
|
|
(v) -> openConversationDetails(conversation)
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
actionBar.setTitle(R.string.app_name);
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(false);
|
|
|
|
ActionBarUtil.resetActionBarOnClickListeners(binding.toolbar);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openConversationDetails(final Conversation conversation) {
|
|
|
|
if (conversation.getMode() == Conversational.MODE_MULTI) {
|
|
|
|
ConferenceDetailsActivity.open(this, conversation);
|
|
|
|
} else {
|
|
|
|
final Contact contact = conversation.getContact();
|
|
|
|
if (contact.isSelf()) {
|
|
|
|
switchToAccount(conversation.getAccount());
|
|
|
|
} else {
|
|
|
|
switchToContactDetails(contact);
|
2018-09-16 08:09:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConversationArchived(Conversation conversation) {
|
|
|
|
if (performRedirectIfNecessary(conversation, false)) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-20 06:22:55 +00:00
|
|
|
final FragmentManager fragmentManager = getSupportFragmentManager();
|
2021-08-25 18:04:47 +00:00
|
|
|
final Fragment mainFragment = fragmentManager.findFragmentById(R.id.main_fragment);
|
2018-10-24 18:00:25 +00:00
|
|
|
if (mainFragment instanceof ConversationFragment) {
|
2018-09-16 08:09:22 +00:00
|
|
|
try {
|
2021-08-25 18:04:47 +00:00
|
|
|
fragmentManager.popBackStack();
|
|
|
|
} catch (final IllegalStateException e) {
|
2018-09-16 08:09:22 +00:00
|
|
|
Log.w(Config.LOGTAG, "state loss while popping back state after archiving conversation", e);
|
|
|
|
//this usually means activity is no longer active; meaning on the next open we will run through this again
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2021-08-25 18:04:47 +00:00
|
|
|
final Fragment secondaryFragment = fragmentManager.findFragmentById(R.id.secondary_fragment);
|
2018-10-24 18:00:25 +00:00
|
|
|
if (secondaryFragment instanceof ConversationFragment) {
|
2018-09-16 08:09:22 +00:00
|
|
|
if (((ConversationFragment) secondaryFragment).getConversation() == conversation) {
|
2021-09-20 06:22:55 +00:00
|
|
|
Conversation suggestion = ConversationsOverviewFragment.getSuggestion(getSupportFragmentManager(), conversation);
|
2018-09-16 08:09:22 +00:00
|
|
|
if (suggestion != null) {
|
|
|
|
openConversation(suggestion, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConversationsListItemUpdated() {
|
2021-09-20 06:22:55 +00:00
|
|
|
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.main_fragment);
|
2018-10-24 18:00:25 +00:00
|
|
|
if (fragment instanceof ConversationsOverviewFragment) {
|
2018-09-16 08:09:22 +00:00
|
|
|
((ConversationsOverviewFragment) fragment).refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void switchToConversation(Conversation conversation) {
|
|
|
|
Log.d(Config.LOGTAG, "override");
|
|
|
|
openConversation(conversation, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConversationRead(Conversation conversation, String upToUuid) {
|
|
|
|
if (!mActivityPaused && pendingViewIntent.peek() == null) {
|
|
|
|
xmppConnectionService.sendReadMarker(conversation, upToUuid);
|
|
|
|
} else {
|
2021-01-23 08:25:34 +00:00
|
|
|
Log.d(Config.LOGTAG, "ignoring read callback. mActivityPaused=" + mActivityPaused);
|
2018-09-16 08:09:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAccountUpdate() {
|
|
|
|
this.refreshUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConversationUpdate() {
|
|
|
|
if (performRedirectIfNecessary(false)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.refreshUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRosterUpdate() {
|
|
|
|
this.refreshUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void OnUpdateBlocklist(OnUpdateBlocklist.Status status) {
|
|
|
|
this.refreshUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onShowErrorToast(int resId) {
|
|
|
|
runOnUiThread(() -> Toast.makeText(this, resId, Toast.LENGTH_SHORT).show());
|
|
|
|
}
|
2018-03-07 18:05:28 +00:00
|
|
|
}
|