2015-06-09 07:37:20 -07:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2017-11-24 22:00:30 -08:00
|
|
|
import android.annotation.SuppressLint;
|
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;
|
2019-12-03 11:05:03 -05:00
|
|
|
import android.telephony.PhoneNumberUtils;
|
|
|
|
import android.util.Pair;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2019-06-05 15:47:14 -04:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2019-12-03 11:05:03 -05:00
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
import androidx.core.view.ViewCompat;
|
2019-06-05 15:47:14 -04:00
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.loader.app.LoaderManager;
|
|
|
|
import androidx.loader.content.Loader;
|
|
|
|
import androidx.preference.CheckBoxPreference;
|
|
|
|
import androidx.preference.ListPreference;
|
|
|
|
import androidx.preference.Preference;
|
|
|
|
import androidx.preference.PreferenceCategory;
|
2019-10-22 10:30:11 -04:00
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2017-10-16 13:11:42 -07:00
|
|
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
2019-12-03 11:05:03 -05:00
|
|
|
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
2017-10-16 13:11:42 -07:00
|
|
|
|
2015-06-30 09:16:05 -07:00
|
|
|
import org.thoughtcrime.securesms.color.MaterialColor;
|
|
|
|
import org.thoughtcrime.securesms.color.MaterialColors;
|
2019-12-03 11:05:03 -05:00
|
|
|
import org.thoughtcrime.securesms.components.SwitchPreferenceCompat;
|
2017-09-20 18:14:28 -07:00
|
|
|
import org.thoughtcrime.securesms.components.ThreadPhotoRailView;
|
2019-12-03 11:05:03 -05: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;
|
2015-06-09 07:37:20 -07:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord;
|
2019-12-03 11:05:03 -05:00
|
|
|
import org.thoughtcrime.securesms.database.MediaDatabase;
|
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;
|
2019-12-03 11:05:03 -05:00
|
|
|
import org.thoughtcrime.securesms.database.loaders.RecipientMediaLoader;
|
|
|
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
2016-08-26 16:53:23 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
|
2019-12-03 11:05:03 -05:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
|
|
|
import org.thoughtcrime.securesms.mediaoverview.MediaOverviewActivity;
|
2017-10-16 13:11:42 -07:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
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;
|
2019-08-07 14:22:51 -04:00
|
|
|
import org.thoughtcrime.securesms.recipients.LiveRecipient;
|
2017-08-01 08:56:00 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2019-08-07 14:22:51 -04:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
2019-11-25 10:19:43 -05:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientUtil;
|
2018-07-24 17:14:30 -04:00
|
|
|
import org.thoughtcrime.securesms.util.CommunicationActions;
|
2019-10-07 15:43:36 -03:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicDarkToolbarTheme;
|
2015-06-09 07:37:20 -07:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2019-10-31 13:20:55 -03:00
|
|
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
2016-08-29 17:49:49 -07:00
|
|
|
import org.thoughtcrime.securesms.util.IdentityUtil;
|
2020-02-13 16:02:12 -05:00
|
|
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
2017-12-19 14:42:00 -08:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2019-10-07 15:43:36 -03:00
|
|
|
import org.thoughtcrime.securesms.util.ThemeUtil;
|
2020-02-13 16:02:12 -05: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;
|
2019-12-03 11:05:03 -05:00
|
|
|
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
2016-08-24 18:51:45 -07:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2017-11-24 22:00:30 -08:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2019-08-07 14:22:51 -04:00
|
|
|
public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActivity implements LoaderManager.LoaderCallbacks<Cursor>
|
2015-06-09 07:37:20 -07:00
|
|
|
{
|
|
|
|
private static final String TAG = RecipientPreferenceActivity.class.getSimpleName();
|
|
|
|
|
2020-03-02 08:33:25 -05:00
|
|
|
public static final String RECIPIENT_ID = "recipient";
|
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";
|
|
|
|
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 07:37:20 -07:00
|
|
|
|
2019-10-07 15:43:36 -03:00
|
|
|
private final DynamicTheme dynamicTheme = new DynamicDarkToolbarTheme();
|
2015-06-09 07:37:20 -07:00
|
|
|
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;
|
2019-08-07 14:22:51 -04:00
|
|
|
private RecipientId recipientId;
|
2017-09-20 18:14:28 -07:00
|
|
|
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
|
|
|
|
2020-03-02 08:33:25 -05:00
|
|
|
public static @NonNull Intent getLaunchIntent(@NonNull Context context, @NonNull RecipientId id) {
|
|
|
|
Intent intent = new Intent(context, RecipientPreferenceActivity.class);
|
|
|
|
intent.putExtra(RecipientPreferenceActivity.RECIPIENT_ID, id);
|
|
|
|
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
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);
|
2019-08-07 14:22:51 -04:00
|
|
|
this.recipientId = getIntent().getParcelableExtra(RECIPIENT_ID);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
LiveRecipient recipient = Recipient.live(recipientId);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
initializeToolbar();
|
2019-08-07 14:22:51 -04:00
|
|
|
setHeader(recipient.get());
|
|
|
|
recipient.observe(this, this::setHeader);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-10-07 15:43:36 -03:00
|
|
|
this.toolbarLayout.setExpandedTitleColor(ThemeUtil.getThemedColor(this, R.attr.conversation_title_color));
|
|
|
|
this.toolbarLayout.setCollapsedTitleTextColor(ThemeUtil.getThemedColor(this, R.attr.conversation_title_color));
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2020-04-09 18:09:29 -03:00
|
|
|
this.threadPhotoRailView.setListener(mediaRecord ->
|
|
|
|
startActivity(MediaPreviewActivity.intentFromMediaRecord(RecipientPreferenceActivity.this,
|
|
|
|
mediaRecord,
|
|
|
|
ViewCompat.getLayoutDirection(threadPhotoRailView) == ViewCompat.LAYOUT_DIRECTION_LTR)));
|
2017-09-20 18:14:28 -07:00
|
|
|
|
2019-12-03 11:05:03 -05:00
|
|
|
SimpleTask.run(
|
|
|
|
() -> DatabaseFactory.getThreadDatabase(this).getThreadIdFor(recipientId),
|
|
|
|
(threadId) -> {
|
|
|
|
if (threadId == null) {
|
2019-12-04 10:11:49 -05:00
|
|
|
Log.i(TAG, "No thread id for recipient.");
|
|
|
|
} else {
|
|
|
|
this.threadPhotoRailLabel.setOnClickListener(v -> startActivity(MediaOverviewActivity.forThread(this, threadId)));
|
2019-12-03 11:05:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2017-09-20 18:14:28 -07:00
|
|
|
|
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);
|
2020-01-07 12:00:44 -05:00
|
|
|
|
|
|
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.recipient_preference_root), (v, insets) -> {
|
|
|
|
ViewUtil.setTopMargin(toolbar, insets.getSystemWindowInsetTop());
|
|
|
|
return insets;
|
|
|
|
});
|
2017-09-12 22:48:30 -07:00
|
|
|
}
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
2017-09-12 22:48:30 -07:00
|
|
|
private void setHeader(@NonNull Recipient recipient) {
|
2020-03-25 18:43:02 -04:00
|
|
|
ContactPhoto contactPhoto = recipient.isLocalNumber() ? new ProfileContactPhoto(recipient, recipient.getProfileAvatar())
|
2019-01-13 23:30:54 -08:00
|
|
|
: recipient.getContactPhoto();
|
2019-10-07 15:43:36 -03:00
|
|
|
FallbackContactPhoto fallbackPhoto = recipient.isLocalNumber() ? new ResourceContactPhoto(R.drawable.ic_profile_outline_40, R.drawable.ic_profile_outline_20, R.drawable.ic_person_large)
|
2019-01-13 23:30:54 -08:00
|
|
|
: 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));
|
2019-10-31 13:20:55 -03:00
|
|
|
this.toolbarLayout.setTitle(recipient.toShortString(this));
|
2017-10-16 13:11:42 -07:00
|
|
|
this.toolbarLayout.setContentScrimColor(recipient.getColor().toActionBarColor(this));
|
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) {
|
2019-12-03 11:05:03 -05:00
|
|
|
return new RecipientMediaLoader(this, recipientId, RecipientMediaLoader.MediaType.GALLERY, MediaDatabase.Sorting.Newest);
|
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) {
|
|
|
|
this.threadPhotoRailLabel.setVisibility(View.VISIBLE);
|
|
|
|
this.threadPhotoRailView.setVisibility(View.VISIBLE);
|
|
|
|
} 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();
|
2019-08-07 14:22:51 -04:00
|
|
|
bundle.putParcelable(RECIPIENT_ID, recipientId);
|
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
|
|
|
}
|
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
public static class RecipientPreferenceFragment extends CorrectedPreferenceFragment {
|
|
|
|
private LiveRecipient 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
|
|
|
|
2020-03-02 08:33:25 -05:00
|
|
|
this.canHaveSafetyNumber = recipient.get().isRegistered() && !recipient.get().isLocalNumber();
|
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()) {
|
2019-08-07 14:22:51 -04:00
|
|
|
((SwitchPreferenceCompat) customNotificationsPref).setChecked(recipient.get().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);
|
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
if (recipient.get().getNotificationChannel() != null) {
|
|
|
|
final Context context = requireContext();
|
2018-08-30 17:59:15 -07:00
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... voids) {
|
|
|
|
RecipientDatabase db = DatabaseFactory.getRecipientDatabase(getContext());
|
2019-08-07 14:22:51 -04:00
|
|
|
db.setMessageRingtone(recipient.getId(), NotificationChannels.getMessageRingtone(context, recipient.get()));
|
|
|
|
db.setMessageVibrate(recipient.getId(), NotificationChannels.getMessageVibrate(context, recipient.get()) ? 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));
|
|
|
|
this.findPreference(PREFERENCE_CALL_TONE)
|
|
|
|
.setOnPreferenceChangeListener(new RingtoneChangeListener(true));
|
|
|
|
this.findPreference(PREFERENCE_CALL_TONE)
|
|
|
|
.setOnPreferenceClickListener(new RingtoneClickedListener(true));
|
2018-08-30 17:59:15 -07:00
|
|
|
this.findPreference(PREFERENCE_MESSAGE_VIBRATE)
|
|
|
|
.setOnPreferenceChangeListener(new VibrateChangeListener(false));
|
2018-02-16 11:10:35 -08:00
|
|
|
this.findPreference(PREFERENCE_CALL_VIBRATE)
|
|
|
|
.setOnPreferenceChangeListener(new VibrateChangeListener(true));
|
2015-06-09 07:37:20 -07:00
|
|
|
this.findPreference(PREFERENCE_MUTED)
|
|
|
|
.setOnPreferenceClickListener(new MuteClickedListener());
|
|
|
|
this.findPreference(PREFERENCE_BLOCK)
|
|
|
|
.setOnPreferenceClickListener(new BlockClickedListener());
|
2015-06-24 13:17:58 -07:00
|
|
|
this.findPreference(PREFERENCE_COLOR)
|
|
|
|
.setOnPreferenceChangeListener(new ColorChangeListener());
|
2018-04-03 02:28:26 -07:00
|
|
|
((ContactPreference)this.findPreference(PREFERENCE_ABOUT))
|
|
|
|
.setListener(new AboutNumberClickedListener());
|
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();
|
2019-08-07 14:22:51 -04:00
|
|
|
setSummaries(recipient.get());
|
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();
|
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);
|
|
|
|
|
|
|
|
findPreference(PREFERENCE_CALL_TONE).getOnPreferenceChangeListener().onPreferenceChange(findPreference(PREFERENCE_CALL_TONE), uri);
|
2017-12-01 12:55:24 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-22 10:30:11 -04:00
|
|
|
@Override
|
|
|
|
public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
|
|
|
RecyclerView recyclerView = super.onCreateRecyclerView(inflater, parent, savedInstanceState);
|
|
|
|
recyclerView.setItemAnimator(null);
|
|
|
|
recyclerView.setLayoutAnimation(null);
|
|
|
|
return recyclerView;
|
|
|
|
}
|
|
|
|
|
2016-08-15 20:23:56 -07:00
|
|
|
private void initializeRecipients() {
|
2019-08-07 14:22:51 -04:00
|
|
|
this.recipient = Recipient.live(getArguments().getParcelable(RECIPIENT_ID));
|
|
|
|
this.recipient.observe(this, this::setSummaries);
|
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);
|
|
|
|
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);
|
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");
|
2018-04-03 02:28:26 -07: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()) : "");
|
2018-02-16 11:10:35 -08: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
|
|
|
|
2018-02-16 11:10:35 -08:00
|
|
|
vibrateCallPreference.setSummary(vibrateCallSummary.first);
|
|
|
|
vibrateCallPreference.setValueIndex(vibrateCallSummary.second);
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2019-11-25 10:19:43 -05:00
|
|
|
blockPreference.setVisible(RecipientUtil.isBlockable(recipient));
|
|
|
|
if (recipient.isBlocked()) blockPreference.setTitle(R.string.RecipientPreferenceActivity_unblock);
|
|
|
|
else blockPreference.setTitle(R.string.RecipientPreferenceActivity_block);
|
|
|
|
|
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);
|
2019-12-02 22:42:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (recipient.isGroup()) {
|
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 {
|
2019-09-06 23:40:06 -04:00
|
|
|
colorPreference.setColors(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(requireActivity()));
|
|
|
|
colorPreference.setColor(recipient.getColor().toActionBarColor(requireActivity()));
|
2018-10-09 12:55:39 -07:00
|
|
|
|
2019-12-19 17:41:21 -05:00
|
|
|
if (FeatureFlags.profileDisplay()) {
|
2019-10-31 13:20:55 -03:00
|
|
|
aboutPreference.setTitle(recipient.getDisplayName(requireContext()));
|
|
|
|
aboutPreference.setSummary(recipient.resolve().getE164().or(""));
|
|
|
|
} else {
|
|
|
|
aboutPreference.setTitle(formatRecipient(recipient));
|
|
|
|
aboutPreference.setSummary(recipient.getCustomLabel());
|
|
|
|
}
|
2019-10-09 13:57:36 -03:00
|
|
|
|
2018-04-03 02:28:26 -07:00
|
|
|
aboutPreference.setSecure(recipient.getRegistered() == RecipientDatabase.RegisteredState.REGISTERED);
|
|
|
|
|
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
|
|
|
}
|
2019-11-25 10:19:43 -05:00
|
|
|
|
|
|
|
if (recipient.isMmsGroup() && privacyCategory != null) {
|
|
|
|
privacyCategory.setVisible(false);
|
|
|
|
}
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
2019-10-31 13:20:55 -03:00
|
|
|
private @NonNull String formatRecipient(@NonNull Recipient recipient) {
|
|
|
|
if (recipient.getE164().isPresent()) return PhoneNumberUtils.formatNumber(recipient.requireE164());
|
|
|
|
else if (recipient.getEmail().isPresent()) return recipient.requireEmail();
|
|
|
|
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
|
|
|
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) {
|
2019-08-07 14:22:51 -04:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setCallRingtone(recipient.getId(), params[0]);
|
2018-08-30 17:59:15 -07:00
|
|
|
} else {
|
2019-08-07 14:22:51 -04:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setMessageRingtone(recipient.getId(), params[0]);
|
|
|
|
NotificationChannels.updateMessageRingtone(context, recipient.get(), 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) {
|
2019-08-07 14:22:51 -04:00
|
|
|
current = recipient.get().getCallRingtone();
|
2018-02-16 11:10:35 -08:00
|
|
|
defaultUri = TextSecurePreferences.getCallNotificationRingtone(getContext());
|
|
|
|
} else {
|
2019-08-07 14:22:51 -04:00
|
|
|
current = recipient.get().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) {
|
2019-08-07 14:22:51 -04:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setCallVibrate(recipient.getId(), vibrateState);
|
2018-08-30 17:59:15 -07:00
|
|
|
}
|
|
|
|
else {
|
2019-08-07 14:22:51 -04:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setMessageVibrate(recipient.getId(), vibrateState);
|
|
|
|
NotificationChannels.updateMessageVibrate(context, recipient.get(), 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);
|
2019-08-07 14:22:51 -04:00
|
|
|
final MaterialColor currentColor = recipient.get().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) {
|
2019-08-07 14:22:51 -04:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setColor(recipient.getId(), selectedColor);
|
2016-08-26 16:53:23 -07:00
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
if (recipient.get().resolve().getRegistered() == RecipientDatabase.RegisteredState.REGISTERED) {
|
2019-10-15 15:47:54 -04:00
|
|
|
ApplicationDependencies.getJobManager().add(new MultiDeviceContactUpdateJob(recipient.getId()));
|
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) {
|
2019-08-07 14:22:51 -04:00
|
|
|
if (recipient.get().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) {
|
2019-08-07 14:22:51 -04:00
|
|
|
MuteDialog.show(context, until -> setMuted(context, recipient.get(), until));
|
2015-06-09 07:37:20 -07:00
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
setSummaries(recipient.get());
|
2015-06-09 07:37:20 -07:00
|
|
|
}
|
|
|
|
|
2018-10-20 22:22:07 -07:00
|
|
|
private void handleUnmute(@NonNull Context context) {
|
2019-08-07 14:22:51 -04:00
|
|
|
setMuted(context, recipient.get(), 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) {
|
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)
|
2019-08-07 14:22:51 -04:00
|
|
|
.setMuted(recipient.getId(), 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);
|
2019-08-07 14:22:51 -04:00
|
|
|
verifyIdentityIntent.putExtra(VerifyIdentityActivity.RECIPIENT_EXTRA, recipient.getId());
|
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) {
|
2020-04-01 15:09:14 -03:00
|
|
|
if (recipient.get().isBlocked()) BlockUnblockDialog.handleUnblock(preference.getContext(), getLifecycle(), recipient.getId(), null);
|
|
|
|
else BlockUnblockDialog.handleBlock(preference.getContext(), getLifecycle(), recipient.getId());
|
2015-06-09 07:37:20 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2018-04-03 02:28:26 -07:00
|
|
|
|
|
|
|
private class AboutNumberClickedListener implements ContactPreference.Listener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMessageClicked() {
|
2019-10-01 08:16:57 -04:00
|
|
|
CommunicationActions.startConversation(getContext(), recipient.get(), null);
|
2018-04-03 02:28:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSecureCallClicked() {
|
2019-08-07 14:22:51 -04:00
|
|
|
CommunicationActions.startVoiceCall(getActivity(), recipient.get());
|
2018-04-03 02:28:26 -07:00
|
|
|
}
|
|
|
|
|
2019-12-03 16:26:05 -04:00
|
|
|
@Override
|
|
|
|
public void onSecureVideoClicked() {
|
|
|
|
CommunicationActions.startVideoCall(getActivity(), recipient.get());
|
|
|
|
}
|
|
|
|
|
2018-04-03 02:28:26 -07:00
|
|
|
@Override
|
|
|
|
public void onInSecureCallClicked() {
|
2020-03-05 12:38:05 -04:00
|
|
|
CommunicationActions.startInsecureCall(requireActivity(), recipient.get());
|
2018-04-03 02:28:26 -07:00
|
|
|
}
|
|
|
|
}
|
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) {
|
2019-08-07 14:22:51 -04:00
|
|
|
String channel = NotificationChannels.createChannelFor(context, recipient.get());
|
|
|
|
DatabaseFactory.getRecipientDatabase(context).setNotificationChannel(recipient.getId(), channel);
|
2018-08-16 09:47:43 -07:00
|
|
|
} else {
|
2019-08-07 14:22:51 -04:00
|
|
|
NotificationChannels.deleteChannelFor(context, recipient.get());
|
|
|
|
DatabaseFactory.getRecipientDatabase(context).setNotificationChannel(recipient.getId(), 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
|
|
|
}
|
|
|
|
}
|