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.appcompat)
implementation(androidx.biometricktx)
implementation(androidx.browser)
implementation(androidx.constraintlayout)
implementation(androidx.coordinatorlayout)
implementation(androidx.corektx)

View File

@ -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)

View File

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

View File

@ -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)
}

View File

@ -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"