Skip to content

Commit

Permalink
PDF thumbnails list support.
Browse files Browse the repository at this point in the history
Upping versionCode to 91
  • Loading branch information
Dima-Android committed Aug 27, 2024
1 parent 9aa6836 commit c33e586
Show file tree
Hide file tree
Showing 19 changed files with 654 additions and 58 deletions.
26 changes: 26 additions & 0 deletions app/src/main/java/org/zotero/android/files/FileStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,32 @@ class FileStore @Inject constructor (
return folderPath
}

val pageThumbnails: File get() {
val folderPath = File(getRootDirectory(), "thumbnails")
folderPath.mkdirs()
return folderPath
}

fun pageThumbnail(pageIndex: Int, key: String, libraryId: LibraryIdentifier, isDark: Boolean): File {
val folderPath = File(getRootDirectory(), "thumbnails/${libraryId.folderName}/$key")
folderPath.mkdirs()
val name = pageIndex.toString() + (if(isDark) "_dark" else "") + ".png"
val result = File(folderPath, name)
return result
}

fun pageThumbnails(key: String, libraryId: LibraryIdentifier):File {
val folderPath = File(getRootDirectory(), "thumbnails/${libraryId.folderName}/$key")
folderPath.mkdirs()
return folderPath
}

fun pageThumbnails(libraryId: LibraryIdentifier): File {
val folderPath = File(getRootDirectory(), "thumbnails/${libraryId.folderName}")
folderPath.mkdirs()
return folderPath
}

