Fix crash when opening contacts app when none are present.
This can also happen when the system contacts app has been disabled. Fixes #11794
This commit is contained in:
parent
562a255478
commit
3242d97c75
2 changed files with 17 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
package org.thoughtcrime.securesms.recipients.ui.bottomsheet;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Bundle;
|
||||
|
@ -23,6 +24,7 @@ import androidx.lifecycle.ViewModelProviders;
|
|||
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.badges.BadgeImageView;
|
||||
import org.thoughtcrime.securesms.badges.view.ViewBadgeBottomSheetDialogFragment;
|
||||
|
@ -54,6 +56,8 @@ import kotlin.Unit;
|
|||
*/
|
||||
public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = Log.tag(RecipientBottomSheetDialogFragment.class);
|
||||
|
||||
public static final int REQUEST_CODE_SYSTEM_CONTACT_SHEET = 1111;
|
||||
|
||||
private static final String ARGS_RECIPIENT_ID = "RECIPIENT_ID";
|
||||
|
@ -247,14 +251,14 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
|
|||
} else {
|
||||
addContactButton.setVisibility(View.VISIBLE);
|
||||
addContactButton.setOnClickListener(v -> {
|
||||
startActivityForResult(RecipientExporter.export(recipient).asAddContactIntent(), REQUEST_CODE_SYSTEM_CONTACT_SHEET);
|
||||
openSystemContactSheet(RecipientExporter.export(recipient).asAddContactIntent());
|
||||
});
|
||||
}
|
||||
|
||||
if (recipient.isSystemContact() && !recipient.isGroup() && !recipient.isSelf()) {
|
||||
contactDetailsButton.setVisibility(View.VISIBLE);
|
||||
contactDetailsButton.setOnClickListener(v -> {
|
||||
startActivityForResult(new Intent(Intent.ACTION_VIEW, recipient.getContactUri()), REQUEST_CODE_SYSTEM_CONTACT_SHEET);
|
||||
openSystemContactSheet(new Intent(Intent.ACTION_VIEW, recipient.getContactUri()));
|
||||
});
|
||||
} else {
|
||||
contactDetailsButton.setVisibility(View.GONE);
|
||||
|
@ -315,6 +319,15 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
|
|||
});
|
||||
}
|
||||
|
||||
private void openSystemContactSheet(@NonNull Intent intent) {
|
||||
try {
|
||||
startActivityForResult(intent, REQUEST_CODE_SYSTEM_CONTACT_SHEET);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.w(TAG, "No activity existed to open the contact.");
|
||||
Toast.makeText(requireContext(), R.string.RecipientBottomSheet_unable_to_open_contacts, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE_SYSTEM_CONTACT_SHEET) {
|
||||
|
|
|
@ -3250,6 +3250,8 @@
|
|||
<string name="RecipientBottomSheet_block">Block</string>
|
||||
<string name="RecipientBottomSheet_unblock">Unblock</string>
|
||||
<string name="RecipientBottomSheet_add_to_contacts">Add to contacts</string>
|
||||
<!-- Error message that displays when a user tries to tap to view system contact details but has no app that supports it -->
|
||||
<string name="RecipientBottomSheet_unable_to_open_contacts">Can\'t find an app able to open contacts.</string>
|
||||
<string name="RecipientBottomSheet_add_to_a_group">Add to a group</string>
|
||||
<string name="RecipientBottomSheet_add_to_another_group">Add to another group</string>
|
||||
<string name="RecipientBottomSheet_view_safety_number">View safety number</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue