mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
basically show the member list
This commit is contained in:
@@ -184,7 +184,8 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity {
|
||||
switch(tabId) {
|
||||
case TAB_SETTINGS:
|
||||
fragment = new ProfileSettingsFragment();
|
||||
args.putString(ProfileSettingsFragment.ADDRESS_EXTRA, getRecipient().getAddress().serialize());
|
||||
args.putInt(ProfileSettingsFragment.CHAT_ID_EXTRA, dcChat==null? -1 : chatId);
|
||||
args.putInt(ProfileSettingsFragment.CONTACT_ID_EXTRA, dcContact==null? -1 : contactId);
|
||||
args.putSerializable(ProfileSettingsFragment.LOCALE_EXTRA, dynamicLanguage.getCurrentLocale());
|
||||
break;
|
||||
|
||||
|
||||
@@ -0,0 +1,357 @@
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.b44t.messenger.DcContact;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcContactsLoader;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.contacts.ContactSelectionListItem;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.util.LRUCache;
|
||||
import org.thoughtcrime.securesms.util.StickyHeaderDecoration.StickyHeaderAdapter;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ProfileSettingsAdapter extends RecyclerView.Adapter
|
||||
implements StickyHeaderAdapter<ProfileSettingsAdapter.HeaderViewHolder>
|
||||
{
|
||||
private final static String TAG = ProfileSettingsAdapter.class.getSimpleName();
|
||||
|
||||
private static final int VIEW_TYPE_CONTACT = 0;
|
||||
private static final int VIEW_TYPE_DIVIDER = 1;
|
||||
|
||||
private final static int STYLE_ATTRIBUTES[] = new int[]{R.attr.contact_selection_push_user,
|
||||
R.attr.contact_selection_lay_user};
|
||||
|
||||
private static final int MAX_CACHE_SIZE = 100;
|
||||
|
||||
private final Map<Integer,SoftReference<DcContact>> recordCache =
|
||||
Collections.synchronizedMap(new LRUCache<Integer,SoftReference<DcContact>>(MAX_CACHE_SIZE));
|
||||
|
||||
private final @NonNull Context context;
|
||||
private final @NonNull ApplicationDcContext dcContext;
|
||||
private @NonNull int[] dcContactList = new int[0];
|
||||
private final boolean multiSelect;
|
||||
private final boolean longPressSelect;
|
||||
private final LayoutInflater li;
|
||||
private final ItemClickListener clickListener;
|
||||
private final GlideRequests glideRequests;
|
||||
private final Set<String> selectedContacts = new HashSet<>(); // TODO: maybe better use contact-id here
|
||||
private final SparseIntArray actionModeSelection = new SparseIntArray();
|
||||
|
||||
public ProfileSettingsAdapter(@NonNull Context context,
|
||||
@NonNull GlideRequests glideRequests,
|
||||
@Nullable ItemClickListener clickListener,
|
||||
boolean multiSelect,
|
||||
boolean longPressSelect)
|
||||
{
|
||||
super();
|
||||
this.context = context;
|
||||
this.dcContext = DcHelper.getContext(context);
|
||||
this.li = LayoutInflater.from(context);
|
||||
this.glideRequests = glideRequests;
|
||||
this.multiSelect = multiSelect;
|
||||
this.clickListener = clickListener;
|
||||
this.longPressSelect = longPressSelect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return dcContactList.length;
|
||||
}
|
||||
|
||||
private @NonNull DcContact getContact(int position) {
|
||||
if(position<0 || position>=dcContactList.length) {
|
||||
return new DcContact(0);
|
||||
}
|
||||
|
||||
final SoftReference<DcContact> reference = recordCache.get(position);
|
||||
if (reference != null) {
|
||||
final DcContact fromCache = reference.get();
|
||||
if (fromCache != null) {
|
||||
return fromCache;
|
||||
}
|
||||
}
|
||||
|
||||
final DcContact fromDb = dcContext.getContact(dcContactList[position]);
|
||||
recordCache.put(position, new SoftReference<>(fromDb));
|
||||
return fromDb;
|
||||
}
|
||||
|
||||
public void resetActionModeSelection() {
|
||||
actionModeSelection.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void selectAll() {
|
||||
actionModeSelection.clear();
|
||||
for(int index = 0; index < dcContactList.length; index++) {
|
||||
int value = dcContactList[index];
|
||||
if (value > 0) {
|
||||
actionModeSelection.put(index, value);
|
||||
}
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private boolean isActionModeEnabled() {
|
||||
return actionModeSelection.size() != 0;
|
||||
}
|
||||
|
||||
public abstract static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
|
||||
public abstract void bind(@NonNull GlideRequests glideRequests, int type, DcContact contact, String name, String number, String label, boolean multiSelect, boolean enabled);
|
||||
public abstract void unbind(@NonNull GlideRequests glideRequests);
|
||||
public abstract void setChecked(boolean checked);
|
||||
public abstract void setSelected(boolean enabled);
|
||||
public abstract void setEnabled(boolean enabled);
|
||||
}
|
||||
|
||||
public class ContactViewHolder extends ViewHolder {
|
||||
|
||||
ContactViewHolder(@NonNull final View itemView,
|
||||
@Nullable final ItemClickListener clickListener) {
|
||||
super(itemView);
|
||||
itemView.setOnClickListener(view -> {
|
||||
if (clickListener != null) {
|
||||
if (isActionModeEnabled()) {
|
||||
toggleSelection();
|
||||
clickListener.onItemClick(getView(), true);
|
||||
} else {
|
||||
clickListener.onItemClick(getView(), false);
|
||||
}
|
||||
}
|
||||
});
|
||||
itemView.setOnLongClickListener(view -> {
|
||||
if (clickListener != null) {
|
||||
int contactId = getContactId(getAdapterPosition());
|
||||
if (contactId > 0) {
|
||||
toggleSelection();
|
||||
clickListener.onItemLongClick(getView());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private int getContactId(int adapterPosition) {
|
||||
return ProfileSettingsAdapter.this.dcContactList[adapterPosition];
|
||||
}
|
||||
|
||||
private void toggleSelection() {
|
||||
if (!longPressSelect) {
|
||||
return;
|
||||
}
|
||||
int adapterPosition = getAdapterPosition();
|
||||
int contactId = getContactId(adapterPosition);
|
||||
boolean enabled = actionModeSelection.indexOfKey(adapterPosition) > -1;
|
||||
if (enabled) {
|
||||
ProfileSettingsAdapter.this.actionModeSelection.delete(adapterPosition);
|
||||
} else {
|
||||
ProfileSettingsAdapter.this.actionModeSelection.put(adapterPosition, contactId);
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public ContactSelectionListItem getView() {
|
||||
return (ContactSelectionListItem) itemView;
|
||||
}
|
||||
|
||||
public void bind(@NonNull GlideRequests glideRequests, int type, DcContact contact, String name, String addr, String label, boolean multiSelect, boolean enabled) {
|
||||
getView().set(glideRequests, type, contact, name, addr, label, multiSelect, enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind(@NonNull GlideRequests glideRequests) {
|
||||
getView().unbind(glideRequests);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChecked(boolean checked) {
|
||||
getView().setChecked(checked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(boolean enabled) {
|
||||
getView().setSelected(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
getView().setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DividerViewHolder extends ViewHolder {
|
||||
|
||||
private final TextView label;
|
||||
|
||||
DividerViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
this.label = itemView.findViewById(R.id.label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(@NonNull GlideRequests glideRequests, int type, DcContact contact, String name, String number, String label, boolean multiSelect, boolean enabled) {
|
||||
this.label.setText(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind(@NonNull GlideRequests glideRequests) {}
|
||||
|
||||
@Override
|
||||
public void setChecked(boolean checked) {}
|
||||
|
||||
@Override
|
||||
public void setSelected(boolean enabled) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static class HeaderViewHolder extends RecyclerView.ViewHolder {
|
||||
HeaderViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileSettingsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
if (viewType == VIEW_TYPE_CONTACT) {
|
||||
return new ContactViewHolder(li.inflate(R.layout.contact_selection_list_item, parent, false), clickListener);
|
||||
} else {
|
||||
return new DividerViewHolder(li.inflate(R.layout.contact_selection_list_divider, parent, false));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
|
||||
|
||||
int id = dcContactList[i];
|
||||
DcContact dcContact = null;
|
||||
String label = null;
|
||||
String name;
|
||||
String addr = null;
|
||||
boolean itemMultiSelect = multiSelect;
|
||||
|
||||
if (id == DcContact.DC_CONTACT_ID_NEW_CONTACT) {
|
||||
name = context.getString(R.string.group_add_members);
|
||||
itemMultiSelect = false;
|
||||
} else if (id == DcContact.DC_CONTACT_ID_NEW_GROUP) {
|
||||
name = context.getString(R.string.menu_new_group);
|
||||
} else if (id == DcContact.DC_CONTACT_ID_NEW_VERIFIED_GROUP) {
|
||||
name = context.getString(R.string.qrshow_title);
|
||||
} else {
|
||||
dcContact = getContact(i);
|
||||
name = dcContact.getDisplayName();
|
||||
addr = dcContact.getAddr();
|
||||
}
|
||||
|
||||
ViewHolder holder = (ViewHolder) viewHolder;
|
||||
holder.unbind(glideRequests);
|
||||
boolean enabled = true;
|
||||
if (dcContact == null) {
|
||||
holder.setSelected(false);
|
||||
holder.setEnabled(!isActionModeEnabled());
|
||||
if (isActionModeEnabled()) {
|
||||
enabled = false;
|
||||
}
|
||||
} else {
|
||||
boolean selected = actionModeSelection.indexOfValue(id) > -1;
|
||||
holder.setSelected(selected);
|
||||
}
|
||||
holder.bind(glideRequests, id, dcContact, name, addr, label, itemMultiSelect, enabled);
|
||||
holder.setChecked(selectedContacts.contains(addr));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int i) {
|
||||
return VIEW_TYPE_CONTACT;
|
||||
}
|
||||
|
||||
public Set<String> getSelectedContacts() {
|
||||
return selectedContacts;
|
||||
}
|
||||
|
||||
public SparseIntArray getActionModeSelection() {
|
||||
return actionModeSelection;
|
||||
}
|
||||
|
||||
public interface ItemClickListener {
|
||||
void onItemClick(ContactSelectionListItem item, boolean handleActionMode);
|
||||
|
||||
void onItemLongClick(ContactSelectionListItem view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getHeaderId(int position) {
|
||||
if (position < 0 || position >= getItemCount()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return Util.hashCode(getHeaderString(position));
|
||||
}
|
||||
|
||||
private @NonNull String getHeaderString(int position) {
|
||||
DcContact dcContact = getContact(position);
|
||||
String name = dcContact.getDisplayName();
|
||||
if (!TextUtils.isEmpty(name)) {
|
||||
String firstChar = name.trim().substring(0, 1).toUpperCase();
|
||||
if (Character.isLetterOrDigit(firstChar.codePointAt(0))) {
|
||||
return firstChar;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public HeaderViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
|
||||
return new HeaderViewHolder(LayoutInflater.from(context).inflate(R.layout.contact_selection_recyclerview_header, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindHeaderViewHolder(HeaderViewHolder viewHolder, int position) {
|
||||
((TextView)viewHolder.itemView).setText(getHeaderString(position));
|
||||
}
|
||||
|
||||
|
||||
public void changeData(@Nullable int[] contactList) {
|
||||
if(contactList!=null) {
|
||||
final int additionalItems = 1;
|
||||
dcContactList = new int[contactList.length + additionalItems];
|
||||
dcContactList[0] = DcContact.DC_CONTACT_ID_NEW_CONTACT;
|
||||
for (int i = 0; i < contactList.length; i++) {
|
||||
dcContactList[i + additionalItems] = contactList[i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
dcContactList = new int[0];
|
||||
}
|
||||
|
||||
recordCache.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
@@ -1,81 +1,73 @@
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.b44t.messenger.DcChat;
|
||||
import com.b44t.messenger.DcContact;
|
||||
import com.b44t.messenger.DcContext;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.CursorRecyclerViewAdapter;
|
||||
import org.thoughtcrime.securesms.database.loaders.ThreadMediaLoader;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class ProfileSettingsFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
public class ProfileSettingsFragment extends Fragment {
|
||||
|
||||
public static final String LOCALE_EXTRA = "locale_extra";
|
||||
public static final String ADDRESS_EXTRA = "address";
|
||||
public static final String CHAT_ID_EXTRA = "chat_id";
|
||||
public static final String CONTACT_ID_EXTRA = "contact_id";
|
||||
|
||||
protected RecyclerView recyclerView;
|
||||
private RecyclerView recyclerView;
|
||||
private ProfileSettingsAdapter adapter;
|
||||
|
||||
protected Recipient recipient;
|
||||
protected Locale locale;
|
||||
private Locale locale;
|
||||
private ApplicationDcContext dcContext;
|
||||
protected int chatId;
|
||||
private DcChat dcChat;
|
||||
private int contactId;
|
||||
private DcContact dcContact;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
|
||||
Locale locale = (Locale)getArguments().getSerializable(LOCALE_EXTRA);
|
||||
if (locale == null) throw new AssertionError();
|
||||
this.locale = locale;
|
||||
locale = (Locale)getArguments().getSerializable(LOCALE_EXTRA);
|
||||
if (locale == null) throw new AssertionError();
|
||||
chatId = getArguments().getInt(CHAT_ID_EXTRA, -1);
|
||||
contactId = getArguments().getInt(CONTACT_ID_EXTRA, -1);
|
||||
dcContext = DcHelper.getContext(getContext());
|
||||
|
||||
String address = getArguments().getString(ADDRESS_EXTRA);
|
||||
if (address == null) throw new AssertionError();
|
||||
this.recipient = Recipient.from(getContext(), Address.fromSerialized(address));
|
||||
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
// if given, the ids really belong together, this is checked in ProfileActivity
|
||||
if (contactId>0) { dcContact = dcContext.getContact(contactId); }
|
||||
if (chatId>0) { dcChat = dcContext.getChat(chatId); }
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.profile_settings_fragment, container, false);
|
||||
//ProfileDocumentsAdapter adapter = new ProfileDocumentsAdapter(getContext(), null, locale);
|
||||
View view = inflater.inflate(R.layout.profile_settings_fragment, container, false);
|
||||
adapter = new ProfileSettingsAdapter(getContext(), GlideApp.with(this), null, false, false);
|
||||
|
||||
this.recyclerView = ViewUtil.findById(view, R.id.recycler_view);
|
||||
|
||||
//this.recyclerView.setAdapter(adapter);
|
||||
this.recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
|
||||
recyclerView = ViewUtil.findById(view, R.id.recycler_view);
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
|
||||
//this.recyclerView.addItemDecoration(new StickyHeaderDecoration(adapter, false, true));
|
||||
this.recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
|
||||
//recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
|
||||
|
||||
if (chatId>0) {
|
||||
adapter.changeData(dcContext.getChatContacts(chatId));
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||
return new ThreadMediaLoader(getContext(), recipient.getAddress(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
||||
//((CursorRecyclerViewAdapter)this.recyclerView.getAdapter()).changeCursor(data);
|
||||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> loader) {
|
||||
((CursorRecyclerViewAdapter)this.recyclerView.getAdapter()).changeCursor(null);
|
||||
getActivity().invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user