diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ConductorExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ConductorExtensions.kt index f5c2277ac..ce9fbb586 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ConductorExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/ConductorExtensions.kt @@ -1,11 +1,14 @@ package eu.kanade.tachiyomi.ui.base.controller +import android.content.Intent import android.content.pm.PackageManager.PERMISSION_GRANTED import android.os.Build import androidx.core.content.ContextCompat +import androidx.core.net.toUri import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Router import com.bluelinelabs.conductor.RouterTransaction +import eu.kanade.tachiyomi.util.system.toast fun Router.popControllerWithTag(tag: String): Boolean { val controller = getControllerWithTag(tag) @@ -32,3 +35,12 @@ fun Controller.withFadeTransaction(): RouterTransaction { .pushChangeHandler(OneWayFadeChangeHandler()) .popChangeHandler(OneWayFadeChangeHandler()) } + +fun Controller.openInBrowser(url: String) { + try { + val intent = Intent(Intent.ACTION_VIEW, url.toUri()) + startActivity(intent) + } catch (e: Throwable) { + activity?.toast(e.message) + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt index 67245bd62..49a981e4f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/details/ExtensionDetailsController.kt @@ -14,7 +14,6 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.view.ContextThemeWrapper -import androidx.core.net.toUri import androidx.core.os.bundleOf import androidx.preference.Preference import androidx.preference.PreferenceGroupAdapter @@ -36,6 +35,7 @@ import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.getPreferenceKey import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.ToolbarLiftOnScrollController +import eu.kanade.tachiyomi.ui.base.controller.openInBrowser import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.util.preference.DSL import eu.kanade.tachiyomi.util.preference.onChange @@ -213,8 +213,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) : !pkgFactory.isNullOrEmpty() -> "$URL_EXTENSION_COMMITS/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/$pkgFactory" else -> "$URL_EXTENSION_COMMITS/src/${pkgName.replace(".", "/")}" } - val intent = Intent(Intent.ACTION_VIEW, url.toUri()) - startActivity(intent) + openInBrowser(url) } private fun openInSettings() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/WhatsNewDialogController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/WhatsNewDialogController.kt index 7497d42ea..b1b5dd335 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/WhatsNewDialogController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/WhatsNewDialogController.kt @@ -1,13 +1,12 @@ package eu.kanade.tachiyomi.ui.main import android.app.Dialog -import android.content.Intent import android.os.Bundle -import androidx.core.net.toUri import com.afollestad.materialdialogs.MaterialDialog import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.base.controller.DialogController +import eu.kanade.tachiyomi.ui.base.controller.openInBrowser class WhatsNewDialogController(bundle: Bundle? = null) : DialogController(bundle) { @@ -16,9 +15,7 @@ class WhatsNewDialogController(bundle: Bundle? = null) : DialogController(bundle .title(text = activity!!.getString(R.string.updated_version, BuildConfig.VERSION_NAME)) .positiveButton(android.R.string.ok) .neutralButton(R.string.whats_new) { - val url = "https://github.com/tachiyomiorg/tachiyomi/releases/tag/v${BuildConfig.VERSION_NAME}" - val intent = Intent(Intent.ACTION_VIEW, url.toUri()) - startActivity(intent) + openInBrowser("https://github.com/tachiyomiorg/tachiyomi/releases/tag/v${BuildConfig.VERSION_NAME}") } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt index cd5c24778..5699bcef6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt @@ -1,13 +1,12 @@ package eu.kanade.tachiyomi.ui.manga.track -import android.content.Intent import android.os.Bundle import android.view.ViewGroup -import androidx.core.net.toUri import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.bottomsheet.BottomSheetBehavior import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.databinding.TrackControllerBinding +import eu.kanade.tachiyomi.ui.base.controller.openInBrowser import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.util.system.copyToClipboard import eu.kanade.tachiyomi.widget.sheet.BaseBottomSheetDialog @@ -65,7 +64,7 @@ class TrackSheet( val track = adapter.getItem(position)?.track ?: return if (track.tracking_url.isNotBlank()) { - controller.activity?.startActivity(Intent(Intent.ACTION_VIEW, track.tracking_url.toUri())) + controller.openInBrowser(track.tracking_url) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt index ca83ab4df..6f48aff70 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt @@ -1,10 +1,8 @@ package eu.kanade.tachiyomi.ui.more import android.app.Dialog -import android.content.Intent import android.os.Build import android.os.Bundle -import androidx.core.net.toUri import androidx.core.os.bundleOf import androidx.preference.PreferenceScreen import com.afollestad.materialdialogs.MaterialDialog @@ -15,6 +13,7 @@ import eu.kanade.tachiyomi.data.updater.UpdateResult import eu.kanade.tachiyomi.data.updater.UpdaterService import eu.kanade.tachiyomi.data.updater.github.GithubUpdateChecker import eu.kanade.tachiyomi.ui.base.controller.DialogController +import eu.kanade.tachiyomi.ui.base.controller.openInBrowser import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.util.lang.launchNow import eu.kanade.tachiyomi.util.lang.toDateTimestampString @@ -76,19 +75,15 @@ class AboutController : SettingsController() { } else { "https://github.com/tachiyomiorg/tachiyomi/releases/tag/v${BuildConfig.VERSION_NAME}" } - - val intent = Intent(Intent.ACTION_VIEW, url.toUri()) - startActivity(intent) + openInBrowser(url) } } if (BuildConfig.DEBUG) { preference { key = "pref_about_notices" titleRes = R.string.notices - onClick { - val intent = Intent(Intent.ACTION_VIEW, "https://github.com/tachiyomiorg/tachiyomi/blob/master/PREVIEW_RELEASE_NOTES.md".toUri()) - startActivity(intent) + openInBrowser("https://github.com/tachiyomiorg/tachiyomi/blob/master/PREVIEW_RELEASE_NOTES.md") } } } @@ -100,8 +95,7 @@ class AboutController : SettingsController() { val url = "https://tachiyomi.org" summary = url onClick { - val intent = Intent(Intent.ACTION_VIEW, url.toUri()) - startActivity(intent) + openInBrowser(url) } } preference { @@ -110,8 +104,7 @@ class AboutController : SettingsController() { val url = "https://discord.gg/tachiyomi" summary = url onClick { - val intent = Intent(Intent.ACTION_VIEW, url.toUri()) - startActivity(intent) + openInBrowser(url) } } preference { @@ -120,8 +113,7 @@ class AboutController : SettingsController() { val url = "https://github.com/tachiyomiorg/tachiyomi" summary = url onClick { - val intent = Intent(Intent.ACTION_VIEW, url.toUri()) - startActivity(intent) + openInBrowser(url) } } preference { @@ -130,8 +122,7 @@ class AboutController : SettingsController() { val url = "https://github.com/tachiyomiorg/tachiyomi-extensions" summary = url onClick { - val intent = Intent(Intent.ACTION_VIEW, url.toUri()) - startActivity(intent) + openInBrowser(url) } } preference {