Skip to content

Commit

Permalink
chore: merge branch 'release/1.8.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
ghasemdev committed Sep 23, 2023
2 parents 2119dab + 77442e8 commit 268d61b
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 16 deletions.
3 changes: 3 additions & 0 deletions affogato-pdf-viewer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ android {

defaultConfig {
minSdk = MIN_SDK
consumerProguardFiles("consumer-rules.pro")
}
buildFeatures {
compose = true
Expand All @@ -41,6 +42,8 @@ dependencies {
implementation(libs.retrofit)
// PdfBox ---------------------------------------------------------------------------------------
api(libs.pdfbox)
// Android Pdf Viewer ----------------------------------------------------------------------------
implementation(libs.android.pdf.viewer)
}

afterEvaluate {
Expand Down
1 change: 1 addition & 0 deletions affogato-pdf-viewer/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-keep class com.shockwave.**
5 changes: 5 additions & 0 deletions affogato-pdf-viewer/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import com.parsuomash.affogato.pdfviewer.zoomable.rememberZoomableState
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun HorizontalPDFReader(
modifier: Modifier = Modifier,
state: HorizontalPdfReaderState,
zoomableState: ZoomableState = rememberZoomableState(
minScale = ZoomableDefaults.DefaultScale
),
modifier: Modifier
)
) {
BoxWithConstraints(
modifier = modifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
@file:Suppress("unused")

package com.parsuomash.affogato.pdfviewer

import android.net.Uri
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView
import com.github.barteksc.pdfviewer.PDFView
import com.github.barteksc.pdfviewer.util.FitPolicy
import com.parsuomash.affogato.pdfviewer.zoomable.ZoomableDefaults
import com.parsuomash.affogato.pdfviewer.zoomable.ZoomableState
import com.parsuomash.affogato.pdfviewer.zoomable.rememberZoomableState
import java.io.File
import java.io.InputStream

@Composable
fun HorizontalPDFView(
modifier: Modifier = Modifier,
uri: Uri,
zoomableState: ZoomableState = rememberZoomableState(
minScale = ZoomableDefaults.DefaultScale
)
) {
HorizontalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) {
it.fromUri(uri)
}
}

@Composable
fun HorizontalPDFView(
modifier: Modifier = Modifier,
file: File,
zoomableState: ZoomableState = rememberZoomableState(
minScale = ZoomableDefaults.DefaultScale
)
) {
HorizontalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) {
it.fromFile(file)
}
}

@Composable
fun HorizontalPDFView(
modifier: Modifier = Modifier,
assetName: String,
zoomableState: ZoomableState = rememberZoomableState(
minScale = ZoomableDefaults.DefaultScale
)
) {
HorizontalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) {
it.fromAsset(assetName)
}
}

@Composable
fun HorizontalPDFView(
modifier: Modifier = Modifier,
bytes: ByteArray,
zoomableState: ZoomableState = rememberZoomableState(
minScale = ZoomableDefaults.DefaultScale
)
) {
HorizontalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) {
it.fromBytes(bytes)
}
}

@Composable
fun HorizontalPDFView(
modifier: Modifier = Modifier,
stream: InputStream,
zoomableState: ZoomableState = rememberZoomableState(
minScale = ZoomableDefaults.DefaultScale
)
) {
HorizontalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) {
it.fromStream(stream)
}
}

