mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
if sth. is entered in the contact list, add a link to create a new contact at the end of the contact list
This commit is contained in:
@@ -28,6 +28,7 @@ public class DcContact {
|
||||
public final static int DC_CONTACT_ID_SELF = 1;
|
||||
public final static int DC_CONTACT_ID_DEVICE = 2;
|
||||
public final static int DC_CONTACT_ID_LAST_SPECIAL = 9;
|
||||
public final static int DC_CONTACT_ID_NEW_CONTACT = -1; // used by the UI, not valid to the core
|
||||
|
||||
public DcContact(long contactCPtr) {
|
||||
this.contactCPtr = contactCPtr;
|
||||
|
||||
@@ -63,7 +63,7 @@ import java.util.Set;
|
||||
*
|
||||
*/
|
||||
public class ContactSelectionListFragment extends Fragment
|
||||
implements LoaderManager.LoaderCallbacks<int[]>
|
||||
implements LoaderManager.LoaderCallbacks<DcContactsLoader.Ret>
|
||||
{
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = ContactSelectionListFragment.class.getSimpleName();
|
||||
@@ -159,7 +159,6 @@ public class ContactSelectionListFragment extends Fragment
|
||||
private void initializeCursor() {
|
||||
ContactSelectionListAdapter adapter = new ContactSelectionListAdapter(getActivity(),
|
||||
GlideApp.with(this),
|
||||
null,
|
||||
new ListClickListener(),
|
||||
isMulti());
|
||||
selectedContacts = adapter.getSelectedContacts();
|
||||
@@ -212,13 +211,12 @@ public class ContactSelectionListFragment extends Fragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<int[]> onCreateLoader(int id, Bundle args) {
|
||||
String query = (cursorFilter==null||cursorFilter.isEmpty())? null : cursorFilter;
|
||||
return new DcContactsLoader(getActivity(), 0, query);
|
||||
public Loader<DcContactsLoader.Ret> onCreateLoader(int id, Bundle args) {
|
||||
return new DcContactsLoader(getActivity(), 0, cursorFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<int[]> loader, int[] data) {
|
||||
public void onLoadFinished(Loader<DcContactsLoader.Ret> loader, DcContactsLoader.Ret data) {
|
||||
swipeRefresh.setVisibility(View.VISIBLE);
|
||||
showContactsLayout.setVisibility(View.GONE);
|
||||
|
||||
@@ -233,7 +231,7 @@ public class ContactSelectionListFragment extends Fragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<int[]> loader) {
|
||||
public void onLoaderReset(Loader<DcContactsLoader.Ret> loader) {
|
||||
((ContactSelectionListAdapter) recyclerView.getAdapter()).changeData(null);
|
||||
fastScroller.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@@ -5,9 +5,13 @@ import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.b44t.messenger.DcContact;
|
||||
import com.b44t.messenger.DcContext;
|
||||
|
||||
import org.thoughtcrime.securesms.util.AsyncLoader;
|
||||
|
||||
public class DcContactsLoader extends AsyncLoader<int[]> {
|
||||
public class DcContactsLoader extends AsyncLoader<DcContactsLoader.Ret> {
|
||||
|
||||
private static final String TAG = DcContactsLoader.class.getName();
|
||||
|
||||
@@ -17,19 +21,30 @@ public class DcContactsLoader extends AsyncLoader<int[]> {
|
||||
public DcContactsLoader(Context context, int listflags, String query) {
|
||||
super(context);
|
||||
this.listflags = listflags;
|
||||
this.query = query;
|
||||
this.query = (query==null||query.isEmpty())? null : query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull
|
||||
int[] loadInBackground() {
|
||||
try {
|
||||
return DcHelper.getContext(getContext()).getContacts(listflags, query);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, e);
|
||||
DcContactsLoader.Ret loadInBackground() {
|
||||
DcContext dcContext = DcHelper.getContext(getContext());
|
||||
int[] ids = dcContext.getContacts(listflags, query);
|
||||
if(query!=null) {
|
||||
// show the "new" link also for partly typed e-mail addresses, so that the user knows he can continue
|
||||
if( dcContext.lookupContactIdByAddr(query)==0) {
|
||||
ids = ArrayUtils.appendInt(ids, DcContact.DC_CONTACT_ID_NEW_CONTACT);
|
||||
}
|
||||
}
|
||||
return new DcContactsLoader.Ret(ids, query);
|
||||
}
|
||||
|
||||
return new int[0];
|
||||
public class Ret {
|
||||
public int[] ids;
|
||||
public String query;
|
||||
|
||||
Ret(int[] ids, String query) {
|
||||
this.ids = ids;
|
||||
this.query = query;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.b44t.messenger.DcContact;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.RecyclerViewFastScroller.FastScrollAdapter;
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcContactsLoader;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.contacts.ContactSelectionListAdapter.HeaderViewHolder;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
@@ -67,6 +68,7 @@ public class ContactSelectionListAdapter extends RecyclerView.Adapter
|
||||
private final @NonNull Context context;
|
||||
private final @NonNull ApplicationDcContext dcContext;
|
||||
private @NonNull int[] dcContactList = new int[0];
|
||||
private String query;
|
||||
private final boolean multiSelect;
|
||||
private final LayoutInflater li;
|
||||
private final TypedArray drawables;
|
||||
@@ -80,7 +82,7 @@ public class ContactSelectionListAdapter extends RecyclerView.Adapter
|
||||
super(itemView);
|
||||
}
|
||||
|
||||
public abstract void bind(@NonNull GlideRequests glideRequests, DcContact contact, String name, String number, String label, int color, boolean multiSelect);
|
||||
public abstract void bind(@NonNull GlideRequests glideRequests, int type, DcContact contact, String name, String number, String label, int color, boolean multiSelect);
|
||||
public abstract void unbind(@NonNull GlideRequests glideRequests);
|
||||
public abstract void setChecked(boolean checked);
|
||||
}
|
||||
@@ -99,8 +101,8 @@ public class ContactSelectionListAdapter extends RecyclerView.Adapter
|
||||
return (ContactSelectionListItem) itemView;
|
||||
}
|
||||
|
||||
public void bind(@NonNull GlideRequests glideRequests, DcContact contact, String name, String addr, String label, int color, boolean multiSelect) {
|
||||
getView().set(glideRequests, contact, name, addr, label, color, multiSelect);
|
||||
public void bind(@NonNull GlideRequests glideRequests, int type, DcContact contact, String name, String addr, String label, int color, boolean multiSelect) {
|
||||
getView().set(glideRequests, type, contact, name, addr, label, color, multiSelect);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,7 +126,7 @@ public class ContactSelectionListAdapter extends RecyclerView.Adapter
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(@NonNull GlideRequests glideRequests, DcContact contact, String name, String number, String label, int color, boolean multiSelect) {
|
||||
public void bind(@NonNull GlideRequests glideRequests, int type, DcContact contact, String name, String number, String label, int color, boolean multiSelect) {
|
||||
this.label.setText(name);
|
||||
}
|
||||
|
||||
@@ -143,7 +145,6 @@ public class ContactSelectionListAdapter extends RecyclerView.Adapter
|
||||
|
||||
public ContactSelectionListAdapter(@NonNull Context context,
|
||||
@NonNull GlideRequests glideRequests,
|
||||
@Nullable Cursor cursor,
|
||||
@Nullable ItemClickListener clickListener,
|
||||
boolean multiSelect)
|
||||
{
|
||||
@@ -186,15 +187,29 @@ public class ContactSelectionListAdapter extends RecyclerView.Adapter
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
|
||||
|
||||
int id = dcContactList[i];
|
||||
DcContact dcContact = dcContext.getContact(id);
|
||||
String name = dcContact.getDisplayName();
|
||||
String addr = dcContact.getAddr();
|
||||
int type = id==DcContact.DC_CONTACT_ID_NEW_CONTACT? ContactsDatabase.NEW_TYPE : ContactsDatabase.NORMAL_TYPE;
|
||||
int color = drawables.getColor(0, 0xff000000);
|
||||
DcContact dcContact = null;
|
||||
String label = null;
|
||||
String name;
|
||||
String addr;
|
||||
|
||||
if(id==DcContact.DC_CONTACT_ID_NEW_CONTACT) {
|
||||
name = context.getString(R.string.contact_selection_list__unknown_contact);
|
||||
addr = query==null? "" : query;
|
||||
label = "\u21e2";
|
||||
}
|
||||
else {
|
||||
dcContact = id==DcContact.DC_CONTACT_ID_NEW_CONTACT? null : dcContext.getContact(id);
|
||||
name = dcContact.getDisplayName();
|
||||
addr = dcContact.getAddr();
|
||||
}
|
||||
|
||||
ViewHolder holder = (ViewHolder)viewHolder;
|
||||
holder.unbind(glideRequests);
|
||||
holder.bind(glideRequests, dcContact, name, addr, "", color, multiSelect);
|
||||
holder.bind(glideRequests, type, dcContact, name, addr, label, color, multiSelect);
|
||||
holder.setChecked(selectedContacts.contains(addr));
|
||||
}
|
||||
|
||||
@@ -261,8 +276,9 @@ public class ContactSelectionListAdapter extends RecyclerView.Adapter
|
||||
void onItemClick(ContactSelectionListItem item);
|
||||
}
|
||||
|
||||
public void changeData(int[] dcContactList) {
|
||||
this.dcContactList = dcContactList==null? new int[0] : dcContactList;
|
||||
public void changeData(DcContactsLoader.Ret loaderRet) {
|
||||
this.dcContactList = loaderRet==null? new int[0] : loaderRet.ids;
|
||||
this.query = loaderRet==null? null : loaderRet.query;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.contacts;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
@@ -57,22 +56,27 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientM
|
||||
ViewUtil.setTextViewGravityStart(this.nameView, getContext());
|
||||
}
|
||||
|
||||
public void set(@NonNull GlideRequests glideRequests, DcContact contact, String name, String number, String label, int color, boolean multiSelect) {
|
||||
public void set(@NonNull GlideRequests glideRequests, int type, DcContact contact, String name, String number, String label, int color, boolean multiSelect) {
|
||||
this.glideRequests = glideRequests;
|
||||
this.number = number;
|
||||
|
||||
this.recipient = DcHelper.getContext(getContext()).getRecipient(contact);
|
||||
this.recipient.addListener(this);
|
||||
|
||||
if (this.recipient.getName() != null) {
|
||||
name = this.recipient.getName();
|
||||
if(type == ContactsDatabase.NEW_TYPE) {
|
||||
this.recipient = null;
|
||||
this.contactPhotoImage.setAvatar(glideRequests, Recipient.from(getContext(), Address.UNKNOWN, true), false);
|
||||
}
|
||||
else {
|
||||
this.recipient = DcHelper.getContext(getContext()).getRecipient(contact);
|
||||
this.recipient.addListener(this);
|
||||
if (this.recipient.getName() != null) {
|
||||
name = this.recipient.getName();
|
||||
}
|
||||
}
|
||||
|
||||
this.nameView.setTextColor(color);
|
||||
this.numberView.setTextColor(color);
|
||||
this.contactPhotoImage.setAvatar(glideRequests, recipient, false);
|
||||
|
||||
setText(ContactsDatabase.NORMAL_TYPE, name, number, label);
|
||||
setText(type, name, number, label);
|
||||
|
||||
if (multiSelect) this.checkBox.setVisibility(View.VISIBLE);
|
||||
else this.checkBox.setVisibility(View.GONE);
|
||||
|
||||
Reference in New Issue
Block a user