diff --git a/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java b/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java index 5b1694fef..342deb253 100644 --- a/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java +++ b/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java @@ -257,7 +257,8 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter } if (dcContact!=null) { - itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_BLOCK_CONTACT, context.getString(R.string.menu_block_contact))); + itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_BLOCK_CONTACT, + context.getString(dcContact.isBlocked()? R.string.menu_unblock_contact : R.string.menu_block_contact))); } notifyDataSetChanged(); diff --git a/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java b/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java index b6d9f549b..6ebfec4e6 100644 --- a/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java +++ b/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java @@ -1,5 +1,6 @@ package org.thoughtcrime.securesms; +import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.Fragment; @@ -115,6 +116,12 @@ public class ProfileSettingsFragment extends Fragment case ProfileSettingsAdapter.SETTING_ENCRYPTION: onEncrInfo(); break; + case ProfileSettingsAdapter.SETTING_NEW_CHAT: + onNewChat(); + break; + case ProfileSettingsAdapter.SETTING_BLOCK_CONTACT: + onBlockContact(); + break; } } @@ -155,4 +162,43 @@ public class ProfileSettingsFragment extends Fragment .setNegativeButton(android.R.string.cancel, null) .show(); } + + private void onNewChat() { + DcContact dcContact = dcContext.getContact(contactId); + new AlertDialog.Builder(getActivity()) + .setMessage(getActivity().getString(R.string.ask_start_chat_with, dcContact.getNameNAddr())) + .setPositiveButton(android.R.string.ok, (dialog, which) -> { + int chatId = dcContext.createChatByContactId(dcContact.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(); + } + + private void onBlockContact() { + DcContact dcContact = dcContext.getContact(contactId); + if(dcContact.isBlocked()) { + 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) -> { + dcContext.blockContact(contactId, 0); + }).show(); + } + else { + 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) -> { + dcContext.blockContact(contactId, 1); + }).show(); + } + } }