@Composable
private fun HorizontalPDFViewImpl(
modifier: Modifier,
zoomableState: ZoomableState,
configurator: (PDFView) -> PDFView.Configurator
) {
var currentPage by rememberSaveable { mutableIntStateOf(0) }
var isDefaultPageLoaded by rememberSaveable { mutableStateOf(false) }

AndroidView(
modifier = modifier,
factory = { context ->
PDFView(context, null).also {
it.clipToOutline = true
}
},
update = { pdfView ->
pdfView.apply {
configurator(pdfView).apply {
minZoom = zoomableState.minScale
midZoom = zoomableState.doubleTapScale
maxZoom = zoomableState.maxScale
pageFitPolicy(FitPolicy.WIDTH)
useBestQuality(true)

swipeHorizontal(true)
pageSnap(true)
autoSpacing(true)
pageFling(true)

if (isDefaultPageLoaded.not()) {
defaultPage(currentPage)
isDefaultPageLoaded = true
}
}.load()
}
},
onRelease = { pdfView ->
currentPage = pdfView.currentPage
isDefaultPageLoaded = false
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import com.parsuomash.affogato.pdfviewer.zoomable.rememberZoomableState

@Composable
fun VerticalPDFReader(
modifier: Modifier = Modifier,
state: VerticalPdfReaderState,
zoomableState: ZoomableState = rememberZoomableState(
minScale = ZoomableDefaults.DefaultScale
),
modifier: Modifier
)
) {
BoxWithConstraints(
modifier = modifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
@file:Suppress("unused")

package com.parsuomash.affogato.pdfviewer

import android.net.Uri
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView
import com.github.barteksc.pdfviewer.PDFView
import com.github.barteksc.pdfviewer.util.FitPolicy
import com.parsuomash.affogato.pdfviewer.zoomable.ZoomableDefaults
import com.parsuomash.affogato.pdfviewer.zoomable.ZoomableState
import com.parsuomash.affogato.pdfviewer.zoomable.rememberZoomableState
import java.io.File
import java.io.InputStream

@Composable
fun VerticalPDFView(
modifier: Modifier = Modifier,
uri: Uri,
zoomableState: ZoomableState = rememberZoomableState(
minScale = ZoomableDefaults.DefaultScale
)
) {
VerticalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) {
it.fromUri(uri)
}
}

@Composable
fun VerticalPDFView(
modifier: Modifier = Modifier,
file: File,
zoomableState: ZoomableState = rememberZoomableState(
minScale = ZoomableDefaults.DefaultScale
)
) {
VerticalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) {
it.fromFile(file)
}
}

@Composable
fun VerticalPDFView(
modifier: Modifier = Modifier,
assetName: String,
zoomableState: ZoomableState = rememberZoomableState(
minScale = ZoomableDefaults.DefaultScale
)
) {
VerticalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) {
it.fromAsset(assetName)
}
}

@Composable
fun VerticalPDFView(
modifier: Modifier = Modifier,
bytes: ByteArray,
zoomableState: ZoomableState = rememberZoomableState(
minScale = ZoomableDefaults.DefaultScale
)
) {
VerticalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) {
it.fromBytes(bytes)
}
}

@Composable
fun VerticalPDFView(
modifier: Modifier = Modifier,
stream: InputStream,
zoomableState: ZoomableState = rememberZoomableState(
minScale = ZoomableDefaults.DefaultScale
)
) {
VerticalPDFViewImpl(modifier = modifier, zoomableState = zoomableState) {
it.fromStream(stream)
}
}

@Composable
private fun VerticalPDFViewImpl(
modifier: Modifier,
zoomableState: ZoomableState,
configurator: (PDFView) -> PDFView.Configurator
) {
var currentPage by rememberSaveable { mutableIntStateOf(0) }
var isDefaultPageLoaded by rememberSaveable { mutableStateOf(false) }

AndroidView(
modifier = modifier,
factory = { context ->
PDFView(context, null).also {
it.clipToOutline = true
}
},
update = { pdfView ->
pdfView.apply {
configurator(pdfView).apply {
minZoom = zoomableState.minScale
midZoom = zoomableState.doubleTapScale
maxZoom = zoomableState.maxScale
pageFitPolicy(FitPolicy.WIDTH)
useBestQuality(true)

if (isDefaultPageLoaded.not()) {
defaultPage(currentPage)
isDefaultPageLoaded = true
}
}.load()
}
},
onRelease = { pdfView ->
currentPage = pdfView.currentPage
isDefaultPageLoaded = false
}
)
}
8 changes: 7 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[versions]
accompanist = "0.32.0"
affogato = "1.8.3"
affogato = "1.8.4"
agp = "8.1.1"
android-pdf-viewer = "3.2.0-beta.3"
case-format = "0.2.0"
compose = "1.5.1"
compose-activity = "1.8.0-beta01"
Expand Down Expand Up @@ -36,10 +37,13 @@ timber = "5.0.1"
truth = "1.1.5"
retrofit = "2.9.0"
window = "1.1.0"
appcompat = "1.6.1"
material = "1.9.0"

[libraries]
accompanist-pager = { module = "com.google.accompanist:accompanist-pager", version.ref = "accompanist" }
accompanist-pager-indicators = { module = "com.google.accompanist:accompanist-pager-indicators", version.ref = "accompanist" }
android-pdf-viewer = { module = "com.github.mhiew:android-pdf-viewer", version.ref = "android-pdf-viewer" }
androidx-junit = { module = "androidx.test.ext:junit", version.ref = "junit-android" }
case-format = { module = "com.fleshgrinder.kotlin:case-format", version.ref = "case-format" }
compose-activity = { module = "androidx.activity:activity-compose", version.ref = "compose-activity" }
Expand Down Expand Up @@ -92,6 +96,8 @@ timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
truth = { module = "com.google.truth:truth", version.ref = "truth" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
window = { module = "androidx.window:window", version.ref = "window" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down
1 change: 0 additions & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
Expand Down
Loading

0 comments on commit 268d61b

Please sign in to comment.