mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 08:47:46 +00:00
Don't crash direct share service if avatar photo is missing
Fixes #7541
This commit is contained in:
parent
26a16bf0ca
commit
261296e41b
@ -11,7 +11,9 @@ import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.service.chooser.ChooserTarget;
|
||||
import android.service.chooser.ChooserTargetService;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.ShareActivity;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
@ -27,6 +29,9 @@ import java.util.concurrent.ExecutionException;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
public class DirectShareService extends ChooserTargetService {
|
||||
|
||||
private static final String TAG = DirectShareService.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName,
|
||||
IntentFilter matchedFilter)
|
||||
@ -41,24 +46,26 @@ public class DirectShareService extends ChooserTargetService {
|
||||
ThreadRecord record;
|
||||
|
||||
while ((record = reader.getNext()) != null && results.size() < 10) {
|
||||
try {
|
||||
Recipient recipient = Recipient.from(this, record.getRecipient().getAddress(), false);
|
||||
String name = recipient.toShortString();
|
||||
|
||||
Bitmap avatar;
|
||||
|
||||
if (recipient.getContactPhoto() != null) {
|
||||
avatar = GlideApp.with(this)
|
||||
.asBitmap()
|
||||
.load(recipient.getContactPhoto())
|
||||
.circleCrop()
|
||||
.submit(getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
|
||||
getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width))
|
||||
.get();
|
||||
try {
|
||||
avatar = GlideApp.with(this)
|
||||
.asBitmap()
|
||||
.load(recipient.getContactPhoto())
|
||||
.circleCrop()
|
||||
.submit(getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
|
||||
getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width))
|
||||
.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
Log.w(TAG, e);
|
||||
avatar = getFallbackDrawable(recipient);
|
||||
}
|
||||
} else {
|
||||
avatar = BitmapUtil.createFromDrawable(recipient.getFallbackContactPhotoDrawable(this, false),
|
||||
getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
|
||||
getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height));
|
||||
avatar = getFallbackDrawable(recipient);
|
||||
}
|
||||
|
||||
Parcel parcel = Parcel.obtain();
|
||||
@ -72,9 +79,7 @@ public class DirectShareService extends ChooserTargetService {
|
||||
|
||||
results.add(new ChooserTarget(name, Icon.createWithBitmap(avatar), 1.0f, componentName, bundle));
|
||||
parcel.recycle();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return results;
|
||||
@ -82,4 +87,10 @@ public class DirectShareService extends ChooserTargetService {
|
||||
if (cursor != null) cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap getFallbackDrawable(@NonNull Recipient recipient) {
|
||||
return BitmapUtil.createFromDrawable(recipient.getFallbackContactPhotoDrawable(this, false),
|
||||
getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
|
||||
getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user