mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Support for static RecipientDetails for certain shortcodes.
Closes #3813 // FREEBIE
This commit is contained in:
parent
e2e5aa32a8
commit
bbf33f88e0
BIN
res/drawable-hdpi/ic_amazon.png
Normal file
BIN
res/drawable-hdpi/ic_amazon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
BIN
res/drawable-mdpi/ic_amazon.png
Normal file
BIN
res/drawable-mdpi/ic_amazon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 704 B |
BIN
res/drawable-xhdpi/ic_amazon.png
Normal file
BIN
res/drawable-xhdpi/ic_amazon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
res/drawable-xxhdpi/ic_amazon.png
Normal file
BIN
res/drawable-xxhdpi/ic_amazon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
BIN
res/drawable-xxxhdpi/ic_amazon.png
Normal file
BIN
res/drawable-xxxhdpi/ic_amazon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
@ -6,6 +6,8 @@ import android.net.Uri;
|
|||||||
import android.os.Build.VERSION;
|
import android.os.Build.VERSION;
|
||||||
import android.os.Build.VERSION_CODES;
|
import android.os.Build.VERSION_CODES;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
|
import android.support.annotation.DrawableRes;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -17,6 +19,7 @@ import org.thoughtcrime.securesms.util.BitmapUtil;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class ContactPhotoFactory {
|
public class ContactPhotoFactory {
|
||||||
|
|
||||||
private static final String TAG = ContactPhotoFactory.class.getSimpleName();
|
private static final String TAG = ContactPhotoFactory.class.getSimpleName();
|
||||||
|
|
||||||
public static ContactPhoto getLoadingPhoto() {
|
public static ContactPhoto getLoadingPhoto() {
|
||||||
@ -28,6 +31,10 @@ public class ContactPhotoFactory {
|
|||||||
else return new GeneratedContactPhoto("#");
|
else return new GeneratedContactPhoto("#");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ContactPhoto getResourceContactPhoto(@DrawableRes int resourceId) {
|
||||||
|
return new ResourceContactPhoto(resourceId);
|
||||||
|
}
|
||||||
|
|
||||||
public static ContactPhoto getDefaultGroupPhoto() {
|
public static ContactPhoto getDefaultGroupPhoto() {
|
||||||
return new ResourceContactPhoto(R.drawable.ic_group_white_24dp);
|
return new ResourceContactPhoto(R.drawable.ic_group_white_24dp);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import android.graphics.ColorFilter;
|
|||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.LayerDrawable;
|
import android.graphics.drawable.LayerDrawable;
|
||||||
|
import android.support.annotation.DrawableRes;
|
||||||
import android.support.v4.graphics.ColorUtils;
|
import android.support.v4.graphics.ColorUtils;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ public class ResourceContactPhoto implements ContactPhoto {
|
|||||||
|
|
||||||
private final int resourceId;
|
private final int resourceId;
|
||||||
|
|
||||||
ResourceContactPhoto(int resourceId) {
|
ResourceContactPhoto(@DrawableRes int resourceId) {
|
||||||
this.resourceId = resourceId;
|
this.resourceId = resourceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ import android.database.Cursor;
|
|||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.telephony.PhoneNumberUtils;
|
import android.telephony.PhoneNumberUtils;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -97,7 +98,7 @@ public class CanonicalAddressDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAddressFromId(long id) {
|
public @NonNull String getAddressFromId(long id) {
|
||||||
String cachedAddress = idCache.get(id);
|
String cachedAddress = idCache.get(id);
|
||||||
|
|
||||||
if (cachedAddress != null)
|
if (cachedAddress != null)
|
||||||
|
@ -25,7 +25,9 @@ import android.support.annotation.NonNull;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||||
|
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
||||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
|
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
|
||||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhotoFactory;
|
import org.thoughtcrime.securesms.contacts.avatars.ContactPhotoFactory;
|
||||||
import org.thoughtcrime.securesms.database.CanonicalAddressDatabase;
|
import org.thoughtcrime.securesms.database.CanonicalAddressDatabase;
|
||||||
@ -40,7 +42,7 @@ import org.whispersystems.libaxolotl.util.guava.Optional;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -62,6 +64,12 @@ public class RecipientProvider {
|
|||||||
PhoneLookup.NUMBER
|
PhoneLookup.NUMBER
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final Map<String, RecipientDetails> STATIC_DETAILS = new HashMap<String, RecipientDetails>() {{
|
||||||
|
put("262966", new RecipientDetails("Amazon", "262966", null,
|
||||||
|
ContactPhotoFactory.getResourceContactPhoto(R.drawable.ic_amazon),
|
||||||
|
ContactColors.UNKNOWN_COLOR));
|
||||||
|
}};
|
||||||
|
|
||||||
Recipient getRecipient(Context context, long recipientId, boolean asynchronous) {
|
Recipient getRecipient(Context context, long recipientId, boolean asynchronous) {
|
||||||
Recipient cachedRecipient = recipientCache.get(recipientId);
|
Recipient cachedRecipient = recipientCache.get(recipientId);
|
||||||
if (cachedRecipient != null && !cachedRecipient.isStale()) return cachedRecipient;
|
if (cachedRecipient != null && !cachedRecipient.isStale()) return cachedRecipient;
|
||||||
@ -102,7 +110,7 @@ public class RecipientProvider {
|
|||||||
|
|
||||||
private @NonNull ListenableFutureTask<RecipientDetails> getRecipientDetailsAsync(final Context context,
|
private @NonNull ListenableFutureTask<RecipientDetails> getRecipientDetailsAsync(final Context context,
|
||||||
final long recipientId,
|
final long recipientId,
|
||||||
final String number)
|
final @NonNull String number)
|
||||||
{
|
{
|
||||||
Callable<RecipientDetails> task = new Callable<RecipientDetails>() {
|
Callable<RecipientDetails> task = new Callable<RecipientDetails>() {
|
||||||
@Override
|
@Override
|
||||||
@ -116,12 +124,12 @@ public class RecipientProvider {
|
|||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
||||||
private @NonNull RecipientDetails getRecipientDetailsSync(Context context, long recipientId, String number) {
|
private @NonNull RecipientDetails getRecipientDetailsSync(Context context, long recipientId, @NonNull String number) {
|
||||||
if (GroupUtil.isEncodedGroup(number)) return getGroupRecipientDetails(context, number);
|
if (GroupUtil.isEncodedGroup(number)) return getGroupRecipientDetails(context, number);
|
||||||
else return getIndividualRecipientDetails(context, recipientId, number);
|
else return getIndividualRecipientDetails(context, recipientId, number);
|
||||||
}
|
}
|
||||||
|
|
||||||
private @NonNull RecipientDetails getIndividualRecipientDetails(Context context, long recipientId, String number) {
|
private @NonNull RecipientDetails getIndividualRecipientDetails(Context context, long recipientId, @NonNull String number) {
|
||||||
Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(new long[]{recipientId});
|
Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(new long[]{recipientId});
|
||||||
MaterialColor color = preferences.isPresent() ? preferences.get().getColor() : null;
|
MaterialColor color = preferences.isPresent() ? preferences.get().getColor() : null;
|
||||||
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
|
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
|
||||||
@ -143,7 +151,8 @@ public class RecipientProvider {
|
|||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RecipientDetails(null, number, null, ContactPhotoFactory.getDefaultContactPhoto(null), color);
|
if (STATIC_DETAILS.containsKey(number)) return STATIC_DETAILS.get(number);
|
||||||
|
else return new RecipientDetails(null, number, null, ContactPhotoFactory.getDefaultContactPhoto(null), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
private @NonNull RecipientDetails getGroupRecipientDetails(Context context, String groupId) {
|
private @NonNull RecipientDetails getGroupRecipientDetails(Context context, String groupId) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user