Bug fixes (#319)
* Fix TTS speaker persistence * optimized redundant WebView updates * Bumped version to 1.0.48
This commit is contained in:
parent
70c272baa7
commit
bcf34af719
11 changed files with 781 additions and 173 deletions
|
|
@ -13,6 +13,8 @@ import android.print.PrintDocumentInfo
|
|||
import android.provider.OpenableColumns
|
||||
import android.util.LruCache
|
||||
import androidx.core.graphics.createBitmap
|
||||
import com.aryan.reader.pdf.data.PdfAnnotation
|
||||
import com.aryan.reader.pdf.data.PdfTextBox
|
||||
import io.legere.pdfiumandroid.suspend.PdfiumCoreKt
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
|
@ -135,6 +137,25 @@ internal fun getSuggestedFilename(originalName: String?, isAnnotated: Boolean):
|
|||
return "${safeBase}${suffix}_${shortId}.pdf"
|
||||
}
|
||||
|
||||
internal fun hasExportablePdfAnnotations(
|
||||
annotations: Map<Int, List<PdfAnnotation>>,
|
||||
textBoxes: List<PdfTextBox>,
|
||||
highlights: List<PdfUserHighlight>
|
||||
): Boolean {
|
||||
return annotations.any { (_, pageAnnotations) -> pageAnnotations.isNotEmpty() } ||
|
||||
textBoxes.isNotEmpty() ||
|
||||
highlights.isNotEmpty()
|
||||
}
|
||||
|
||||
internal fun shouldShowPdfAnnotationExportChoice(
|
||||
sidecarsReady: Boolean,
|
||||
annotations: Map<Int, List<PdfAnnotation>>,
|
||||
textBoxes: List<PdfTextBox>,
|
||||
highlights: List<PdfUserHighlight>
|
||||
): Boolean {
|
||||
return !sidecarsReady || hasExportablePdfAnnotations(annotations, textBoxes, highlights)
|
||||
}
|
||||
|
||||
internal fun getFastFileId(context: Context, uri: Uri): String {
|
||||
var result = uri.toString()
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -2256,6 +2256,91 @@ fun PdfViewerScreen(
|
|||
var showShareDialog by remember { mutableStateOf(false) }
|
||||
var showSaveDialog by remember { mutableStateOf(false) }
|
||||
var isShareLoading by remember { mutableStateOf(false) }
|
||||
val shouldShowAnnotationExportChoice = shouldShowPdfAnnotationExportChoice(
|
||||
sidecarsReady = sidecarsReadyForCurrentBook,
|
||||
annotations = visibleAllAnnotations,
|
||||
textBoxes = visibleTextBoxes,
|
||||
highlights = visibleUserHighlights
|
||||
)
|
||||
|
||||
val launchOriginalSaveCopy: () -> Unit = {
|
||||
pendingSaveMode = SaveMode.ORIGINAL
|
||||
val suggestedName = getSuggestedFilename(
|
||||
originalFileName, isAnnotated = false
|
||||
)
|
||||
saveLauncher.launch(suggestedName)
|
||||
}
|
||||
|
||||
val launchAnnotatedSaveCopy: () -> Unit = {
|
||||
pendingSaveMode = SaveMode.ANNOTATED
|
||||
val suggestedName = getSuggestedFilename(
|
||||
originalFileName, isAnnotated = true
|
||||
)
|
||||
saveLauncher.launch(suggestedName)
|
||||
}
|
||||
|
||||
val shareOriginalPdf: () -> Unit = {
|
||||
isShareLoading = true
|
||||
val filename = getSuggestedFilename(
|
||||
originalFileName, isAnnotated = false
|
||||
)
|
||||
coroutineScope.launch {
|
||||
try {
|
||||
viewModel.sharePdf(
|
||||
activityContext = context,
|
||||
sourceUri = pdfUri,
|
||||
annotations = emptyMap(),
|
||||
includeAnnotations = false,
|
||||
filename = filename
|
||||
)
|
||||
} finally {
|
||||
isShareLoading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val shareAnnotatedPdf: () -> Unit = {
|
||||
isShareLoading = true
|
||||
Timber.tag("PdfExportDebug").i("SHARE TRIGGERED: userHighlights count: ${visibleUserHighlights.size}")
|
||||
val filename = getSuggestedFilename(
|
||||
originalFileName, isAnnotated = true
|
||||
)
|
||||
coroutineScope.launch {
|
||||
try {
|
||||
val currentRichTextLayouts = richTextController?.pageLayouts
|
||||
|
||||
viewModel.sharePdf(
|
||||
activityContext = context,
|
||||
sourceUri = effectivePdfUri,
|
||||
annotations = visibleAllAnnotations,
|
||||
richTextPageLayouts = currentRichTextLayouts,
|
||||
textBoxes = visibleTextBoxes,
|
||||
highlights = visibleUserHighlights,
|
||||
includeAnnotations = true,
|
||||
filename = filename,
|
||||
bookId = currentBookId
|
||||
)
|
||||
} finally {
|
||||
isShareLoading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val requestSaveCopy: () -> Unit = {
|
||||
if (shouldShowAnnotationExportChoice) {
|
||||
showSaveDialog = true
|
||||
} else {
|
||||
launchOriginalSaveCopy()
|
||||
}
|
||||
}
|
||||
|
||||
val requestShare: () -> Unit = {
|
||||
if (shouldShowAnnotationExportChoice) {
|
||||
showShareDialog = true
|
||||
} else {
|
||||
shareOriginalPdf()
|
||||
}
|
||||
}
|
||||
|
||||
var ocrUsedForCurrentPageTts by remember { mutableStateOf(false) }
|
||||
|
||||
|
|
@ -5358,8 +5443,8 @@ fun PdfViewerScreen(
|
|||
}
|
||||
}
|
||||
},
|
||||
onShare = { showShareDialog = true },
|
||||
onSaveCopy = { showSaveDialog = true },
|
||||
onShare = requestShare,
|
||||
onSaveCopy = requestSaveCopy,
|
||||
onPrint = onPrintDocument,
|
||||
onTabClick = { tabBookId ->
|
||||
coroutineScope.launch {
|
||||
|
|
@ -7030,11 +7115,7 @@ fun PdfViewerScreen(
|
|||
TextButton(
|
||||
onClick = {
|
||||
showSaveDialog = false
|
||||
pendingSaveMode = SaveMode.ANNOTATED
|
||||
val suggestedName = getSuggestedFilename(
|
||||
originalFileName, isAnnotated = true
|
||||
)
|
||||
saveLauncher.launch(suggestedName)
|
||||
launchAnnotatedSaveCopy()
|
||||
}) { Text(stringResource(R.string.action_with_annotations)) }
|
||||
|
||||
}
|
||||
|
|
@ -7044,11 +7125,7 @@ fun PdfViewerScreen(
|
|||
TextButton(
|
||||
onClick = {
|
||||
showSaveDialog = false
|
||||
pendingSaveMode = SaveMode.ORIGINAL
|
||||
val suggestedName = getSuggestedFilename(
|
||||
originalFileName, isAnnotated = false
|
||||
)
|
||||
saveLauncher.launch(suggestedName)
|
||||
launchOriginalSaveCopy()
|
||||
}) { Text(stringResource(R.string.action_original)) }
|
||||
|
||||
Spacer(Modifier.width(8.dp))
|
||||
|
|
@ -7072,27 +7149,7 @@ fun PdfViewerScreen(
|
|||
TextButton(
|
||||
onClick = {
|
||||
showShareDialog = false
|
||||
isShareLoading = true
|
||||
Timber.tag("PdfExportDebug").i("SHARE TRIGGERED: userHighlights count: ${visibleUserHighlights.size}")
|
||||
val filename = getSuggestedFilename(
|
||||
originalFileName, isAnnotated = true
|
||||
)
|
||||
coroutineScope.launch {
|
||||
val currentRichTextLayouts = richTextController?.pageLayouts
|
||||
|
||||
viewModel.sharePdf(
|
||||
activityContext = context,
|
||||
sourceUri = effectivePdfUri,
|
||||
annotations = visibleAllAnnotations,
|
||||
richTextPageLayouts = currentRichTextLayouts,
|
||||
textBoxes = visibleTextBoxes,
|
||||
highlights = visibleUserHighlights,
|
||||
includeAnnotations = true,
|
||||
filename = filename,
|
||||
bookId = currentBookId
|
||||
)
|
||||
isShareLoading = false
|
||||
}
|
||||
shareAnnotatedPdf()
|
||||
}) { Text(stringResource(R.string.action_with_annotations)) }
|
||||
|
||||
}
|
||||
|
|
@ -7102,20 +7159,7 @@ fun PdfViewerScreen(
|
|||
TextButton(
|
||||
onClick = {
|
||||
showShareDialog = false
|
||||
isShareLoading = true
|
||||
val filename = getSuggestedFilename(
|
||||
originalFileName, isAnnotated = false
|
||||
)
|
||||
coroutineScope.launch {
|
||||
viewModel.sharePdf(
|
||||
activityContext = context,
|
||||
sourceUri = pdfUri,
|
||||
annotations = emptyMap(),
|
||||
includeAnnotations = false,
|
||||
filename = filename
|
||||
)
|
||||
isShareLoading = false
|
||||
}
|
||||
shareOriginalPdf()
|
||||
}) { Text(stringResource(R.string.action_original)) }
|
||||
Spacer(Modifier.width(8.dp))
|
||||
TextButton(onClick = { showShareDialog = false }) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue