mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2025-01-03 15:41:50 +01:00
Avoid crash when device fails to handle opening a URL
This commit is contained in:
parent
2e2663bad9
commit
61e5440b7c
@ -1,11 +1,14 @@
|
|||||||
package eu.kanade.tachiyomi.ui.base.controller
|
package eu.kanade.tachiyomi.ui.base.controller
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager.PERMISSION_GRANTED
|
import android.content.pm.PackageManager.PERMISSION_GRANTED
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.net.toUri
|
||||||
import com.bluelinelabs.conductor.Controller
|
import com.bluelinelabs.conductor.Controller
|
||||||
import com.bluelinelabs.conductor.Router
|
import com.bluelinelabs.conductor.Router
|
||||||
import com.bluelinelabs.conductor.RouterTransaction
|
import com.bluelinelabs.conductor.RouterTransaction
|
||||||
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
|
|
||||||
fun Router.popControllerWithTag(tag: String): Boolean {
|
fun Router.popControllerWithTag(tag: String): Boolean {
|
||||||
val controller = getControllerWithTag(tag)
|
val controller = getControllerWithTag(tag)
|
||||||
@ -32,3 +35,12 @@ fun Controller.withFadeTransaction(): RouterTransaction {
|
|||||||
.pushChangeHandler(OneWayFadeChangeHandler())
|
.pushChangeHandler(OneWayFadeChangeHandler())
|
||||||
.popChangeHandler(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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -14,7 +14,6 @@ import android.view.MenuItem
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.view.ContextThemeWrapper
|
import androidx.appcompat.view.ContextThemeWrapper
|
||||||
import androidx.core.net.toUri
|
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceGroupAdapter
|
import androidx.preference.PreferenceGroupAdapter
|
||||||
@ -36,6 +35,7 @@ import eu.kanade.tachiyomi.source.Source
|
|||||||
import eu.kanade.tachiyomi.source.getPreferenceKey
|
import eu.kanade.tachiyomi.source.getPreferenceKey
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.ToolbarLiftOnScrollController
|
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.ui.base.controller.withFadeTransaction
|
||||||
import eu.kanade.tachiyomi.util.preference.DSL
|
import eu.kanade.tachiyomi.util.preference.DSL
|
||||||
import eu.kanade.tachiyomi.util.preference.onChange
|
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"
|
!pkgFactory.isNullOrEmpty() -> "$URL_EXTENSION_COMMITS/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/$pkgFactory"
|
||||||
else -> "$URL_EXTENSION_COMMITS/src/${pkgName.replace(".", "/")}"
|
else -> "$URL_EXTENSION_COMMITS/src/${pkgName.replace(".", "/")}"
|
||||||
}
|
}
|
||||||
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
|
openInBrowser(url)
|
||||||
startActivity(intent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openInSettings() {
|
private fun openInSettings() {
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
package eu.kanade.tachiyomi.ui.main
|
package eu.kanade.tachiyomi.ui.main
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.core.net.toUri
|
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import eu.kanade.tachiyomi.BuildConfig
|
import eu.kanade.tachiyomi.BuildConfig
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||||
|
import eu.kanade.tachiyomi.ui.base.controller.openInBrowser
|
||||||
|
|
||||||
class WhatsNewDialogController(bundle: Bundle? = null) : DialogController(bundle) {
|
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))
|
.title(text = activity!!.getString(R.string.updated_version, BuildConfig.VERSION_NAME))
|
||||||
.positiveButton(android.R.string.ok)
|
.positiveButton(android.R.string.ok)
|
||||||
.neutralButton(R.string.whats_new) {
|
.neutralButton(R.string.whats_new) {
|
||||||
val url = "https://github.com/tachiyomiorg/tachiyomi/releases/tag/v${BuildConfig.VERSION_NAME}"
|
openInBrowser("https://github.com/tachiyomiorg/tachiyomi/releases/tag/v${BuildConfig.VERSION_NAME}")
|
||||||
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
|
|
||||||
startActivity(intent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
package eu.kanade.tachiyomi.ui.manga.track
|
package eu.kanade.tachiyomi.ui.manga.track
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.net.toUri
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.databinding.TrackControllerBinding
|
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.ui.manga.MangaController
|
||||||
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
||||||
import eu.kanade.tachiyomi.widget.sheet.BaseBottomSheetDialog
|
import eu.kanade.tachiyomi.widget.sheet.BaseBottomSheetDialog
|
||||||
@ -65,7 +64,7 @@ class TrackSheet(
|
|||||||
val track = adapter.getItem(position)?.track ?: return
|
val track = adapter.getItem(position)?.track ?: return
|
||||||
|
|
||||||
if (track.tracking_url.isNotBlank()) {
|
if (track.tracking_url.isNotBlank()) {
|
||||||
controller.activity?.startActivity(Intent(Intent.ACTION_VIEW, track.tracking_url.toUri()))
|
controller.openInBrowser(track.tracking_url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package eu.kanade.tachiyomi.ui.more
|
package eu.kanade.tachiyomi.ui.more
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.core.net.toUri
|
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
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.UpdaterService
|
||||||
import eu.kanade.tachiyomi.data.updater.github.GithubUpdateChecker
|
import eu.kanade.tachiyomi.data.updater.github.GithubUpdateChecker
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
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.ui.setting.SettingsController
|
||||||
import eu.kanade.tachiyomi.util.lang.launchNow
|
import eu.kanade.tachiyomi.util.lang.launchNow
|
||||||
import eu.kanade.tachiyomi.util.lang.toDateTimestampString
|
import eu.kanade.tachiyomi.util.lang.toDateTimestampString
|
||||||
@ -76,19 +75,15 @@ class AboutController : SettingsController() {
|
|||||||
} else {
|
} else {
|
||||||
"https://github.com/tachiyomiorg/tachiyomi/releases/tag/v${BuildConfig.VERSION_NAME}"
|
"https://github.com/tachiyomiorg/tachiyomi/releases/tag/v${BuildConfig.VERSION_NAME}"
|
||||||
}
|
}
|
||||||
|
openInBrowser(url)
|
||||||
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
|
|
||||||
startActivity(intent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
preference {
|
preference {
|
||||||
key = "pref_about_notices"
|
key = "pref_about_notices"
|
||||||
titleRes = R.string.notices
|
titleRes = R.string.notices
|
||||||
|
|
||||||
onClick {
|
onClick {
|
||||||
val intent = Intent(Intent.ACTION_VIEW, "https://github.com/tachiyomiorg/tachiyomi/blob/master/PREVIEW_RELEASE_NOTES.md".toUri())
|
openInBrowser("https://github.com/tachiyomiorg/tachiyomi/blob/master/PREVIEW_RELEASE_NOTES.md")
|
||||||
startActivity(intent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,8 +95,7 @@ class AboutController : SettingsController() {
|
|||||||
val url = "https://tachiyomi.org"
|
val url = "https://tachiyomi.org"
|
||||||
summary = url
|
summary = url
|
||||||
onClick {
|
onClick {
|
||||||
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
|
openInBrowser(url)
|
||||||
startActivity(intent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
preference {
|
preference {
|
||||||
@ -110,8 +104,7 @@ class AboutController : SettingsController() {
|
|||||||
val url = "https://discord.gg/tachiyomi"
|
val url = "https://discord.gg/tachiyomi"
|
||||||
summary = url
|
summary = url
|
||||||
onClick {
|
onClick {
|
||||||
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
|
openInBrowser(url)
|
||||||
startActivity(intent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
preference {
|
preference {
|
||||||
@ -120,8 +113,7 @@ class AboutController : SettingsController() {
|
|||||||
val url = "https://github.com/tachiyomiorg/tachiyomi"
|
val url = "https://github.com/tachiyomiorg/tachiyomi"
|
||||||
summary = url
|
summary = url
|
||||||
onClick {
|
onClick {
|
||||||
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
|
openInBrowser(url)
|
||||||
startActivity(intent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
preference {
|
preference {
|
||||||
@ -130,8 +122,7 @@ class AboutController : SettingsController() {
|
|||||||
val url = "https://github.com/tachiyomiorg/tachiyomi-extensions"
|
val url = "https://github.com/tachiyomiorg/tachiyomi-extensions"
|
||||||
summary = url
|
summary = url
|
||||||
onClick {
|
onClick {
|
||||||
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
|
openInBrowser(url)
|
||||||
startActivity(intent)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
preference {
|
preference {
|
||||||
|
Loading…
Reference in New Issue
Block a user