mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
add contacts from system address book to contact database #46
This commit is contained in:
@@ -52,6 +52,7 @@ import org.thoughtcrime.securesms.components.RecyclerViewFastScroller;
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcContactsLoader;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||
import org.thoughtcrime.securesms.contacts.ContactSelectionListAdapter;
|
||||
import org.thoughtcrime.securesms.contacts.ContactSelectionListItem;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
@@ -192,8 +193,9 @@ public class ContactSelectionListFragment extends Fragment
|
||||
}
|
||||
};
|
||||
|
||||
swipeRefresh.setEnabled(getActivity().getIntent().getBooleanExtra(REFRESHABLE, true) &&
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN);
|
||||
// There shouldn't be the need to pull to refresh the contacts
|
||||
// swipeRefresh.setEnabled(getActivity().getIntent().getBooleanExtra(REFRESHABLE, true) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN);
|
||||
swipeRefresh.setEnabled(false);
|
||||
|
||||
return view;
|
||||
}
|
||||
@@ -349,6 +351,11 @@ public class ContactSelectionListFragment extends Fragment
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
try {
|
||||
DirectoryHelper.refreshDirectory(getContext(), false);
|
||||
ContactAccessor contactAccessor = ContactAccessor.getInstance();
|
||||
String allSystemContacts = contactAccessor.getAllSystemContactsAsString(getContext());
|
||||
if (!allSystemContacts.isEmpty()) {
|
||||
dcContext.addAddressBook(allSystemContacts);
|
||||
}
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.database.MergeCursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.provider.ContactsContract;
|
||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||
import android.provider.ContactsContract.Contacts;
|
||||
import android.provider.ContactsContract.PhoneLookup;
|
||||
@@ -56,6 +57,10 @@ import static org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
|
||||
|
||||
public class ContactAccessor {
|
||||
|
||||
private static final int CONTACT_CURSOR_NAME = 0;
|
||||
|
||||
private static final int CONTACT_CURSOR_MAIL = 1;
|
||||
|
||||
public static final String PUSH_COLUMN = "push";
|
||||
|
||||
private static final ContactAccessor instance = new ContactAccessor();
|
||||
@@ -79,7 +84,25 @@ public class ContactAccessor {
|
||||
}
|
||||
|
||||
public Cursor getAllSystemContacts(Context context) {
|
||||
return context.getContentResolver().query(Phone.CONTENT_URI, new String[] {Phone.NUMBER, Phone.DISPLAY_NAME, Phone.LABEL, Phone.PHOTO_URI, Phone._ID, Phone.LOOKUP_KEY}, null, null, null);
|
||||
return context.getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, new String[] {ContactsContract.Data.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.ADDRESS}, null, null, null);
|
||||
}
|
||||
|
||||
public String getAllSystemContactsAsString(Context context) {
|
||||
Cursor systemContactsCursor = getAllSystemContacts(context);
|
||||
StringBuilder result = new StringBuilder();
|
||||
List<String> mailList = new ArrayList<>();
|
||||
while (systemContactsCursor != null && systemContactsCursor.moveToNext()) {
|
||||
String name = systemContactsCursor.getString(CONTACT_CURSOR_NAME);
|
||||
String mail= systemContactsCursor.getString(CONTACT_CURSOR_MAIL);
|
||||
if (mail != null && !mail.isEmpty() && !mailList.contains(mail)) {
|
||||
mailList.add(mail);
|
||||
if (name.isEmpty()) {
|
||||
name = mail;
|
||||
}
|
||||
result.append(name).append("\n").append(mail).append("\n");
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public boolean isSystemContact(Context context, String number) {
|
||||
|
||||
Reference in New Issue
Block a user