2015-06-09 14:37:20 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2017-11-25 06:00:30 +00:00
|
|
|
import android.annotation.SuppressLint;
|
2018-04-03 09:28:26 +00:00
|
|
|
import android.content.ActivityNotFoundException;
|
2016-08-16 03:23:56 +00:00
|
|
|
import android.content.Context;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.content.Intent;
|
2017-09-21 01:14:28 +00:00
|
|
|
import android.database.Cursor;
|
2017-09-13 05:48:30 +00:00
|
|
|
import android.graphics.Color;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.media.Ringtone;
|
|
|
|
import android.media.RingtoneManager;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.AsyncTask;
|
2015-06-29 22:33:36 +00:00
|
|
|
import android.os.Build;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.provider.Settings;
|
|
|
|
import android.support.annotation.NonNull;
|
2017-09-21 01:14:28 +00:00
|
|
|
import android.support.annotation.Nullable;
|
2017-09-13 05:48:30 +00:00
|
|
|
import android.support.design.widget.CollapsingToolbarLayout;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.support.v4.app.Fragment;
|
2017-09-21 01:14:28 +00:00
|
|
|
import android.support.v4.app.LoaderManager;
|
|
|
|
import android.support.v4.content.Loader;
|
2018-01-23 21:43:37 +00:00
|
|
|
import android.support.v4.view.ViewCompat;
|
2015-05-20 21:36:30 +00:00
|
|
|
import android.support.v7.app.AlertDialog;
|
2017-09-21 01:14:28 +00:00
|
|
|
import android.support.v7.preference.CheckBoxPreference;
|
|
|
|
import android.support.v7.preference.ListPreference;
|
|
|
|
import android.support.v7.preference.Preference;
|
2017-10-04 00:05:52 +00:00
|
|
|
import android.support.v7.preference.PreferenceCategory;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.support.v7.widget.Toolbar;
|
2018-04-03 09:28:26 +00:00
|
|
|
import android.telephony.PhoneNumberUtils;
|
2018-08-16 16:47:43 +00:00
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat;
|
2018-09-10 15:40:00 +00:00
|
|
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
2018-08-01 15:09:24 +00:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2018-02-16 19:10:35 +00:00
|
|
|
import android.util.Pair;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.view.MenuItem;
|
2017-09-21 01:14:28 +00:00
|
|
|
import android.view.View;
|
2017-09-13 05:48:30 +00:00
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.widget.ImageView;
|
2017-09-21 01:14:28 +00:00
|
|
|
import android.widget.TextView;
|
2018-09-10 15:40:00 +00:00
|
|
|
import android.widget.Toast;
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-10-16 20:11:42 +00:00
|
|
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|
|
|
|
2015-06-30 16:16:05 +00:00
|
|
|
import org.thoughtcrime.securesms.color.MaterialColor;
|
|
|
|
import org.thoughtcrime.securesms.color.MaterialColors;
|
2017-09-21 01:14:28 +00:00
|
|
|
import org.thoughtcrime.securesms.components.ThreadPhotoRailView;
|
2016-08-25 01:51:45 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
|
2017-07-26 16:59:15 +00:00
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
2015-06-09 14:37:20 +00:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2017-06-07 01:03:09 +00:00
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord;
|
2017-08-22 17:44:04 +00:00
|
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
2017-08-22 01:37:39 +00:00
|
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase.VibrateState;
|
2017-09-21 01:14:28 +00:00
|
|
|
import org.thoughtcrime.securesms.database.loaders.ThreadMediaLoader;
|
2016-08-26 23:53:23 +00:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
|
2017-10-16 20:11:42 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
2018-09-10 15:40:00 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
2018-08-16 16:47:43 +00:00
|
|
|
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
2018-04-03 09:28:26 +00:00
|
|
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
2017-10-16 20:11:42 +00:00
|
|
|
import org.thoughtcrime.securesms.preferences.CorrectedPreferenceFragment;
|
2017-09-21 17:03:05 +00:00
|
|
|
import org.thoughtcrime.securesms.preferences.widgets.ColorPickerPreference;
|
2018-04-03 09:28:26 +00:00
|
|
|
import org.thoughtcrime.securesms.preferences.widgets.ContactPreference;
|
2017-08-01 15:56:00 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
2018-09-10 15:40:00 +00:00
|
|
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
2018-07-24 21:14:30 +00:00
|
|
|
import org.thoughtcrime.securesms.util.CommunicationActions;
|
2018-04-03 09:28:26 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Dialogs;
|
2015-06-09 14:37:20 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2018-09-10 15:40:00 +00:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2016-08-30 00:49:49 +00:00
|
|
|
import org.thoughtcrime.securesms.util.IdentityUtil;
|
2017-12-19 22:42:00 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2017-09-10 06:46:48 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2017-09-13 05:48:30 +00:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2016-08-25 01:51:45 +00:00
|
|
|
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-11-25 06:00:30 +00:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2017-09-21 01:14:28 +00:00
|
|
|
public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActivity implements RecipientModifiedListener, LoaderManager.LoaderCallbacks<Cursor>
|
2015-06-09 14:37:20 +00:00
|
|
|
{
|
|
|
|
private static final String TAG = RecipientPreferenceActivity.class.getSimpleName();
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
public static final String ADDRESS_EXTRA = "recipient_address";
|
2016-12-11 18:04:57 +00:00
|
|
|
public static final String CAN_HAVE_SAFETY_NUMBER_EXTRA = "can_have_safety_number";
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2018-08-16 16:47:43 +00:00
|
|
|
private static final String PREFERENCE_MUTED = "pref_key_recipient_mute";
|
|
|
|
private static final String PREFERENCE_MESSAGE_TONE = "pref_key_recipient_ringtone";
|
|
|
|
private static final String PREFERENCE_CALL_TONE = "pref_key_recipient_call_ringtone";
|
|
|
|
private static final String PREFERENCE_MESSAGE_VIBRATE = "pref_key_recipient_vibrate";
|
|
|
|
private static final String PREFERENCE_CALL_VIBRATE = "pref_key_recipient_call_vibrate";
|
|
|
|
private static final String PREFERENCE_BLOCK = "pref_key_recipient_block";
|
|
|
|
private static final String PREFERENCE_COLOR = "pref_key_recipient_color";
|
|
|
|
private static final String PREFERENCE_IDENTITY = "pref_key_recipient_identity";
|
|
|
|
private static final String PREFERENCE_ABOUT = "pref_key_number";
|
|
|
|
private static final String PREFERENCE_CUSTOM_NOTIFICATIONS = "pref_key_recipient_custom_notifications";
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
private ImageView avatar;
|
2017-10-16 20:11:42 +00:00
|
|
|
private GlideRequests glideRequests;
|
2017-09-21 01:14:28 +00:00
|
|
|
private Address address;
|
|
|
|
private TextView threadPhotoRailLabel;
|
|
|
|
private ThreadPhotoRailView threadPhotoRailView;
|
2017-09-13 05:48:30 +00:00
|
|
|
private CollapsingToolbarLayout toolbarLayout;
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreCreate() {
|
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
dynamicLanguage.onCreate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-02 03:22:48 +00:00
|
|
|
public void onCreate(Bundle instanceState, boolean ready) {
|
2015-06-09 14:37:20 +00:00
|
|
|
setContentView(R.layout.recipient_preference_activity);
|
2017-10-16 20:11:42 +00:00
|
|
|
this.glideRequests = GlideApp.with(this);
|
|
|
|
this.address = getIntent().getParcelableExtra(ADDRESS_EXTRA);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-08-22 01:32:38 +00:00
|
|
|
Recipient recipient = Recipient.from(this, address, true);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
initializeToolbar();
|
2017-08-01 15:56:00 +00:00
|
|
|
setHeader(recipient);
|
|
|
|
recipient.addListener(this);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-09-21 01:14:28 +00:00
|
|
|
getSupportLoaderManager().initLoader(0, null, this);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
|
|
|
dynamicLanguage.onResume(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.preference_fragment);
|
|
|
|
fragment.onActivityResult(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
super.onOptionsItemSelected(item);
|
|
|
|
switch (item.getItemId()) {
|
2015-07-18 08:50:29 +00:00
|
|
|
case android.R.id.home:
|
2017-09-13 05:48:30 +00:00
|
|
|
onBackPressed();
|
2015-07-18 08:50:29 +00:00
|
|
|
return true;
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
finish();
|
|
|
|
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
private void initializeToolbar() {
|
2017-09-21 01:14:28 +00:00
|
|
|
this.toolbarLayout = ViewUtil.findById(this, R.id.collapsing_toolbar);
|
|
|
|
this.avatar = ViewUtil.findById(this, R.id.avatar);
|
|
|
|
this.threadPhotoRailView = ViewUtil.findById(this, R.id.recent_photos);
|
|
|
|
this.threadPhotoRailLabel = ViewUtil.findById(this, R.id.rail_label);
|
2016-12-17 23:52:27 +00:00
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
this.toolbarLayout.setExpandedTitleColor(getResources().getColor(R.color.white));
|
|
|
|
this.toolbarLayout.setCollapsedTitleTextColor(getResources().getColor(R.color.white));
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-09-21 01:14:28 +00:00
|
|
|
this.threadPhotoRailView.setListener(mediaRecord -> {
|
|
|
|
Intent intent = new Intent(RecipientPreferenceActivity.this, MediaPreviewActivity.class);
|
|
|
|
intent.putExtra(MediaPreviewActivity.ADDRESS_EXTRA, address);
|
2017-10-04 18:35:16 +00:00
|
|
|
intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, mediaRecord.isOutgoing());
|
2017-09-21 01:14:28 +00:00
|
|
|
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, mediaRecord.getDate());
|
|
|
|
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, mediaRecord.getAttachment().getSize());
|
2018-01-23 21:43:37 +00:00
|
|
|
intent.putExtra(MediaPreviewActivity.LEFT_IS_RECENT_EXTRA, ViewCompat.getLayoutDirection(threadPhotoRailView) == ViewCompat.LAYOUT_DIRECTION_LTR);
|
2017-09-21 01:14:28 +00:00
|
|
|
intent.setDataAndType(mediaRecord.getAttachment().getDataUri(), mediaRecord.getContentType());
|
|
|
|
startActivity(intent);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.threadPhotoRailLabel.setOnClickListener(v -> {
|
|
|
|
Intent intent = new Intent(this, MediaOverviewActivity.class);
|
|
|
|
intent.putExtra(MediaOverviewActivity.ADDRESS_EXTRA, address);
|
|
|
|
startActivity(intent);
|
|
|
|
});
|
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
Toolbar toolbar = ViewUtil.findById(this, R.id.toolbar);
|
|
|
|
setSupportActionBar(toolbar);
|
2015-06-09 14:37:20 +00:00
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
2017-09-13 05:48:30 +00:00
|
|
|
getSupportActionBar().setLogo(null);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
|
|
|
getWindow().setStatusBarColor(Color.TRANSPARENT);
|
|
|
|
}
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
private void setHeader(@NonNull Recipient recipient) {
|
2017-10-16 20:11:42 +00:00
|
|
|
glideRequests.load(recipient.getContactPhoto())
|
|
|
|
.fallback(recipient.getFallbackContactPhoto().asCallCard(this))
|
2018-03-19 21:10:21 +00:00
|
|
|
.error(recipient.getFallbackContactPhoto().asCallCard(this))
|
2017-10-16 20:11:42 +00:00
|
|
|
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
|
|
|
.into(this.avatar);
|
2017-10-04 22:23:33 +00:00
|
|
|
|
2017-10-16 20:11:42 +00:00
|
|
|
if (recipient.getContactPhoto() == null) this.avatar.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
|
|
|
else this.avatar.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
2017-10-04 22:23:33 +00:00
|
|
|
|
2017-10-16 20:11:42 +00:00
|
|
|
this.avatar.setBackgroundColor(recipient.getColor().toActionBarColor(this));
|
|
|
|
this.toolbarLayout.setTitle(recipient.toShortString());
|
|
|
|
this.toolbarLayout.setContentScrimColor(recipient.getColor().toActionBarColor(this));
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-01 15:56:00 +00:00
|
|
|
public void onModified(final Recipient recipient) {
|
2017-09-13 05:48:30 +00:00
|
|
|
Util.runOnMain(() -> setHeader(recipient));
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 01:14:28 +00:00
|
|
|
@Override
|
|
|
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
2018-02-02 03:22:48 +00:00
|
|
|
return new ThreadMediaLoader(this, address, true);
|
2017-09-21 01:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
|
|
|
if (data != null && data.getCount() > 0) {
|
|
|
|
this.threadPhotoRailLabel.setVisibility(View.VISIBLE);
|
|
|
|
this.threadPhotoRailView.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
this.threadPhotoRailLabel.setVisibility(View.GONE);
|
|
|
|
this.threadPhotoRailView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2018-02-02 03:22:48 +00:00
|
|
|
this.threadPhotoRailView.setCursor(glideRequests, data);
|
2017-09-21 01:14:28 +00:00
|
|
|
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putParcelable(ADDRESS_EXTRA, address);
|
2018-02-02 03:22:48 +00:00
|
|
|
initFragment(R.id.preference_fragment, new RecipientPreferenceFragment(), null, bundle);
|
2017-09-21 01:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoaderReset(Loader<Cursor> loader) {
|
2018-02-02 03:22:48 +00:00
|
|
|
this.threadPhotoRailView.setCursor(glideRequests, null);
|
2017-09-21 01:14:28 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
public static class RecipientPreferenceFragment
|
2017-09-21 01:14:28 +00:00
|
|
|
extends CorrectedPreferenceFragment
|
2017-08-01 15:56:00 +00:00
|
|
|
implements RecipientModifiedListener
|
2015-06-09 14:37:20 +00:00
|
|
|
{
|
2017-11-25 06:00:30 +00:00
|
|
|
private Recipient recipient;
|
|
|
|
private boolean canHaveSafetyNumber;
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle icicle) {
|
2018-08-02 13:25:33 +00:00
|
|
|
Log.i(TAG, "onCreate (fragment)");
|
2015-06-09 14:37:20 +00:00
|
|
|
super.onCreate(icicle);
|
|
|
|
|
2016-08-16 03:23:56 +00:00
|
|
|
initializeRecipients();
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2016-12-11 18:04:57 +00:00
|
|
|
this.canHaveSafetyNumber = getActivity().getIntent()
|
|
|
|
.getBooleanExtra(RecipientPreferenceActivity.CAN_HAVE_SAFETY_NUMBER_EXTRA, false);
|
2016-08-25 01:51:45 +00:00
|
|
|
|
2018-08-16 16:47:43 +00:00
|
|
|
Preference customNotificationsPref = this.findPreference(PREFERENCE_CUSTOM_NOTIFICATIONS);
|
|
|
|
|
|
|
|
if (NotificationChannels.supported()) {
|
2018-08-31 00:59:15 +00:00
|
|
|
((SwitchPreferenceCompat) customNotificationsPref).setChecked(recipient.getNotificationChannel() != null);
|
2018-08-16 16:47:43 +00:00
|
|
|
customNotificationsPref.setOnPreferenceChangeListener(new CustomNotificationsChangedListener());
|
2018-08-31 00:59:15 +00:00
|
|
|
|
|
|
|
this.findPreference(PREFERENCE_MESSAGE_TONE).setDependency(PREFERENCE_CUSTOM_NOTIFICATIONS);
|
|
|
|
this.findPreference(PREFERENCE_MESSAGE_VIBRATE).setDependency(PREFERENCE_CUSTOM_NOTIFICATIONS);
|
|
|
|
|
|
|
|
if (recipient.getNotificationChannel() != null) {
|
|
|
|
final Context context = getContext();
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... voids) {
|
|
|
|
RecipientDatabase db = DatabaseFactory.getRecipientDatabase(getContext());
|
|
|
|
db.setMessageRingtone(recipient, NotificationChannels.getMessageRingtone(context, recipient));
|
|
|
|
db.setMessageVibrate(recipient, NotificationChannels.getMessageVibrate(context, recipient) ? VibrateState.ENABLED : VibrateState.DISABLED);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
2018-08-16 16:47:43 +00:00
|
|
|
} else {
|
|
|
|
customNotificationsPref.setVisible(false);
|
|
|
|
}
|
|
|
|
|
2018-08-31 00:59:15 +00:00
|
|
|
this.findPreference(PREFERENCE_MESSAGE_TONE)
|
|
|
|
.setOnPreferenceChangeListener(new RingtoneChangeListener(false));
|
2018-02-16 19:10:35 +00:00
|
|
|
this.findPreference(PREFERENCE_MESSAGE_TONE)
|
|
|
|
.setOnPreferenceClickListener(new RingtoneClickedListener(false));
|
|
|
|
this.findPreference(PREFERENCE_CALL_TONE)
|
|
|
|
.setOnPreferenceChangeListener(new RingtoneChangeListener(true));
|
|
|
|
this.findPreference(PREFERENCE_CALL_TONE)
|
|
|
|
.setOnPreferenceClickListener(new RingtoneClickedListener(true));
|
2018-08-31 00:59:15 +00:00
|
|
|
this.findPreference(PREFERENCE_MESSAGE_VIBRATE)
|
|
|
|
.setOnPreferenceChangeListener(new VibrateChangeListener(false));
|
2018-02-16 19:10:35 +00:00
|
|
|
this.findPreference(PREFERENCE_CALL_VIBRATE)
|
|
|
|
.setOnPreferenceChangeListener(new VibrateChangeListener(true));
|
2015-06-09 14:37:20 +00:00
|
|
|
this.findPreference(PREFERENCE_MUTED)
|
|
|
|
.setOnPreferenceClickListener(new MuteClickedListener());
|
|
|
|
this.findPreference(PREFERENCE_BLOCK)
|
|
|
|
.setOnPreferenceClickListener(new BlockClickedListener());
|
2015-06-24 20:17:58 +00:00
|
|
|
this.findPreference(PREFERENCE_COLOR)
|
|
|
|
.setOnPreferenceChangeListener(new ColorChangeListener());
|
2018-04-03 09:28:26 +00:00
|
|
|
((ContactPreference)this.findPreference(PREFERENCE_ABOUT))
|
|
|
|
.setListener(new AboutNumberClickedListener());
|
2017-09-21 01:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey) {
|
2018-08-02 13:25:33 +00:00
|
|
|
Log.i(TAG, "onCreatePreferences...");
|
2017-09-21 01:14:28 +00:00
|
|
|
addPreferencesFromResource(R.xml.recipient_preferences);
|
|
|
|
}
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
@Override
|
2018-04-03 15:51:28 +00:00
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
|
|
|
|
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-09 14:37:20 +00:00
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2017-08-01 15:56:00 +00:00
|
|
|
setSummaries(recipient);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
2015-06-23 01:18:06 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2015-06-23 01:30:42 +00:00
|
|
|
super.onDestroy();
|
2017-08-01 15:56:00 +00:00
|
|
|
this.recipient.removeListener(this);
|
2016-08-16 03:23:56 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 20:55:24 +00:00
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
if (requestCode == 1 && resultCode == RESULT_OK && data != null) {
|
|
|
|
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
findPreference(PREFERENCE_MESSAGE_TONE).getOnPreferenceChangeListener().onPreferenceChange(findPreference(PREFERENCE_MESSAGE_TONE), uri);
|
|
|
|
} else if (requestCode == 2 && resultCode == RESULT_OK && data != null) {
|
|
|
|
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
|
|
|
|
|
|
|
findPreference(PREFERENCE_CALL_TONE).getOnPreferenceChangeListener().onPreferenceChange(findPreference(PREFERENCE_CALL_TONE), uri);
|
2017-12-01 20:55:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 03:23:56 +00:00
|
|
|
private void initializeRecipients() {
|
2017-10-16 20:11:42 +00:00
|
|
|
this.recipient = Recipient.from(getActivity(), getArguments().getParcelable(ADDRESS_EXTRA), true);
|
2017-08-01 15:56:00 +00:00
|
|
|
this.recipient.addListener(this);
|
2015-06-23 01:18:06 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
private void setSummaries(Recipient recipient) {
|
2018-02-16 19:10:35 +00:00
|
|
|
CheckBoxPreference mutePreference = (CheckBoxPreference) this.findPreference(PREFERENCE_MUTED);
|
|
|
|
Preference ringtoneMessagePreference = this.findPreference(PREFERENCE_MESSAGE_TONE);
|
|
|
|
Preference ringtoneCallPreference = this.findPreference(PREFERENCE_CALL_TONE);
|
|
|
|
ListPreference vibrateMessagePreference = (ListPreference) this.findPreference(PREFERENCE_MESSAGE_VIBRATE);
|
|
|
|
ListPreference vibrateCallPreference = (ListPreference) this.findPreference(PREFERENCE_CALL_VIBRATE);
|
|
|
|
ColorPickerPreference colorPreference = (ColorPickerPreference) this.findPreference(PREFERENCE_COLOR);
|
|
|
|
Preference blockPreference = this.findPreference(PREFERENCE_BLOCK);
|
|
|
|
Preference identityPreference = this.findPreference(PREFERENCE_IDENTITY);
|
2018-04-03 09:28:26 +00:00
|
|
|
PreferenceCategory aboutCategory = (PreferenceCategory)this.findPreference("about");
|
2018-04-19 17:53:37 +00:00
|
|
|
PreferenceCategory aboutDivider = (PreferenceCategory)this.findPreference("about_divider");
|
2018-04-03 09:28:26 +00:00
|
|
|
ContactPreference aboutPreference = (ContactPreference)this.findPreference(PREFERENCE_ABOUT);
|
2018-02-16 19:10:35 +00:00
|
|
|
PreferenceCategory privacyCategory = (PreferenceCategory) this.findPreference("privacy_settings");
|
|
|
|
PreferenceCategory divider = (PreferenceCategory) this.findPreference("divider");
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
mutePreference.setChecked(recipient.isMuted());
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2018-09-07 23:18:26 +00:00
|
|
|
ringtoneMessagePreference.setSummary(ringtoneMessagePreference.isEnabled() ? getRingtoneSummary(getContext(), recipient.getMessageRingtone()) : "");
|
2018-02-16 19:10:35 +00:00
|
|
|
ringtoneCallPreference.setSummary(getRingtoneSummary(getContext(), recipient.getCallRingtone()));
|
2015-12-24 14:27:10 +00:00
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
Pair<String, Integer> vibrateMessageSummary = getVibrateSummary(getContext(), recipient.getMessageVibrate());
|
|
|
|
Pair<String, Integer> vibrateCallSummary = getVibrateSummary(getContext(), recipient.getCallVibrate());
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2018-08-31 00:59:15 +00:00
|
|
|
vibrateMessagePreference.setSummary(vibrateMessagePreference.isEnabled() ? vibrateMessageSummary.first : "");
|
2018-02-16 19:10:35 +00:00
|
|
|
vibrateMessagePreference.setValueIndex(vibrateMessageSummary.second);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
vibrateCallPreference.setSummary(vibrateCallSummary.first);
|
|
|
|
vibrateCallPreference.setValueIndex(vibrateCallSummary.second);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
if (recipient.isGroupRecipient()) {
|
2018-07-12 19:28:11 +00:00
|
|
|
if (colorPreference != null) colorPreference.setVisible(false);
|
2017-10-04 00:05:52 +00:00
|
|
|
if (identityPreference != null) identityPreference.setVisible(false);
|
2018-04-19 17:53:37 +00:00
|
|
|
if (aboutCategory != null) getPreferenceScreen().removePreference(aboutCategory);
|
|
|
|
if (aboutDivider != null) getPreferenceScreen().removePreference(aboutDivider);
|
2015-06-09 14:37:20 +00:00
|
|
|
} else {
|
2017-09-21 01:14:28 +00:00
|
|
|
colorPreference.setColors(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(getActivity()));
|
|
|
|
colorPreference.setColor(recipient.getColor().toActionBarColor(getActivity()));
|
2015-09-29 21:26:37 +00:00
|
|
|
|
2018-06-22 20:24:36 +00:00
|
|
|
aboutPreference.setTitle(formatAddress(recipient.getAddress()));
|
2018-04-03 09:28:26 +00:00
|
|
|
aboutPreference.setSummary(recipient.getCustomLabel());
|
|
|
|
aboutPreference.setSecure(recipient.getRegistered() == RecipientDatabase.RegisteredState.REGISTERED);
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
if (recipient.isBlocked()) blockPreference.setTitle(R.string.RecipientPreferenceActivity_unblock);
|
2017-09-21 01:14:28 +00:00
|
|
|
else blockPreference.setTitle(R.string.RecipientPreferenceActivity_block);
|
2016-08-25 01:51:45 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
IdentityUtil.getRemoteIdentityKey(getActivity(), recipient).addListener(new ListenableFuture.Listener<Optional<IdentityRecord>>() {
|
2016-08-25 01:51:45 +00:00
|
|
|
@Override
|
2017-06-07 01:03:09 +00:00
|
|
|
public void onSuccess(Optional<IdentityRecord> result) {
|
2016-08-25 01:51:45 +00:00
|
|
|
if (result.isPresent()) {
|
2016-10-08 21:04:33 +00:00
|
|
|
if (identityPreference != null) identityPreference.setOnPreferenceClickListener(new IdentityClickedListener(result.get()));
|
|
|
|
if (identityPreference != null) identityPreference.setEnabled(true);
|
2016-12-11 18:04:57 +00:00
|
|
|
} else if (canHaveSafetyNumber) {
|
|
|
|
if (identityPreference != null) identityPreference.setSummary(R.string.RecipientPreferenceActivity_available_once_a_message_has_been_sent_or_received);
|
|
|
|
if (identityPreference != null) identityPreference.setEnabled(false);
|
2016-08-25 01:51:45 +00:00
|
|
|
} else {
|
2016-10-08 21:04:33 +00:00
|
|
|
if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
|
2016-08-25 01:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(ExecutionException e) {
|
2016-10-08 21:04:33 +00:00
|
|
|
if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
|
2016-08-25 01:51:45 +00:00
|
|
|
}
|
|
|
|
});
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 20:24:36 +00:00
|
|
|
private @NonNull String formatAddress(@NonNull Address address) {
|
|
|
|
if (address.isPhone()) return PhoneNumberUtils.formatNumber(address.toPhoneString());
|
|
|
|
else if (address.isEmail()) return address.toEmailString();
|
|
|
|
else return "";
|
|
|
|
}
|
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
private @NonNull String getRingtoneSummary(@NonNull Context context, @Nullable Uri ringtone) {
|
|
|
|
if (ringtone == null) {
|
|
|
|
return context.getString(R.string.preferences__default);
|
|
|
|
} else if (ringtone.toString().isEmpty()) {
|
|
|
|
return context.getString(R.string.preferences__silent);
|
|
|
|
} else {
|
|
|
|
Ringtone tone = RingtoneManager.getRingtone(getActivity(), ringtone);
|
|
|
|
|
|
|
|
if (tone != null) {
|
|
|
|
return tone.getTitle(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return context.getString(R.string.preferences__default);
|
|
|
|
}
|
|
|
|
|
|
|
|
private @NonNull Pair<String, Integer> getVibrateSummary(@NonNull Context context, @NonNull VibrateState vibrateState) {
|
|
|
|
if (vibrateState == VibrateState.DEFAULT) {
|
|
|
|
return new Pair<>(context.getString(R.string.preferences__default), 0);
|
|
|
|
} else if (vibrateState == VibrateState.ENABLED) {
|
|
|
|
return new Pair<>(context.getString(R.string.RecipientPreferenceActivity_enabled), 1);
|
|
|
|
} else {
|
|
|
|
return new Pair<>(context.getString(R.string.RecipientPreferenceActivity_disabled), 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
@Override
|
2017-08-01 15:56:00 +00:00
|
|
|
public void onModified(final Recipient recipient) {
|
2018-08-24 19:00:02 +00:00
|
|
|
Util.runOnMain(() -> {
|
|
|
|
if (getContext() != null && getActivity() != null && !getActivity().isFinishing()) {
|
|
|
|
setSummaries(recipient);
|
|
|
|
}
|
|
|
|
});
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private class RingtoneChangeListener implements Preference.OnPreferenceChangeListener {
|
2018-02-16 19:10:35 +00:00
|
|
|
|
|
|
|
private final boolean calls;
|
|
|
|
|
|
|
|
RingtoneChangeListener(boolean calls) {
|
|
|
|
this.calls = calls;
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
2017-09-21 01:14:28 +00:00
|
|
|
Uri value = (Uri)newValue;
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
Uri defaultValue;
|
|
|
|
|
|
|
|
if (calls) defaultValue = TextSecurePreferences.getCallNotificationRingtone(getContext());
|
|
|
|
else defaultValue = TextSecurePreferences.getNotificationRingtone(getContext());
|
|
|
|
|
|
|
|
if (defaultValue.equals(value)) value = null;
|
|
|
|
else if (value == null) value = Uri.EMPTY;
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
new AsyncTask<Uri, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Uri... params) {
|
2018-08-31 00:59:15 +00:00
|
|
|
if (calls) {
|
|
|
|
DatabaseFactory.getRecipientDatabase(getActivity()).setCallRingtone(recipient, params[0]);
|
|
|
|
} else {
|
|
|
|
DatabaseFactory.getRecipientDatabase(getActivity()).setMessageRingtone(recipient, params[0]);
|
|
|
|
NotificationChannels.updateMessageRingtone(getActivity(), recipient, params[0]);
|
|
|
|
}
|
2015-06-09 14:37:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 20:03:32 +00:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, value);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 20:55:24 +00:00
|
|
|
private class RingtoneClickedListener implements Preference.OnPreferenceClickListener {
|
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
private final boolean calls;
|
|
|
|
|
|
|
|
RingtoneClickedListener(boolean calls) {
|
|
|
|
this.calls = calls;
|
|
|
|
}
|
|
|
|
|
2017-12-01 20:55:24 +00:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2018-02-16 19:10:35 +00:00
|
|
|
Uri current;
|
|
|
|
Uri defaultUri;
|
|
|
|
|
|
|
|
if (calls) {
|
|
|
|
current = recipient.getCallRingtone();
|
|
|
|
defaultUri = TextSecurePreferences.getCallNotificationRingtone(getContext());
|
|
|
|
} else {
|
2018-09-07 23:18:26 +00:00
|
|
|
current = recipient.getMessageRingtone();
|
2018-02-16 19:10:35 +00:00
|
|
|
defaultUri = TextSecurePreferences.getNotificationRingtone(getContext());
|
|
|
|
}
|
2017-12-01 20:55:24 +00:00
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
if (current == null) current = Settings.System.DEFAULT_NOTIFICATION_URI;
|
|
|
|
else if (current.toString().isEmpty()) current = null;
|
2017-12-01 20:55:24 +00:00
|
|
|
|
|
|
|
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
|
|
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
|
|
|
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
|
2018-02-16 19:10:35 +00:00
|
|
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, defaultUri);
|
|
|
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, calls ? RingtoneManager.TYPE_RINGTONE : RingtoneManager.TYPE_NOTIFICATION);
|
|
|
|
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, current);
|
2017-12-01 20:55:24 +00:00
|
|
|
|
2018-02-16 19:10:35 +00:00
|
|
|
startActivityForResult(intent, calls ? 2 : 1);
|
2017-12-01 20:55:24 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
private class VibrateChangeListener implements Preference.OnPreferenceChangeListener {
|
2018-02-16 19:10:35 +00:00
|
|
|
|
|
|
|
private final boolean call;
|
|
|
|
|
|
|
|
VibrateChangeListener(boolean call) {
|
|
|
|
this.call = call;
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
int value = Integer.parseInt((String) newValue);
|
|
|
|
final VibrateState vibrateState = VibrateState.fromId(value);
|
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2018-08-31 00:59:15 +00:00
|
|
|
if (call) {
|
|
|
|
DatabaseFactory.getRecipientDatabase(getActivity()).setCallVibrate(recipient, vibrateState);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DatabaseFactory.getRecipientDatabase(getActivity()).setMessageVibrate(recipient, vibrateState);
|
|
|
|
NotificationChannels.updateMessageVibrate(getActivity(), recipient, vibrateState);
|
|
|
|
}
|
2015-06-09 14:37:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 20:03:32 +00:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-24 20:17:58 +00:00
|
|
|
private class ColorChangeListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
2018-04-04 15:34:46 +00:00
|
|
|
final Context context = getContext();
|
|
|
|
if (context == null) return true;
|
|
|
|
|
2015-06-30 16:16:05 +00:00
|
|
|
final int value = (Integer) newValue;
|
2018-04-04 15:34:46 +00:00
|
|
|
final MaterialColor selectedColor = MaterialColors.CONVERSATION_PALETTE.getByColor(context, value);
|
2017-08-01 15:56:00 +00:00
|
|
|
final MaterialColor currentColor = recipient.getColor();
|
2015-06-30 16:16:05 +00:00
|
|
|
|
2015-07-01 19:22:42 +00:00
|
|
|
if (selectedColor == null) return true;
|
2015-06-24 20:17:58 +00:00
|
|
|
|
2015-06-30 16:16:05 +00:00
|
|
|
if (preference.isEnabled() && !currentColor.equals(selectedColor)) {
|
2015-06-24 20:17:58 +00:00
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2017-08-22 17:44:04 +00:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setColor(recipient, selectedColor);
|
2016-08-26 23:53:23 +00:00
|
|
|
|
2018-07-12 19:28:11 +00:00
|
|
|
if (recipient.resolve().getRegistered() == RecipientDatabase.RegisteredState.REGISTERED) {
|
2016-10-05 23:57:52 +00:00
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
2017-08-01 15:56:00 +00:00
|
|
|
.add(new MultiDeviceContactUpdateJob(context, recipient.getAddress()));
|
2016-10-05 23:57:52 +00:00
|
|
|
}
|
2015-06-24 20:17:58 +00:00
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 20:03:32 +00:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2015-06-24 20:17:58 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
private class MuteClickedListener implements Preference.OnPreferenceClickListener {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2017-08-01 15:56:00 +00:00
|
|
|
if (recipient.isMuted()) handleUnmute();
|
|
|
|
else handleMute();
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleMute() {
|
2017-10-16 20:11:42 +00:00
|
|
|
MuteDialog.show(getActivity(), until -> setMuted(recipient, until));
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
setSummaries(recipient);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleUnmute() {
|
2017-08-01 15:56:00 +00:00
|
|
|
setMuted(recipient, 0);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
private void setMuted(final Recipient recipient, final long until) {
|
|
|
|
recipient.setMuted(until);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2017-08-22 01:47:37 +00:00
|
|
|
DatabaseFactory.getRecipientDatabase(getActivity())
|
2017-08-01 15:56:00 +00:00
|
|
|
.setMuted(recipient, until);
|
2015-06-09 14:37:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 20:03:32 +00:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 21:26:37 +00:00
|
|
|
private class IdentityClickedListener implements Preference.OnPreferenceClickListener {
|
2016-08-25 01:51:45 +00:00
|
|
|
|
2017-06-07 01:03:09 +00:00
|
|
|
private final IdentityRecord identityKey;
|
2016-08-25 01:51:45 +00:00
|
|
|
|
2017-06-07 01:03:09 +00:00
|
|
|
private IdentityClickedListener(IdentityRecord identityKey) {
|
2018-08-02 13:25:33 +00:00
|
|
|
Log.i(TAG, "Identity record: " + identityKey);
|
2016-08-25 01:51:45 +00:00
|
|
|
this.identityKey = identityKey;
|
|
|
|
}
|
|
|
|
|
2015-09-29 21:26:37 +00:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
Intent verifyIdentityIntent = new Intent(getActivity(), VerifyIdentityActivity.class);
|
2017-08-01 15:56:00 +00:00
|
|
|
verifyIdentityIntent.putExtra(VerifyIdentityActivity.ADDRESS_EXTRA, recipient.getAddress());
|
2017-06-07 01:03:09 +00:00
|
|
|
verifyIdentityIntent.putExtra(VerifyIdentityActivity.IDENTITY_EXTRA, new IdentityKeyParcelable(identityKey.getIdentityKey()));
|
|
|
|
verifyIdentityIntent.putExtra(VerifyIdentityActivity.VERIFIED_EXTRA, identityKey.getVerifiedStatus() == IdentityDatabase.VerifiedStatus.VERIFIED);
|
2015-09-29 21:26:37 +00:00
|
|
|
startActivity(verifyIdentityIntent);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
private class BlockClickedListener implements Preference.OnPreferenceClickListener {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2017-08-01 15:56:00 +00:00
|
|
|
if (recipient.isBlocked()) handleUnblock();
|
|
|
|
else handleBlock();
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleBlock() {
|
2018-09-10 15:40:00 +00:00
|
|
|
new AsyncTask<Void, Void, Pair<Integer, Integer>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Pair<Integer, Integer> doInBackground(Void... voids) {
|
|
|
|
int titleRes = R.string.RecipientPreferenceActivity_block_this_contact_question;
|
|
|
|
int bodyRes = R.string.RecipientPreferenceActivity_you_will_no_longer_receive_messages_and_calls_from_this_contact;
|
|
|
|
|
|
|
|
if (recipient.isGroupRecipient()) {
|
|
|
|
bodyRes = R.string.RecipientPreferenceActivity_block_and_leave_group_description;
|
|
|
|
|
|
|
|
if (recipient.isGroupRecipient() && DatabaseFactory.getGroupDatabase(getContext()).isActive(recipient.getAddress().toGroupString())) {
|
|
|
|
titleRes = R.string.RecipientPreferenceActivity_block_and_leave_group;
|
|
|
|
} else {
|
|
|
|
titleRes = R.string.RecipientPreferenceActivity_block_group;
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
2018-09-10 15:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new Pair<>(titleRes, bodyRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Pair<Integer, Integer> titleAndBody) {
|
|
|
|
new AlertDialog.Builder(getActivity())
|
|
|
|
.setTitle(titleAndBody.first)
|
|
|
|
.setMessage(titleAndBody.second)
|
|
|
|
.setCancelable(true)
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.setPositiveButton(R.string.RecipientPreferenceActivity_block, (dialog, which) -> {
|
|
|
|
setBlocked(recipient, true);
|
|
|
|
}).show();
|
|
|
|
}
|
|
|
|
}.execute();
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleUnblock() {
|
2018-09-10 15:40:00 +00:00
|
|
|
int titleRes = R.string.RecipientPreferenceActivity_unblock_this_contact_question;
|
|
|
|
int bodyRes = R.string.RecipientPreferenceActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact;
|
|
|
|
|
|
|
|
if (recipient.isGroupRecipient()) {
|
|
|
|
titleRes = R.string.RecipientPreferenceActivity_unblock_this_group_question;
|
|
|
|
bodyRes = R.string.RecipientPreferenceActivity_unblock_this_group_description;
|
|
|
|
}
|
|
|
|
|
2015-05-20 21:36:30 +00:00
|
|
|
new AlertDialog.Builder(getActivity())
|
2018-09-10 15:40:00 +00:00
|
|
|
.setTitle(titleRes)
|
|
|
|
.setMessage(bodyRes)
|
|
|
|
.setCancelable(true)
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.setPositiveButton(R.string.RecipientPreferenceActivity_unblock, (dialog, which) -> setBlocked(recipient, false)).show();
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
private void setBlocked(final Recipient recipient, final boolean blocked) {
|
2015-06-09 14:37:20 +00:00
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2016-08-26 23:53:23 +00:00
|
|
|
Context context = getActivity();
|
|
|
|
|
2017-08-22 01:47:37 +00:00
|
|
|
DatabaseFactory.getRecipientDatabase(context)
|
2017-08-01 15:56:00 +00:00
|
|
|
.setBlocked(recipient, blocked);
|
2016-08-26 23:53:23 +00:00
|
|
|
|
2018-09-10 15:40:00 +00:00
|
|
|
if (recipient.isGroupRecipient() && DatabaseFactory.getGroupDatabase(context).isActive(recipient.getAddress().toGroupString())) {
|
|
|
|
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
|
|
|
|
Optional<OutgoingGroupMediaMessage> leaveMessage = GroupUtil.createGroupLeaveMessage(context, recipient);
|
|
|
|
|
|
|
|
if (threadId != -1 && leaveMessage.isPresent()) {
|
|
|
|
MessageSender.send(context, leaveMessage.get(), threadId, false, null);
|
|
|
|
|
|
|
|
GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
|
|
|
|
String groupId = recipient.getAddress().toGroupString();
|
|
|
|
groupDatabase.setActive(groupId, false);
|
|
|
|
groupDatabase.remove(groupId, Address.fromSerialized(TextSecurePreferences.getLocalNumber(context)));
|
|
|
|
} else {
|
|
|
|
Log.w(TAG, "Failed to leave group. Can't block.");
|
|
|
|
Toast.makeText(context, R.string.RecipientPreferenceActivity_error_leaving_group, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-26 23:53:23 +00:00
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
|
|
|
.add(new MultiDeviceBlockedUpdateJob(context));
|
2015-06-09 14:37:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 20:03:32 +00:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-03 09:28:26 +00:00
|
|
|
|
|
|
|
private class AboutNumberClickedListener implements ContactPreference.Listener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMessageClicked() {
|
2018-07-24 21:14:30 +00:00
|
|
|
CommunicationActions.startConversation(getContext(), recipient, null);
|
2018-04-03 09:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSecureCallClicked() {
|
2018-07-24 21:14:30 +00:00
|
|
|
CommunicationActions.startVoiceCall(getActivity(), recipient);
|
2018-04-03 09:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onInSecureCallClicked() {
|
|
|
|
try {
|
|
|
|
Intent dialIntent = new Intent(Intent.ACTION_DIAL,
|
|
|
|
Uri.parse("tel:" + recipient.getAddress().serialize()));
|
|
|
|
startActivity(dialIntent);
|
|
|
|
} catch (ActivityNotFoundException anfe) {
|
|
|
|
Log.w(TAG, anfe);
|
|
|
|
Dialogs.showAlertDialog(getContext(),
|
|
|
|
getString(R.string.ConversationActivity_calls_not_supported),
|
|
|
|
getString(R.string.ConversationActivity_this_device_does_not_appear_to_support_dial_actions));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-16 16:47:43 +00:00
|
|
|
|
|
|
|
private class CustomNotificationsChangedListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
final boolean enabled = (boolean) newValue;
|
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
if (enabled) {
|
|
|
|
String channel = NotificationChannels.createChannelFor(getActivity(), recipient);
|
|
|
|
DatabaseFactory.getRecipientDatabase(getActivity()).setNotificationChannel(recipient, channel);
|
|
|
|
} else {
|
|
|
|
NotificationChannels.deleteChannelFor(getActivity(), recipient);
|
|
|
|
DatabaseFactory.getRecipientDatabase(getActivity()).setNotificationChannel(recipient, null);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
}
|