Stop using custom tabs (closes #6821)

This commit is contained in:
arkon 2022-03-26 15:45:58 -04:00
parent b89acb5853
commit c06ad8b87e
5 changed files with 15 additions and 64 deletions

View File

@ -144,7 +144,6 @@ dependencies {
implementation(androidx.annotation) implementation(androidx.annotation)
implementation(androidx.appcompat) implementation(androidx.appcompat)
implementation(androidx.biometricktx) implementation(androidx.biometricktx)
implementation(androidx.browser)
implementation(androidx.constraintlayout) implementation(androidx.constraintlayout)
implementation(androidx.coordinatorlayout) implementation(androidx.coordinatorlayout)
implementation(androidx.corektx) implementation(androidx.corektx)

View File

@ -53,10 +53,10 @@ class SettingsTrackingController :
titleRes = R.string.services titleRes = R.string.services
trackPreference(trackManager.myAnimeList) { trackPreference(trackManager.myAnimeList) {
activity?.openInBrowser(MyAnimeListApi.authUrl(), trackManager.myAnimeList.getLogoColor()) activity?.openInBrowser(MyAnimeListApi.authUrl())
} }
trackPreference(trackManager.aniList) { trackPreference(trackManager.aniList) {
activity?.openInBrowser(AnilistApi.authUrl(), trackManager.aniList.getLogoColor()) activity?.openInBrowser(AnilistApi.authUrl())
} }
trackPreference(trackManager.kitsu) { trackPreference(trackManager.kitsu) {
val dialog = TrackLoginDialog(trackManager.kitsu, R.string.email) val dialog = TrackLoginDialog(trackManager.kitsu, R.string.email)
@ -64,10 +64,10 @@ class SettingsTrackingController :
dialog.showDialog(router) dialog.showDialog(router)
} }
trackPreference(trackManager.shikimori) { trackPreference(trackManager.shikimori) {
activity?.openInBrowser(ShikimoriApi.authUrl(), trackManager.shikimori.getLogoColor()) activity?.openInBrowser(ShikimoriApi.authUrl())
} }
trackPreference(trackManager.bangumi) { trackPreference(trackManager.bangumi) {
activity?.openInBrowser(BangumiApi.authUrl(), trackManager.bangumi.getLogoColor()) activity?.openInBrowser(BangumiApi.authUrl())
} }
infoPreference(R.string.tracking_info) infoPreference(R.string.tracking_info)

View File

@ -200,7 +200,7 @@ class WebViewActivity : BaseViewBindingActivity<WebviewActivityBinding>() {
} }
private fun openInBrowser() { private fun openInBrowser() {
openInBrowser(binding.webview.url!!) openInBrowser(binding.webview.url!!, forceDefaultBrowser = true)
} }
companion object { companion object {

View File

@ -4,12 +4,10 @@ import android.app.ActivityManager
import android.app.KeyguardManager import android.app.KeyguardManager
import android.app.Notification import android.app.Notification
import android.app.NotificationManager import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.ClipData import android.content.ClipData
import android.content.ClipboardManager import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.res.Configuration import android.content.res.Configuration
import android.content.res.Resources import android.content.res.Resources
@ -31,8 +29,6 @@ import androidx.annotation.AttrRes
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.appcompat.view.ContextThemeWrapper import androidx.appcompat.view.ContextThemeWrapper
import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
@ -41,7 +37,6 @@ import androidx.core.graphics.blue
import androidx.core.graphics.green import androidx.core.graphics.green
import androidx.core.graphics.red import androidx.core.graphics.red
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.data.preference.PreferenceValues
@ -229,42 +224,6 @@ fun Context.acquireWakeLock(tag: String): PowerManager.WakeLock {
return 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. * Returns true if the given service class is running.
*/ */
@ -276,25 +235,19 @@ fun Context.isServiceRunning(serviceClass: Class<*>): Boolean {
.any { className == it.service.className } .any { className == it.service.className }
} }
/** fun Context.openInBrowser(url: String, forceDefaultBrowser: Boolean = false) {
* Opens a URL in a custom tab. this.openInBrowser(url.toUri(), forceDefaultBrowser)
*/
fun Context.openInBrowser(url: String, @ColorInt toolbarColor: Int? = null) {
this.openInBrowser(url.toUri(), toolbarColor)
} }
fun Context.openInBrowser(uri: Uri, @ColorInt toolbarColor: Int? = null) { fun Context.openInBrowser(uri: Uri, forceDefaultBrowser: Boolean = false) {
try { try {
val intent = CustomTabsIntent.Builder() val intent = Intent(Intent.ACTION_VIEW, uri).apply {
.setDefaultColorSchemeParams( // Force default browser so that verified extensions don't re-open Tachiyomi
CustomTabColorSchemeParams.Builder() if (forceDefaultBrowser) {
.setToolbarColor(toolbarColor ?: getResourceColor(R.attr.colorPrimary)) defaultBrowserPackageName()?.let { setPackage(it) }
.build() }
) }
.build() startActivity(intent)
// Force default browser so that verified extensions don't re-open Tachiyomi
defaultBrowserPackageName()?.let { intent.intent.setPackage(it) }
intent.launchUrl(this, uri)
} catch (e: Exception) { } catch (e: Exception) {
toast(e.message) toast(e.message)
} }

View File

@ -6,7 +6,6 @@ lifecycle_version = "2.5.0-alpha05"
annotation = "androidx.annotation:annotation:1.4.0-alpha02" annotation = "androidx.annotation:annotation:1.4.0-alpha02"
appcompat = "androidx.appcompat:appcompat:1.4.1" appcompat = "androidx.appcompat:appcompat:1.4.1"
biometricktx = "androidx.biometric:biometric-ktx:1.2.0-alpha04" biometricktx = "androidx.biometric:biometric-ktx:1.2.0-alpha04"
browser = "androidx.browser:browser:1.4.0"
constraintlayout = "androidx.constraintlayout:constraintlayout:2.1.3" constraintlayout = "androidx.constraintlayout:constraintlayout:2.1.3"
coordinatorlayout = "androidx.coordinatorlayout:coordinatorlayout:1.2.0" coordinatorlayout = "androidx.coordinatorlayout:coordinatorlayout:1.2.0"
corektx = "androidx.core:core-ktx:1.8.0-alpha05" corektx = "androidx.core:core-ktx:1.8.0-alpha05"