Skip to content

Commit a4ee3e1

Browse files
committed
fix parcelize crash and sharing not attaching files due to permissions
1 parent 75dd54a commit a4ee3e1

4 files changed

Lines changed: 14 additions & 10 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ This library provides an easy to consume Android Composable that will display PD
77
## Add the dependency
88

99
```Gradle
10-
implementation 'com.pnuema.android:pdfviewer:1.3.3'
10+
implementation 'com.pnuema.android:pdfviewer:1.3.4'
1111
```
1212
```Kotlin(KTS)
13-
implementation("com.pnuema.android:pdfviewer:1.3.3")
13+
implementation("com.pnuema.android:pdfviewer:1.3.4")
1414
```
1515
```TOML
16-
pdfviewer = { module = "com.pnuema.android:pdfviewer", version.ref = "1.3.3" }
16+
pdfviewer = { module = "com.pnuema.android:pdfviewer", version.ref = "1.3.4" }
1717
```
1818

1919
## Usage

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
2828
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true
2929

3030
GROUP=com.pnuema.android
31-
VERSION_NAME=1.3.3
31+
VERSION_NAME=1.3.4
3232

3333
POM_NAME=PdfViewer
3434
POM_ARTIFACT_ID=pdfviewer

pdfviewer/src/main/kotlin/com/pnuema/android/pdfviewer/PdfOptions.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
1111
import kotlinx.coroutines.flow.asStateFlow
1212
import kotlinx.coroutines.flow.update
1313
import kotlinx.parcelize.Parcelize
14-
import kotlinx.parcelize.RawValue
1514

1615
data class PdfOptions(
1716
val maxScale: Float = 5f,
@@ -51,7 +50,7 @@ data class PdfOptions(
5150
allowSharing = state.allowSharing,
5251
removeFileWhenFinished = state.removeFileWhenFinished,
5352
backgroundColor = state.backgroundColor.value,
54-
spacingBetweenPages = state.spacingBetweenPages
53+
spacingBetweenPages = state.spacingBetweenPages.value
5554
)
5655
},
5756
restore = { saved ->
@@ -62,7 +61,7 @@ data class PdfOptions(
6261
allowSharing = saved.allowSharing,
6362
removeFileWhenFinished = saved.removeFileWhenFinished,
6463
backgroundColor = Color(saved.backgroundColor),
65-
spacingBetweenPages = saved.spacingBetweenPages
64+
spacingBetweenPages = saved.spacingBetweenPages.dp
6665
)
6766
},
6867
)
@@ -96,5 +95,5 @@ data class PdfOptionsSavedState(
9695
val allowSharing: Boolean,
9796
val removeFileWhenFinished: Boolean,
9897
val backgroundColor: ULong,
99-
val spacingBetweenPages: @RawValue Dp
98+
val spacingBetweenPages: Float
10099
) : Parcelable

pdfviewer/src/main/kotlin/com/pnuema/android/pdfviewer/actions/PdfActionUtil.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import android.content.Context.PRINT_SERVICE
55
import android.content.Intent
66
import android.print.PrintManager
77
import androidx.compose.ui.unit.IntSize
8-
import androidx.core.net.toUri
8+
import androidx.core.content.FileProvider
99
import com.pnuema.android.pdfviewer.generator.PdfBitmapGenerator
1010
import com.pnuema.android.pdfviewer.print.PdfPrintDocumentAdapter
1111
import java.io.File
1212

13+
1314
object PdfActionUtil {
1415
fun print(
1516
context: Context,
@@ -31,11 +32,15 @@ object PdfActionUtil {
3132
}
3233

3334
fun share(context: Context, file: File) {
35+
val uri = FileProvider.getUriForFile(
36+
context,
37+
context.applicationContext.packageName + ".provider", file
38+
)
3439
context.startActivity(
3540
Intent(Intent.ACTION_SEND).apply {
3641
setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
3742
setType("application/pdf")
38-
putExtra(Intent.EXTRA_STREAM, file.path.toUri())
43+
putExtra(Intent.EXTRA_STREAM, uri)
3944
}
4045
)
4146
}

0 commit comments

Comments
 (0)