From 907714080071351f31495d95bbd4f8470cf2a1c6 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sun, 18 Jul 2021 00:56:32 -0400 Subject: [PATCH] Supporting Recents URL sharing Manga Details and reader will share manga url Browse Source will share source url --- .../kanade/tachiyomi/ui/main/MainActivity.kt | 22 +++++++++++++++++++ .../tachiyomi/ui/reader/ReaderActivity.kt | 15 +++++++++++++ .../tachiyomi/ui/reader/ReaderPresenter.kt | 4 ++++ 3 files changed, 41 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 55e124b954..1c385eabd5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -3,10 +3,12 @@ package eu.kanade.tachiyomi.ui.main import android.animation.AnimatorSet import android.animation.ValueAnimator import android.app.Dialog +import android.app.assist.AssistContent import android.content.Intent import android.graphics.Color import android.graphics.Rect import android.graphics.drawable.Drawable +import android.net.Uri import android.os.Build import android.os.Bundle import android.os.Handler @@ -55,6 +57,7 @@ import eu.kanade.tachiyomi.data.updater.UpdateResult import eu.kanade.tachiyomi.data.updater.UpdaterNotifier import eu.kanade.tachiyomi.databinding.MainActivityBinding import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi +import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.MaterialMenuSheet import eu.kanade.tachiyomi.ui.base.activity.BaseActivity import eu.kanade.tachiyomi.ui.base.controller.BaseController @@ -647,6 +650,25 @@ open class MainActivity : BaseActivity(), DownloadServiceLi return true } + override fun onProvideAssistContent(outContent: AssistContent) { + super.onProvideAssistContent(outContent) + when (val controller = router.backstack.lastOrNull()?.controller) { + is MangaDetailsController -> { + val source = controller.presenter.source as? HttpSource ?: return + val url = try { + source.mangaDetailsRequest(controller.presenter.manga).url.toString() + } catch (e: Exception) { + return + } + outContent.webUri = Uri.parse(url) + } + is BrowseSourceController -> { + val source = controller.presenter.source as? HttpSource ?: return + outContent.webUri = Uri.parse(source.baseUrl) + } + } + } + override fun onDestroy() { super.onDestroy() overflowDialog?.dismiss() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index c137ac181a..62b408a7d7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.reader import android.annotation.SuppressLint +import android.app.assist.AssistContent import android.content.ClipData import android.content.Context import android.content.Intent @@ -9,6 +10,7 @@ import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.Color import android.graphics.drawable.LayerDrawable +import android.net.Uri import android.os.Build import android.os.Bundle import android.view.KeyEvent @@ -41,6 +43,7 @@ import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn import eu.kanade.tachiyomi.data.preference.toggle import eu.kanade.tachiyomi.databinding.ReaderActivityBinding import eu.kanade.tachiyomi.source.model.Page +import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.MaterialMenuSheet import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity import eu.kanade.tachiyomi.ui.main.MainActivity @@ -1225,6 +1228,18 @@ class ReaderActivity : startActivity(Intent.createChooser(intent, getString(R.string.share))) } + override fun onProvideAssistContent(outContent: AssistContent) { + super.onProvideAssistContent(outContent) + val manga = presenter.manga ?: return + val source = presenter.source as? HttpSource ?: return + val url = try { + source.mangaDetailsRequest(manga).url.toString() + } catch (e: Exception) { + return + } + outContent.webUri = Uri.parse(url) + } + /** * Called from the page sheet. It delegates saving the image of the given [page] on external * storage to the presenter. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index da4db21345..e50384e9f8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.DelayedTrackingUpdateJob import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.source.LocalSource +import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.online.HttpSource @@ -76,6 +77,9 @@ class ReaderPresenter( var manga: Manga? = null private set + val source: Source? + get() = manga?.source?.let { sourceManager.getOrStub(it) } + /** * The chapter id of the currently loaded chapter. Used to restore from process kill. */