2015-06-09 07:37:20 -07:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2017-11-24 22:00:30 -08:00
|
|
|
import android.annotation.SuppressLint;
|
2018-04-03 02:28:26 -07:00
|
|
|
import android.content.ActivityNotFoundException;
|
2016-08-15 20:23:56 -07:00
|
|
|
import android.content.Context;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.content.Intent;
|
2017-09-20 18:14:28 -07:00
|
|
|
import android.database.Cursor;
|
2017-09-12 22:48:30 -07:00
|
|
|
import android.graphics.Color;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.media.Ringtone;
|
|
|
|
import android.media.RingtoneManager;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.AsyncTask;
|
2015-06-29 15:33:36 -07:00
|
|
|
import android.os.Build;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.provider.Settings;
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.loader.app.LoaderManager;
|
|
|
|
import androidx.loader.content.Loader;
|
|
|
|
import androidx.core.view.ViewCompat;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.preference.CheckBoxPreference;
|
|
|
|
import androidx.preference.ListPreference;
|
|
|
|
import androidx.preference.Preference;
|
|
|
|
import androidx.preference.PreferenceCategory;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
2018-04-03 02:28:26 -07:00
|
|
|
import android.telephony.PhoneNumberUtils;
|
2018-02-16 11:10:35 -08:00
|
|
|
import android.util.Pair;
|
2015-06-09 07:37:20 -07:00
|
|
|
import android.view.MenuItem;
|
2017-09-20 18:14:28 -07:00
|
|
|
import android.view.View;
|
2017-09-12 22:48:30 -07:00
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.widget.ImageView;
|
2017-09-20 18:14:28 -07:00
|
|
|
import android.widget.TextView;
|
2018-09-10 08:40:00 -07:00
|
|
|
import android.widget.Toast;
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-10-16 13:11:42 -07:00
|
|
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
|
|
|
|
2015-06-30 09:16:05 -07:00
|
|
|
import org.thoughtcrime.securesms.color.MaterialColor;
|
|
|
|
import org.thoughtcrime.securesms.color.MaterialColors;
|
2019-07-19 15:59:51 +10:00
|
|
|
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat;
|
2017-09-20 18:14:28 -07:00
|
|
|
import org.thoughtcrime.securesms.components.ThreadPhotoRailView;
|
2019-07-19 15:59:51 +10:00
|
|
|
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
|
|
|
|
import org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto;
|
|
|
|
import org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto;
|
|
|
|
import org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto;
|
2016-08-24 18:51:45 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
|
2017-07-26 09:59:15 -07:00
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
2015-06-09 07:37:20 -07:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2019-07-19 15:59:51 +10:00
|
|
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord;
|
2017-08-22 10:44:04 -07:00
|
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
2017-08-21 18:37:39 -07:00
|
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase.VibrateState;
|
2017-09-20 18:14:28 -07:00
|
|
|
import org.thoughtcrime.securesms.database.loaders.ThreadMediaLoader;
|
2016-08-26 16:53:23 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
|
2019-07-19 15:59:51 +10:00
|
|
|
import org.thoughtcrime.securesms.jobs.RotateProfileKeyJob;
|
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2017-10-16 13:11:42 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
2018-09-10 08:40:00 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
2018-08-16 09:47:43 -07:00
|
|
|
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
2018-04-03 02:28:26 -07:00
|
|
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
2017-10-16 13:11:42 -07:00
|
|
|
import org.thoughtcrime.securesms.preferences.CorrectedPreferenceFragment;
|
2017-09-21 10:03:05 -07:00
|
|
|
import org.thoughtcrime.securesms.preferences.widgets.ColorPickerPreference;
|
2018-04-03 02:28:26 -07:00
|
|
|
import org.thoughtcrime.securesms.preferences.widgets.ContactPreference;
|
2017-08-01 08:56:00 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
2018-09-10 08:40:00 -07:00
|
|
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
2018-07-24 17:14:30 -04:00
|
|
|
import org.thoughtcrime.securesms.util.CommunicationActions;
|
2018-04-03 02:28:26 -07:00
|
|
|
import org.thoughtcrime.securesms.util.Dialogs;
|
2015-06-09 07:37:20 -07:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2018-09-10 08:40:00 -07:00
|
|
|
import org.thoughtcrime.securesms.util.GroupUtil;
|
2016-08-29 17:49:49 -07:00
|
|
|
import org.thoughtcrime.securesms.util.IdentityUtil;
|
2017-12-19 14:42:00 -08:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2017-09-09 23:46:48 -07:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2017-09-12 22:48:30 -07:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2016-08-24 18:51:45 -07:00
|
|
|
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2019-07-24 12:30:23 +10:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2017-11-24 22:00:30 -08:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2017-09-20 18:14:28 -07:00
|
|
|
public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActivity implements RecipientModifiedListener, LoaderManager.LoaderCallbacks<Cursor>
|
2015-06-09 07:37:20 -07:00
|
|
|
{
|
|
|
|
private static final String TAG = RecipientPreferenceActivity.class.getSimpleName();
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
public static final String ADDRESS_EXTRA = "recipient_address";
|
2019-07-19 15:59:51 +10:00
|
|
|
// public static final String CAN_HAVE_SAFETY_NUMBER_EXTRA = "can_have_safety_number";
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2018-08-16 09:47:43 -07:00
|
|
|
private static final String PREFERENCE_MUTED = "pref_key_recipient_mute";
|
|
|
|
private static final String PREFERENCE_MESSAGE_TONE = "pref_key_recipient_ringtone";
|
2019-07-19 15:59:51 +10:00
|
|
|
// private static final String PREFERENCE_CALL_TONE = "pref_key_recipient_call_ringtone";
|
2018-08-16 09:47:43 -07:00
|
|
|
private static final String PREFERENCE_MESSAGE_VIBRATE = "pref_key_recipient_vibrate";
|
2019-07-19 15:59:51 +10:00
|
|
|
// private static final String PREFERENCE_CALL_VIBRATE = "pref_key_recipient_call_vibrate";
|
|
|
|
// private static final String PREFERENCE_BLOCK = "pref_key_recipient_block";
|
2018-08-16 09:47:43 -07:00
|
|
|
private static final String PREFERENCE_COLOR = "pref_key_recipient_color";
|
|
|
|
private static final String PREFERENCE_IDENTITY = "pref_key_recipient_identity";
|
2019-07-19 15:59:51 +10:00
|
|
|
// private static final String PREFERENCE_ABOUT = "pref_key_number";
|
2018-08-16 09:47:43 -07:00
|
|
|
private static final String PREFERENCE_CUSTOM_NOTIFICATIONS = "pref_key_recipient_custom_notifications";
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
2017-09-12 22:48:30 -07:00
|
|
|
private ImageView avatar;
|
2017-10-16 13:11:42 -07:00
|
|
|
private GlideRequests glideRequests;
|
2017-09-20 18:14:28 -07:00
|
|
|
private Address address;
|
|
|
|
private TextView threadPhotoRailLabel;
|
|
|
|
private ThreadPhotoRailView threadPhotoRailView;
|
2017-09-12 22:48:30 -07:00
|
|
|
private CollapsingToolbarLayout toolbarLayout;
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreCreate() {
|
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
dynamicLanguage.onCreate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-01 19:22:48 -08:00
|
|
|
public void onCreate(Bundle instanceState, boolean ready) {
|
2015-06-09 07:37:20 -07:00
|
|
|
setContentView(R.layout.recipient_preference_activity);
|
2017-10-16 13:11:42 -07:00
|
|
|
this.glideRequests = GlideApp.with(this);
|
|
|
|
this.address = getIntent().getParcelableExtra(ADDRESS_EXTRA);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-08-21 18:32:38 -07:00
|
|
|
Recipient recipient = Recipient.from(this, address, true);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
initializeToolbar();
|
2017-08-01 08:56:00 -07:00
|
|
|
setHeader(recipient);
|
|
|
|
recipient.addListener(this);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-09-20 18:14:28 -07:00
|
|
|
getSupportLoaderManager().initLoader(0, null, this);
|
2015-06-09 07:37:20 -07: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 10:50:29 +02:00
|
|
|
case android.R.id.home:
|
2017-09-12 22:48:30 -07:00
|
|
|
onBackPressed();
|
2015-07-18 10:50:29 +02:00
|
|
|
return true;
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-12 22:48:30 -07:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
finish();
|
|
|
|
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
|
|
|
|
}
|
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
private void initializeToolbar() {
|
2017-09-20 18:14:28 -07: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 15:52:27 -08:00
|
|
|
|
2017-09-12 22:48:30 -07:00
|
|
|
this.toolbarLayout.setExpandedTitleColor(getResources().getColor(R.color.white));
|
|
|
|
this.toolbarLayout.setCollapsedTitleTextColor(getResources().getColor(R.color.white));
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-09-20 18:14:28 -07:00
|
|
|
this.threadPhotoRailView.setListener(mediaRecord -> {
|
|
|
|
Intent intent = new Intent(RecipientPreferenceActivity.this, MediaPreviewActivity.class);
|
|
|
|
intent.putExtra(MediaPreviewActivity.ADDRESS_EXTRA, address);
|
2017-10-04 11:35:16 -07:00
|
|
|
intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, mediaRecord.isOutgoing());
|
2017-09-20 18:14:28 -07:00
|
|
|
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, mediaRecord.getDate());
|
|
|
|
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, mediaRecord.getAttachment().getSize());
|
2018-11-08 23:33:37 -08:00
|
|
|
intent.putExtra(MediaPreviewActivity.CAPTION_EXTRA, mediaRecord.getAttachment().getCaption());
|
2018-01-23 13:43:37 -08:00
|
|
|
intent.putExtra(MediaPreviewActivity.LEFT_IS_RECENT_EXTRA, ViewCompat.getLayoutDirection(threadPhotoRailView) == ViewCompat.LAYOUT_DIRECTION_LTR);
|
2017-09-20 18:14:28 -07: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-12 22:48:30 -07:00
|
|
|
Toolbar toolbar = ViewUtil.findById(this, R.id.toolbar);
|
|
|
|
setSupportActionBar(toolbar);
|
2015-06-09 07:37:20 -07:00
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
2017-09-12 22:48:30 -07:00
|
|
|
getSupportActionBar().setLogo(null);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-09-12 22:48:30 -07: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 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
2017-09-12 22:48:30 -07:00
|
|
|
private void setHeader(@NonNull Recipient recipient) {
|
2019-01-13 23:30:54 -08:00
|
|
|
ContactPhoto contactPhoto = recipient.isLocalNumber() ? new ProfileContactPhoto(recipient.getAddress(), String.valueOf(TextSecurePreferences.getProfileAvatarId(this)))
|
|
|
|
: recipient.getContactPhoto();
|
|
|
|
FallbackContactPhoto fallbackPhoto = recipient.isLocalNumber() ? new ResourceContactPhoto(R.drawable.ic_profile_default, R.drawable.ic_person_large)
|
|
|
|
: recipient.getFallbackContactPhoto();
|
|
|
|
|
|
|
|
glideRequests.load(contactPhoto)
|
|
|
|
.fallback(fallbackPhoto.asCallCard(this))
|
|
|
|
.error(fallbackPhoto.asCallCard(this))
|
2017-10-16 13:11:42 -07:00
|
|
|
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
|
|
|
.into(this.avatar);
|
2017-10-04 15:23:33 -07:00
|
|
|
|
2019-01-13 23:30:54 -08:00
|
|
|
if (contactPhoto == null) this.avatar.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
|
|
|
else this.avatar.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
2017-10-04 15:23:33 -07:00
|
|
|
|
2017-10-16 13:11:42 -07:00
|
|
|
this.avatar.setBackgroundColor(recipient.getColor().toActionBarColor(this));
|
|
|
|
this.toolbarLayout.setTitle(recipient.toShortString());
|
|
|
|
this.toolbarLayout.setContentScrimColor(recipient.getColor().toActionBarColor(this));
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-01 08:56:00 -07:00
|
|
|
public void onModified(final Recipient recipient) {
|
2017-09-12 22:48:30 -07:00
|
|
|
Util.runOnMain(() -> setHeader(recipient));
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
2017-09-20 18:14:28 -07:00
|
|
|
@Override
|
2019-05-22 13:51:56 -03:00
|
|
|
public @NonNull Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
2018-02-01 19:22:48 -08:00
|
|
|
return new ThreadMediaLoader(this, address, true);
|
2017-09-20 18:14:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-22 13:51:56 -03:00
|
|
|
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor data) {
|
2017-09-20 18:14:28 -07:00
|
|
|
if (data != null && data.getCount() > 0) {
|
2019-07-19 15:59:51 +10:00
|
|
|
this.threadPhotoRailLabel.setVisibility(View.GONE);
|
|
|
|
this.threadPhotoRailView.setVisibility(View.GONE);
|
2017-09-20 18:14:28 -07:00
|
|
|
} else {
|
|
|
|
this.threadPhotoRailLabel.setVisibility(View.GONE);
|
|
|
|
this.threadPhotoRailView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2018-02-01 19:22:48 -08:00
|
|
|
this.threadPhotoRailView.setCursor(glideRequests, data);
|
2017-09-20 18:14:28 -07:00
|
|
|
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putParcelable(ADDRESS_EXTRA, address);
|
2018-02-01 19:22:48 -08:00
|
|
|
initFragment(R.id.preference_fragment, new RecipientPreferenceFragment(), null, bundle);
|
2017-09-20 18:14:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-22 13:51:56 -03:00
|
|
|
public void onLoaderReset(@NonNull Loader<Cursor> loader) {
|
2018-02-01 19:22:48 -08:00
|
|
|
this.threadPhotoRailView.setCursor(glideRequests, null);
|
2017-09-20 18:14:28 -07:00
|
|
|
}
|
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
public static class RecipientPreferenceFragment
|
2017-09-20 18:14:28 -07:00
|
|
|
extends CorrectedPreferenceFragment
|
2017-08-01 08:56:00 -07:00
|
|
|
implements RecipientModifiedListener
|
2015-06-09 07:37:20 -07:00
|
|
|
{
|
2017-11-24 22:00:30 -08:00
|
|
|
private Recipient recipient;
|
|
|
|
private boolean canHaveSafetyNumber;
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle icicle) {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "onCreate (fragment)");
|
2015-06-09 07:37:20 -07:00
|
|
|
super.onCreate(icicle);
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
initializeRecipients();
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2019-07-19 15:59:51 +10:00
|
|
|
/*
|
2016-12-11 19:04:57 +01:00
|
|
|
this.canHaveSafetyNumber = getActivity().getIntent()
|
|
|
|
.getBooleanExtra(RecipientPreferenceActivity.CAN_HAVE_SAFETY_NUMBER_EXTRA, false);
|
2019-07-19 15:59:51 +10:00
|
|
|
*/
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2018-08-16 09:47:43 -07:00
|
|
|
Preference customNotificationsPref = this.findPreference(PREFERENCE_CUSTOM_NOTIFICATIONS);
|
|
|
|
|
|
|
|
if (NotificationChannels.supported()) {
|
2018-08-30 17:59:15 -07:00
|
|
|
((SwitchPreferenceCompat) customNotificationsPref).setChecked(recipient.getNotificationChannel() != null);
|
2018-08-16 09:47:43 -07:00
|
|
|
customNotificationsPref.setOnPreferenceChangeListener(new CustomNotificationsChangedListener());
|
2018-08-30 17:59:15 -07: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);
|
2019-01-30 10:19:03 -08:00
|
|
|
NotificationChannels.ensureCustomChannelConsistency(context);
|
2018-08-30 17:59:15 -07:00
|
|
|
return null;
|
|
|
|
}
|
2018-10-20 22:42:35 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
2018-08-30 17:59:15 -07:00
|
|
|
}
|
2018-08-16 09:47:43 -07:00
|
|
|
} else {
|
|
|
|
customNotificationsPref.setVisible(false);
|
|
|
|
}
|
|
|
|
|
2018-08-30 17:59:15 -07:00
|
|
|
this.findPreference(PREFERENCE_MESSAGE_TONE)
|
|
|
|
.setOnPreferenceChangeListener(new RingtoneChangeListener(false));
|
2018-02-16 11:10:35 -08:00
|
|
|
this.findPreference(PREFERENCE_MESSAGE_TONE)
|
|
|
|
.setOnPreferenceClickListener(new RingtoneClickedListener(false));
|
2019-07-19 15:59:51 +10:00
|
|
|
/*
|
2018-02-16 11:10:35 -08:00
|
|
|
this.findPreference(PREFERENCE_CALL_TONE)
|
|
|
|
.setOnPreferenceChangeListener(new RingtoneChangeListener(true));
|
|
|
|
this.findPreference(PREFERENCE_CALL_TONE)
|
|
|
|
.setOnPreferenceClickListener(new RingtoneClickedListener(true));
|
2019-07-19 15:59:51 +10:00
|
|
|
*/
|
2018-08-30 17:59:15 -07:00
|
|
|
this.findPreference(PREFERENCE_MESSAGE_VIBRATE)
|
|
|
|
.setOnPreferenceChangeListener(new VibrateChangeListener(false));
|
2019-07-19 15:59:51 +10:00
|
|
|
/*
|
2018-02-16 11:10:35 -08:00
|
|
|
this.findPreference(PREFERENCE_CALL_VIBRATE)
|
|
|
|
.setOnPreferenceChangeListener(new VibrateChangeListener(true));
|
2019-07-19 15:59:51 +10:00
|
|
|
*/
|
2015-06-09 07:37:20 -07:00
|
|
|
this.findPreference(PREFERENCE_MUTED)
|
|
|
|
.setOnPreferenceClickListener(new MuteClickedListener());
|
2019-07-19 15:59:51 +10:00
|
|
|
/*
|
2015-06-09 07:37:20 -07:00
|
|
|
this.findPreference(PREFERENCE_BLOCK)
|
|
|
|
.setOnPreferenceClickListener(new BlockClickedListener());
|
2019-07-19 15:59:51 +10:00
|
|
|
*/
|
2015-06-24 13:17:58 -07:00
|
|
|
this.findPreference(PREFERENCE_COLOR)
|
|
|
|
.setOnPreferenceChangeListener(new ColorChangeListener());
|
2019-07-19 15:59:51 +10:00
|
|
|
/*
|
2018-04-03 02:28:26 -07:00
|
|
|
((ContactPreference)this.findPreference(PREFERENCE_ABOUT))
|
|
|
|
.setListener(new AboutNumberClickedListener());
|
2019-07-19 15:59:51 +10:00
|
|
|
*/
|
2017-09-20 18:14:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey) {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "onCreatePreferences...");
|
2017-09-20 18:14:28 -07:00
|
|
|
addPreferencesFromResource(R.xml.recipient_preferences);
|
|
|
|
}
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
@Override
|
2018-04-03 08:51:28 -07:00
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
|
|
|
|
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-09 07:37:20 -07:00
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2017-08-01 08:56:00 -07:00
|
|
|
setSummaries(recipient);
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
2015-06-22 18:18:06 -07:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2015-06-22 18:30:42 -07:00
|
|
|
super.onDestroy();
|
2017-08-01 08:56:00 -07:00
|
|
|
this.recipient.removeListener(this);
|
2016-08-15 20:23:56 -07:00
|
|
|
}
|
|
|
|
|
2017-12-01 12:55:24 -08: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 11:10:35 -08: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);
|
|
|
|
|
2019-07-19 15:59:51 +10:00
|
|
|
// findPreference(PREFERENCE_CALL_TONE).getOnPreferenceChangeListener().onPreferenceChange(findPreference(PREFERENCE_CALL_TONE), uri);
|
2017-12-01 12:55:24 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
private void initializeRecipients() {
|
2017-10-16 13:11:42 -07:00
|
|
|
this.recipient = Recipient.from(getActivity(), getArguments().getParcelable(ADDRESS_EXTRA), true);
|
2017-08-01 08:56:00 -07:00
|
|
|
this.recipient.addListener(this);
|
2015-06-22 18:18:06 -07:00
|
|
|
}
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
private void setSummaries(Recipient recipient) {
|
2018-02-16 11:10:35 -08:00
|
|
|
CheckBoxPreference mutePreference = (CheckBoxPreference) this.findPreference(PREFERENCE_MUTED);
|
2019-01-13 23:30:54 -08:00
|
|
|
Preference customPreference = this.findPreference(PREFERENCE_CUSTOM_NOTIFICATIONS);
|
2018-02-16 11:10:35 -08:00
|
|
|
Preference ringtoneMessagePreference = this.findPreference(PREFERENCE_MESSAGE_TONE);
|
2019-07-19 15:59:51 +10:00
|
|
|
// Preference ringtoneCallPreference = this.findPreference(PREFERENCE_CALL_TONE);
|
2018-02-16 11:10:35 -08:00
|
|
|
ListPreference vibrateMessagePreference = (ListPreference) this.findPreference(PREFERENCE_MESSAGE_VIBRATE);
|
2019-07-19 15:59:51 +10:00
|
|
|
// ListPreference vibrateCallPreference = (ListPreference) this.findPreference(PREFERENCE_CALL_VIBRATE);
|
2018-02-16 11:10:35 -08:00
|
|
|
ColorPickerPreference colorPreference = (ColorPickerPreference) this.findPreference(PREFERENCE_COLOR);
|
2019-07-19 15:59:51 +10:00
|
|
|
// Preference blockPreference = this.findPreference(PREFERENCE_BLOCK);
|
2018-02-16 11:10:35 -08:00
|
|
|
Preference identityPreference = this.findPreference(PREFERENCE_IDENTITY);
|
2019-01-30 16:32:48 -08:00
|
|
|
PreferenceCategory callCategory = (PreferenceCategory)this.findPreference("call_settings");
|
2018-04-03 02:28:26 -07:00
|
|
|
PreferenceCategory aboutCategory = (PreferenceCategory)this.findPreference("about");
|
2018-04-19 10:53:37 -07:00
|
|
|
PreferenceCategory aboutDivider = (PreferenceCategory)this.findPreference("about_divider");
|
2019-07-19 15:59:51 +10:00
|
|
|
// ContactPreference aboutPreference = (ContactPreference)this.findPreference(PREFERENCE_ABOUT);
|
2018-02-16 11:10:35 -08:00
|
|
|
PreferenceCategory privacyCategory = (PreferenceCategory) this.findPreference("privacy_settings");
|
|
|
|
PreferenceCategory divider = (PreferenceCategory) this.findPreference("divider");
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
mutePreference.setChecked(recipient.isMuted());
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2018-09-07 16:18:26 -07:00
|
|
|
ringtoneMessagePreference.setSummary(ringtoneMessagePreference.isEnabled() ? getRingtoneSummary(getContext(), recipient.getMessageRingtone()) : "");
|
2019-07-19 15:59:51 +10:00
|
|
|
// ringtoneCallPreference.setSummary(getRingtoneSummary(getContext(), recipient.getCallRingtone()));
|
2015-12-24 15:27:10 +01:00
|
|
|
|
2018-02-16 11:10:35 -08:00
|
|
|
Pair<String, Integer> vibrateMessageSummary = getVibrateSummary(getContext(), recipient.getMessageVibrate());
|
|
|
|
Pair<String, Integer> vibrateCallSummary = getVibrateSummary(getContext(), recipient.getCallVibrate());
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2018-08-30 17:59:15 -07:00
|
|
|
vibrateMessagePreference.setSummary(vibrateMessagePreference.isEnabled() ? vibrateMessageSummary.first : "");
|
2018-02-16 11:10:35 -08:00
|
|
|
vibrateMessagePreference.setValueIndex(vibrateMessageSummary.second);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2019-07-19 15:59:51 +10:00
|
|
|
// vibrateCallPreference.setSummary(vibrateCallSummary.first);
|
|
|
|
// vibrateCallPreference.setValueIndex(vibrateCallSummary.second);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2019-01-13 23:30:54 -08:00
|
|
|
if (recipient.isLocalNumber()) {
|
|
|
|
mutePreference.setVisible(false);
|
|
|
|
customPreference.setVisible(false);
|
|
|
|
ringtoneMessagePreference.setVisible(false);
|
|
|
|
vibrateMessagePreference.setVisible(false);
|
|
|
|
|
|
|
|
if (identityPreference != null) identityPreference.setVisible(false);
|
|
|
|
if (aboutCategory != null) aboutCategory.setVisible(false);
|
|
|
|
if (aboutDivider != null) aboutDivider.setVisible(false);
|
|
|
|
if (privacyCategory != null) privacyCategory.setVisible(false);
|
|
|
|
if (divider != null) divider.setVisible(false);
|
|
|
|
if (callCategory != null) callCategory.setVisible(false);
|
|
|
|
} if (recipient.isGroupRecipient()) {
|
2018-10-09 12:55:39 -07:00
|
|
|
if (colorPreference != null) colorPreference.setVisible(false);
|
2017-10-03 17:05:52 -07:00
|
|
|
if (identityPreference != null) identityPreference.setVisible(false);
|
2019-01-30 16:32:48 -08:00
|
|
|
if (callCategory != null) callCategory.setVisible(false);
|
|
|
|
if (aboutCategory != null) aboutCategory.setVisible(false);
|
|
|
|
if (aboutDivider != null) aboutDivider.setVisible(false);
|
|
|
|
if (divider != null) divider.setVisible(false);
|
2015-06-09 07:37:20 -07:00
|
|
|
} else {
|
2018-10-09 12:55:39 -07:00
|
|
|
colorPreference.setColors(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(getActivity()));
|
|
|
|
colorPreference.setColor(recipient.getColor().toActionBarColor(getActivity()));
|
|
|
|
|
2019-07-19 15:59:51 +10:00
|
|
|
/*
|
2018-06-22 13:24:36 -07:00
|
|
|
aboutPreference.setTitle(formatAddress(recipient.getAddress()));
|
2018-04-03 02:28:26 -07:00
|
|
|
aboutPreference.setSummary(recipient.getCustomLabel());
|
|
|
|
aboutPreference.setSecure(recipient.getRegistered() == RecipientDatabase.RegisteredState.REGISTERED);
|
2019-07-19 15:59:51 +10:00
|
|
|
*/
|
2018-04-03 02:28:26 -07:00
|
|
|
|
2019-07-19 15:59:51 +10:00
|
|
|
/*
|
2017-08-01 08:56:00 -07:00
|
|
|
if (recipient.isBlocked()) blockPreference.setTitle(R.string.RecipientPreferenceActivity_unblock);
|
2017-09-20 18:14:28 -07:00
|
|
|
else blockPreference.setTitle(R.string.RecipientPreferenceActivity_block);
|
2019-07-19 15:59:51 +10:00
|
|
|
*/
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
IdentityUtil.getRemoteIdentityKey(getActivity(), recipient).addListener(new ListenableFuture.Listener<Optional<IdentityRecord>>() {
|
2016-08-24 18:51:45 -07:00
|
|
|
@Override
|
2017-06-06 18:03:09 -07:00
|
|
|
public void onSuccess(Optional<IdentityRecord> result) {
|
2016-08-24 18:51:45 -07:00
|
|
|
if (result.isPresent()) {
|
2016-10-08 14:04:33 -07:00
|
|
|
if (identityPreference != null) identityPreference.setOnPreferenceClickListener(new IdentityClickedListener(result.get()));
|
|
|
|
if (identityPreference != null) identityPreference.setEnabled(true);
|
2016-12-11 19:04:57 +01: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-24 18:51:45 -07:00
|
|
|
} else {
|
2016-10-08 14:04:33 -07:00
|
|
|
if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
|
2016-08-24 18:51:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(ExecutionException e) {
|
2016-10-08 14:04:33 -07:00
|
|
|
if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
|
2016-08-24 18:51:45 -07:00
|
|
|
}
|
|
|
|
});
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 13:24:36 -07: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 11:10:35 -08: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 07:37:20 -07:00
|
|
|
@Override
|
2017-08-01 08:56:00 -07:00
|
|
|
public void onModified(final Recipient recipient) {
|
2018-08-24 12:00:02 -07:00
|
|
|
Util.runOnMain(() -> {
|
|
|
|
if (getContext() != null && getActivity() != null && !getActivity().isFinishing()) {
|
|
|
|
setSummaries(recipient);
|
|
|
|
}
|
|
|
|
});
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private class RingtoneChangeListener implements Preference.OnPreferenceChangeListener {
|
2018-02-16 11:10:35 -08:00
|
|
|
|
|
|
|
private final boolean calls;
|
|
|
|
|
|
|
|
RingtoneChangeListener(boolean calls) {
|
|
|
|
this.calls = calls;
|
|
|
|
}
|
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
2018-10-20 22:22:07 -07:00
|
|
|
final Context context = preference.getContext();
|
|
|
|
|
2017-09-20 18:14:28 -07:00
|
|
|
Uri value = (Uri)newValue;
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2018-02-16 11:10:35 -08:00
|
|
|
Uri defaultValue;
|
|
|
|
|
2018-10-20 22:22:07 -07:00
|
|
|
if (calls) defaultValue = TextSecurePreferences.getCallNotificationRingtone(context);
|
|
|
|
else defaultValue = TextSecurePreferences.getNotificationRingtone(context);
|
2018-02-16 11:10:35 -08:00
|
|
|
|
|
|
|
if (defaultValue.equals(value)) value = null;
|
|
|
|
else if (value == null) value = Uri.EMPTY;
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2018-10-20 22:22:07 -07:00
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
new AsyncTask<Uri, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Uri... params) {
|
2018-08-30 17:59:15 -07:00
|
|
|
if (calls) {
|
2018-10-20 22:22:07 -07:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setCallRingtone(recipient, params[0]);
|
2018-08-30 17:59:15 -07:00
|
|
|
} else {
|
2018-10-20 22:22:07 -07:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setMessageRingtone(recipient, params[0]);
|
|
|
|
NotificationChannels.updateMessageRingtone(context, recipient, params[0]);
|
2018-08-30 17:59:15 -07:00
|
|
|
}
|
2015-06-09 07:37:20 -07:00
|
|
|
return null;
|
|
|
|
}
|
2018-10-20 22:42:35 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, value);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 12:55:24 -08:00
|
|
|
private class RingtoneClickedListener implements Preference.OnPreferenceClickListener {
|
|
|
|
|
2018-02-16 11:10:35 -08:00
|
|
|
private final boolean calls;
|
|
|
|
|
|
|
|
RingtoneClickedListener(boolean calls) {
|
|
|
|
this.calls = calls;
|
|
|
|
}
|
|
|
|
|
2017-12-01 12:55:24 -08:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2018-02-16 11:10:35 -08:00
|
|
|
Uri current;
|
|
|
|
Uri defaultUri;
|
|
|
|
|
|
|
|
if (calls) {
|
|
|
|
current = recipient.getCallRingtone();
|
|
|
|
defaultUri = TextSecurePreferences.getCallNotificationRingtone(getContext());
|
|
|
|
} else {
|
2018-09-07 16:18:26 -07:00
|
|
|
current = recipient.getMessageRingtone();
|
2018-02-16 11:10:35 -08:00
|
|
|
defaultUri = TextSecurePreferences.getNotificationRingtone(getContext());
|
|
|
|
}
|
2017-12-01 12:55:24 -08:00
|
|
|
|
2018-02-16 11:10:35 -08:00
|
|
|
if (current == null) current = Settings.System.DEFAULT_NOTIFICATION_URI;
|
|
|
|
else if (current.toString().isEmpty()) current = null;
|
2017-12-01 12:55:24 -08: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 11:10:35 -08: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 12:55:24 -08:00
|
|
|
|
2018-02-16 11:10:35 -08:00
|
|
|
startActivityForResult(intent, calls ? 2 : 1);
|
2017-12-01 12:55:24 -08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
private class VibrateChangeListener implements Preference.OnPreferenceChangeListener {
|
2018-02-16 11:10:35 -08:00
|
|
|
|
|
|
|
private final boolean call;
|
|
|
|
|
|
|
|
VibrateChangeListener(boolean call) {
|
|
|
|
this.call = call;
|
|
|
|
}
|
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
int value = Integer.parseInt((String) newValue);
|
|
|
|
final VibrateState vibrateState = VibrateState.fromId(value);
|
2018-10-20 22:22:07 -07:00
|
|
|
final Context context = preference.getContext();
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2018-08-30 17:59:15 -07:00
|
|
|
if (call) {
|
2018-10-20 22:22:07 -07:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setCallVibrate(recipient, vibrateState);
|
2018-08-30 17:59:15 -07:00
|
|
|
}
|
|
|
|
else {
|
2018-10-20 22:22:07 -07:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setMessageVibrate(recipient, vibrateState);
|
|
|
|
NotificationChannels.updateMessageVibrate(context, recipient, vibrateState);
|
2018-08-30 17:59:15 -07:00
|
|
|
}
|
2015-06-09 07:37:20 -07:00
|
|
|
return null;
|
|
|
|
}
|
2018-10-20 22:42:35 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-24 13:17:58 -07:00
|
|
|
private class ColorChangeListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
2018-04-04 08:34:46 -07:00
|
|
|
final Context context = getContext();
|
|
|
|
if (context == null) return true;
|
|
|
|
|
2015-06-30 09:16:05 -07:00
|
|
|
final int value = (Integer) newValue;
|
2018-04-04 08:34:46 -07:00
|
|
|
final MaterialColor selectedColor = MaterialColors.CONVERSATION_PALETTE.getByColor(context, value);
|
2017-08-01 08:56:00 -07:00
|
|
|
final MaterialColor currentColor = recipient.getColor();
|
2015-06-30 09:16:05 -07:00
|
|
|
|
2015-07-01 12:22:42 -07:00
|
|
|
if (selectedColor == null) return true;
|
2015-06-24 13:17:58 -07:00
|
|
|
|
2015-06-30 09:16:05 -07:00
|
|
|
if (preference.isEnabled() && !currentColor.equals(selectedColor)) {
|
2015-06-24 13:17:58 -07:00
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2017-08-22 10:44:04 -07:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setColor(recipient, selectedColor);
|
2016-08-26 16:53:23 -07:00
|
|
|
|
2018-10-09 12:55:39 -07:00
|
|
|
if (recipient.resolve().getRegistered() == RecipientDatabase.RegisteredState.REGISTERED) {
|
2016-10-05 16:57:52 -07:00
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
2017-08-01 08:56:00 -07:00
|
|
|
.add(new MultiDeviceContactUpdateJob(context, recipient.getAddress()));
|
2016-10-05 16:57:52 -07:00
|
|
|
}
|
2015-06-24 13:17:58 -07:00
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2015-06-24 13:17:58 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
private class MuteClickedListener implements Preference.OnPreferenceClickListener {
|
2018-10-20 22:22:07 -07:00
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2018-10-20 22:22:07 -07:00
|
|
|
if (recipient.isMuted()) handleUnmute(preference.getContext());
|
|
|
|
else handleMute(preference.getContext());
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-20 22:22:07 -07:00
|
|
|
private void handleMute(@NonNull Context context) {
|
|
|
|
MuteDialog.show(context, until -> setMuted(context, recipient, until));
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
setSummaries(recipient);
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
2018-10-20 22:22:07 -07:00
|
|
|
private void handleUnmute(@NonNull Context context) {
|
|
|
|
setMuted(context, recipient, 0);
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
2018-10-20 22:22:07 -07:00
|
|
|
private void setMuted(@NonNull final Context context, final Recipient recipient, final long until) {
|
2017-08-01 08:56:00 -07:00
|
|
|
recipient.setMuted(until);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2018-10-20 22:22:07 -07:00
|
|
|
DatabaseFactory.getRecipientDatabase(context)
|
2017-08-01 08:56:00 -07:00
|
|
|
.setMuted(recipient, until);
|
2015-06-09 07:37:20 -07:00
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 14:26:37 -07:00
|
|
|
private class IdentityClickedListener implements Preference.OnPreferenceClickListener {
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
private final IdentityRecord identityKey;
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
private IdentityClickedListener(IdentityRecord identityKey) {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "Identity record: " + identityKey);
|
2016-08-24 18:51:45 -07:00
|
|
|
this.identityKey = identityKey;
|
|
|
|
}
|
|
|
|
|
2015-09-29 14:26:37 -07:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2018-10-20 22:22:07 -07:00
|
|
|
Intent verifyIdentityIntent = new Intent(preference.getContext(), VerifyIdentityActivity.class);
|
2017-08-01 08:56:00 -07:00
|
|
|
verifyIdentityIntent.putExtra(VerifyIdentityActivity.ADDRESS_EXTRA, recipient.getAddress());
|
2017-06-06 18:03:09 -07:00
|
|
|
verifyIdentityIntent.putExtra(VerifyIdentityActivity.IDENTITY_EXTRA, new IdentityKeyParcelable(identityKey.getIdentityKey()));
|
|
|
|
verifyIdentityIntent.putExtra(VerifyIdentityActivity.VERIFIED_EXTRA, identityKey.getVerifiedStatus() == IdentityDatabase.VerifiedStatus.VERIFIED);
|
2015-09-29 14:26:37 -07:00
|
|
|
startActivity(verifyIdentityIntent);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 07:37:20 -07:00
|
|
|
private class BlockClickedListener implements Preference.OnPreferenceClickListener {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2018-10-20 22:22:07 -07:00
|
|
|
if (recipient.isBlocked()) handleUnblock(preference.getContext());
|
|
|
|
else handleBlock(preference.getContext());
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-20 22:22:07 -07:00
|
|
|
private void handleBlock(@NonNull final Context context) {
|
2018-09-10 08:40:00 -07: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;
|
|
|
|
|
2018-10-20 22:22:07 -07:00
|
|
|
if (recipient.isGroupRecipient() && DatabaseFactory.getGroupDatabase(context).isActive(recipient.getAddress().toGroupString())) {
|
2018-09-10 08:40:00 -07:00
|
|
|
titleRes = R.string.RecipientPreferenceActivity_block_and_leave_group;
|
|
|
|
} else {
|
|
|
|
titleRes = R.string.RecipientPreferenceActivity_block_group;
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
2018-09-10 08:40:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return new Pair<>(titleRes, bodyRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Pair<Integer, Integer> titleAndBody) {
|
2018-10-20 22:22:07 -07:00
|
|
|
new AlertDialog.Builder(context)
|
2018-09-10 08:40:00 -07:00
|
|
|
.setTitle(titleAndBody.first)
|
|
|
|
.setMessage(titleAndBody.second)
|
|
|
|
.setCancelable(true)
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.setPositiveButton(R.string.RecipientPreferenceActivity_block, (dialog, which) -> {
|
2018-10-20 22:22:07 -07:00
|
|
|
setBlocked(context, recipient, true);
|
2018-09-10 08:40:00 -07:00
|
|
|
}).show();
|
|
|
|
}
|
|
|
|
}.execute();
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
2018-10-20 22:22:07 -07:00
|
|
|
private void handleUnblock(@NonNull Context context) {
|
2018-09-10 08:40:00 -07: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;
|
|
|
|
}
|
|
|
|
|
2018-10-20 22:22:07 -07:00
|
|
|
new AlertDialog.Builder(context)
|
2018-09-10 08:40:00 -07:00
|
|
|
.setTitle(titleRes)
|
|
|
|
.setMessage(bodyRes)
|
|
|
|
.setCancelable(true)
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
2018-10-20 22:22:07 -07:00
|
|
|
.setPositiveButton(R.string.RecipientPreferenceActivity_unblock, (dialog, which) -> setBlocked(context, recipient, false)).show();
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
2018-10-20 22:22:07 -07:00
|
|
|
private void setBlocked(@NonNull final Context context, final Recipient recipient, final boolean blocked) {
|
2015-06-09 07:37:20 -07:00
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2017-08-21 18:47:37 -07:00
|
|
|
DatabaseFactory.getRecipientDatabase(context)
|
2017-08-01 08:56:00 -07:00
|
|
|
.setBlocked(recipient, blocked);
|
2016-08-26 16:53:23 -07:00
|
|
|
|
2018-09-10 08:40:00 -07: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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 16:45:22 -07:00
|
|
|
if (blocked && (recipient.resolve().isSystemContact() || recipient.resolve().isProfileSharing())) {
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
2019-03-28 08:56:35 -07:00
|
|
|
.add(new RotateProfileKeyJob());
|
2018-10-11 16:45:22 -07:00
|
|
|
}
|
|
|
|
|
2016-08-26 16:53:23 -07:00
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
2019-03-28 08:56:35 -07:00
|
|
|
.add(new MultiDeviceBlockedUpdateJob());
|
2015-06-09 07:37:20 -07:00
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
}
|
2018-04-03 02:28:26 -07:00
|
|
|
|
|
|
|
private class AboutNumberClickedListener implements ContactPreference.Listener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMessageClicked() {
|
2018-07-24 17:14:30 -04:00
|
|
|
CommunicationActions.startConversation(getContext(), recipient, null);
|
2018-04-03 02:28:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSecureCallClicked() {
|
2018-07-24 17:14:30 -04:00
|
|
|
CommunicationActions.startVoiceCall(getActivity(), recipient);
|
2018-04-03 02:28:26 -07: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 09:47:43 -07:00
|
|
|
|
|
|
|
private class CustomNotificationsChangedListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
2018-10-20 22:22:07 -07:00
|
|
|
final Context context = preference.getContext();
|
2018-08-16 09:47:43 -07:00
|
|
|
final boolean enabled = (boolean) newValue;
|
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
if (enabled) {
|
2018-10-20 22:22:07 -07:00
|
|
|
String channel = NotificationChannels.createChannelFor(context, recipient);
|
|
|
|
DatabaseFactory.getRecipientDatabase(context).setNotificationChannel(recipient, channel);
|
2018-08-16 09:47:43 -07:00
|
|
|
} else {
|
2018-10-20 22:22:07 -07:00
|
|
|
NotificationChannels.deleteChannelFor(context, recipient);
|
|
|
|
DatabaseFactory.getRecipientDatabase(context).setNotificationChannel(recipient, null);
|
2018-08-16 09:47:43 -07:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
}
|