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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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.showBrowserIntent(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.showBrowserIntent(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 @@ -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.showBrowserIntent(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.showBrowserIntent(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.showBrowserIntent(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.showBrowserIntent(WebxdcStoreActivity.this, url);
}
return true;
}
Expand Down
10 changes: 9 additions & 1 deletion 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 @@ -21,7 +25,11 @@ public static boolean isResolvable(@NonNull Context context, @NonNull Intent int

public static void showBrowserIntent(Context context, String url) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about renaming it to showInBrowser()? showBrowserIntent() sounds to me like it will return an intent that shows the URL in the browser.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

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
Loading