|
|
|
@@ -30,6 +30,18 @@ import java.util.Map;
|
|
|
|
|
public class ProfileSettingsAdapter extends RecyclerView.Adapter
|
|
|
|
|
implements StickyHeaderAdapter<ProfileSettingsAdapter.HeaderViewHolder>
|
|
|
|
|
{
|
|
|
|
|
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<Integer,SoftReference<DcContact>> recordCache =
|
|
|
|
|
Collections.synchronizedMap(new LRUCache<>(MAX_CACHE_SIZE));
|
|
|
|
@@ -41,24 +53,37 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter
|
|
|
|
|
private @NonNull ArrayList<ItemData> 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();
|
|
|
|
|
}
|
|
|
|
|