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