From 7f0b5ec5d877e1ac3c9da66436d06e41a7d5f991 Mon Sep 17 00:00:00 2001 From: Nutrient <> Date: Thu, 21 Nov 2024 12:33:44 +0000 Subject: [PATCH] Update example to Nutrient for Android 2024.8.0 --- app/build.gradle.kts | 4 +-- .../example/ui/screens/pdf/PdfScreen.kt | 32 ++++++++++++++++++- settings.gradle.kts | 4 +-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ab5c2c0..553d26e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -48,9 +48,9 @@ android { dependencies { - // PSPDFKit is integrated from the PSPDFKit Maven repository. See the `repositories` block at the beginning + // Nutrient is integrated from the Nutrient Maven repository. See the `repositories` block at the beginning // of this file, which shows how to set up the repository in your app. - implementation("com.pspdfkit:pspdfkit:2024.7.0") + implementation("com.pspdfkit:pspdfkit:2024.8.0") implementation("androidx.datastore:datastore-preferences:1.1.1") diff --git a/app/src/main/java/com/pspdfkit/example/ui/screens/pdf/PdfScreen.kt b/app/src/main/java/com/pspdfkit/example/ui/screens/pdf/PdfScreen.kt index 67f8409..e796413 100644 --- a/app/src/main/java/com/pspdfkit/example/ui/screens/pdf/PdfScreen.kt +++ b/app/src/main/java/com/pspdfkit/example/ui/screens/pdf/PdfScreen.kt @@ -17,17 +17,23 @@ import androidx.compose.animation.fadeOut import androidx.compose.animation.shrinkVertically import androidx.compose.animation.slideInVertically import androidx.compose.animation.slideOutVertically +import androidx.compose.foundation.clickable import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.outlined.ArrowBack +import androidx.compose.material.icons.outlined.Square import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.derivedStateOf @@ -44,6 +50,7 @@ import androidx.compose.ui.unit.dp import androidx.core.net.toUri import com.pspdfkit.compose.theme.MainToolbarColors import com.pspdfkit.compose.theme.ToolbarPopupColors +import com.pspdfkit.compose.theme.UiTheme import com.pspdfkit.compose.theme.getUiColors import com.pspdfkit.configuration.activity.PdfActivityConfiguration import com.pspdfkit.configuration.activity.UserInterfaceViewMode @@ -92,7 +99,7 @@ fun PdfUI(pdf: File, context: Context, theme: Int, isDark: Boolean, navigateTo: val localDensity = LocalDensity.current val pdfActivityConfiguration = PdfActivityConfiguration .Builder(context) - .disableDefaultToolbar() + .defaultToolbarEnabled(false) .setUserInterfaceViewMode(UserInterfaceViewMode.USER_INTERFACE_VIEW_MODE_AUTOMATIC) .themeMode(ThemeMode.DEFAULT) .themeDark(R.style.PSPDFCompose_Theme_Dark) @@ -150,6 +157,29 @@ fun PdfUI(pdf: File, context: Context, theme: Int, isDark: Boolean, navigateTo: Icon(imageVector = Icons.AutoMirrored.Outlined.ArrowBack, contentDescription = "Back", tint = it) } }, + overFlowActions = { + Row( + Modifier.clickable { + documentState.documentConnection.showToolbarMenu.invoke(false) + Toast.makeText(context, "Custom Action Button Clicked", Toast.LENGTH_LONG).show() + }.padding(horizontal = 16.dp, vertical = 13.dp) + ) { + Icon(imageVector = Icons.Outlined.Square, contentDescription = "Custom Action", tint = it) + Spacer(modifier = Modifier.width(8.dp)) + Text(text = "Custom Action", color = UiTheme.colors.mainToolbar.textColor) + } + /* + For Material 2 use this + DropdownMenuItem(onClick = { + documentState.documentConnection.showToolbarMenu.invoke(false) + Toast.makeText(context, "Custom Action Button Clicked", Toast.LENGTH_LONG).show() + }) { + Icon(imageVector = Icons.Outlined.Square, contentDescription = "Custom Action", tint = it) + Spacer(modifier = Modifier.width(8.dp)) + Text(text = "Custom Action", color = UiTheme.colors.mainToolbar.textColor) + } + */ + }, onHeightChanged = { height -> toolbarHeight = with(localDensity) { height.toDp() } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 4d041f6..18e9f27 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -10,8 +10,8 @@ dependencyResolutionManagement { repositories { google() mavenCentral() - // The PSPDFKit library is loaded from the PSPDFKit Maven repository, added by this configuration. - maven(url = "https://customers.pspdfkit.com/maven/") + // The Nutrient library is loaded from the Nutrient Maven repository, added by this configuration. + maven(url = "https://my.nutrient.io/maven/") } versionCatalogs {