mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +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.os.Parcel;
|
||||||
import android.service.chooser.ChooserTarget;
|
import android.service.chooser.ChooserTarget;
|
||||||
import android.service.chooser.ChooserTargetService;
|
import android.service.chooser.ChooserTargetService;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.RequiresApi;
|
import android.support.annotation.RequiresApi;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.ShareActivity;
|
import org.thoughtcrime.securesms.ShareActivity;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
@ -27,6 +29,9 @@ import java.util.concurrent.ExecutionException;
|
|||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||||
public class DirectShareService extends ChooserTargetService {
|
public class DirectShareService extends ChooserTargetService {
|
||||||
|
|
||||||
|
private static final String TAG = DirectShareService.class.getSimpleName();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName,
|
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName,
|
||||||
IntentFilter matchedFilter)
|
IntentFilter matchedFilter)
|
||||||
@ -41,24 +46,26 @@ public class DirectShareService extends ChooserTargetService {
|
|||||||
ThreadRecord record;
|
ThreadRecord record;
|
||||||
|
|
||||||
while ((record = reader.getNext()) != null && results.size() < 10) {
|
while ((record = reader.getNext()) != null && results.size() < 10) {
|
||||||
try {
|
|
||||||
Recipient recipient = Recipient.from(this, record.getRecipient().getAddress(), false);
|
Recipient recipient = Recipient.from(this, record.getRecipient().getAddress(), false);
|
||||||
String name = recipient.toShortString();
|
String name = recipient.toShortString();
|
||||||
|
|
||||||
Bitmap avatar;
|
Bitmap avatar;
|
||||||
|
|
||||||
if (recipient.getContactPhoto() != null) {
|
if (recipient.getContactPhoto() != null) {
|
||||||
avatar = GlideApp.with(this)
|
try {
|
||||||
.asBitmap()
|
avatar = GlideApp.with(this)
|
||||||
.load(recipient.getContactPhoto())
|
.asBitmap()
|
||||||
.circleCrop()
|
.load(recipient.getContactPhoto())
|
||||||
.submit(getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
|
.circleCrop()
|
||||||
getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width))
|
.submit(getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
|
||||||
.get();
|
getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width))
|
||||||
|
.get();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
Log.w(TAG, e);
|
||||||
|
avatar = getFallbackDrawable(recipient);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
avatar = BitmapUtil.createFromDrawable(recipient.getFallbackContactPhotoDrawable(this, false),
|
avatar = getFallbackDrawable(recipient);
|
||||||
getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
|
|
||||||
getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Parcel parcel = Parcel.obtain();
|
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));
|
results.add(new ChooserTarget(name, Icon.createWithBitmap(avatar), 1.0f, componentName, bundle));
|
||||||
parcel.recycle();
|
parcel.recycle();
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
@ -82,4 +87,10 @@ public class DirectShareService extends ChooserTargetService {
|
|||||||
if (cursor != null) cursor.close();
|
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