From 1bdf106f84ea0693ccf40e9f1e86f747e3b7fb40 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 22 May 2019 14:07:26 +0200 Subject: [PATCH] add buttons to settings --- res/layout/profile_settings_item.xml | 15 ++++ res/values/strings.xml | 2 + .../securesms/ProfileSettingsAdapter.java | 81 ++++++++++++++++--- .../securesms/ProfileSettingsFragment.java | 2 +- .../securesms/ProfileSettingsItem.java | 29 +++++++ 5 files changed, 116 insertions(+), 13 deletions(-) create mode 100644 res/layout/profile_settings_item.xml create mode 100644 src/org/thoughtcrime/securesms/ProfileSettingsItem.java diff --git a/res/layout/profile_settings_item.xml b/res/layout/profile_settings_item.xml new file mode 100644 index 000000000..50039569e --- /dev/null +++ b/res/layout/profile_settings_item.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 2716282bf..6e3658612 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -76,6 +76,7 @@ Video Documents Contact + Verified contact Camera Location Gallery @@ -111,6 +112,7 @@ Send Toggle emoji keyboard Edit group + Group name and image Show map Show all locations Archive chat diff --git a/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java b/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java index 81fe38d6f..69e6e6275 100644 --- a/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java +++ b/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java @@ -30,6 +30,18 @@ import java.util.Map; public class ProfileSettingsAdapter extends RecyclerView.Adapter implements StickyHeaderAdapter { + public static final int SETTING_CONTACT_ADDR = 110; + public static final int SETTING_NEW_CHAT = 120; + public static final int SETTING_CONTACT_NAME = 130; + public static final int SETTING_ENCRYPTION = 140; + public static final int SETTING_BLOCK_CONTACT = 150; + + public static final int SETTING_GROUP_NAME_N_IMAGE = 210; + + public static final int SETTING_NOTIFY = 310; + public static final int SETTING_SOUND = 320; + public static final int SETTING_VIBRATE = 330; + private static final int MAX_CACHE_SIZE = 100; private final Map> recordCache = Collections.synchronizedMap(new LRUCache<>(MAX_CACHE_SIZE)); @@ -41,24 +53,37 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter private @NonNull ArrayList itemData = new ArrayList<>(); private int itemDataMemberCount; private DcChatlist itemDataSharedChats; + private DcContact itemDataContact; private final LayoutInflater layoutInflater; private final ItemClickListener clickListener; private final GlideRequests glideRequests; static class ItemData { - static final int TYPE_MEMBER = 0; - static final int TYPE_SHARED_CHAT = 1; + static final int TYPE_PRIMARY_SETTING = 1; + static final int TYPE_MEMBER = 2; + static final int TYPE_SHARED_CHAT = 3; + static final int TYPE_SECONDARY_SETTING = 4; int type; int contactId; int chatlistIndex; int settingsId; + String label; - ItemData(int type, int contactId, int chatlistIndex, int settingsId) { + ItemData(int type, int settingsId, String label) { + this(type, 0, 0, settingsId, label); + } + + ItemData(int type, int contactId, int chatlistIndex) { + this(type, contactId, chatlistIndex, 0, null); + } + + ItemData(int type, int contactId, int chatlistIndex, int settingsId, @Nullable String label) { this.type = type; this.contactId = contactId; this.chatlistIndex = chatlistIndex; this.settingsId = settingsId; + this.label = label; } }; @@ -120,11 +145,15 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter item.setNoHeaderPadding(); return new ViewHolder(item); } - else { + else if (viewType == ItemData.TYPE_SHARED_CHAT) { final ConversationListItem item = (ConversationListItem)layoutInflater.inflate(R.layout.conversation_list_item_view, parent, false); item.hideItemDivider(); return new ViewHolder(item); } + else { + final ProfileSettingsItem item = (ProfileSettingsItem)layoutInflater.inflate(R.layout.profile_settings_item, parent, false); + return new ViewHolder(item); + } } @Override @@ -163,7 +192,10 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter conversationListItem.bind(dcContext.getThreadRecord(summary, chat), itemDataSharedChats.getMsgId(chatlistIndex), summary, glideRequests, locale, Collections.emptySet(), false); - + } + else if(holder.itemView instanceof ProfileSettingsItem) { + ProfileSettingsItem profileSettingsItem = (ProfileSettingsItem) holder.itemView; + profileSettingsItem.set(itemData.get(i).label); } } @@ -197,35 +229,60 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter case ItemData.TYPE_SHARED_CHAT: txt = context.getString(R.string.profile_shared_chats); break; + case ItemData.TYPE_PRIMARY_SETTING: + if(itemDataContact!=null && itemDataContact.isVerified()) { + txt = context.getString(R.string.verified_contact); + } + else { + txt = context.getString(R.string.contact); + } + break; default: - txt = ""; + txt = context.getString(R.string.menu_settings); break; } viewHolder.textView.setText(txt); } - public void changeData(@Nullable int[] memberList, @Nullable DcChatlist sharedChats) { + public void changeData(@Nullable int[] memberList, @Nullable DcContact dcContact, @Nullable DcChatlist sharedChats, @Nullable DcChat dcChat) { itemData.clear(); itemDataMemberCount = 0; itemDataSharedChats = null; + itemDataContact = null; if (memberList!=null) { itemDataMemberCount = memberList.length; - itemData.add(new ItemData(ItemData.TYPE_MEMBER, DcContact.DC_CONTACT_ID_ADD_MEMBER, 0, 0)); - itemData.add(new ItemData(ItemData.TYPE_MEMBER, DcContact.DC_CONTACT_ID_QR_INVITE, 0, 0)); + itemData.add(new ItemData(ItemData.TYPE_MEMBER, DcContact.DC_CONTACT_ID_ADD_MEMBER, 0)); + itemData.add(new ItemData(ItemData.TYPE_MEMBER, DcContact.DC_CONTACT_ID_QR_INVITE, 0)); for (int i = 0; i < memberList.length; i++) { - itemData.add(new ItemData(ItemData.TYPE_MEMBER, memberList[i], 0, 0)); + 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))); } - else if (sharedChats!=null) { + 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_NEW_CHAT, context.getString(R.string.menu_new_chat))); itemDataSharedChats = sharedChats; int sharedChatsCnt = sharedChats.getCnt(); for (int i = 0; i < sharedChatsCnt; i++) { - itemData.add(new ItemData(ItemData.TYPE_SHARED_CHAT, 0, i, 0)); + itemData.add(new ItemData(ItemData.TYPE_SHARED_CHAT, 0, i)); } } + if(dcChat!=null) { + itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_NOTIFY, context.getString(R.string.pref_notifications))); + 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_ENCRYPTION, context.getString(R.string.profile_encryption))); + itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_BLOCK_CONTACT, context.getString(R.string.menu_block_contact))); + } + recordCache.clear(); notifyDataSetChanged(); } diff --git a/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java b/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java index ae017376a..259480338 100644 --- a/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java +++ b/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java @@ -80,6 +80,6 @@ public class ProfileSettingsFragment extends Fragment { } - adapter.changeData(memberList, sharedChats); + adapter.changeData(memberList, dcContact, sharedChats, dcChat); } } diff --git a/src/org/thoughtcrime/securesms/ProfileSettingsItem.java b/src/org/thoughtcrime/securesms/ProfileSettingsItem.java new file mode 100644 index 000000000..c14a029a0 --- /dev/null +++ b/src/org/thoughtcrime/securesms/ProfileSettingsItem.java @@ -0,0 +1,29 @@ +package org.thoughtcrime.securesms; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.LinearLayout; +import android.widget.TextView; + +public class ProfileSettingsItem extends LinearLayout { + + private TextView labelView; + + public ProfileSettingsItem(Context context) { + super(context); + } + + public ProfileSettingsItem(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + labelView = findViewById(R.id.label); + } + + public void set(String label) { + labelView.setText(label==null? "" : label); + } +}