mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-23 19:26:17 +00:00
Extract 'invite to signal' into an InviteActions object.
This commit is contained in:
committed by
Greyson Parrelli
parent
d88534e71f
commit
2883c16560
@@ -196,6 +196,7 @@ import org.thoughtcrime.securesms.groups.ui.invitesandrequests.ManagePendingAndR
|
||||
import org.thoughtcrime.securesms.groups.ui.migration.GroupsV1MigrationInitiationBottomSheetDialogFragment;
|
||||
import org.thoughtcrime.securesms.groups.ui.migration.GroupsV1MigrationSuggestionsDialog;
|
||||
import org.thoughtcrime.securesms.insights.InsightsLauncher;
|
||||
import org.thoughtcrime.securesms.invites.InviteActions;
|
||||
import org.thoughtcrime.securesms.invites.InviteReminderModel;
|
||||
import org.thoughtcrime.securesms.invites.InviteReminderRepository;
|
||||
import org.thoughtcrime.securesms.jobs.ForceUpdateGroupV2Job;
|
||||
@@ -1142,27 +1143,18 @@ public class ConversationParentFragment extends Fragment
|
||||
|
||||
@Override
|
||||
public void handleInviteLink() {
|
||||
String inviteText = getString(R.string.ConversationActivity_lets_switch_to_signal, getString(R.string.install_url));
|
||||
|
||||
if (viewModel.isDefaultSmsApplication() && SignalStore.misc().getSmsExportPhase().isSmsSupported()) {
|
||||
composeText.appendInvite(inviteText);
|
||||
} else if (recipient.get().hasSmsAddress()) {
|
||||
Intent intent = new Intent(Intent.ACTION_SENDTO);
|
||||
intent.setData(Uri.parse("smsto:" + recipient.get().requireSmsAddress()));
|
||||
intent.putExtra("sms_body", inviteText);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, inviteText);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Intent sendIntent = new Intent();
|
||||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, inviteText);
|
||||
sendIntent.setType("text/plain");
|
||||
if (sendIntent.resolveActivity(requireContext().getPackageManager()) != null) {
|
||||
startActivity(Intent.createChooser(sendIntent, getString(R.string.InviteActivity_invite_to_signal)));
|
||||
} else {
|
||||
Toast.makeText(requireContext(), R.string.InviteActivity_no_app_to_share_to, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
InviteActions.INSTANCE.inviteUserToSignal(
|
||||
requireContext(),
|
||||
recipient.get(),
|
||||
text -> {
|
||||
composeText.appendInvite(text);
|
||||
return Unit.INSTANCE;
|
||||
},
|
||||
intent -> {
|
||||
startActivity(intent);
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.thoughtcrime.securesms.invites
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.MainThread
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.util.CommunicationActions
|
||||
import org.thoughtcrime.securesms.util.Util
|
||||
|
||||
/**
|
||||
* Handles 'invite to signal' actions.
|
||||
*/
|
||||
object InviteActions {
|
||||
/**
|
||||
* Called to send a message to a user to invite them to Signal.
|
||||
* The invite can be sent in one of three ways:
|
||||
*
|
||||
* 1. If Signal is the user's default SMS app, we can simply append the message to the composer.
|
||||
* 2. If the user has an sms address, we generate a SENDTO intent and request it to be launched.
|
||||
* 3. Otherwise, we generate a share intent to allow the user to select how to send the invite.
|
||||
*/
|
||||
@MainThread
|
||||
fun inviteUserToSignal(
|
||||
context: Context,
|
||||
recipient: Recipient,
|
||||
appendInviteToComposer: ((String) -> Unit)?,
|
||||
launchIntent: (Intent) -> Unit
|
||||
) {
|
||||
val inviteText = context.getString(
|
||||
R.string.ConversationActivity_lets_switch_to_signal,
|
||||
context.getString(R.string.install_url)
|
||||
)
|
||||
|
||||
if (appendInviteToComposer != null && Util.isDefaultSmsProvider(context) && SignalStore.misc().smsExportPhase.isSmsSupported()) {
|
||||
appendInviteToComposer(inviteText)
|
||||
} else if (recipient.hasSmsAddress()) {
|
||||
launchIntent(
|
||||
CommunicationActions.createIntentToComposeSmsThroughDefaultApp(recipient, inviteText)
|
||||
)
|
||||
} else {
|
||||
val intent = CommunicationActions.createIntentToShareTextViaShareSheet(inviteText)
|
||||
|
||||
if (intent.resolveActivity(context.packageManager) != null) {
|
||||
launchIntent(Intent.createChooser(intent, context.getString(R.string.InviteActivity_invite_to_signal)))
|
||||
} else {
|
||||
Toast.makeText(context, R.string.InviteActivity_no_app_to_share_to, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,11 +178,25 @@ public class CommunicationActions {
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void composeSmsThroughDefaultApp(@NonNull Context context, @NonNull Recipient recipient, @Nullable String text) {
|
||||
public static @NonNull Intent createIntentToShareTextViaShareSheet(@NonNull String text) {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType("text/plain");
|
||||
intent.putExtra(Intent.EXTRA_TEXT, text);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static @NonNull Intent createIntentToComposeSmsThroughDefaultApp(@NonNull Recipient recipient, @Nullable String text) {
|
||||
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + recipient.requireSmsAddress()));
|
||||
if (text != null) {
|
||||
intent.putExtra("sms_body", text);
|
||||
}
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
public static void composeSmsThroughDefaultApp(@NonNull Context context, @NonNull Recipient recipient, @Nullable String text) {
|
||||
Intent intent = createIntentToComposeSmsThroughDefaultApp(recipient, text);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user