Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix IntentUtils.showBrowserIntent() and use it everywhere #3535

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.thoughtcrime.securesms.proxy.ProxySettingsActivity;
import org.thoughtcrime.securesms.qr.RegistrationQrActivity;
import org.thoughtcrime.securesms.scribbles.ScribbleActivity;
import org.thoughtcrime.securesms.util.IntentUtils;
import org.thoughtcrime.securesms.util.Prefs;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.views.ProgressDialog;
Expand Down Expand Up @@ -331,7 +332,7 @@ private void initializeResources() {

privacyPolicyBtn.setOnClickListener(view -> {
if (!isDcLogin) {
WebViewActivity.openUrlInBrowser(this, "https://" + providerHost + "/privacy.html");
IntentUtils.showInBrowser(this, "https://" + providerHost + "/privacy.html");
}
});

Expand All @@ -350,7 +351,7 @@ private void showOtherOptionsDialog() {
.create();

view.findViewById(R.id.use_other_server).setOnClickListener((v) -> {
WebViewActivity.openUrlInBrowser(this, INSTANCES_URL);
IntentUtils.showInBrowser(this, INSTANCES_URL);
signUpDialog.dismiss();
});
view.findViewById(R.id.login_button).setOnClickListener((v) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import static org.thoughtcrime.securesms.connect.DcHelper.getContext;
import static org.thoughtcrime.securesms.service.IPCAddAccountsService.ACCOUNT_DATA;

import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
Expand Down Expand Up @@ -438,7 +437,7 @@ protected void onPostExecute(Void result) {
.setPositiveButton(R.string.perm_continue, (dialog, which)-> {
// pass control to browser, we'll be back in business at (**)
activity.oauth2Requested = System.currentTimeMillis();
IntentUtils.showBrowserIntent(activity, oauth2url);
IntentUtils.showInBrowser(activity, oauth2url);
oauth2started.set(true);
})
.setCancelable(false)
Expand Down Expand Up @@ -493,11 +492,7 @@ private void onProviderLink() {
if (provider!=null) {
String url = provider.getOverviewPage();
if(!url.isEmpty()) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
} catch (ActivityNotFoundException e) {
Toast.makeText(this, R.string.no_browser_installed, Toast.LENGTH_LONG).show();
}
IntentUtils.showInBrowser(this, url);
} else {
// this should normally not happen
Toast.makeText(this, "ErrProviderWithoutUrl", Toast.LENGTH_LONG).show();
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/org/thoughtcrime/securesms/WebViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import androidx.webkit.ProxyConfig;

import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.IntentUtils;

public class WebViewActivity extends PassphraseRequiredActionBarActivity
implements SearchView.OnQueryTextListener,
Expand Down Expand Up @@ -278,16 +279,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
// onBackPressed() can be overwritten by derived classes as needed.
// the default behavior (close the activity) is just fine eg. for Webxdc, Connectivity, HTML-mails

public static void openUrlInBrowser(Context context, String url) {
try {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
} catch (ActivityNotFoundException e) {
Toast.makeText(context, R.string.no_browser_installed, Toast.LENGTH_LONG).show();
}
}

protected boolean openOnlineUrl(String url) {
openUrlInBrowser(this, url);
IntentUtils.showInBrowser(this, url);
// returning `true` causes the WebView to abort loading
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/thoughtcrime/securesms/WebxdcActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Base64;
Expand Down Expand Up @@ -45,6 +44,7 @@
import org.thoughtcrime.securesms.connect.AccountManager;
import org.thoughtcrime.securesms.connect.DcEventCenter;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.util.IntentUtils;
import org.thoughtcrime.securesms.util.JsonUtils;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.Prefs;
Expand Down Expand Up @@ -290,7 +290,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
addToHomeScreen(this, dcAppMsg.getId());
return true;
case R.id.source_code:
openUrlInBrowser(this, sourceCodeUrl);
IntentUtils.showInBrowser(this, sourceCodeUrl);
return true;
case R.id.show_in_chat:
showInChat();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
import org.thoughtcrime.securesms.util.IntentUtils;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.Prefs;
import org.thoughtcrime.securesms.util.Util;
Expand Down Expand Up @@ -68,7 +69,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
}
});
} else {
WebViewActivity.openUrlInBrowser(WebxdcStoreActivity.this, url);
IntentUtils.showInBrowser(WebxdcStoreActivity.this, url);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void handleQrData(String rawString) {
showDoneToast(activity);
});
if (rawString.toLowerCase().startsWith("http")) {
builder.setNeutralButton(R.string.open, (d, b) -> IntentUtils.showBrowserIntent(activity, rawString));
builder.setNeutralButton(R.string.open, (d, b) -> IntentUtils.showInBrowser(activity, rawString));
}
builder.setNegativeButton(R.string.cancel, null);
builder.setCancelable(false);
Expand Down Expand Up @@ -182,7 +182,7 @@ private void showQrUrl(AlertDialog.Builder builder, DcLot qrParsed) {
final String url = qrParsed.getText1();
String msg = String.format(activity.getString(R.string.qrscan_contains_url), url);
builder.setMessage(msg);
builder.setPositiveButton(R.string.open, (dialog, which) -> IntentUtils.showBrowserIntent(activity, url));
builder.setPositiveButton(R.string.open, (dialog, which) -> IntentUtils.showInBrowser(activity, url));
builder.setNegativeButton(android.R.string.cancel, null);
builder.setNeutralButton(R.string.menu_copy_to_clipboard, (dialog, which) -> {
Util.writeTextToClipboard(activity, url);
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/thoughtcrime/securesms/util/IntentUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@


import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.widget.Toast;

import androidx.annotation.NonNull;

import org.thoughtcrime.securesms.R;

import java.util.List;

public class IntentUtils {
Expand All @@ -19,9 +23,13 @@ public static boolean isResolvable(@NonNull Context context, @NonNull Intent int
return resolveInfoList != null && resolveInfoList.size() > 1;
}

public static void showBrowserIntent(Context context, String url) {
public static void showInBrowser(Context context, String url) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
context.startActivity(browserIntent);
try {
context.startActivity(browserIntent);
} catch (ActivityNotFoundException e) {
Toast.makeText(context, R.string.no_browser_installed, Toast.LENGTH_LONG).show();
}
}

public static int FLAG_MUTABLE() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void onClick(View widget) {
QrCodeHandler qrCodeHandler = new QrCodeHandler(activity);
qrCodeHandler.handleQrData(url);
} else {
IntentUtils.showBrowserIntent(widget.getContext(), url);
IntentUtils.showInBrowser(widget.getContext(), url);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void join(Activity activity, int msgId) {
DcContext dcContext = DcHelper.getContext(activity);
DcMsg dcMsg = dcContext.getMsg(msgId);
String videochatUrl = dcMsg.getVideochatUrl();
IntentUtils.showBrowserIntent(activity, videochatUrl);
IntentUtils.showInBrowser(activity, videochatUrl);
}

}
Loading