2015-06-09 14:37:20 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2016-08-16 03:23:56 +00:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
2016-08-16 03:23:56 +00:00
|
|
|
import android.content.IntentFilter;
|
2017-09-21 01:14:28 +00:00
|
|
|
import android.database.Cursor;
|
2017-09-13 05:48:30 +00:00
|
|
|
import android.graphics.Color;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.media.Ringtone;
|
|
|
|
import android.media.RingtoneManager;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.AsyncTask;
|
2015-06-29 22:33:36 +00:00
|
|
|
import android.os.Build;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.provider.Settings;
|
|
|
|
import android.support.annotation.NonNull;
|
2017-09-21 01:14:28 +00:00
|
|
|
import android.support.annotation.Nullable;
|
2017-09-13 05:48:30 +00:00
|
|
|
import android.support.design.widget.CollapsingToolbarLayout;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.support.v4.app.Fragment;
|
2017-09-21 01:14:28 +00:00
|
|
|
import android.support.v4.app.LoaderManager;
|
|
|
|
import android.support.v4.content.Loader;
|
2015-05-20 21:36:30 +00:00
|
|
|
import android.support.v7.app.AlertDialog;
|
2017-09-21 01:14:28 +00:00
|
|
|
import android.support.v7.preference.CheckBoxPreference;
|
|
|
|
import android.support.v7.preference.ListPreference;
|
|
|
|
import android.support.v7.preference.Preference;
|
2017-10-04 00:05:52 +00:00
|
|
|
import android.support.v7.preference.PreferenceCategory;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.support.v7.widget.Toolbar;
|
2017-06-07 01:03:09 +00:00
|
|
|
import android.util.Log;
|
2015-06-09 14:37:20 +00:00
|
|
|
import android.view.MenuItem;
|
2017-09-21 01:14:28 +00:00
|
|
|
import android.view.View;
|
2017-09-13 05:48:30 +00:00
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.widget.ImageView;
|
2017-09-21 01:14:28 +00:00
|
|
|
import android.widget.TextView;
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2015-06-30 16:16:05 +00:00
|
|
|
import org.thoughtcrime.securesms.color.MaterialColor;
|
|
|
|
import org.thoughtcrime.securesms.color.MaterialColors;
|
2017-09-21 01:14:28 +00:00
|
|
|
import org.thoughtcrime.securesms.components.ThreadPhotoRailView;
|
2017-10-04 22:23:33 +00:00
|
|
|
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
|
2016-08-25 01:51:45 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
|
2015-06-09 14:37:20 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2017-07-26 16:59:15 +00:00
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
2015-06-09 14:37:20 +00:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2016-08-16 03:23:56 +00:00
|
|
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
2017-06-07 01:03:09 +00:00
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord;
|
2017-08-22 17:44:04 +00:00
|
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
2017-08-22 01:37:39 +00:00
|
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase.VibrateState;
|
2017-09-21 01:14:28 +00:00
|
|
|
import org.thoughtcrime.securesms.database.loaders.ThreadMediaLoader;
|
2016-08-26 23:53:23 +00:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
|
2017-09-21 17:03:05 +00:00
|
|
|
import org.thoughtcrime.securesms.preferences.widgets.AdvancedRingtonePreference;
|
|
|
|
import org.thoughtcrime.securesms.preferences.widgets.ColorPickerPreference;
|
2017-09-21 01:14:28 +00:00
|
|
|
import org.thoughtcrime.securesms.preferences.CorrectedPreferenceFragment;
|
2017-08-01 15:56:00 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
2015-06-09 14:37:20 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2016-08-30 00:49:49 +00:00
|
|
|
import org.thoughtcrime.securesms.util.IdentityUtil;
|
2017-10-09 01:46:09 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2017-09-10 06:46:48 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2017-09-13 05:48:30 +00:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2016-08-25 01:51:45 +00:00
|
|
|
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-09-21 01:14:28 +00:00
|
|
|
public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActivity implements RecipientModifiedListener, LoaderManager.LoaderCallbacks<Cursor>
|
2015-06-09 14:37:20 +00:00
|
|
|
{
|
|
|
|
private static final String TAG = RecipientPreferenceActivity.class.getSimpleName();
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
public static final String ADDRESS_EXTRA = "recipient_address";
|
2016-12-11 18:04:57 +00:00
|
|
|
public static final String CAN_HAVE_SAFETY_NUMBER_EXTRA = "can_have_safety_number";
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2015-09-29 21:26:37 +00:00
|
|
|
private static final String PREFERENCE_MUTED = "pref_key_recipient_mute";
|
|
|
|
private static final String PREFERENCE_TONE = "pref_key_recipient_ringtone";
|
|
|
|
private static final String PREFERENCE_VIBRATE = "pref_key_recipient_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";
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
private ImageView avatar;
|
2017-09-21 01:14:28 +00:00
|
|
|
private MasterSecret masterSecret;
|
|
|
|
private Address address;
|
|
|
|
private TextView threadPhotoRailLabel;
|
|
|
|
private ThreadPhotoRailView threadPhotoRailView;
|
2017-09-13 05:48:30 +00:00
|
|
|
private CollapsingToolbarLayout toolbarLayout;
|
|
|
|
private BroadcastReceiver staleReceiver;
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreCreate() {
|
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
dynamicLanguage.onCreate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle instanceState, @NonNull MasterSecret masterSecret) {
|
|
|
|
setContentView(R.layout.recipient_preference_activity);
|
2017-09-21 01:14:28 +00:00
|
|
|
this.masterSecret = masterSecret;
|
|
|
|
this.address = getIntent().getParcelableExtra(ADDRESS_EXTRA);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-08-22 01:32:38 +00:00
|
|
|
Recipient recipient = Recipient.from(this, address, true);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
initializeToolbar();
|
2016-08-16 03:23:56 +00:00
|
|
|
initializeReceivers();
|
2017-08-01 15:56:00 +00:00
|
|
|
setHeader(recipient);
|
|
|
|
recipient.addListener(this);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-09-21 01:14:28 +00:00
|
|
|
getSupportLoaderManager().initLoader(0, null, this);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
|
|
|
dynamicLanguage.onResume(this);
|
|
|
|
}
|
|
|
|
|
2016-08-16 03:23:56 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
unregisterReceiver(staleReceiver);
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.preference_fragment);
|
|
|
|
fragment.onActivityResult(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
super.onOptionsItemSelected(item);
|
|
|
|
switch (item.getItemId()) {
|
2015-07-18 08:50:29 +00:00
|
|
|
case android.R.id.home:
|
2017-09-13 05:48:30 +00:00
|
|
|
onBackPressed();
|
2015-07-18 08:50:29 +00:00
|
|
|
return true;
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
finish();
|
|
|
|
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
private void initializeToolbar() {
|
2017-09-21 01:14:28 +00:00
|
|
|
this.toolbarLayout = ViewUtil.findById(this, R.id.collapsing_toolbar);
|
|
|
|
this.avatar = ViewUtil.findById(this, R.id.avatar);
|
|
|
|
this.threadPhotoRailView = ViewUtil.findById(this, R.id.recent_photos);
|
|
|
|
this.threadPhotoRailLabel = ViewUtil.findById(this, R.id.rail_label);
|
2016-12-17 23:52:27 +00:00
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
this.toolbarLayout.setExpandedTitleColor(getResources().getColor(R.color.white));
|
|
|
|
this.toolbarLayout.setCollapsedTitleTextColor(getResources().getColor(R.color.white));
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-09-21 01:14:28 +00:00
|
|
|
this.threadPhotoRailView.setListener(mediaRecord -> {
|
|
|
|
Intent intent = new Intent(RecipientPreferenceActivity.this, MediaPreviewActivity.class);
|
|
|
|
intent.putExtra(MediaPreviewActivity.ADDRESS_EXTRA, address);
|
2017-10-04 18:35:16 +00:00
|
|
|
intent.putExtra(MediaPreviewActivity.OUTGOING_EXTRA, mediaRecord.isOutgoing());
|
2017-09-21 01:14:28 +00:00
|
|
|
intent.putExtra(MediaPreviewActivity.DATE_EXTRA, mediaRecord.getDate());
|
|
|
|
intent.putExtra(MediaPreviewActivity.SIZE_EXTRA, mediaRecord.getAttachment().getSize());
|
|
|
|
intent.setDataAndType(mediaRecord.getAttachment().getDataUri(), mediaRecord.getContentType());
|
|
|
|
startActivity(intent);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.threadPhotoRailLabel.setOnClickListener(v -> {
|
|
|
|
Intent intent = new Intent(this, MediaOverviewActivity.class);
|
|
|
|
intent.putExtra(MediaOverviewActivity.ADDRESS_EXTRA, address);
|
|
|
|
startActivity(intent);
|
|
|
|
});
|
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
Toolbar toolbar = ViewUtil.findById(this, R.id.toolbar);
|
|
|
|
setSupportActionBar(toolbar);
|
2015-06-09 14:37:20 +00:00
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
2017-09-13 05:48:30 +00:00
|
|
|
getSupportActionBar().setLogo(null);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
|
|
|
getWindow().setStatusBarColor(Color.TRANSPARENT);
|
|
|
|
}
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
2016-08-16 03:23:56 +00:00
|
|
|
private void initializeReceivers() {
|
|
|
|
this.staleReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2017-08-22 01:32:38 +00:00
|
|
|
Recipient recipient = Recipient.from(context, (Address)getIntent().getParcelableExtra(ADDRESS_EXTRA), true);
|
2017-08-01 15:56:00 +00:00
|
|
|
recipient.addListener(RecipientPreferenceActivity.this);
|
|
|
|
onModified(recipient);
|
2016-08-16 03:23:56 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IntentFilter staleFilter = new IntentFilter();
|
|
|
|
staleFilter.addAction(GroupDatabase.DATABASE_UPDATE_ACTION);
|
2017-08-22 01:32:38 +00:00
|
|
|
staleFilter.addAction(Recipient.RECIPIENT_CLEAR_ACTION);
|
2016-08-16 03:23:56 +00:00
|
|
|
|
|
|
|
registerReceiver(staleReceiver, staleFilter);
|
|
|
|
}
|
|
|
|
|
2017-09-13 05:48:30 +00:00
|
|
|
private void setHeader(@NonNull Recipient recipient) {
|
2017-10-04 22:23:33 +00:00
|
|
|
ContactPhoto contactPhoto = recipient.getContactPhoto();
|
|
|
|
|
|
|
|
if (contactPhoto.isGenerated() || contactPhoto.isResource()) this.avatar.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
|
|
|
else this.avatar.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
|
|
|
|
|
this.avatar.setImageDrawable(contactPhoto.asCallCard(this));
|
|
|
|
this.avatar.setBackgroundColor(recipient.getColor().toActionBarColor(this));
|
2017-09-13 05:48:30 +00:00
|
|
|
this.toolbarLayout.setTitle(recipient.toShortString());
|
|
|
|
this.toolbarLayout.setContentScrimColor(recipient.getColor().toActionBarColor(this));
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-01 15:56:00 +00:00
|
|
|
public void onModified(final Recipient recipient) {
|
2017-09-13 05:48:30 +00:00
|
|
|
Util.runOnMain(() -> setHeader(recipient));
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 01:14:28 +00:00
|
|
|
@Override
|
|
|
|
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
2017-09-25 15:32:45 +00:00
|
|
|
return new ThreadMediaLoader(this, masterSecret, address, true);
|
2017-09-21 01:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
|
|
|
if (data != null && data.getCount() > 0) {
|
|
|
|
this.threadPhotoRailLabel.setVisibility(View.VISIBLE);
|
|
|
|
this.threadPhotoRailView.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
this.threadPhotoRailLabel.setVisibility(View.GONE);
|
|
|
|
this.threadPhotoRailView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.threadPhotoRailView.setCursor(data, masterSecret);
|
|
|
|
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putParcelable(ADDRESS_EXTRA, address);
|
|
|
|
initFragment(R.id.preference_fragment, new RecipientPreferenceFragment(), masterSecret, null, bundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLoaderReset(Loader<Cursor> loader) {
|
|
|
|
this.threadPhotoRailView.setCursor(null, masterSecret);
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
public static class RecipientPreferenceFragment
|
2017-09-21 01:14:28 +00:00
|
|
|
extends CorrectedPreferenceFragment
|
2017-08-01 15:56:00 +00:00
|
|
|
implements RecipientModifiedListener
|
2015-06-09 14:37:20 +00:00
|
|
|
{
|
2017-08-01 15:56:00 +00:00
|
|
|
private Recipient recipient;
|
2016-08-16 03:23:56 +00:00
|
|
|
private BroadcastReceiver staleReceiver;
|
2016-12-11 18:04:57 +00:00
|
|
|
private boolean canHaveSafetyNumber;
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle icicle) {
|
2017-09-21 01:14:28 +00:00
|
|
|
Log.w(TAG, "onCreate (fragment)");
|
2015-06-09 14:37:20 +00:00
|
|
|
super.onCreate(icicle);
|
|
|
|
|
2016-08-16 03:23:56 +00:00
|
|
|
initializeRecipients();
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2016-12-11 18:04:57 +00:00
|
|
|
this.canHaveSafetyNumber = getActivity().getIntent()
|
|
|
|
.getBooleanExtra(RecipientPreferenceActivity.CAN_HAVE_SAFETY_NUMBER_EXTRA, false);
|
2016-08-25 01:51:45 +00:00
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
this.findPreference(PREFERENCE_TONE)
|
|
|
|
.setOnPreferenceChangeListener(new RingtoneChangeListener());
|
|
|
|
this.findPreference(PREFERENCE_VIBRATE)
|
|
|
|
.setOnPreferenceChangeListener(new VibrateChangeListener());
|
|
|
|
this.findPreference(PREFERENCE_MUTED)
|
|
|
|
.setOnPreferenceClickListener(new MuteClickedListener());
|
|
|
|
this.findPreference(PREFERENCE_BLOCK)
|
|
|
|
.setOnPreferenceClickListener(new BlockClickedListener());
|
2015-06-24 20:17:58 +00:00
|
|
|
this.findPreference(PREFERENCE_COLOR)
|
|
|
|
.setOnPreferenceChangeListener(new ColorChangeListener());
|
2017-09-21 01:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey) {
|
2017-10-04 00:05:52 +00:00
|
|
|
Log.w(TAG, "onCreatePreferences...");
|
2017-09-21 01:14:28 +00:00
|
|
|
addPreferencesFromResource(R.xml.recipient_preferences);
|
|
|
|
}
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2017-08-01 15:56:00 +00:00
|
|
|
setSummaries(recipient);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
2015-06-23 01:18:06 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2015-06-23 01:30:42 +00:00
|
|
|
super.onDestroy();
|
2017-08-01 15:56:00 +00:00
|
|
|
this.recipient.removeListener(this);
|
2016-08-16 03:23:56 +00:00
|
|
|
getActivity().unregisterReceiver(staleReceiver);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeRecipients() {
|
2017-08-22 01:32:38 +00:00
|
|
|
this.recipient = Recipient.from(getActivity(),
|
|
|
|
(Address)getArguments().getParcelable(ADDRESS_EXTRA),
|
|
|
|
true);
|
2016-08-16 03:23:56 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
this.recipient.addListener(this);
|
2016-08-16 03:23:56 +00:00
|
|
|
|
|
|
|
this.staleReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2017-08-01 15:56:00 +00:00
|
|
|
recipient.removeListener(RecipientPreferenceFragment.this);
|
2017-08-22 01:32:38 +00:00
|
|
|
recipient = Recipient.from(getActivity(), (Address)getArguments().getParcelable(ADDRESS_EXTRA), true);
|
2017-08-01 15:56:00 +00:00
|
|
|
onModified(recipient);
|
2016-08-16 03:23:56 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
IntentFilter intentFilter = new IntentFilter();
|
|
|
|
intentFilter.addAction(GroupDatabase.DATABASE_UPDATE_ACTION);
|
2017-08-22 01:32:38 +00:00
|
|
|
intentFilter.addAction(Recipient.RECIPIENT_CLEAR_ACTION);
|
2016-08-16 03:23:56 +00:00
|
|
|
|
|
|
|
getActivity().registerReceiver(staleReceiver, intentFilter);
|
2015-06-23 01:18:06 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
private void setSummaries(Recipient recipient) {
|
2015-06-25 18:59:36 +00:00
|
|
|
CheckBoxPreference mutePreference = (CheckBoxPreference) this.findPreference(PREFERENCE_MUTED);
|
|
|
|
AdvancedRingtonePreference ringtonePreference = (AdvancedRingtonePreference) this.findPreference(PREFERENCE_TONE);
|
|
|
|
ListPreference vibratePreference = (ListPreference) this.findPreference(PREFERENCE_VIBRATE);
|
2017-09-21 01:14:28 +00:00
|
|
|
ColorPickerPreference colorPreference = (ColorPickerPreference) this.findPreference(PREFERENCE_COLOR);
|
2015-06-25 18:59:36 +00:00
|
|
|
Preference blockPreference = this.findPreference(PREFERENCE_BLOCK);
|
2017-09-21 01:14:28 +00:00
|
|
|
Preference identityPreference = this.findPreference(PREFERENCE_IDENTITY);
|
2017-10-04 00:05:52 +00:00
|
|
|
PreferenceCategory privacyCategory = (PreferenceCategory)this.findPreference("privacy_settings");
|
|
|
|
PreferenceCategory divider = (PreferenceCategory)this.findPreference("divider");
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
mutePreference.setChecked(recipient.isMuted());
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
final Uri toneUri = recipient.getRingtone();
|
2015-12-24 14:27:10 +00:00
|
|
|
|
|
|
|
if (toneUri == null) {
|
|
|
|
ringtonePreference.setSummary(R.string.preferences__default);
|
2017-10-09 01:46:09 +00:00
|
|
|
ringtonePreference.setCurrentRingtone(Uri.parse(TextSecurePreferences.getNotificationRingtone(getContext())));
|
2015-12-24 14:27:10 +00:00
|
|
|
} else if (toneUri.toString().isEmpty()) {
|
|
|
|
ringtonePreference.setSummary(R.string.preferences__silent);
|
|
|
|
ringtonePreference.setCurrentRingtone(null);
|
|
|
|
} else {
|
|
|
|
Ringtone tone = RingtoneManager.getRingtone(getActivity(), toneUri);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
if (tone != null) {
|
|
|
|
ringtonePreference.setSummary(tone.getTitle(getActivity()));
|
2015-12-24 14:27:10 +00:00
|
|
|
ringtonePreference.setCurrentRingtone(toneUri);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
if (recipient.getVibrate() == VibrateState.DEFAULT) {
|
2015-06-09 14:37:20 +00:00
|
|
|
vibratePreference.setSummary(R.string.preferences__default);
|
2015-06-11 20:26:13 +00:00
|
|
|
vibratePreference.setValueIndex(0);
|
2017-08-01 15:56:00 +00:00
|
|
|
} else if (recipient.getVibrate() == VibrateState.ENABLED) {
|
2015-06-12 09:08:21 +00:00
|
|
|
vibratePreference.setSummary(R.string.RecipientPreferenceActivity_enabled);
|
2015-06-11 20:26:13 +00:00
|
|
|
vibratePreference.setValueIndex(1);
|
2015-06-09 14:37:20 +00:00
|
|
|
} else {
|
2015-06-12 09:08:21 +00:00
|
|
|
vibratePreference.setSummary(R.string.RecipientPreferenceActivity_disabled);
|
2015-06-11 20:26:13 +00:00
|
|
|
vibratePreference.setValueIndex(2);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
if (recipient.isGroupRecipient()) {
|
2017-10-04 00:05:52 +00:00
|
|
|
if (colorPreference != null) colorPreference.setVisible(false);
|
|
|
|
if (blockPreference != null) blockPreference.setVisible(false);
|
|
|
|
if (identityPreference != null) identityPreference.setVisible(false);
|
|
|
|
if (privacyCategory != null) privacyCategory.setVisible(false);
|
|
|
|
if (divider != null) divider.setVisible(false);
|
2015-06-09 14:37:20 +00:00
|
|
|
} else {
|
2017-09-21 01:14:28 +00:00
|
|
|
colorPreference.setColors(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(getActivity()));
|
|
|
|
colorPreference.setColor(recipient.getColor().toActionBarColor(getActivity()));
|
2015-09-29 21:26:37 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
if (recipient.isBlocked()) blockPreference.setTitle(R.string.RecipientPreferenceActivity_unblock);
|
2017-09-21 01:14:28 +00:00
|
|
|
else blockPreference.setTitle(R.string.RecipientPreferenceActivity_block);
|
2016-08-25 01:51:45 +00:00
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
IdentityUtil.getRemoteIdentityKey(getActivity(), recipient).addListener(new ListenableFuture.Listener<Optional<IdentityRecord>>() {
|
2016-08-25 01:51:45 +00:00
|
|
|
@Override
|
2017-06-07 01:03:09 +00:00
|
|
|
public void onSuccess(Optional<IdentityRecord> result) {
|
2016-08-25 01:51:45 +00:00
|
|
|
if (result.isPresent()) {
|
2016-10-08 21:04:33 +00:00
|
|
|
if (identityPreference != null) identityPreference.setOnPreferenceClickListener(new IdentityClickedListener(result.get()));
|
|
|
|
if (identityPreference != null) identityPreference.setEnabled(true);
|
2016-12-11 18:04:57 +00:00
|
|
|
} else if (canHaveSafetyNumber) {
|
|
|
|
if (identityPreference != null) identityPreference.setSummary(R.string.RecipientPreferenceActivity_available_once_a_message_has_been_sent_or_received);
|
|
|
|
if (identityPreference != null) identityPreference.setEnabled(false);
|
2016-08-25 01:51:45 +00:00
|
|
|
} else {
|
2016-10-08 21:04:33 +00:00
|
|
|
if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
|
2016-08-25 01:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(ExecutionException e) {
|
2016-10-08 21:04:33 +00:00
|
|
|
if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
|
2016-08-25 01:51:45 +00:00
|
|
|
}
|
|
|
|
});
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-01 15:56:00 +00:00
|
|
|
public void onModified(final Recipient recipient) {
|
2017-09-10 06:46:48 +00:00
|
|
|
Util.runOnMain(() -> setSummaries(recipient));
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private class RingtoneChangeListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
2017-09-21 01:14:28 +00:00
|
|
|
Uri value = (Uri)newValue;
|
2015-06-09 14:37:20 +00:00
|
|
|
|
2017-09-21 01:14:28 +00:00
|
|
|
if (Settings.System.DEFAULT_NOTIFICATION_URI.equals(value)) {
|
|
|
|
value = null;
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
new AsyncTask<Uri, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Uri... params) {
|
2017-08-22 01:47:37 +00:00
|
|
|
DatabaseFactory.getRecipientDatabase(getActivity())
|
2017-08-01 15:56:00 +00:00
|
|
|
.setRingtone(recipient, params[0]);
|
2015-06-09 14:37:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
2017-09-21 01:14:28 +00:00
|
|
|
}.execute(value);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class VibrateChangeListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
|
|
int value = Integer.parseInt((String) newValue);
|
|
|
|
final VibrateState vibrateState = VibrateState.fromId(value);
|
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2017-08-22 01:47:37 +00:00
|
|
|
DatabaseFactory.getRecipientDatabase(getActivity())
|
2017-08-01 15:56:00 +00:00
|
|
|
.setVibrate(recipient, vibrateState);
|
2015-06-09 14:37:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-24 20:17:58 +00:00
|
|
|
private class ColorChangeListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
2015-06-30 16:16:05 +00:00
|
|
|
final int value = (Integer) newValue;
|
2015-07-01 19:22:42 +00:00
|
|
|
final MaterialColor selectedColor = MaterialColors.CONVERSATION_PALETTE.getByColor(getActivity(), value);
|
2017-08-01 15:56:00 +00:00
|
|
|
final MaterialColor currentColor = recipient.getColor();
|
2015-06-30 16:16:05 +00:00
|
|
|
|
2015-07-01 19:22:42 +00:00
|
|
|
if (selectedColor == null) return true;
|
2015-06-24 20:17:58 +00:00
|
|
|
|
2015-06-30 16:16:05 +00:00
|
|
|
if (preference.isEnabled() && !currentColor.equals(selectedColor)) {
|
2015-06-24 20:17:58 +00:00
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2016-08-26 23:53:23 +00:00
|
|
|
Context context = getActivity();
|
2017-08-22 17:44:04 +00:00
|
|
|
DatabaseFactory.getRecipientDatabase(context).setColor(recipient, selectedColor);
|
2016-08-26 23:53:23 +00:00
|
|
|
|
2017-08-22 17:44:04 +00:00
|
|
|
if (recipient.resolve().getRegistered() == RecipientDatabase.RegisteredState.REGISTERED) {
|
2016-10-05 23:57:52 +00:00
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
2017-08-01 15:56:00 +00:00
|
|
|
.add(new MultiDeviceContactUpdateJob(context, recipient.getAddress()));
|
2016-10-05 23:57:52 +00:00
|
|
|
}
|
2015-06-24 20:17:58 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
private class MuteClickedListener implements Preference.OnPreferenceClickListener {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2017-08-01 15:56:00 +00:00
|
|
|
if (recipient.isMuted()) handleUnmute();
|
|
|
|
else handleMute();
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleMute() {
|
|
|
|
MuteDialog.show(getActivity(), new MuteDialog.MuteSelectionListener() {
|
|
|
|
@Override
|
|
|
|
public void onMuted(long until) {
|
2017-08-01 15:56:00 +00:00
|
|
|
setMuted(recipient, until);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
setSummaries(recipient);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleUnmute() {
|
2017-08-01 15:56:00 +00:00
|
|
|
setMuted(recipient, 0);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
private void setMuted(final Recipient recipient, final long until) {
|
|
|
|
recipient.setMuted(until);
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2017-08-22 01:47:37 +00:00
|
|
|
DatabaseFactory.getRecipientDatabase(getActivity())
|
2017-08-01 15:56:00 +00:00
|
|
|
.setMuted(recipient, until);
|
2015-06-09 14:37:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-29 21:26:37 +00:00
|
|
|
private class IdentityClickedListener implements Preference.OnPreferenceClickListener {
|
2016-08-25 01:51:45 +00:00
|
|
|
|
2017-06-07 01:03:09 +00:00
|
|
|
private final IdentityRecord identityKey;
|
2016-08-25 01:51:45 +00:00
|
|
|
|
2017-06-07 01:03:09 +00:00
|
|
|
private IdentityClickedListener(IdentityRecord identityKey) {
|
|
|
|
Log.w(TAG, "Identity record: " + identityKey);
|
2016-08-25 01:51:45 +00:00
|
|
|
this.identityKey = identityKey;
|
|
|
|
}
|
|
|
|
|
2015-09-29 21:26:37 +00:00
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
Intent verifyIdentityIntent = new Intent(getActivity(), VerifyIdentityActivity.class);
|
2017-08-01 15:56:00 +00:00
|
|
|
verifyIdentityIntent.putExtra(VerifyIdentityActivity.ADDRESS_EXTRA, recipient.getAddress());
|
2017-06-07 01:03:09 +00:00
|
|
|
verifyIdentityIntent.putExtra(VerifyIdentityActivity.IDENTITY_EXTRA, new IdentityKeyParcelable(identityKey.getIdentityKey()));
|
|
|
|
verifyIdentityIntent.putExtra(VerifyIdentityActivity.VERIFIED_EXTRA, identityKey.getVerifiedStatus() == IdentityDatabase.VerifiedStatus.VERIFIED);
|
2015-09-29 21:26:37 +00:00
|
|
|
startActivity(verifyIdentityIntent);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
private class BlockClickedListener implements Preference.OnPreferenceClickListener {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
2017-08-01 15:56:00 +00:00
|
|
|
if (recipient.isBlocked()) handleUnblock();
|
|
|
|
else handleBlock();
|
2015-06-09 14:37:20 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleBlock() {
|
2015-05-20 21:36:30 +00:00
|
|
|
new AlertDialog.Builder(getActivity())
|
2015-06-09 14:37:20 +00:00
|
|
|
.setTitle(R.string.RecipientPreferenceActivity_block_this_contact_question)
|
2016-09-17 15:00:11 +00:00
|
|
|
.setMessage(R.string.RecipientPreferenceActivity_you_will_no_longer_receive_messages_and_calls_from_this_contact)
|
2015-06-09 14:37:20 +00:00
|
|
|
.setCancelable(true)
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.setPositiveButton(R.string.RecipientPreferenceActivity_block, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2017-08-01 15:56:00 +00:00
|
|
|
setBlocked(recipient, true);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
}).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleUnblock() {
|
2015-05-20 21:36:30 +00:00
|
|
|
new AlertDialog.Builder(getActivity())
|
2015-06-09 14:37:20 +00:00
|
|
|
.setTitle(R.string.RecipientPreferenceActivity_unblock_this_contact_question)
|
2016-09-17 15:00:11 +00:00
|
|
|
.setMessage(R.string.RecipientPreferenceActivity_you_will_once_again_be_able_to_receive_messages_and_calls_from_this_contact)
|
2015-06-09 14:37:20 +00:00
|
|
|
.setCancelable(true)
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.setPositiveButton(R.string.RecipientPreferenceActivity_unblock, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2017-08-01 15:56:00 +00:00
|
|
|
setBlocked(recipient, false);
|
2015-06-09 14:37:20 +00:00
|
|
|
}
|
|
|
|
}).show();
|
|
|
|
}
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
private void setBlocked(final Recipient recipient, final boolean blocked) {
|
2015-06-09 14:37:20 +00:00
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
2016-08-26 23:53:23 +00:00
|
|
|
Context context = getActivity();
|
|
|
|
|
2017-08-22 01:47:37 +00:00
|
|
|
DatabaseFactory.getRecipientDatabase(context)
|
2017-08-01 15:56:00 +00:00
|
|
|
.setBlocked(recipient, blocked);
|
2016-08-26 23:53:23 +00:00
|
|
|
|
|
|
|
ApplicationContext.getInstance(context)
|
|
|
|
.getJobManager()
|
|
|
|
.add(new MultiDeviceBlockedUpdateJob(context));
|
2015-06-09 14:37:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|