diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 0058fca71..f570d7c97 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -225,10 +225,6 @@ android:clearTaskOnLaunch="true" android:finishOnTaskLaunch="true" /> - - diff --git a/res/xml/recipient_preferences.xml b/res/xml/recipient_preferences.xml deleted file mode 100644 index c668d1474..000000000 --- a/res/xml/recipient_preferences.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 2ffe1322f..bf0177670 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -546,14 +546,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } } -// private void handleConversationSettings() { -// if(chatId != DcChat.DC_CHAT_ID_DEADDROP) { -// Intent intent = new Intent(ConversationActivity.this, RecipientPreferenceActivity.class); -// intent.putExtra(RecipientPreferenceActivity.ADDRESS_EXTRA, recipient.getAddress()); -// startActivitySceneTransition(intent, titleView.findViewById(R.id.contact_photo_image), "avatar"); -// } -// } - private void handleUnmuteNotifications() { Prefs.setChatMutedUntil(this, chatId, 0); titleView.setTitle(glideRequests, dcChat); // update title-mute-icon diff --git a/src/org/thoughtcrime/securesms/GroupCreateActivity.java b/src/org/thoughtcrime/securesms/GroupCreateActivity.java index 8680403a8..bf7541e3c 100644 --- a/src/org/thoughtcrime/securesms/GroupCreateActivity.java +++ b/src/org/thoughtcrime/securesms/GroupCreateActivity.java @@ -1,20 +1,3 @@ -/* - * Copyright (C) 2014 Open Whisper Systems - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - package org.thoughtcrime.securesms; import android.app.Activity; @@ -34,7 +17,6 @@ import android.view.WindowManager; import android.widget.EditText; import android.widget.ImageView; import android.widget.ListView; -import android.widget.TextView; import android.widget.Toast; import com.b44t.messenger.DcContext; @@ -66,17 +48,10 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; -/** - * Activity to create and update groups - * - * @author Jake McGinty - */ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity implements OnRecipientDeletedListener, DcEventCenter.DcEventDelegate { - private final static String TAG = GroupCreateActivity.class.getSimpleName(); - public static final String EDIT_GROUP_CHAT_ID = "edit_group_chat_id"; public static final String GROUP_CREATE_VERIFIED_EXTRA = "group_create_verified"; @@ -92,7 +67,6 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity private EditText groupName; private ListView lv; private ImageView avatar; - private TextView creatingText; private Bitmap avatarBmp; private int groupChatId; private boolean isEdit; @@ -123,8 +97,8 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity initializeExistingGroup(); initializeResources(); - dcContext.eventCenter.addObserver(this, DcContext.DC_EVENT_CHAT_MODIFIED); - dcContext.eventCenter.addObserver(this, DcContext.DC_EVENT_CONTACTS_CHANGED); + dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CHAT_MODIFIED, this); + dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this); } @Override @@ -216,7 +190,6 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity lv = ViewUtil.findById(this, R.id.selected_contacts_list); avatar = ViewUtil.findById(this, R.id.avatar); groupName = ViewUtil.findById(this, R.id.group_name); - creatingText = ViewUtil.findById(this, R.id.creating_group_text); SelectedRecipientsAdapter adapter = new SelectedRecipientsAdapter(this); adapter.setOnRecipientDeletedListener(this); lv.setAdapter(adapter); diff --git a/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java b/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java deleted file mode 100644 index ba7f2811f..000000000 --- a/src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java +++ /dev/null @@ -1,574 +0,0 @@ -package org.thoughtcrime.securesms; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.content.Intent; -import android.graphics.Color; -import android.media.Ringtone; -import android.media.RingtoneManager; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.provider.Settings; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.design.widget.CollapsingToolbarLayout; -import android.support.v4.app.Fragment; -import android.support.v7.app.AlertDialog; -import android.support.v7.preference.CheckBoxPreference; -import android.support.v7.preference.ListPreference; -import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceCategory; -import android.support.v7.widget.Toolbar; -import android.util.Log; -import android.util.Pair; -import android.view.MenuItem; -import android.view.WindowManager; -import android.widget.EditText; -import android.widget.ImageView; -import android.widget.Toast; - -import com.b44t.messenger.DcChat; -import com.b44t.messenger.DcContact; -import com.b44t.messenger.DcContext; -import com.b44t.messenger.DcEventCenter; -import com.bumptech.glide.load.engine.DiskCacheStrategy; - -import org.thoughtcrime.securesms.connect.ApplicationDcContext; -import org.thoughtcrime.securesms.connect.DcHelper; -import org.thoughtcrime.securesms.database.Address; -import org.thoughtcrime.securesms.mms.GlideApp; -import org.thoughtcrime.securesms.mms.GlideRequests; -import org.thoughtcrime.securesms.permissions.Permissions; -import org.thoughtcrime.securesms.preferences.CorrectedPreferenceFragment; -import org.thoughtcrime.securesms.recipients.Recipient; -import org.thoughtcrime.securesms.util.DynamicLanguage; -import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme; -import org.thoughtcrime.securesms.util.DynamicTheme; -import org.thoughtcrime.securesms.util.Prefs; -import org.thoughtcrime.securesms.util.Prefs.VibrateState; -import org.thoughtcrime.securesms.util.Util; -import org.thoughtcrime.securesms.util.ViewUtil; - -@SuppressLint("StaticFieldLeak") -public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActivity implements DcEventCenter.DcEventDelegate -{ - private static final String TAG = RecipientPreferenceActivity.class.getSimpleName(); - - public static final String ADDRESS_EXTRA = "recipient_address"; - - 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_MESSAGE_VIBRATE = "pref_key_recipient_vibrate"; - private static final String PREFERENCE_BLOCK = "pref_key_recipient_block"; - private static final String PREFERENCE_ENCRYPTION = "pref_key_recipient_encryption_info"; - - private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme(); - private final DynamicLanguage dynamicLanguage = new DynamicLanguage(); - - private ImageView avatar; - private GlideRequests glideRequests; - private Address address; - private CollapsingToolbarLayout toolbarLayout; - - private ApplicationDcContext dcContext; - - private static final int REQUEST_CODE_PICK_RINGTONE = 1; - - @Override - public void onPreCreate() { - dynamicTheme.onCreate(this); - dynamicLanguage.onCreate(this); - } - - @Override - public void onCreate(Bundle instanceState, boolean ready) { - dcContext = DcHelper.getContext(this); - - setContentView(R.layout.recipient_preference_activity); - this.glideRequests = GlideApp.with(this); - this.address = getIntent().getParcelableExtra(ADDRESS_EXTRA); - - Recipient recipient = Recipient.from(this, address); - - initializeToolbar(); - setHeader(recipient); - - Bundle bundle = new Bundle(); - bundle.putParcelable(ADDRESS_EXTRA, address); - initFragment(R.id.preference_fragment, new RecipientPreferenceFragment(), null, bundle); - - dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this); - } - - @Override - protected void onDestroy() { - dcContext.eventCenter.removeObservers(this); - super.onDestroy(); - } - - @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 void handleEvent(int eventId, Object data1, Object data2) { - if(eventId==DcContext.DC_EVENT_CONTACTS_CHANGED) { - Recipient recipient = Recipient.from(this, address); - setHeader(recipient); - } - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - super.onOptionsItemSelected(item); - switch (item.getItemId()) { - case android.R.id.home: - onBackPressed(); - return true; - } - - return false; - } - - @Override - public void onBackPressed() { - finish(); - overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); - } - - private void initializeToolbar() { - this.toolbarLayout = ViewUtil.findById(this, R.id.collapsing_toolbar); - this.avatar = ViewUtil.findById(this, R.id.avatar); - - this.toolbarLayout.setExpandedTitleColor(getResources().getColor(R.color.white)); - this.toolbarLayout.setCollapsedTitleTextColor(getResources().getColor(R.color.white)); - - Toolbar toolbar = ViewUtil.findById(this, R.id.toolbar); - setSupportActionBar(toolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setLogo(null); - - 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); - } - } - - private void setHeader(@NonNull Recipient recipient) { - glideRequests.load(recipient.getContactPhoto(this)) - .fallback(recipient.getFallbackContactPhoto().asCallCard(this)) - .error(recipient.getFallbackContactPhoto().asCallCard(this)) - .diskCacheStrategy(DiskCacheStrategy.NONE) - .into(this.avatar); - - if (recipient.getContactPhoto(this) == null) this.avatar.setScaleType(ImageView.ScaleType.CENTER_INSIDE); - else this.avatar.setScaleType(ImageView.ScaleType.CENTER_CROP); - - this.avatar.setBackgroundColor(recipient.getFallbackAvatarColor(this)); - this.toolbarLayout.setTitle(recipient.toShortString()); - this.toolbarLayout.setContentScrimColor(recipient.getFallbackAvatarColor(this)); - } - - - // the fragment - ////////////////////////////////////////////////////////////////////////////////////////////////// - - public static class RecipientPreferenceFragment - extends CorrectedPreferenceFragment - implements DcEventCenter.DcEventDelegate - { - private ApplicationDcContext dcContext; - private Recipient profileRecipient; // the recipient the profile was opened for, may be a chat or a contact - private DcChat chatToEdit; // may be an invalid chat that returns 0 as id - private Recipient chatToEditRecipient; - private Recipient contactToEditRecipient; - - @Override - public void onCreate(Bundle icicle) { - super.onCreate(icicle); - - dcContext = DcHelper.getContext(getActivity()); - profileRecipient = Recipient.from(getActivity(), getArguments().getParcelable(ADDRESS_EXTRA)); - - - // set the recipient to edit as the chat. - // when the profile shows a contact, this is _not_ the contact but the chat with the contact (if exists) - int chatToEditId = profileRecipient.getAddress().isDcChat()? profileRecipient.getAddress().getDcChatId() : 0; - if(chatToEditId==0 && profileRecipient.getAddress().isDcContact()) { - chatToEditId = dcContext.getChatIdByContactId(profileRecipient.getAddress().getDcContactId()); - } - chatToEdit = dcContext.getChat(chatToEditId); - chatToEditRecipient = Recipient.from(getActivity(), Address.fromChat(chatToEditId)); - - // set the recipent really to edit as the contact - int contactToEditId = profileRecipient.getAddress().isDcContact()? profileRecipient.getAddress().getDcContactId() : 0; - if(contactToEditId==0 && !chatToEdit.isGroup() ) { - int members[] = dcContext.getChatContacts(chatToEdit.getId()); - if(members.length>=1) { - contactToEditId = members[0]; - } - } - contactToEditRecipient = Recipient.from(getActivity(), Address.fromContact(contactToEditId)); - - - this.findPreference(PREFERENCE_MESSAGE_TONE) - .setOnPreferenceChangeListener(new RingtoneChangeListener()); - this.findPreference(PREFERENCE_MESSAGE_TONE) - .setOnPreferenceClickListener(new RingtoneClickedListener()); - this.findPreference(PREFERENCE_MESSAGE_VIBRATE) - .setOnPreferenceChangeListener(new VibrateChangeListener()); - this.findPreference(PREFERENCE_MUTED) - .setOnPreferenceClickListener(new MuteClickedListener()); - this.findPreference(PREFERENCE_BLOCK) - .setOnPreferenceClickListener(new BlockClickedListener()); - - dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this); - } - - @Override - public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey) { - Log.w(TAG, "onCreatePreferences..."); - addPreferencesFromResource(R.xml.recipient_preferences); - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { - Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults); - } - - @Override - public void onResume() { - super.onResume(); - setSummaries(); - } - - @Override - public void onDestroy() { - dcContext.eventCenter.removeObservers(this); - super.onDestroy(); - } - - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == REQUEST_CODE_PICK_RINGTONE && resultCode == RESULT_OK && data != null) { - Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); - - findPreference(PREFERENCE_MESSAGE_TONE).getOnPreferenceChangeListener().onPreferenceChange(findPreference(PREFERENCE_MESSAGE_TONE), uri); - } - } - - private void setSummaries() { - - // chat settings - PreferenceCategory notificationCategory = (PreferenceCategory)this.findPreference("notification_settings"); - CheckBoxPreference mutePreference = (CheckBoxPreference) this.findPreference(PREFERENCE_MUTED); - Preference ringtoneMessagePreference = this.findPreference(PREFERENCE_MESSAGE_TONE); - ListPreference vibrateMessagePreference = (ListPreference) this.findPreference(PREFERENCE_MESSAGE_VIBRATE); - - // contact settings - PreferenceCategory contactInfoCategory = (PreferenceCategory) this.findPreference("contact_info"); - PreferenceCategory contactInfoDivider = (PreferenceCategory) this.findPreference("contact_divider"); - Preference addrPreference = this.findPreference("pref_key_recipient_addr"); - Preference encryptionPreference = this.findPreference(PREFERENCE_ENCRYPTION); - Preference editNamePreference = this.findPreference("pref_key_recipient_edit_name"); - Preference blockPreference = this.findPreference(PREFERENCE_BLOCK); - Preference newChatPreference = this.findPreference("pref_key_new_chat"); - - - editNamePreference.setOnPreferenceClickListener(new EditContactNameListener()); - encryptionPreference.setOnPreferenceClickListener(new ShowEncrInfoListener()); - - mutePreference.setChecked(Prefs.isChatMuted(getContext(), chatToEdit.getId())); - - ringtoneMessagePreference.setSummary(getRingtoneSummary(getContext(), chatToEditRecipient.getMessageRingtone())); - - VibrateState vibrateState = Prefs.getChatVibrate(getContext(), chatToEdit.getId()); - Pair vibrateMessageSummary = getVibrateSummary(getContext(), vibrateState); - - vibrateMessagePreference.setSummary(vibrateMessageSummary.first); - vibrateMessagePreference.setValueIndex(vibrateMessageSummary.second); - - if (chatToEdit.getId()!=0 && chatToEdit.isGroup()) { - // group - if (contactInfoCategory != null) contactInfoCategory.setVisible(false); - if (addrPreference != null) addrPreference.setVisible(false); - if (encryptionPreference != null) encryptionPreference.setVisible(false); - if (editNamePreference != null) editNamePreference.setVisible(false); // group name is currently somewhere else ... - if (blockPreference != null) blockPreference.setVisible(false); - if (newChatPreference != null) newChatPreference.setVisible(false); - - if (contactInfoDivider != null) contactInfoDivider.setVisible(false); - } - else { - // contact view - DcContact contact = getProfileContact(); - String address = contact.getAddr(); - addrPreference.setTitle(address); - addrPreference.setOnPreferenceClickListener(preference -> { - new AlertDialog.Builder(getContext()) - .setTitle(address) - .setItems(new CharSequence[]{ - getContext().getString(R.string.menu_copy_to_clipboard) - }, - (dialogInterface, i) -> { - Util.writeTextToClipboard(getContext(), address); - Toast.makeText(getContext(), getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show(); - }) - .setNegativeButton(R.string.cancel, null) - .show(); - return false; - }); - - newChatPreference.setOnPreferenceClickListener(preference -> { - new AlertDialog.Builder(getActivity()) - .setMessage(getActivity().getString(R.string.ask_start_chat_with, contact.getNameNAddr())) - .setPositiveButton(android.R.string.ok, (dialog, which) -> { - int chatId = dcContext.createChatByContactId(contact.getId()); - if (chatId != 0) { - Intent intent = new Intent(getActivity(), ConversationActivity.class); - intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId); - getActivity().startActivity(intent); - getActivity().finish(); - } - }) - .setNegativeButton(R.string.cancel, null) - .show(); - return false; - }); - - if (contactToEditRecipient.isBlocked()) blockPreference.setTitle(R.string.menu_unblock_contact); - else blockPreference.setTitle(R.string.menu_block_contact); - - if(chatToEdit.getId()==0) { - mutePreference.setVisible(false); - ringtoneMessagePreference.setVisible(false); - vibrateMessagePreference.setVisible(false); - notificationCategory.setVisible(false); - } - } - } - - private DcContact getProfileContact() { - if(profileRecipient.getAddress().isDcContact()) { - return dcContext.getContact(profileRecipient.getAddress().getDcContactId()); - } - else if(profileRecipient.getAddress().isDcChat()) { - int members[] = dcContext.getChatContacts(profileRecipient.getAddress().getDcChatId()); - if(members.length>=1) { - return dcContext.getContact(members[0]); - } - } - return dcContext.getContact(0); - } - - private @NonNull String getRingtoneSummary(@NonNull Context context, @Nullable Uri ringtone) { - if (ringtone == null) { - return context.getString(R.string.def); - } else if (ringtone.toString().isEmpty()) { - return context.getString(R.string.pref_silent); - } else { - Ringtone tone = RingtoneManager.getRingtone(getActivity(), ringtone); - - if (tone != null) { - return tone.getTitle(context); - } - } - - return context.getString(R.string.def); - } - - private @NonNull Pair getVibrateSummary(@NonNull Context context, @NonNull VibrateState vibrateState) { - if (vibrateState == VibrateState.DEFAULT) { - return new Pair<>(context.getString(R.string.def), 0); - } else if (vibrateState == VibrateState.ENABLED) { - return new Pair<>(context.getString(R.string.on), 1); - } else { - return new Pair<>(context.getString(R.string.off), 2); - } - } - - @Override - public void handleEvent(int eventId, Object data1, Object data2) { - if(eventId==DcContext.DC_EVENT_CONTACTS_CHANGED) { - setSummaries(); - } - } - - private class RingtoneChangeListener implements Preference.OnPreferenceChangeListener { - - RingtoneChangeListener() { - } - - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - Uri value = (Uri)newValue; - - Uri defaultValue = Prefs.getNotificationRingtone(getContext()); - - if (defaultValue.equals(value)) value = null; - else if (value == null) value = Uri.EMPTY; - - Prefs.setChatRingtone(getContext(), chatToEdit.getId(), value); - - return false; - } - } - - private class RingtoneClickedListener implements Preference.OnPreferenceClickListener { - - RingtoneClickedListener() { - } - - @Override - public boolean onPreferenceClick(Preference preference) { - Uri current = chatToEditRecipient.getMessageRingtone(); - Uri defaultUri = Prefs.getNotificationRingtone(getContext()); - - if (current == null) current = Settings.System.DEFAULT_NOTIFICATION_URI; - else if (current.toString().isEmpty()) current = null; - - Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, defaultUri); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, current); - - startActivityForResult(intent, REQUEST_CODE_PICK_RINGTONE); - - return true; - } - } - - private class VibrateChangeListener implements Preference.OnPreferenceChangeListener { - - VibrateChangeListener() { - } - - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - int value = Integer.parseInt((String) newValue); - final VibrateState vibrateState = VibrateState.fromId(value); - - Prefs.setChatVibrate(getContext(), chatToEdit.getId(), vibrateState); - - return false; - } - } - - private class MuteClickedListener implements Preference.OnPreferenceClickListener { - @Override - public boolean onPreferenceClick(Preference preference) { - if (Prefs.isChatMuted(getContext(), chatToEdit.getId())) { - handleUnmute(); - } - else { - handleMute(); - } - - return true; - } - - private void handleMute() { - MuteDialog.show(getActivity(), until -> setMuted(until)); - } - - private void handleUnmute() { - setMuted(0); - } - - private void setMuted(final long until) { - if(chatToEditRecipient.getAddress().isDcChat()) { - Prefs.setChatMutedUntil(getActivity(), chatToEditRecipient.getAddress().getDcChatId(), until); - setSummaries(); - } - } - } - - private class ShowEncrInfoListener implements Preference.OnPreferenceClickListener { - @Override - public boolean onPreferenceClick(Preference preference) { - String info_str = dcContext.getContactEncrInfo(contactToEditRecipient.getAddress().getDcContactId()); - new AlertDialog.Builder(getActivity()) - .setMessage(info_str) - .setPositiveButton(android.R.string.ok, null) - .show(); - return true; - } - } - - private class EditContactNameListener implements Preference.OnPreferenceClickListener { - @Override - public boolean onPreferenceClick(Preference preference) { - final DcContact dcContact = dcContext.getContact(contactToEditRecipient.getAddress().getDcContactId()); - final EditText txt = new EditText(getActivity()); - txt.setText(dcContact.getName()); - new AlertDialog.Builder(getActivity()) - .setTitle(R.string.menu_edit_name) - .setView(txt) - .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> { - String newName = txt.getText().toString(); - dcContext.createContact(newName, dcContact.getAddr()); - }) - .setNegativeButton(android.R.string.cancel, null) - .show(); - return true; - } - } - - private class BlockClickedListener implements Preference.OnPreferenceClickListener { - @Override - public boolean onPreferenceClick(Preference preference) { - if (contactToEditRecipient.isBlocked()) handleUnblock(); - else handleBlock(); - - return true; - } - - private void handleBlock() { - new AlertDialog.Builder(getActivity()) - .setMessage(R.string.ask_block_contact) - .setCancelable(true) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(R.string.menu_block_contact, (dialog, which) -> { - setBlocked(true); - contactToEditRecipient.reload(getActivity()); - }).show(); - } - - private void handleUnblock() { - new AlertDialog.Builder(getActivity()) - .setMessage(R.string.ask_unblock_contact) - .setCancelable(true) - .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(R.string.menu_unblock_contact, (dialog, which) -> { - setBlocked(false); - contactToEditRecipient.reload(getActivity()); - }).show(); - } - - private void setBlocked(final boolean blocked) { - new AsyncTask() { - @Override - protected Void doInBackground(Void... params) { - dcContext.blockContact(contactToEditRecipient.getAddress().getDcContactId(), blocked ? 1 : 0); - return null; - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } - } -}