-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring of the UI and VM callbacks on PdfReaderScreen.
Upping versionCode to 87.
- Loading branch information
Dima Petrov
committed
Aug 6, 2024
1 parent
1de9c65
commit 1f0202b
Showing
12 changed files
with
278 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
app/src/main/java/org/zotero/android/pdf/reader/PdfReaderModes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package org.zotero.android.pdf.reader | ||
|
||
import android.net.Uri | ||
import androidx.compose.animation.AnimatedContent | ||
import androidx.compose.animation.AnimatedContentTransitionScope | ||
import androidx.compose.animation.ContentTransform | ||
import androidx.compose.animation.SizeTransform | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.animation.slideInHorizontally | ||
import androidx.compose.animation.slideOutHorizontally | ||
import androidx.compose.animation.with | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.lazy.LazyListState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.FocusRequester | ||
import androidx.compose.ui.unit.IntOffset | ||
import androidx.compose.ui.unit.dp | ||
import org.zotero.android.architecture.ui.CustomLayoutSize | ||
import org.zotero.android.pdf.reader.sidebar.PdfReaderSidebar | ||
import org.zotero.android.pdf.reader.sidebar.SidebarDivider | ||
import org.zotero.android.uicomponents.theme.CustomTheme | ||
|
||
@Composable | ||
internal fun PdfReaderTabletMode( | ||
vMInterface: PdfReaderVMInterface, | ||
viewState: PdfReaderViewState, | ||
lazyListState: LazyListState, | ||
layoutType: CustomLayoutSize.LayoutType, | ||
uri: Uri, | ||
focusRequester: FocusRequester, | ||
) { | ||
Row(modifier = Modifier.fillMaxSize()) { | ||
AnimatedContent(targetState = viewState.showSideBar, transitionSpec = { | ||
createSidebarTransitionSpec() | ||
}, label = "") { showSideBar -> | ||
if (showSideBar) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxHeight() | ||
.fillMaxWidth(0.3f) | ||
) { | ||
PdfReaderSidebar( | ||
vMInterface = vMInterface, | ||
viewState = viewState, | ||
lazyListState = lazyListState, | ||
layoutType = layoutType, | ||
focusRequester = focusRequester, | ||
) | ||
} | ||
} | ||
} | ||
if (viewState.showSideBar) { | ||
SidebarDivider( | ||
modifier = Modifier | ||
.width(2.dp) | ||
.fillMaxHeight() | ||
) | ||
} | ||
|
||
PdfReaderPspdfKitBox( | ||
uri = uri, | ||
viewState = viewState, | ||
vMInterface = vMInterface, | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
internal fun PdfReaderPhoneMode( | ||
vMInterface: PdfReaderVMInterface, | ||
viewState: PdfReaderViewState, | ||
lazyListState: LazyListState, | ||
layoutType: CustomLayoutSize.LayoutType, | ||
uri: Uri, | ||
focusRequester: FocusRequester, | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
) { | ||
PdfReaderPspdfKitBox( | ||
uri = uri, | ||
viewState = viewState, | ||
vMInterface = vMInterface | ||
) | ||
AnimatedContent( | ||
targetState = viewState.showSideBar, | ||
transitionSpec = { | ||
createSidebarTransitionSpec() | ||
}, label = "" | ||
) { showSideBar -> | ||
if (showSideBar) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.background(CustomTheme.colors.pdfAnnotationsFormBackground) | ||
) { | ||
PdfReaderSidebar( | ||
viewState = viewState, | ||
vMInterface = vMInterface, | ||
lazyListState = lazyListState, | ||
layoutType = layoutType, | ||
focusRequester = focusRequester | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun AnimatedContentTransitionScope<Boolean>.createSidebarTransitionSpec(): ContentTransform { | ||
val intOffsetSpec = tween<IntOffset>() | ||
return (slideInHorizontally(intOffsetSpec) { -it } with | ||
slideOutHorizontally(intOffsetSpec) { -it }).using( | ||
// Disable clipping since the faded slide-in/out should | ||
// be displayed out of bounds. | ||
SizeTransform( | ||
clip = false, | ||
sizeAnimationSpec = { _, _ -> tween() } | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.