mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 13:58:40 +00:00
directory changes to use number instead of token, group ui progress
This commit is contained in:
@@ -20,7 +20,9 @@ import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.database.MergeCursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
@@ -36,6 +38,7 @@ import android.util.Log;
|
||||
|
||||
import org.whispersystems.textsecure.crypto.IdentityKey;
|
||||
import org.whispersystems.textsecure.crypto.InvalidKeyException;
|
||||
import org.whispersystems.textsecure.directory.Directory;
|
||||
import org.whispersystems.textsecure.util.Base64;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -58,6 +61,8 @@ import java.util.List;
|
||||
|
||||
public class ContactAccessor {
|
||||
|
||||
public static final String PUSH_COLUMN = "push";
|
||||
|
||||
private static final ContactAccessor instance = new ContactAccessor();
|
||||
|
||||
public static synchronized ContactAccessor getInstance() {
|
||||
@@ -85,6 +90,27 @@ public class ContactAccessor {
|
||||
ContactsContract.Contacts.DISPLAY_NAME + " ASC");
|
||||
}
|
||||
|
||||
public Cursor getCursorForContactsWithPush(Context context) {
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
final String[] inProjection = new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME};
|
||||
final String[] outProjection = new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME, PUSH_COLUMN};
|
||||
MatrixCursor cursor = new MatrixCursor(outProjection);
|
||||
List<String> pushNumbers = Directory.getInstance(context).getActiveNumbers();
|
||||
for (String pushNumber : pushNumbers) {
|
||||
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(pushNumber));
|
||||
Cursor lookupCursor = resolver.query(uri, inProjection, null, null, null);
|
||||
try {
|
||||
if (lookupCursor != null && lookupCursor.moveToFirst()) {
|
||||
cursor.addRow(new Object[]{lookupCursor.getLong(0), lookupCursor.getString(1), 1});
|
||||
}
|
||||
} finally {
|
||||
if (lookupCursor != null)
|
||||
lookupCursor.close();
|
||||
}
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
|
||||
public String getNameFromContact(Context context, Uri uri) {
|
||||
Cursor cursor = null;
|
||||
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
package org.thoughtcrime.securesms.contacts;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.CursorWrapper;
|
||||
import android.os.Debug;
|
||||
import android.provider.ContactsContract;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.textsecure.util.InvalidNumberException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PushFilterCursorWrapper extends CursorWrapper {
|
||||
private int[] pushIndex;
|
||||
private int[] normalIndex;
|
||||
private int count = 0;
|
||||
private int pushCount = 0;
|
||||
private int pos = 0;
|
||||
|
||||
private final ContactAccessor contactAccessor = ContactAccessor.getInstance();
|
||||
|
||||
/*
|
||||
* Don't know of a better way to do this without a large filtering through the entire dataset at first
|
||||
*/
|
||||
public PushFilterCursorWrapper(Cursor cursor, Context context) {
|
||||
super(cursor);
|
||||
this.count = super.getCount();
|
||||
this.pushIndex = new int[this.count];
|
||||
this.normalIndex = new int[this.count];
|
||||
int pushPos = 0;
|
||||
int normalPos = 0;
|
||||
for (int i = 0; i < this.count; i++) {
|
||||
super.moveToPosition(i);
|
||||
|
||||
|
||||
List<ContactAccessor.NumberData> numbers = contactAccessor.getContactData(context, cursor).numbers;
|
||||
if (numbers.size() > 0) {
|
||||
try {
|
||||
if (Util.isPushTransport(context, Util.canonicalizeNumber(context, numbers.get(0).number)))
|
||||
this.pushIndex[pushPos++] = i;
|
||||
else
|
||||
this.normalIndex[normalPos++] = i;
|
||||
} catch (InvalidNumberException ine) {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.pushCount = pushPos;
|
||||
super.moveToFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean move(int offset) {
|
||||
return this.moveToPosition(this.pos + offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToNext() {
|
||||
return this.moveToPosition(this.pos + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToPrevious() {
|
||||
return this.moveToPosition(this.pos - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToFirst() {
|
||||
return this.moveToPosition(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToLast() {
|
||||
return this.moveToPosition(this.count - 1);
|
||||
}
|
||||
|
||||
private int getPostFilteredPosition(int preFilteredPosition) {
|
||||
return preFilteredPosition < this.pushCount
|
||||
? this.pushIndex[preFilteredPosition]
|
||||
: this.normalIndex[preFilteredPosition - pushCount];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToPosition(int position) {
|
||||
if (position >= this.count || position < 0)
|
||||
return false;
|
||||
pos = position;
|
||||
return super.moveToPosition(getPostFilteredPosition(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public int getPushCount() {
|
||||
return this.pushCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPosition() {
|
||||
return this.pos;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user