Skip to content

Commit

Permalink
Merge pull request #3 from arcanegolem/feature/page_dialog_scaling
Browse files Browse the repository at this point in the history
Feature/page dialog scaling
  • Loading branch information
arcanegolem authored Nov 29, 2023
2 parents 7d55c91 + a4df055 commit 31538d1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ private data class ZoomableBoxScopeImplementation(
internal fun ImageDialog(
img: Any,
backgroundColor : Color,
onDismissRequest : () -> Unit
minScale: Float,
maxScale: Float,
onDismissRequest : () -> Unit,
){
Dialog(
properties = DialogProperties(usePlatformDefaultWidth = false),
Expand All @@ -118,7 +120,9 @@ internal fun ImageDialog(
){
ZoomableImage(
modifier = Modifier.fillMaxSize(),
img = img
img = img,
minScale = minScale,
maxScale = maxScale
)
IconButton(
modifier = Modifier.align(Alignment.TopEnd),
Expand Down
42 changes: 32 additions & 10 deletions lycoris/src/main/java/ru/spektrit/lycoris/viewdocument/PdfViewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -74,7 +75,9 @@ fun PdfViewer(
@RawRes pdfResId: Int,
documentDescription: String,
verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp),
dialogBackgroundColor: Color = Color.Transparent
dialogBackgroundColor: Color = Color.Transparent,
minPageDialogScale : Float,
maxPageDialogScale : Float
) {
val rendererScope = rememberCoroutineScope()
val mutex = remember { Mutex() }
Expand Down Expand Up @@ -103,7 +106,7 @@ fun PdfViewer(
val pageCount by remember(renderer) { derivedStateOf { renderer?.pageCount ?: 0 } }

val lazyListState = rememberLazyListState()
var currentPage by remember { mutableStateOf(1) }
var currentPage by remember { mutableIntStateOf(1) }

// TODO: Оптимизировать отслеживание текущей страницы
val fullyVisibleIndices: List<Int> by remember {
Expand Down Expand Up @@ -199,7 +202,12 @@ fun PdfViewer(
)

if (isEnlargedDialogDisplayed) {
ImageDialog(img = request, backgroundColor = dialogBackgroundColor) { isEnlargedDialogDisplayed = false }
ImageDialog(
img = request,
backgroundColor = dialogBackgroundColor,
minScale = minPageDialogScale,
maxScale = maxPageDialogScale
) { isEnlargedDialogDisplayed = false }
}
}
}
Expand Down Expand Up @@ -227,7 +235,9 @@ fun PdfViewer(
modifier: Modifier = Modifier.fillMaxSize(),
uri: Uri,
verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp),
dialogBackgroundColor: Color = Color.Transparent
dialogBackgroundColor: Color = Color.Transparent,
minPageDialogScale : Float,
maxPageDialogScale : Float
) {
val rendererScope = rememberCoroutineScope()
val mutex = remember { Mutex() }
Expand All @@ -254,7 +264,7 @@ fun PdfViewer(
val pageCount by remember(renderer) { derivedStateOf { renderer?.pageCount ?: 0 } }

val lazyListState = rememberLazyListState()
var currentPage by remember { mutableStateOf(1) }
var currentPage by remember { mutableIntStateOf(1) }

// TODO: Оптимизировать отслеживание текущей страницы
val fullyVisibleIndices: List<Int> by remember {
Expand Down Expand Up @@ -350,7 +360,12 @@ fun PdfViewer(
)

if (isEnlargedDialogDisplayed) {
ImageDialog(img = request, backgroundColor = dialogBackgroundColor) { isEnlargedDialogDisplayed = false }
ImageDialog(
img = request,
backgroundColor = dialogBackgroundColor,
minScale = minPageDialogScale,
maxScale = maxPageDialogScale
) { isEnlargedDialogDisplayed = false }
}
}
}
Expand Down Expand Up @@ -379,14 +394,16 @@ fun PdfViewer(
@Url url: String,
headers: HashMap<String, String>,
verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp),
dialogBackgroundColor: Color = Color.Transparent
dialogBackgroundColor: Color = Color.Transparent,
minPageDialogScale : Float,
maxPageDialogScale : Float

) {

val rendererScope = rememberCoroutineScope()
val mutex = remember { Mutex() }

var docLoadPercentage by remember { mutableStateOf( 0 ) }
var docLoadPercentage by remember { mutableIntStateOf( 0 ) }
var docLoad = 0
val bufferSize = 8192

Expand Down Expand Up @@ -433,7 +450,7 @@ fun PdfViewer(
val pageCount by remember(renderer) { derivedStateOf { renderer?.pageCount ?: 0 } }

val lazyListState = rememberLazyListState()
var currentPage by remember { mutableStateOf(1) }
var currentPage by remember { mutableIntStateOf(1) }

// TODO: Оптимизировать отслеживание текущей страницы
val fullyVisibleIndices: List<Int> by remember {
Expand Down Expand Up @@ -540,7 +557,12 @@ fun PdfViewer(
)

if (isEnlargedDialogDisplayed) {
ImageDialog(img = request, backgroundColor = dialogBackgroundColor) { isEnlargedDialogDisplayed = false }
ImageDialog(
img = request,
backgroundColor = dialogBackgroundColor,
minScale = minPageDialogScale,
maxScale = maxPageDialogScale
) { isEnlargedDialogDisplayed = false }
}
}
}
Expand Down

0 comments on commit 31538d1

Please sign in to comment.