Skip to content

Commit e354fe7

Browse files
committed
-Updated PdfToolBarMenuItem dialog behavior
-Using List<PdfToolBarMenuItem> instead of filter function for defaultMenu in custom PdfToolBarMenu in compose -Renamed PdfToolBar menu item Download to Save
1 parent cd27eed commit e354fe7

File tree

6 files changed

+221
-198
lines changed

6 files changed

+221
-198
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ android {
1414
minSdk = 23
1515
targetSdk = 35
1616
versionCode = 110
17-
versionName = "1.1.0"
17+
versionName = "1.1.1"
1818

1919
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2020
}

app/release/app-release.apk

11 Bytes
Binary file not shown.

app/src/main/java/com/bhuvaneshw/pdfviewerdemo/ComposePdfViewerActivity.kt

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ private fun Activity.MainScreen(
268268
exit = fadeOut() + slideOutVertically { -it },
269269
) {
270270
var onPickColorCallback by remember { mutableStateOf<((Color) -> Unit)?>(null) }
271+
var showZoomLimitDialog by remember { mutableStateOf(false) }
271272

272273
PdfToolBar(
273274
title = title,
@@ -277,9 +278,10 @@ private fun Activity.MainScreen(
277278
showEditor = true,
278279
dropDownMenu = { onDismiss, defaultMenus ->
279280
ExtendedTooBarMenus(
280-
pdfState,
281-
onDismiss,
282-
defaultMenus
281+
pdfState = pdfState,
282+
showZoomLimitDialog = { showZoomLimitDialog = it },
283+
onDismiss = onDismiss,
284+
defaultMenus = defaultMenus
283285
)
284286
},
285287
pickColor = { onPickColor ->
@@ -298,6 +300,12 @@ private fun Activity.MainScreen(
298300
onPickColorCallback = null
299301
}
300302
)
303+
304+
if (showZoomLimitDialog)
305+
ZoomLimitDialog(
306+
state = pdfState,
307+
onDismiss = { showZoomLimitDialog = false }
308+
)
301309
}
302310
},
303311
pdfScrollBar = { parentSize ->
@@ -329,20 +337,19 @@ private fun Activity.MainScreen(
329337
@OptIn(PdfUnstableApi::class)
330338
@Composable
331339
private fun Activity.ExtendedTooBarMenus(
332-
state: PdfState,
340+
pdfState: PdfState,
341+
showZoomLimitDialog: (Boolean) -> Unit,
333342
onDismiss: () -> Unit,
334-
defaultMenus: @Composable (filter: (PdfToolBarMenuItem) -> Boolean) -> Unit
343+
defaultMenus: @Composable (filtered: List<PdfToolBarMenuItem>) -> Unit
335344
) {
336-
var showZoomLimitDialog by remember { mutableStateOf(false) }
337345
val dropDownModifier = Modifier.padding(start = 6.dp, end = 18.dp)
338346
val authority = "${BuildConfig.APPLICATION_ID}.file.provider"
339347

340-
if (state.pdfViewer?.createSharableUri(authority) != null) {
348+
if (pdfState.pdfViewer?.createSharableUri(authority) != null) {
341349
DropdownMenuItem(
342350
text = { Text(text = "Share", modifier = dropDownModifier) },
343351
onClick = {
344-
onDismiss()
345-
state.pdfViewer
352+
pdfState.pdfViewer
346353
?.createSharableUri(authority)
347354
?.let {
348355
val shareIntent = Intent(Intent.ACTION_SEND).apply {
@@ -352,54 +359,55 @@ private fun Activity.ExtendedTooBarMenus(
352359
}
353360
startActivity(Intent.createChooser(shareIntent, "Share PDF using"))
354361
} ?: toast("Unable to share pdf!")
362+
onDismiss()
355363
}
356364
)
357365
DropdownMenuItem(
358366
text = { Text(text = "Open With", modifier = dropDownModifier) },
359367
onClick = {
360-
onDismiss()
361-
state.pdfViewer
368+
pdfState.pdfViewer
362369
?.createSharableUri(authority)
363370
?.let {
364371
startActivity(Intent(Intent.ACTION_VIEW, it).apply {
365372
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
366373
})
367374
} ?: toast("Unable to open pdf with other apps!")
375+
onDismiss()
368376
}
369377
)
370378
}
371379

372380
DropdownMenuItem(
373381
text = { Text(text = "Print", modifier = dropDownModifier) },
374382
onClick = {
383+
pdfState.pdfViewer?.printFile()
375384
onDismiss()
376-
state.pdfViewer?.printFile()
377385
}
378386
)
379387
DropdownMenuItem(
380388
text = { Text(text = "Zoom Limit", modifier = dropDownModifier) },
381-
onClick = { showZoomLimitDialog = true }
389+
onClick = {
390+
showZoomLimitDialog(true)
391+
onDismiss()
392+
}
382393
)
383394
DropdownMenuItem(
384395
text = {
385396
Text(
386397
text = (
387-
if (state.pdfViewer?.scrollSpeedLimit == PdfViewer.ScrollSpeedLimit.None) "Enable"
398+
if (pdfState.pdfViewer?.scrollSpeedLimit == PdfViewer.ScrollSpeedLimit.None) "Enable"
388399
else "Disable"
389400
) + " scroll speed limit", modifier = dropDownModifier
390401
)
391402
},
392403
onClick = {
393-
if (state.pdfViewer?.scrollSpeedLimit == PdfViewer.ScrollSpeedLimit.None)
394-
state.pdfViewer?.scrollSpeedLimit = PdfViewer.ScrollSpeedLimit.AdaptiveFling()
395-
else state.pdfViewer?.scrollSpeedLimit = PdfViewer.ScrollSpeedLimit.None
404+
if (pdfState.pdfViewer?.scrollSpeedLimit == PdfViewer.ScrollSpeedLimit.None)
405+
pdfState.pdfViewer?.scrollSpeedLimit = PdfViewer.ScrollSpeedLimit.AdaptiveFling()
406+
else pdfState.pdfViewer?.scrollSpeedLimit = PdfViewer.ScrollSpeedLimit.None
396407
onDismiss()
397408
}
398409
)
399-
defaultMenus { true }
400-
401-
if (showZoomLimitDialog)
402-
ZoomLimitDialog(state = state, onDismiss = { showZoomLimitDialog = false; onDismiss() })
410+
defaultMenus(PdfToolBarMenuItem.entries)
403411
}
404412

405413
@OptIn(ExperimentalMaterial3Api::class)

0 commit comments

Comments
 (0)