Skip to content

Commit

Permalink
fix: now readaloud works in read epub activity too
Browse files Browse the repository at this point in the history
  • Loading branch information
plateaukao committed Nov 4, 2024
1 parent cbbc2db commit 7e95976
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2657,7 +2657,7 @@ open class BrowserActivity : FragmentActivity(), BrowserController {
}
}

private fun readArticle() {
protected fun readArticle() {
lifecycleScope.launch {
ttsViewModel.readArticle(ebWebView.getRawText())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/info/plateaukao/einkbro/unit/HelperUnit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
Expand Down

0 comments on commit 7e95976

Please sign in to comment.