2018-02-22 21:23:49 +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.
|
|
|
|
*/
|
|
|
|
|
2014-02-28 17:46:01 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
2014-01-24 01:04:05 +00:00
|
|
|
|
2018-02-22 21:23:49 +00:00
|
|
|
|
2018-02-25 12:22:52 +00:00
|
|
|
import android.annotation.SuppressLint;
|
2018-02-27 13:12:29 +00:00
|
|
|
import android.app.Activity;
|
2018-02-22 21:23:49 +00:00
|
|
|
import android.app.Fragment;
|
|
|
|
import android.app.FragmentManager;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.app.FragmentTransaction;
|
2018-02-25 12:22:52 +00:00
|
|
|
import android.content.ActivityNotFoundException;
|
2018-02-23 09:20:56 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2018-02-22 21:23:49 +00:00
|
|
|
import android.databinding.DataBindingUtil;
|
2018-02-25 12:22:52 +00:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
2014-11-03 19:00:20 +00:00
|
|
|
import android.os.Bundle;
|
2018-02-25 12:22:52 +00:00
|
|
|
import android.provider.Settings;
|
2018-02-22 21:23:49 +00:00
|
|
|
import android.support.annotation.IdRes;
|
2018-02-27 13:12:29 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2018-02-16 11:06:05 +00:00
|
|
|
import android.support.v7.app.ActionBar;
|
2018-02-25 12:22:52 +00:00
|
|
|
import android.support.v7.app.AlertDialog;
|
2015-06-25 15:01:42 +00:00
|
|
|
import android.util.Log;
|
2014-01-24 01:04:05 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2014-05-09 18:46:43 +00:00
|
|
|
import android.widget.Toast;
|
2014-01-24 01:04:05 +00:00
|
|
|
|
2018-02-27 13:12:29 +00:00
|
|
|
import org.openintents.openpgp.util.OpenPgpApi;
|
|
|
|
|
2018-02-24 19:19:35 +00:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
2015-06-25 15:01:42 +00:00
|
|
|
import eu.siacs.conversations.Config;
|
2014-11-03 19:00:20 +00:00
|
|
|
import eu.siacs.conversations.R;
|
2018-02-22 21:23:49 +00:00
|
|
|
import eu.siacs.conversations.databinding.ActivityConversationsBinding;
|
2018-02-24 19:19:35 +00:00
|
|
|
import eu.siacs.conversations.entities.Account;
|
2014-11-03 19:00:20 +00:00
|
|
|
import eu.siacs.conversations.entities.Conversation;
|
2015-07-10 11:28:50 +00:00
|
|
|
import eu.siacs.conversations.services.XmppConnectionService;
|
2018-02-22 21:23:49 +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;
|
2017-09-29 17:44:30 +00:00
|
|
|
import eu.siacs.conversations.ui.service.EmojiService;
|
2018-02-27 13:12:29 +00:00
|
|
|
import eu.siacs.conversations.ui.util.ActivityResult;
|
2018-02-23 09:20:56 +00:00
|
|
|
import eu.siacs.conversations.ui.util.PendingItem;
|
2018-02-25 12:22:52 +00:00
|
|
|
import eu.siacs.conversations.utils.ExceptionHelper;
|
2014-12-21 20:43:58 +00:00
|
|
|
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
|
2014-11-03 19:00:20 +00:00
|
|
|
|
2018-02-24 21:15:07 +00:00
|
|
|
import static eu.siacs.conversations.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
|
|
|
|
|
2018-02-22 21:23:49 +00:00
|
|
|
public class ConversationActivity extends XmppActivity implements OnConversationSelected, OnConversationArchived, OnConversationsListItemUpdated, OnConversationRead, XmppConnectionService.OnAccountUpdate, XmppConnectionService.OnConversationUpdate, XmppConnectionService.OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
|
2014-01-24 09:50:18 +00:00
|
|
|
|
2016-07-25 12:15:47 +00:00
|
|
|
public static final String ACTION_VIEW_CONVERSATION = "eu.siacs.conversations.action.VIEW";
|
2018-02-22 21:23:49 +00:00
|
|
|
public static final String EXTRA_CONVERSATION = "conversationUuid";
|
2016-07-25 12:15:47 +00:00
|
|
|
public static final String EXTRA_DOWNLOAD_UUID = "eu.siacs.conversations.download_uuid";
|
2018-02-22 21:23:49 +00:00
|
|
|
public static final String EXTRA_TEXT = "text";
|
|
|
|
public static final String EXTRA_NICK = "nick";
|
|
|
|
public static final String EXTRA_IS_PRIVATE_MESSAGE = "pm";
|
2015-09-07 13:46:22 +00:00
|
|
|
|
2014-01-24 09:50:18 +00:00
|
|
|
|
2018-02-22 21:23:49 +00:00
|
|
|
//secondary fragment (when holding the conversation, must be initialized before refreshing the overview fragment
|
2018-02-23 09:20:56 +00:00
|
|
|
private static final @IdRes
|
|
|
|
int[] FRAGMENT_ID_NOTIFICATION_ORDER = {R.id.secondary_fragment, R.id.main_fragment};
|
|
|
|
private final PendingItem<Intent> pendingViewIntent = new PendingItem<>();
|
2018-02-27 13:12:29 +00:00
|
|
|
private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
|
2018-02-22 21:23:49 +00:00
|
|
|
private ActivityConversationsBinding binding;
|
2018-02-23 18:22:38 +00:00
|
|
|
private boolean mActivityPaused = true;
|
2018-02-24 19:19:35 +00:00
|
|
|
private AtomicBoolean mRedirectInProcess = new AtomicBoolean(false);
|
2014-06-06 09:39:17 +00:00
|
|
|
|
2018-02-23 09:20:56 +00:00
|
|
|
private static boolean isViewIntent(Intent i) {
|
|
|
|
return i != null && ACTION_VIEW_CONVERSATION.equals(i.getAction()) && i.hasExtra(EXTRA_CONVERSATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Intent createLauncherIntent(Context context) {
|
|
|
|
final Intent intent = new Intent(context, ConversationActivity.class);
|
|
|
|
intent.setAction(Intent.ACTION_MAIN);
|
|
|
|
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
2018-02-22 21:23:49 +00:00
|
|
|
@Override
|
|
|
|
protected void refreshUiReal() {
|
2018-02-23 09:20:56 +00:00
|
|
|
for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
|
2018-02-22 21:23:49 +00:00
|
|
|
refreshFragment(id);
|
2014-10-03 13:00:29 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-05 22:33:52 +00:00
|
|
|
|
2014-11-04 11:15:14 +00:00
|
|
|
@Override
|
2018-02-22 21:23:49 +00:00
|
|
|
void onBackendConnected() {
|
2018-02-24 19:19:35 +00:00
|
|
|
if (performRedirectIfNecessary(true)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-24 16:31:41 +00:00
|
|
|
xmppConnectionService.getNotificationService().setIsInForeground(true);
|
2018-02-23 09:20:56 +00:00
|
|
|
Intent intent = pendingViewIntent.pop();
|
|
|
|
if (intent != null) {
|
2018-02-23 10:35:13 +00:00
|
|
|
if (processViewIntent(intent)) {
|
2018-02-25 07:33:22 +00:00
|
|
|
if (binding.secondaryFragment != null) {
|
|
|
|
notifyFragmentOfBackendConnected(R.id.main_fragment);
|
|
|
|
}
|
|
|
|
invalidateActionBarTitle();
|
2018-02-23 10:35:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-02-25 07:33:22 +00:00
|
|
|
for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
|
|
|
|
notifyFragmentOfBackendConnected(id);
|
|
|
|
}
|
2018-02-27 13:12:29 +00:00
|
|
|
|
|
|
|
ActivityResult activityResult = postponedActivityResult.pop();
|
|
|
|
if (activityResult != null) {
|
|
|
|
handleActivityResult(activityResult);
|
|
|
|
}
|
|
|
|
|
2018-02-25 07:33:22 +00:00
|
|
|
invalidateActionBarTitle();
|
2018-02-23 10:35:13 +00:00
|
|
|
if (binding.secondaryFragment != null && ConversationFragment.getConversation(this) == null) {
|
|
|
|
Conversation conversation = ConversationsOverviewFragment.getSuggestion(this);
|
|
|
|
if (conversation != null) {
|
|
|
|
openConversation(conversation, null);
|
|
|
|
}
|
2018-02-23 09:20:56 +00:00
|
|
|
}
|
2018-02-25 12:22:52 +00:00
|
|
|
showDialogsIfMainIsOverview();
|
2014-11-04 11:15:14 +00:00
|
|
|
}
|
|
|
|
|
2018-02-24 19:19:35 +00:00
|
|
|
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)) {
|
|
|
|
final Intent intent = getRedirectionIntent(noAnimation);
|
|
|
|
runOnUiThread(() -> {
|
|
|
|
startActivity(intent);
|
|
|
|
if (noAnimation) {
|
|
|
|
overridePendingTransition(0, 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return mRedirectInProcess.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Intent getRedirectionIntent(boolean noAnimation) {
|
|
|
|
Account pendingAccount = xmppConnectionService.getPendingAccount();
|
|
|
|
Intent intent;
|
|
|
|
if (pendingAccount != null) {
|
|
|
|
intent = new Intent(this, EditAccountActivity.class);
|
|
|
|
intent.putExtra("jid", pendingAccount.getJid().toBareJid().toString());
|
|
|
|
} else {
|
|
|
|
if (xmppConnectionService.getAccounts().size() == 0) {
|
|
|
|
if (Config.X509_VERIFICATION) {
|
|
|
|
intent = new Intent(this, ManageAccountActivity.class);
|
|
|
|
} else if (Config.MAGIC_CREATE_DOMAIN != null) {
|
|
|
|
intent = new Intent(this, WelcomeActivity.class);
|
|
|
|
WelcomeActivity.addInviteUri(intent, getIntent());
|
|
|
|
} else {
|
|
|
|
intent = new Intent(this, EditAccountActivity.class);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
intent = new Intent(this, StartConversationActivity.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
intent.putExtra("init", true);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
if (noAnimation) {
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
|
|
|
}
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
2018-02-25 12:22:52 +00:00
|
|
|
private void showDialogsIfMainIsOverview() {
|
2018-02-26 09:27:30 +00:00
|
|
|
if (xmppConnectionService == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
|
2018-02-25 12:22:52 +00:00
|
|
|
if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
|
2018-02-26 09:27:30 +00:00
|
|
|
if (ExceptionHelper.checkForCrash(this)) {
|
2018-02-25 12:22:52 +00:00
|
|
|
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()
|
|
|
|
&& getPreferences().getBoolean(getBatteryOptimizationPreferenceKey(), true)) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setTitle(R.string.battery_optimizations_enabled);
|
|
|
|
builder.setMessage(R.string.battery_optimizations_enabled_dialog);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
|
|
|
builder.setOnDismissListener(dialog -> setNeverAskForBatteryOptimizationsAgain());
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-22 21:23:49 +00:00
|
|
|
private void notifyFragmentOfBackendConnected(@IdRes int id) {
|
|
|
|
final Fragment fragment = getFragmentManager().findFragmentById(id);
|
|
|
|
if (fragment != null && fragment instanceof XmppFragment) {
|
|
|
|
((XmppFragment) fragment).onBackendConnected();
|
2014-10-03 13:00:29 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-05 22:33:52 +00:00
|
|
|
|
2018-02-22 21:23:49 +00:00
|
|
|
private void refreshFragment(@IdRes int id) {
|
|
|
|
final Fragment fragment = getFragmentManager().findFragmentById(id);
|
|
|
|
if (fragment != null && fragment instanceof XmppFragment) {
|
|
|
|
((XmppFragment) fragment).refresh();
|
2014-10-03 13:00:29 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-10 12:12:08 +00:00
|
|
|
|
2018-02-23 10:35:13 +00:00
|
|
|
private boolean processViewIntent(Intent intent) {
|
2018-02-25 22:58:56 +00:00
|
|
|
Log.d(Config.LOGTAG,"process view intent");
|
2018-02-23 09:20:56 +00:00
|
|
|
String uuid = intent.getStringExtra(EXTRA_CONVERSATION);
|
|
|
|
Conversation conversation = uuid != null ? xmppConnectionService.findConversationByUuid(uuid) : null;
|
|
|
|
if (conversation == null) {
|
|
|
|
Log.d(Config.LOGTAG, "unable to view conversation with uuid:" + uuid);
|
2018-02-23 10:35:13 +00:00
|
|
|
return false;
|
2018-02-23 09:20:56 +00:00
|
|
|
}
|
|
|
|
openConversation(conversation, intent.getExtras());
|
2018-02-23 10:35:13 +00:00
|
|
|
return true;
|
2018-02-23 09:20:56 +00:00
|
|
|
}
|
|
|
|
|
2018-02-25 22:58:56 +00:00
|
|
|
@Override
|
2018-02-27 13:12:29 +00:00
|
|
|
public void onRequestPermissionsResult(int requestCode,@NonNull String permissions[], @NonNull int[] grantResults) {
|
2018-02-25 22:58:56 +00:00
|
|
|
UriHandlerActivity.onRequestPermissionResult(this, requestCode, grantResults);
|
|
|
|
}
|
|
|
|
|
2014-01-24 01:04:05 +00:00
|
|
|
@Override
|
2018-02-24 21:15:07 +00:00
|
|
|
public void onActivityResult(int requestCode, int resultCode, final Intent data) {
|
2018-02-27 13:12:29 +00:00
|
|
|
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);
|
2018-02-24 21:15:07 +00:00
|
|
|
} else {
|
2018-02-27 13:12:29 +00:00
|
|
|
handleNegativeActivityResult(activityResult.requestCode);
|
2018-02-24 21:15:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleNegativeActivityResult(int requestCode) {
|
2018-02-27 13:12:29 +00:00
|
|
|
Conversation conversation = ConversationFragment.getConversationReliable(this);
|
2018-02-24 21:15:07 +00:00
|
|
|
switch (requestCode) {
|
|
|
|
case REQUEST_DECRYPT_PGP:
|
|
|
|
if (conversation == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
conversation.getAccount().getPgpDecryptionService().giveUpCurrentDecryption();
|
|
|
|
break;
|
2018-02-25 12:22:52 +00:00
|
|
|
case REQUEST_BATTERY_OP:
|
|
|
|
setNeverAskForBatteryOptimizationsAgain();
|
|
|
|
break;
|
2018-02-24 21:15:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handlePositiveActivityResult(int requestCode, final Intent data) {
|
2018-02-27 13:12:29 +00:00
|
|
|
Log.d(Config.LOGTAG,"positive activity result");
|
|
|
|
Conversation conversation = ConversationFragment.getConversationReliable(this);
|
|
|
|
if (conversation == null) {
|
|
|
|
Log.d(Config.LOGTAG,"conversation not found");
|
|
|
|
return;
|
|
|
|
}
|
2018-02-24 21:15:07 +00:00
|
|
|
switch (requestCode) {
|
|
|
|
case REQUEST_DECRYPT_PGP:
|
|
|
|
conversation.getAccount().getPgpDecryptionService().continueDecryption(data);
|
|
|
|
break;
|
2018-02-27 13:12:29 +00:00
|
|
|
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;
|
2018-02-24 21:15:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-14 20:28:27 +00:00
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
2014-01-25 18:33:12 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
2017-09-29 17:44:30 +00:00
|
|
|
new EmojiService(this).init();
|
2018-02-22 21:23:49 +00:00
|
|
|
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_conversations);
|
|
|
|
this.getFragmentManager().addOnBackStackChangedListener(this::invalidateActionBarTitle);
|
2018-02-25 12:22:52 +00:00
|
|
|
this.getFragmentManager().addOnBackStackChangedListener(this::showDialogsIfMainIsOverview);
|
2018-02-22 21:23:49 +00:00
|
|
|
this.initializeFragments();
|
|
|
|
this.invalidateActionBarTitle();
|
2018-02-25 22:58:56 +00:00
|
|
|
final Intent intent;
|
|
|
|
if (savedInstanceState == null) {
|
|
|
|
intent = getIntent();
|
|
|
|
} else {
|
|
|
|
intent = savedInstanceState.getParcelable("intent");
|
|
|
|
}
|
2018-02-23 09:20:56 +00:00
|
|
|
if (isViewIntent(intent)) {
|
|
|
|
pendingViewIntent.push(intent);
|
|
|
|
setIntent(createLauncherIntent(this));
|
|
|
|
}
|
2014-09-29 16:28:13 +00:00
|
|
|
}
|
2014-01-24 09:50:18 +00:00
|
|
|
|
2014-01-24 01:04:05 +00:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
2018-02-20 13:54:32 +00:00
|
|
|
getMenuInflater().inflate(R.menu.activity_conversations, menu);
|
2018-02-24 21:28:01 +00:00
|
|
|
MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
|
|
|
|
if (qrCodeScanMenuItem != null) {
|
|
|
|
Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
|
|
|
|
boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan)
|
|
|
|
&& fragment != null
|
|
|
|
&& fragment instanceof ConversationsOverviewFragment;
|
|
|
|
qrCodeScanMenuItem.setVisible(visible);
|
|
|
|
}
|
2016-02-27 09:25:31 +00:00
|
|
|
return super.onCreateOptionsMenu(menu);
|
2014-01-24 01:04:05 +00:00
|
|
|
}
|
2014-06-06 09:39:17 +00:00
|
|
|
|
2016-01-11 10:17:45 +00:00
|
|
|
@Override
|
2018-02-22 21:23:49 +00:00
|
|
|
public void onConversationSelected(Conversation conversation) {
|
2018-02-26 08:53:17 +00:00
|
|
|
if (ConversationFragment.getConversation(this) == conversation) {
|
|
|
|
Log.d(Config.LOGTAG,"ignore onConversationSelected() because conversation is already open");
|
2018-02-26 09:27:30 +00:00
|
|
|
return;
|
2018-02-26 08:53:17 +00:00
|
|
|
}
|
2018-02-23 09:20:56 +00:00
|
|
|
openConversation(conversation, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openConversation(Conversation conversation, Bundle extras) {
|
2018-02-22 21:23:49 +00:00
|
|
|
ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
|
|
|
|
final boolean mainNeedsRefresh;
|
|
|
|
if (conversationFragment == null) {
|
|
|
|
mainNeedsRefresh = false;
|
2018-02-23 11:53:47 +00:00
|
|
|
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
|
|
|
|
if (mainFragment != null && mainFragment instanceof ConversationFragment) {
|
|
|
|
conversationFragment = (ConversationFragment) mainFragment;
|
|
|
|
} else {
|
|
|
|
conversationFragment = new ConversationFragment();
|
|
|
|
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
|
|
|
fragmentTransaction.replace(R.id.main_fragment, conversationFragment);
|
|
|
|
fragmentTransaction.addToBackStack(null);
|
|
|
|
fragmentTransaction.commit();
|
|
|
|
}
|
2014-09-23 13:06:49 +00:00
|
|
|
} else {
|
2018-02-22 21:23:49 +00:00
|
|
|
mainNeedsRefresh = true;
|
2014-01-24 01:04:05 +00:00
|
|
|
}
|
2018-02-26 10:40:06 +00:00
|
|
|
conversationFragment.reInit(conversation, extras == null ? new Bundle() : extras);
|
2018-02-22 21:23:49 +00:00
|
|
|
if (mainNeedsRefresh) {
|
|
|
|
refreshFragment(R.id.main_fragment);
|
2018-02-23 11:53:47 +00:00
|
|
|
} else {
|
|
|
|
invalidateActionBarTitle();
|
2014-04-20 18:48:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-24 09:50:18 +00:00
|
|
|
@Override
|
2018-02-22 21:23:49 +00:00
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
FragmentManager fm = getFragmentManager();
|
|
|
|
if (fm.getBackStackEntryCount() > 0) {
|
|
|
|
fm.popBackStack();
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-07 18:45:21 +00:00
|
|
|
break;
|
2018-02-24 20:57:42 +00:00
|
|
|
case R.id.action_scan_qr_code:
|
|
|
|
UriHandlerActivity.scan(this);
|
|
|
|
return true;
|
2015-09-07 13:46:22 +00:00
|
|
|
}
|
2018-02-22 21:23:49 +00:00
|
|
|
return super.onOptionsItemSelected(item);
|
2015-09-07 13:46:22 +00:00
|
|
|
}
|
|
|
|
|
2018-02-25 22:58:56 +00:00
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle savedInstanceState) {
|
2018-02-26 11:03:17 +00:00
|
|
|
Intent pendingIntent = pendingViewIntent.pop();
|
|
|
|
savedInstanceState.putParcelable("intent", pendingIntent == null ? pendingIntent : getIntent());
|
2018-02-25 22:58:56 +00:00
|
|
|
super.onSaveInstanceState(savedInstanceState);
|
|
|
|
}
|
|
|
|
|
2018-02-24 11:53:02 +00:00
|
|
|
@Override
|
|
|
|
protected void onStart() {
|
|
|
|
final int theme = findTheme();
|
|
|
|
if (this.mTheme != theme) {
|
2018-02-26 11:03:17 +00:00
|
|
|
this.mSkipBackgroundBinding = true;
|
2018-02-24 11:53:02 +00:00
|
|
|
recreate();
|
2018-02-26 11:03:17 +00:00
|
|
|
} else {
|
|
|
|
this.mSkipBackgroundBinding = false;
|
2018-02-24 11:53:02 +00:00
|
|
|
}
|
2018-02-24 19:19:35 +00:00
|
|
|
mRedirectInProcess.set(false);
|
2018-02-24 11:53:02 +00:00
|
|
|
super.onStart();
|
|
|
|
}
|
|
|
|
|
2018-02-23 09:20:56 +00:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(final Intent intent) {
|
|
|
|
if (isViewIntent(intent)) {
|
|
|
|
if (xmppConnectionService != null) {
|
|
|
|
processViewIntent(intent);
|
|
|
|
} else {
|
|
|
|
pendingViewIntent.push(intent);
|
|
|
|
}
|
|
|
|
}
|
2018-02-26 08:53:17 +00:00
|
|
|
setIntent(createLauncherIntent(this));
|
2018-02-23 09:20:56 +00:00
|
|
|
}
|
|
|
|
|
2018-02-23 18:22:38 +00:00
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
this.mActivityPaused = true;
|
|
|
|
super.onPause();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
this.mActivityPaused = false;
|
|
|
|
}
|
|
|
|
|
2018-02-22 21:23:49 +00:00
|
|
|
private void initializeFragments() {
|
|
|
|
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
|
|
|
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
|
|
|
|
Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
|
|
|
|
if (mainFragment != null) {
|
2018-02-23 09:20:56 +00:00
|
|
|
Log.d(Config.LOGTAG, "initializeFragment(). main fragment exists");
|
2018-02-22 21:23:49 +00:00
|
|
|
if (binding.secondaryFragment != null) {
|
|
|
|
if (mainFragment instanceof ConversationFragment) {
|
2018-02-23 09:20:56 +00:00
|
|
|
Log.d(Config.LOGTAG, "gained secondary fragment. moving...");
|
2018-02-22 21:23:49 +00:00
|
|
|
getFragmentManager().popBackStack();
|
|
|
|
transaction.remove(mainFragment);
|
|
|
|
transaction.commit();
|
|
|
|
getFragmentManager().executePendingTransactions();
|
|
|
|
transaction = getFragmentManager().beginTransaction();
|
|
|
|
transaction.replace(R.id.secondary_fragment, mainFragment);
|
|
|
|
transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
|
|
|
|
transaction.commit();
|
|
|
|
return;
|
2015-10-20 13:27:33 +00:00
|
|
|
}
|
2014-11-07 20:49:31 +00:00
|
|
|
} else {
|
2018-02-22 21:23:49 +00:00
|
|
|
if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
|
2018-02-23 09:20:56 +00:00
|
|
|
Log.d(Config.LOGTAG, "lost secondary fragment. moving...");
|
2018-02-22 21:23:49 +00:00
|
|
|
transaction.remove(secondaryFragment);
|
|
|
|
transaction.commit();
|
|
|
|
getFragmentManager().executePendingTransactions();
|
|
|
|
transaction = getFragmentManager().beginTransaction();
|
|
|
|
transaction.replace(R.id.main_fragment, secondaryFragment);
|
|
|
|
transaction.addToBackStack(null);
|
|
|
|
transaction.commit();
|
|
|
|
return;
|
2014-11-07 20:49:31 +00:00
|
|
|
}
|
2014-10-03 13:00:29 +00:00
|
|
|
}
|
2015-08-24 18:56:25 +00:00
|
|
|
} else {
|
2018-02-22 21:23:49 +00:00
|
|
|
transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
|
2014-01-27 19:40:42 +00:00
|
|
|
}
|
2018-02-22 21:23:49 +00:00
|
|
|
if (binding.secondaryFragment != null && secondaryFragment == null) {
|
|
|
|
transaction.replace(R.id.secondary_fragment, new ConversationFragment());
|
2017-03-06 15:53:54 +00:00
|
|
|
}
|
2018-02-22 21:23:49 +00:00
|
|
|
transaction.commit();
|
2017-03-06 15:53:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 21:23:49 +00:00
|
|
|
private void invalidateActionBarTitle() {
|
|
|
|
final ActionBar actionBar = getSupportActionBar();
|
|
|
|
if (actionBar != null) {
|
|
|
|
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
|
|
|
|
if (mainFragment != null && mainFragment instanceof ConversationFragment) {
|
|
|
|
final Conversation conversation = ((ConversationFragment) mainFragment).getConversation();
|
|
|
|
if (conversation != null) {
|
|
|
|
actionBar.setTitle(conversation.getName());
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
return;
|
2015-01-16 05:36:11 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-22 21:23:49 +00:00
|
|
|
actionBar.setTitle(R.string.app_name);
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(false);
|
2014-11-07 20:49:31 +00:00
|
|
|
}
|
2014-10-24 12:34:46 +00:00
|
|
|
}
|
2014-01-25 18:33:12 +00:00
|
|
|
|
2014-11-11 16:39:28 +00:00
|
|
|
@Override
|
2018-02-22 21:23:49 +00:00
|
|
|
public void onConversationArchived(Conversation conversation) {
|
2018-02-24 19:19:35 +00:00
|
|
|
if (performRedirectIfNecessary(conversation, false)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-24 11:53:02 +00:00
|
|
|
Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
|
|
|
|
if (mainFragment != null && mainFragment instanceof ConversationFragment) {
|
|
|
|
getFragmentManager().popBackStack();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
|
|
|
|
if (secondaryFragment != null && secondaryFragment instanceof ConversationFragment) {
|
|
|
|
if (((ConversationFragment) secondaryFragment).getConversation() == conversation) {
|
|
|
|
Conversation suggestion = ConversationsOverviewFragment.getSuggestion(this, conversation);
|
|
|
|
if (suggestion != null) {
|
|
|
|
openConversation(suggestion, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-11 10:17:45 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 21:23:49 +00:00
|
|
|
@Override
|
|
|
|
public void onConversationsListItemUpdated() {
|
|
|
|
Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
|
|
|
|
if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
|
|
|
|
((ConversationsOverviewFragment) fragment).refresh();
|
2015-04-02 22:06:37 +00:00
|
|
|
}
|
2014-03-19 15:16:40 +00:00
|
|
|
}
|
2014-06-06 09:39:17 +00:00
|
|
|
|
2014-09-10 15:59:57 +00:00
|
|
|
@Override
|
2018-02-22 21:23:49 +00:00
|
|
|
public void onConversationRead(Conversation conversation) {
|
2018-02-23 18:22:38 +00:00
|
|
|
if (!mActivityPaused && pendingViewIntent.peek() == null) {
|
|
|
|
xmppConnectionService.sendReadMarker(conversation);
|
2018-02-25 15:57:59 +00:00
|
|
|
} else {
|
|
|
|
Log.d(Config.LOGTAG,"ignoring read callback. mActivityPaused="+Boolean.toString(mActivityPaused));
|
2018-02-23 18:22:38 +00:00
|
|
|
}
|
2015-02-17 13:18:35 +00:00
|
|
|
}
|
2014-09-10 15:59:57 +00:00
|
|
|
|
2015-02-17 13:18:35 +00:00
|
|
|
@Override
|
|
|
|
public void onAccountUpdate() {
|
|
|
|
this.refreshUi();
|
2014-09-10 15:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConversationUpdate() {
|
2018-02-24 19:19:35 +00:00
|
|
|
if (performRedirectIfNecessary(false)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-02-17 13:18:35 +00:00
|
|
|
this.refreshUi();
|
2014-09-10 15:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRosterUpdate() {
|
2015-02-17 13:18:35 +00:00
|
|
|
this.refreshUi();
|
2014-12-21 20:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-22 21:23:49 +00:00
|
|
|
public void OnUpdateBlocklist(OnUpdateBlocklist.Status status) {
|
2015-02-17 13:18:35 +00:00
|
|
|
this.refreshUi();
|
2014-12-21 20:43:58 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 11:28:50 +00:00
|
|
|
@Override
|
2018-02-22 21:23:49 +00:00
|
|
|
public void onShowErrorToast(int resId) {
|
|
|
|
runOnUiThread(() -> Toast.makeText(this, resId, Toast.LENGTH_SHORT).show());
|
2015-09-07 13:46:22 +00:00
|
|
|
}
|
2014-01-24 01:04:05 +00:00
|
|
|
}
|