Skip to content

Commit

Permalink
Introduce Android X browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornaco committed Sep 25, 2021
1 parent 330b6f5 commit 459e44f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
Expand All @@ -31,6 +30,7 @@
import github.tornaco.android.thanos.settings.ExportPatchUi;
import github.tornaco.android.thanos.settings.PowerSettingsActivity;
import github.tornaco.android.thanos.settings.SettingsDashboardActivity;
import github.tornaco.android.thanos.util.BrowserUtils;
import github.tornaco.android.thanos.widget.ModernAlertDialog;
import github.tornaco.permission.requester.RequiresPermission;
import github.tornaco.permission.requester.RuntimePermissions;
Expand Down Expand Up @@ -81,12 +81,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
SettingsDashboardActivity.start(this);
return true;
case R.id.guide:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(BuildProp.THANOX_URL_DOCS_HOME));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(intent, ""));
}
BrowserUtils.launch(thisActivity(), BuildProp.THANOX_URL_DOCS_HOME);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package github.tornaco.android.thanos.settings;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -17,6 +15,7 @@
import github.tornaco.android.thanos.R;
import github.tornaco.android.thanos.theme.ThemeActivity;
import github.tornaco.android.thanos.util.ActivityUtils;
import github.tornaco.android.thanos.util.BrowserUtils;

public class SettingsDashboardActivity extends ThemeActivity {

Expand All @@ -43,12 +42,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
findViewById(R.id.guide).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(BuildProp.THANOX_URL_DOCS_HOME));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(intent, ""));
}
BrowserUtils.launch(thisActivity(), BuildProp.THANOX_URL_DOCS_HOME);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
Expand All @@ -29,6 +27,7 @@
import github.tornaco.android.thanos.databinding.ActivityStartRulesBinding;
import github.tornaco.android.thanos.theme.ThemeActivity;
import github.tornaco.android.thanos.util.ActivityUtils;
import github.tornaco.android.thanos.util.BrowserUtils;
import github.tornaco.android.thanos.widget.SwitchBar;

public class StartRuleActivity extends ThemeActivity implements StartRuleItemClickListener {
Expand Down Expand Up @@ -180,12 +179,7 @@ private void showInfoDialog() {
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(BuildProp.THANOX_URL_DOCS_START_RULES));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(intent, ""));
}
BrowserUtils.launch(thisActivity(), BuildProp.THANOX_URL_DOCS_START_RULES);
}
})
.setCancelable(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ object Libs {
const val lifeCycleCompiler = "androidx.lifecycle:lifecycle-compiler:2.3.1"

const val biometric = "androidx.biometric:biometric:1.2.0-alpha03"
const val browser = "androidx.browser:browser:1.3.0"
}

object Room {
Expand Down
3 changes: 3 additions & 0 deletions android/modules/module_common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ dependencies {
implementation(Libs.AndroidX.constraint)
implementation(Libs.AndroidX.interpolator)
implementation(Libs.AndroidX.swipeRefreshLayout)
implementation(Libs.AndroidX.browser) {
exclude(group = "com.google.guava", module = "listenablefuture")
}

implementation(Libs.Others.glide)
annotationProcessor(Libs.Others.glideCompiler)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package github.tornaco.android.thanos.util;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import androidx.browser.customtabs.CustomTabsIntent;

public class BrowserUtils {

@SuppressLint("QueryPermissionsNeeded")
public static void launch(Context context, String url) {
try {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(context, Uri.parse(url));
} catch (Throwable e) {
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (intent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(Intent.createChooser(intent, ""));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import github.tornaco.android.thanos.core.profile.RuleInfo;
import github.tornaco.android.thanos.theme.ThemeActivity;
import github.tornaco.android.thanos.util.ActivityUtils;
import github.tornaco.android.thanos.util.BrowserUtils;
import github.tornaco.android.thanos.util.IntentUtils;
import github.tornaco.android.thanos.widget.SwitchBar;
import github.tornaco.permission.requester.RequiresPermission;
Expand Down Expand Up @@ -135,12 +136,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (R.id.action_view_wiki == item.getItemId()) {
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(BuildProp.THANOX_URL_DOCS_PROFILE));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(intent, ""));
}
BrowserUtils.launch(thisActivity(), BuildProp.THANOX_URL_DOCS_PROFILE);
return true;
}

Expand Down

0 comments on commit 459e44f

Please sign in to comment.