Skip to content

Commit 58a12a8

Browse files
mykh-hailoalperozturk96
authored andcommitted
feat: use androidx.browser for AuthenticatorActivity
Signed-off-by: mykh-hailo <kristianderonta0205@gmail.com>
1 parent abb2efb commit 58a12a8

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ dependencies {
374374

375375
// region UI
376376
implementation(libs.bundles.ui)
377+
implementation(libs.browser)
377378
// endregion
378379

379380
// region Worker

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
<package android:name="at.bitfire.davdroid" />
7777
<package android:name="org.fairscan.app" />
7878

79+
<intent>
80+
<action android:name="android.support.customtabs.action.CustomTabsService" />
81+
</intent>
7982
<intent>
8083
<action android:name="android.intent.action.VIEW" />
8184

app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@
128128
import androidx.annotation.Nullable;
129129
import androidx.annotation.VisibleForTesting;
130130
import androidx.appcompat.app.ActionBar;
131+
import androidx.browser.customtabs.CustomTabColorSchemeParams;
132+
import androidx.browser.customtabs.CustomTabsIntent;
133+
import androidx.core.content.ContextCompat;
131134
import androidx.core.graphics.Insets;
132135
import androidx.core.view.ViewCompat;
133136
import androidx.core.view.WindowInsetsCompat;
@@ -492,20 +495,37 @@ private void launchDefaultWebBrowser(String url) {
492495
return;
493496
}
494497

498+
Uri uri = Uri.parse(url);
499+
495500
try {
496-
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
497-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
498-
PackageManager packageManager = getPackageManager();
501+
int toolbarColor = ContextCompat.getColor(this, R.color.primary);
502+
CustomTabColorSchemeParams colorParams = new CustomTabColorSchemeParams.Builder()
503+
.setToolbarColor(toolbarColor)
504+
.build();
505+
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
506+
.setDefaultColorSchemeParams(colorParams)
507+
.setColorScheme(CustomTabsIntent.COLOR_SCHEME_SYSTEM)
508+
.setShowTitle(true)
509+
.setShareState(CustomTabsIntent.SHARE_STATE_OFF)
510+
.build();
511+
customTabsIntent.launchUrl(this, uri);
512+
return;
513+
} catch (Exception e) {
514+
Log_OC.e(TAG, "Custom Tab login URL launch failed: " + e);
515+
}
499516

517+
try {
518+
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
519+
PackageManager packageManager = getPackageManager();
500520
if (intent.resolveActivity(packageManager) != null) {
501521
startActivity(intent);
502-
} else {
503-
DisplayUtils.showSnackMessage(this, R.string.authenticator_activity_no_web_browser_found);
522+
return;
504523
}
505524
} catch (Exception e) {
506-
Log_OC.e(TAG, "Exception launchDefaultWebBrowser: " + e);
507-
DisplayUtils.showSnackMessage(this, R.string.authenticator_activity_login_error);
525+
Log_OC.e(TAG, "External browser launch failed: " + e);
508526
}
527+
528+
DisplayUtils.showSnackMessage(this, R.string.authenticator_activity_no_web_browser_found);
509529
}
510530

511531
private Pair<String, String> extractPollUrlAndToken() {

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ androidxTestVersion = "1.7.0"
1313
annotationVersion = "1.9.1"
1414
annotationsVersion = "3.0.1u2"
1515
appCompatVersion = "1.7.1"
16+
browserVersion = "1.10.0"
1617
bcpkixJdk18onVersion = "1.83"
1718
cardviewVersion = "1.0.0"
1819
checker = "3.21.2"
@@ -93,6 +94,7 @@ conscrypt-android = { module = "org.conscrypt:conscrypt-android", version.ref =
9394
bcpkix-jdk18on = { module = "org.bouncycastle:bcpkix-jdk18on", version.ref = "bcpkixJdk18onVersion" }
9495

9596
# UI
97+
browser = { module = "androidx.browser:browser", version.ref = "browserVersion" }
9698
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appCompatVersion" }
9799
cardview = { module = "androidx.cardview:cardview", version.ref = "cardviewVersion" }
98100
core-ktx = { module = "androidx.test:core-ktx", version.ref = "androidxTestVersion" }

gradle/verification-metadata.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<trusted-key id="0CDE80149711EB46DFF17AE421A24B3F8B0F594A" group="org.apache" name="apache" version="16"/>
5050
<trusted-key id="0D35D3F60078655126908E8AF3D1600878E85A3D" group="io.netty"/>
5151
<trusted-key id="0E225917414670F4442C250DFD533C07C264648F">
52+
<trusting group="androidx.browser" name="browser" version="1.10.0"/>
5253
<trusting group="androidx.core"/>
5354
<trusting group="androidx.databinding"/>
5455
<trusting group="androidx.media3"/>

0 commit comments

Comments
 (0)