From f59687d6afb20a81d90045c7a106d51a56b3def2 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 23 May 2019 18:38:53 +0200 Subject: [PATCH] cleanup, move several options to the more visible menu --- res/menu/profile_chat.xml | 22 ++ res/menu/profile_contact.xml | 18 ++ res/values/strings.xml | 1 + .../securesms/ProfileActivity.java | 193 ++++++++++++++++-- .../securesms/ProfileSettingsAdapter.java | 26 +-- .../securesms/ProfileSettingsFragment.java | 122 ++--------- 6 files changed, 247 insertions(+), 135 deletions(-) create mode 100644 res/menu/profile_chat.xml create mode 100644 res/menu/profile_contact.xml diff --git a/res/menu/profile_chat.xml b/res/menu/profile_chat.xml new file mode 100644 index 000000000..0fcaa467e --- /dev/null +++ b/res/menu/profile_chat.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + diff --git a/res/menu/profile_contact.xml b/res/menu/profile_contact.xml new file mode 100644 index 000000000..bd7d92a5a --- /dev/null +++ b/res/menu/profile_contact.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 7319a468a..c54b2dea0 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -251,6 +251,7 @@ Shared chats Contact Group + Members Gallery Docs Links diff --git a/src/org/thoughtcrime/securesms/ProfileActivity.java b/src/org/thoughtcrime/securesms/ProfileActivity.java index 97c133566..9be7722f6 100644 --- a/src/org/thoughtcrime/securesms/ProfileActivity.java +++ b/src/org/thoughtcrime/securesms/ProfileActivity.java @@ -1,13 +1,22 @@ package org.thoughtcrime.securesms; +import android.app.Activity; +import android.content.Intent; +import android.media.RingtoneManager; +import android.net.Uri; import android.os.Bundle; +import android.provider.Settings; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; +import android.support.v7.app.AlertDialog; import android.support.v7.widget.Toolbar; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; +import android.widget.EditText; import com.b44t.messenger.DcChat; import com.b44t.messenger.DcContact; @@ -19,9 +28,11 @@ import org.thoughtcrime.securesms.connect.DcHelper; 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.ViewUtil; import java.util.ArrayList; +import java.util.List; public class ProfileActivity extends PassphraseRequiredActionBarActivity implements DcEventCenter.DcEventDelegate @@ -40,6 +51,8 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity public static final int TAB_LINKS = 40; public static final int TAB_MAP = 50; + private static final int REQUEST_CODE_PICK_RINGTONE = 1; + private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme(); private final DynamicLanguage dynamicLanguage = new DynamicLanguage(); @@ -73,6 +86,25 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + + if (chatId!=0) { + inflater.inflate(R.menu.profile_chat, menu); + if(!chatIsGroup) { + menu.findItem(R.id.edit_group_name_and_image).setVisible(false); + } + } + + if (isContactProfile()) { + inflater.inflate(R.menu.profile_contact, menu); + } + + super.onCreateOptionsMenu(menu); + return true; + } + @Override public void onResume() { super.onResume(); @@ -86,17 +118,6 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity super.onDestroy(); } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - super.onOptionsItemSelected(item); - - switch (item.getItemId()) { - case android.R.id.home: finish(); return true; - } - - return false; - } - @Override public void handleEvent(int eventId, Object data1, Object data2) { updateToolbar(); @@ -217,7 +238,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity return getString(contactId==DcContact.DC_CONTACT_ID_SELF? R.string.self : R.string.tab_contact); } else { - return getString(R.string.tab_group); + return getString(R.string.tab_members); } case TAB_GALLERY: @@ -237,4 +258,152 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity } } } + + + // handle events + // ========================================================================= + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + super.onOptionsItemSelected(item); + + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + case R.id.menu_mute_notifications: + onNotifyOnOff(); + break; + case R.id.menu_sound: + onSoundSettings(); + break; + case R.id.menu_vibrate: + onVibrateSettings(); + break; + case R.id.edit_group_name_and_image: + onEditGroupNameAndImage(); + break; + case R.id.edit_contact_name: + onEditContactName(); + break; + case R.id.show_encr_info: + onEncrInfo(); + break; + case R.id.block_contact: + onBlockContact(); + break; + } + + return false; + } + + public void onNotifyOnOff() { + if (Prefs.isChatMuted(this, chatId)) { + setMuted(0); + } + else { + MuteDialog.show(this, until -> setMuted(until)); + } + } + + private void setMuted(final long until) { + if(chatId!=0) { + Prefs.setChatMutedUntil(this, chatId, until); + } + } + + public void onSoundSettings() { + Uri current = dcContext.getRecipient(dcContext.getChat(chatId)).getMessageRingtone(); + Uri defaultUri = Prefs.getNotificationRingtone(this); + + 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); + } + + public void onVibrateSettings() { + new AlertDialog.Builder(this) + .setTitle(R.string.pref_vibrate) + .setItems(R.array.recipient_vibrate_entries, (dialog, which) -> { + Prefs.setChatVibrate(this, chatId, Prefs.VibrateState.fromId(which)); + }) + .show(); + } + + public void onEditGroupNameAndImage() { + Intent intent = new Intent(this, GroupCreateActivity.class); + intent.putExtra(GroupCreateActivity.EDIT_GROUP_CHAT_ID, chatId); + if (dcContext.getChat(chatId).isVerified()) { + intent.putExtra(GroupCreateActivity.GROUP_CREATE_VERIFIED_EXTRA, true); + } + startActivity(intent); + } + + public void onEditContactName() { + DcContact dcContact = dcContext.getContact(contactId); + final EditText txt = new EditText(this); + txt.setText(dcContact.getName()); + new AlertDialog.Builder(this) + .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(); + } + + public void onEncrInfo() { + String info_str = dcContext.getContactEncrInfo(contactId); + new AlertDialog.Builder(this) + .setMessage(info_str) + .setPositiveButton(android.R.string.ok, null) + .show(); + } + + public void onBlockContact() { + DcContact dcContact = dcContext.getContact(contactId); + if(dcContact.isBlocked()) { + new AlertDialog.Builder(this) + .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(this) + .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(); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode==REQUEST_CODE_PICK_RINGTONE && resultCode== Activity.RESULT_OK && data!=null) { + Uri value = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); + Uri defaultValue = Prefs.getNotificationRingtone(this); + + if (defaultValue.equals(value)) value = null; + else if (value == null) value = Uri.EMPTY; + + Prefs.setChatRingtone(this, chatId, value); + } + } + } diff --git a/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java b/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java index a0e79c76f..95774a30a 100644 --- a/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java +++ b/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java @@ -269,13 +269,13 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter for (int i = 0; i < memberList.length; i++) { itemData.add(new ItemData(ItemData.TYPE_MEMBER, memberList[i], 0)); } - itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_GROUP_NAME_N_IMAGE, context.getString(R.string.menu_group_name_and_image))); +// itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_GROUP_NAME_N_IMAGE, context.getString(R.string.menu_group_name_and_image))); } else if (sharedChats!=null && dcContact!=null) { itemDataContact = dcContact; itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_CONTACT_ADDR,dcContact.getAddr())); - itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_CONTACT_NAME, context.getString(R.string.menu_edit_name))); - itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_ENCRYPTION, context.getString(R.string.profile_encryption))); +// itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_CONTACT_NAME, context.getString(R.string.menu_edit_name))); +// itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_ENCRYPTION, context.getString(R.string.profile_encryption))); itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_NEW_CHAT, context.getString(R.string.menu_new_chat))); itemDataSharedChats = sharedChats; int sharedChatsCnt = sharedChats.getCnt(); @@ -284,17 +284,17 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter } } - if(dcChat!=null) { - itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_NOTIFY, - context.getString(Prefs.isChatMuted(context, dcChat.getId())? R.string.menu_unmute : R.string.menu_mute))); - itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_SOUND, context.getString(R.string.pref_sound))); - itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_VIBRATE, context.getString(R.string.pref_vibrate))); - } +// if(dcChat!=null) { +// itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_NOTIFY, +// context.getString(Prefs.isChatMuted(context, dcChat.getId())? R.string.menu_unmute : R.string.menu_mute))); +// itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_SOUND, context.getString(R.string.pref_sound))); +// itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_VIBRATE, context.getString(R.string.pref_vibrate))); +// } - if (dcContact!=null) { - 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))); - } +// if (dcContact!=null) { +// 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 0910e3240..6acdc79fb 100644 --- a/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java +++ b/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java @@ -6,7 +6,6 @@ import android.media.RingtoneManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.provider.Settings; import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; @@ -49,7 +48,6 @@ public class ProfileSettingsFragment extends Fragment public static final String CHAT_ID_EXTRA = "chat_id"; public static final String CONTACT_ID_EXTRA = "contact_id"; - private static final int REQUEST_CODE_PICK_RINGTONE = 1; private static final int REQUEST_CODE_PICK_CONTACT = 2; private RecyclerView list; @@ -128,7 +126,7 @@ public class ProfileSettingsFragment extends Fragment } - // handle the various events + // handle events // ========================================================================= @Override @@ -137,26 +135,26 @@ public class ProfileSettingsFragment extends Fragment case ProfileSettingsAdapter.SETTING_CONTACT_ADDR: onContactAddrClicked(); break; - case ProfileSettingsAdapter.SETTING_CONTACT_NAME: - onEditContactName(); - break; - case ProfileSettingsAdapter.SETTING_ENCRYPTION: - onEncrInfo(); - break; case ProfileSettingsAdapter.SETTING_NEW_CHAT: onNewChat(); break; + case ProfileSettingsAdapter.SETTING_CONTACT_NAME: + ((ProfileActivity)getActivity()).onEditContactName(); + break; + case ProfileSettingsAdapter.SETTING_ENCRYPTION: + ((ProfileActivity)getActivity()).onEncrInfo(); + break; case ProfileSettingsAdapter.SETTING_BLOCK_CONTACT: - onBlockContact(); + ((ProfileActivity)getActivity()).onBlockContact(); break; case ProfileSettingsAdapter.SETTING_NOTIFY: - onNotifyOnOff(); + ((ProfileActivity)getActivity()).onNotifyOnOff(); break; case ProfileSettingsAdapter.SETTING_SOUND: - onSoundSettings(); + ((ProfileActivity)getActivity()).onSoundSettings(); break; case ProfileSettingsAdapter.SETTING_VIBRATE: - onVibrateSettings(); + ((ProfileActivity)getActivity()).onVibrateSettings(); break; } } @@ -251,29 +249,6 @@ public class ProfileSettingsFragment extends Fragment .show(); } - private void onEncrInfo() { - String info_str = dcContext.getContactEncrInfo(contactId); - new AlertDialog.Builder(getActivity()) - .setMessage(info_str) - .setPositiveButton(android.R.string.ok, null) - .show(); - } - - private void onEditContactName() { - DcContact dcContact = dcContext.getContact(contactId); - 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(); - } - private void onNewChat() { DcContact dcContact = dcContext.getContact(contactId); new AlertDialog.Builder(getActivity()) @@ -291,70 +266,6 @@ public class ProfileSettingsFragment extends Fragment .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(); - } - } - - private void onNotifyOnOff() { - if (Prefs.isChatMuted(getContext(), chatId)) { - setMuted(0); - } - else { - MuteDialog.show(getActivity(), until -> setMuted(until)); - } - } - - private void setMuted(final long until) { - if(chatId!=0) { - Prefs.setChatMutedUntil(getActivity(), chatId, until); - update(); // in contrast to most other settings, muting is handled in the ui and does not result in an DC_EVENT - } - } - - private void onSoundSettings() { - Uri current = dcContext.getRecipient(dcContext.getChat(chatId)).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); - } - - private void onVibrateSettings() { - new AlertDialog.Builder(getContext()) - .setTitle(R.string.pref_vibrate) - .setItems(R.array.recipient_vibrate_entries, (dialog, which) -> { - Prefs.setChatVibrate(getContext(), chatId, Prefs.VibrateState.fromId(which)); - }) - .show(); - } - private class ActionModeCallback implements ActionMode.Callback { private int originalStatusBarColor; @@ -417,16 +328,7 @@ public class ProfileSettingsFragment extends Fragment @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (requestCode==REQUEST_CODE_PICK_RINGTONE && resultCode==Activity.RESULT_OK && data!=null) { - Uri value = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); - Uri defaultValue = Prefs.getNotificationRingtone(getContext()); - - if (defaultValue.equals(value)) value = null; - else if (value == null) value = Uri.EMPTY; - - Prefs.setChatRingtone(getContext(), chatId, value); - } - else if (requestCode==REQUEST_CODE_PICK_CONTACT && resultCode==Activity.RESULT_OK && data!=null) { + if (requestCode==REQUEST_CODE_PICK_CONTACT && resultCode==Activity.RESULT_OK && data!=null) { List selected = data.getStringArrayListExtra("contacts"); for (String addr : selected) { if (addr!=null) {