fun jsonCacheFile(objectS: SyncObject, libraryId: LibraryIdentifier, key: String): File {
val objectName: String
when (objectS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ 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
Expand All @@ -32,10 +31,10 @@ import org.zotero.android.uicomponents.theme.CustomTheme
internal fun PdfReaderTabletMode(
vMInterface: PdfReaderVMInterface,
viewState: PdfReaderViewState,
lazyListState: LazyListState,
annotationsLazyListState: LazyListState,
thumbnailsLazyListState: LazyListState,
layoutType: CustomLayoutSize.LayoutType,
uri: Uri,
focusRequester: FocusRequester,
) {
Row(modifier = Modifier.fillMaxSize()) {
AnimatedContent(targetState = viewState.showSideBar, transitionSpec = {
Expand All @@ -51,9 +50,9 @@ internal fun PdfReaderTabletMode(
PdfReaderSidebar(
vMInterface = vMInterface,
viewState = viewState,
lazyListState = lazyListState,
annotationsLazyListState = annotationsLazyListState,
thumbnailsLazyListState = thumbnailsLazyListState,
layoutType = layoutType,
focusRequester = focusRequester,
)
}
}
Expand All @@ -78,10 +77,10 @@ internal fun PdfReaderTabletMode(
internal fun PdfReaderPhoneMode(
vMInterface: PdfReaderVMInterface,
viewState: PdfReaderViewState,
lazyListState: LazyListState,
annotationsLazyListState: LazyListState,
thumbnailsLazyListState: LazyListState,
layoutType: CustomLayoutSize.LayoutType,
uri: Uri,
focusRequester: FocusRequester,
) {
Box(
modifier = Modifier
Expand All @@ -107,9 +106,9 @@ internal fun PdfReaderPhoneMode(
PdfReaderSidebar(
viewState = viewState,
vMInterface = vMInterface,
lazyListState = lazyListState,
annotationsLazyListState = annotationsLazyListState,
thumbnailsLazyListState = thumbnailsLazyListState,
layoutType = layoutType,
focusRequester = focusRequester
)
}
}
Expand Down
25 changes: 16 additions & 9 deletions app/src/main/java/org/zotero/android/pdf/reader/PdfReaderScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.remember
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.core.view.WindowCompat
Expand Down Expand Up @@ -56,9 +54,9 @@ internal fun PdfReaderScreen(

val params = viewModel.screenArgs
val uri = params.uri
val lazyListState = rememberLazyListState()
val annotationsLazyListState = rememberLazyListState()
val thumbnailsLazyListState = rememberLazyListState()
val layoutType = CustomLayoutSize.calculateLayoutType()
val focusRequester: FocusRequester = remember { FocusRequester() }
val focusManager = LocalFocusManager.current
LaunchedEffect(key1 = viewEffect) {
when (val consumedEffect = viewEffect?.consume()) {
Expand All @@ -78,9 +76,18 @@ internal fun PdfReaderScreen(
navigateToPdfAnnotation()
}
if (consumedEffect.scrollToIndex != -1) {
lazyListState.animateScrollToItem(index = consumedEffect.scrollToIndex)
annotationsLazyListState.animateScrollToItem(index = consumedEffect.scrollToIndex)
}
}

is PdfReaderViewEffect.ScrollThumbnailListToIndex -> {
val visibleItemsInfo = thumbnailsLazyListState.layoutInfo.visibleItemsInfo
val scrollToIndex = consumedEffect.scrollToIndex
if (visibleItemsInfo.isNotEmpty() && (scrollToIndex < visibleItemsInfo.first().index || scrollToIndex > visibleItemsInfo.last().index)) {
thumbnailsLazyListState.animateScrollToItem(index = scrollToIndex)
}
}

is PdfReaderViewEffect.ShowPdfAnnotationMore -> {
if (!layoutType.isTablet()) {
viewModel.removeFragment()
Expand Down Expand Up @@ -132,19 +139,19 @@ internal fun PdfReaderScreen(
PdfReaderTabletMode(
vMInterface = viewModel,
viewState = viewState,
lazyListState = lazyListState,
annotationsLazyListState = annotationsLazyListState,
thumbnailsLazyListState = thumbnailsLazyListState,
layoutType = layoutType,
focusRequester = focusRequester,
uri = uri,
)
} else {
PdfReaderPhoneMode(
viewState = viewState,
vMInterface = viewModel,
lazyListState = lazyListState,
annotationsLazyListState = annotationsLazyListState,
thumbnailsLazyListState = thumbnailsLazyListState,
layoutType = layoutType,
uri = uri,
focusRequester = focusRequester,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import com.pspdfkit.ui.special_mode.controller.AnnotationTool
import org.zotero.android.pdf.cache.AnnotationPreviewMemoryCache
import org.zotero.android.pdf.data.Annotation
import org.zotero.android.pdf.reader.sidebar.data.Outline
import org.zotero.android.pdf.reader.sidebar.data.PdfReaderThumbnailRow
import org.zotero.android.pdf.reader.sidebar.data.ThumbnailPreviewMemoryCache

interface PdfReaderVMInterface {

var annotationMaxSideSize: Int
val annotationPreviewMemoryCache: AnnotationPreviewMemoryCache
val thumbnailPreviewMemoryCache: ThumbnailPreviewMemoryCache
val activeAnnotationTool: AnnotationTool?
var toolColors: MutableMap<AnnotationTool, String>

Expand All @@ -29,7 +32,7 @@ interface PdfReaderVMInterface {
fun onMoreOptionsForItemClicked()
fun annotation(key: AnnotationKey): Annotation?
fun selectAnnotation(key: AnnotationKey)
fun loadPreviews(keys: List<String>)
fun loadAnnotationPreviews(keys: List<String>)
fun showFilterPopup()
fun toggle(tool: AnnotationTool)
fun showToolOptions()
Expand All @@ -42,4 +45,6 @@ interface PdfReaderVMInterface {
fun onOutlineSearch(text: String)
fun onOutlineItemTapped(outline: Outline)
fun onOutlineItemChevronTapped(outline: Outline)
fun selectThumbnail(row: PdfReaderThumbnailRow)
fun loadThumbnailPreviews(pageIndex: Int)
}
Loading

0 comments on commit c33e586

Please sign in to comment.