From c06ad8b87e22041dc36feb78005dff4011b3271a Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 26 Mar 2022 15:45:58 -0400 Subject: [PATCH] Stop using custom tabs (closes #6821) --- app/build.gradle.kts | 1 - .../ui/setting/SettingsTrackingController.kt | 8 +-- .../tachiyomi/ui/webview/WebViewActivity.kt | 2 +- .../util/system/ContextExtensions.kt | 67 +++---------------- gradle/androidx.versions.toml | 1 - 5 files changed, 15 insertions(+), 64 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index bd067c9468..4e36a73735 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -144,7 +144,6 @@ dependencies { implementation(androidx.annotation) implementation(androidx.appcompat) implementation(androidx.biometricktx) - implementation(androidx.browser) implementation(androidx.constraintlayout) implementation(androidx.coordinatorlayout) implementation(androidx.corektx) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt index 894e8b3cad..bac904f8f4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt @@ -53,10 +53,10 @@ class SettingsTrackingController : titleRes = R.string.services trackPreference(trackManager.myAnimeList) { - activity?.openInBrowser(MyAnimeListApi.authUrl(), trackManager.myAnimeList.getLogoColor()) + activity?.openInBrowser(MyAnimeListApi.authUrl()) } trackPreference(trackManager.aniList) { - activity?.openInBrowser(AnilistApi.authUrl(), trackManager.aniList.getLogoColor()) + activity?.openInBrowser(AnilistApi.authUrl()) } trackPreference(trackManager.kitsu) { val dialog = TrackLoginDialog(trackManager.kitsu, R.string.email) @@ -64,10 +64,10 @@ class SettingsTrackingController : dialog.showDialog(router) } trackPreference(trackManager.shikimori) { - activity?.openInBrowser(ShikimoriApi.authUrl(), trackManager.shikimori.getLogoColor()) + activity?.openInBrowser(ShikimoriApi.authUrl()) } trackPreference(trackManager.bangumi) { - activity?.openInBrowser(BangumiApi.authUrl(), trackManager.bangumi.getLogoColor()) + activity?.openInBrowser(BangumiApi.authUrl()) } infoPreference(R.string.tracking_info) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt index 4ebcf86ec1..5295e34eb4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt @@ -200,7 +200,7 @@ class WebViewActivity : BaseViewBindingActivity() { } private fun openInBrowser() { - openInBrowser(binding.webview.url!!) + openInBrowser(binding.webview.url!!, forceDefaultBrowser = true) } companion object { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index 531f06c463..b229c0deba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -4,12 +4,10 @@ import android.app.ActivityManager import android.app.KeyguardManager import android.app.Notification import android.app.NotificationManager -import android.content.BroadcastReceiver import android.content.ClipData import android.content.ClipboardManager import android.content.Context import android.content.Intent -import android.content.IntentFilter import android.content.pm.PackageManager import android.content.res.Configuration import android.content.res.Resources @@ -31,8 +29,6 @@ import androidx.annotation.AttrRes import androidx.annotation.ColorInt import androidx.annotation.StringRes import androidx.appcompat.view.ContextThemeWrapper -import androidx.browser.customtabs.CustomTabColorSchemeParams -import androidx.browser.customtabs.CustomTabsIntent import androidx.core.app.NotificationCompat import androidx.core.content.ContextCompat import androidx.core.content.getSystemService @@ -41,7 +37,6 @@ import androidx.core.graphics.blue import androidx.core.graphics.green import androidx.core.graphics.red import androidx.core.net.toUri -import androidx.localbroadcastmanager.content.LocalBroadcastManager import com.hippo.unifile.UniFile import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferenceValues @@ -229,42 +224,6 @@ fun Context.acquireWakeLock(tag: String): PowerManager.WakeLock { return wakeLock } -/** - * Function used to send a local broadcast asynchronous - * - * @param intent intent that contains broadcast information - */ -fun Context.sendLocalBroadcast(intent: Intent) { - LocalBroadcastManager.getInstance(this).sendBroadcast(intent) -} - -/** - * Function used to send a local broadcast synchronous - * - * @param intent intent that contains broadcast information - */ -fun Context.sendLocalBroadcastSync(intent: Intent) { - LocalBroadcastManager.getInstance(this).sendBroadcastSync(intent) -} - -/** - * Function used to register local broadcast - * - * @param receiver receiver that gets registered. - */ -fun Context.registerLocalReceiver(receiver: BroadcastReceiver, filter: IntentFilter) { - LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter) -} - -/** - * Function used to unregister local broadcast - * - * @param receiver receiver that gets unregistered. - */ -fun Context.unregisterLocalReceiver(receiver: BroadcastReceiver) { - LocalBroadcastManager.getInstance(this).unregisterReceiver(receiver) -} - /** * Returns true if the given service class is running. */ @@ -276,25 +235,19 @@ fun Context.isServiceRunning(serviceClass: Class<*>): Boolean { .any { className == it.service.className } } -/** - * Opens a URL in a custom tab. - */ -fun Context.openInBrowser(url: String, @ColorInt toolbarColor: Int? = null) { - this.openInBrowser(url.toUri(), toolbarColor) +fun Context.openInBrowser(url: String, forceDefaultBrowser: Boolean = false) { + this.openInBrowser(url.toUri(), forceDefaultBrowser) } -fun Context.openInBrowser(uri: Uri, @ColorInt toolbarColor: Int? = null) { +fun Context.openInBrowser(uri: Uri, forceDefaultBrowser: Boolean = false) { try { - val intent = CustomTabsIntent.Builder() - .setDefaultColorSchemeParams( - CustomTabColorSchemeParams.Builder() - .setToolbarColor(toolbarColor ?: getResourceColor(R.attr.colorPrimary)) - .build() - ) - .build() - // Force default browser so that verified extensions don't re-open Tachiyomi - defaultBrowserPackageName()?.let { intent.intent.setPackage(it) } - intent.launchUrl(this, uri) + val intent = Intent(Intent.ACTION_VIEW, uri).apply { + // Force default browser so that verified extensions don't re-open Tachiyomi + if (forceDefaultBrowser) { + defaultBrowserPackageName()?.let { setPackage(it) } + } + } + startActivity(intent) } catch (e: Exception) { toast(e.message) } diff --git a/gradle/androidx.versions.toml b/gradle/androidx.versions.toml index 4b3b31d2fc..f302ec313f 100644 --- a/gradle/androidx.versions.toml +++ b/gradle/androidx.versions.toml @@ -6,7 +6,6 @@ lifecycle_version = "2.5.0-alpha05" annotation = "androidx.annotation:annotation:1.4.0-alpha02" appcompat = "androidx.appcompat:appcompat:1.4.1" biometricktx = "androidx.biometric:biometric-ktx:1.2.0-alpha04" -browser = "androidx.browser:browser:1.4.0" constraintlayout = "androidx.constraintlayout:constraintlayout:2.1.3" coordinatorlayout = "androidx.coordinatorlayout:coordinatorlayout:1.2.0" corektx = "androidx.core:core-ktx:1.8.0-alpha05"