diff --git a/app/src/main/java/info/plateaukao/einkbro/activity/BrowserActivity.kt b/app/src/main/java/info/plateaukao/einkbro/activity/BrowserActivity.kt index 733fe2c5..6ce22236 100755 --- a/app/src/main/java/info/plateaukao/einkbro/activity/BrowserActivity.kt +++ b/app/src/main/java/info/plateaukao/einkbro/activity/BrowserActivity.kt @@ -2657,7 +2657,7 @@ open class BrowserActivity : FragmentActivity(), BrowserController { } } - private fun readArticle() { + protected fun readArticle() { lifecycleScope.launch { ttsViewModel.readArticle(ebWebView.getRawText()) } diff --git a/app/src/main/java/info/plateaukao/einkbro/activity/EpubReaderActivity.kt b/app/src/main/java/info/plateaukao/einkbro/activity/EpubReaderActivity.kt index 7b95b56d..a9427124 100644 --- a/app/src/main/java/info/plateaukao/einkbro/activity/EpubReaderActivity.kt +++ b/app/src/main/java/info/plateaukao/einkbro/activity/EpubReaderActivity.kt @@ -30,19 +30,32 @@ class EpubReaderActivity: BrowserActivity() { epubReader.showTocDialog() } override fun dispatchIntent(intent: Intent) { - val epubUri= intent.data ?: return - val shouldGotoLastChapter = intent.getBooleanExtra(ARG_TO_LAST_CHAPTER, false) - - addAlbum(url = BrowserUnit.URL_ABOUT_BLANK, enablePreloadWebView = false) // so that it won't miss the preload webview - lifecycleScope.launch { - with(ebWebView as EpubReaderView) { - openEpubFile(epubUri) - if (shouldGotoLastChapter) { - gotoLastChapter() - } else { - gotoPosition(0, 0F) + when (intent.action) { + Intent.ACTION_VIEW -> { + val epubUri = intent.data ?: return + val shouldGotoLastChapter = intent.getBooleanExtra(ARG_TO_LAST_CHAPTER, false) + + addAlbum( + url = BrowserUnit.URL_ABOUT_BLANK, + enablePreloadWebView = false + ) // so that it won't miss the preload webview + lifecycleScope.launch { + with(ebWebView as EpubReaderView) { + openEpubFile(epubUri) + if (shouldGotoLastChapter) { + gotoLastChapter() + } else { + gotoPosition(0, 0F) + } + } } } + ACTION_READ_ALOUD -> { + readArticle() + } + else -> { + super.dispatchIntent(intent) + } } } diff --git a/app/src/main/java/info/plateaukao/einkbro/unit/HelperUnit.kt b/app/src/main/java/info/plateaukao/einkbro/unit/HelperUnit.kt index e6fa24a5..094deab8 100755 --- a/app/src/main/java/info/plateaukao/einkbro/unit/HelperUnit.kt +++ b/app/src/main/java/info/plateaukao/einkbro/unit/HelperUnit.kt @@ -35,6 +35,7 @@ import android.util.Log import android.view.View import android.webkit.MimeTypeMap import androidx.activity.result.ActivityResultLauncher +import androidx.annotation.RequiresApi import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.buildAnnotatedString @@ -149,6 +150,7 @@ object HelperUnit { }) } + @RequiresApi(Build.VERSION_CODES.O) @JvmStatic fun createShortcut(context: Context, title: String?, url: String?, bitmap: Bitmap?) { val url = url ?: return diff --git a/app/src/main/java/info/plateaukao/einkbro/unit/IntentUnit.kt b/app/src/main/java/info/plateaukao/einkbro/unit/IntentUnit.kt index cf05006e..638639ed 100755 --- a/app/src/main/java/info/plateaukao/einkbro/unit/IntentUnit.kt +++ b/app/src/main/java/info/plateaukao/einkbro/unit/IntentUnit.kt @@ -95,7 +95,7 @@ object IntentUnit { fun readCurrentArticle(activity: Activity) { activity.startActivity( - Intent(activity, BrowserActivity::class.java).apply { + Intent(activity, activity::class.java).apply { action = BrowserActivity.ACTION_READ_ALOUD } ) diff --git a/app/src/main/java/info/plateaukao/einkbro/view/dialog/ShortcutEditDialog.kt b/app/src/main/java/info/plateaukao/einkbro/view/dialog/ShortcutEditDialog.kt index 15349d9b..3c1857aa 100644 --- a/app/src/main/java/info/plateaukao/einkbro/view/dialog/ShortcutEditDialog.kt +++ b/app/src/main/java/info/plateaukao/einkbro/view/dialog/ShortcutEditDialog.kt @@ -2,17 +2,19 @@ package info.plateaukao.einkbro.view.dialog import android.app.Activity import android.graphics.Bitmap +import android.os.Build import android.view.LayoutInflater +import androidx.annotation.RequiresApi import info.plateaukao.einkbro.databinding.DialogEditShortcutBinding import info.plateaukao.einkbro.unit.HelperUnit class ShortcutEditDialog( - private val activity: Activity, - private val title: String, - private val url: String, - private val bitmap: Bitmap?, - private val okAction: () -> Unit, - private val cancelAction: () -> Unit, + private val activity: Activity, + private val title: String, + private val url: String, + private val bitmap: Bitmap?, + private val okAction: () -> Unit, + private val cancelAction: () -> Unit, ) { private val dialogManager: DialogManager = DialogManager(activity) @@ -22,13 +24,18 @@ class ShortcutEditDialog( binding.url.setText(url) dialogManager.showOkCancelDialog( - title = activity.getString(info.plateaukao.einkbro.R.string.menu_sc), - view = binding.root, - okAction = { createShortcut(binding) }, - cancelAction = { cancelAction.invoke() } + title = activity.getString(info.plateaukao.einkbro.R.string.menu_sc), + view = binding.root, + okAction = { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + createShortcut(binding) + } + }, + cancelAction = { cancelAction.invoke() } ) } + @RequiresApi(Build.VERSION_CODES.O) private fun createShortcut(binding: DialogEditShortcutBinding) { HelperUnit.createShortcut( activity,