Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF 화면 구성 및 PDF 렌더링 #27

Merged
merged 30 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bdff90f
Feat: PDF 렌더링
Guri999 Dec 5, 2024
e95c491
Feat: PDF Zoom & drag
Guri999 Dec 6, 2024
cf10836
Feat: PDF 해상도 증가
Guri999 Dec 6, 2024
0785726
Feat: PDF Topbar
Guri999 Dec 7, 2024
2d70b89
Feat: PDF TopBar Page calculation
Guri999 Dec 7, 2024
4b66946
Feat: Domain 모듈 제거
Guri999 Dec 7, 2024
58596a1
Feat: Domain 모듈 제거
Guri999 Dec 7, 2024
c4aa77c
Feat: File Model 생성, 파일 찾기 로직 분리
Guri999 Dec 7, 2024
e65341e
Feat: Room 생성
Guri999 Dec 8, 2024
809743a
Refactor: 파일 탐색 백그라운드 스레드로 변경
Guri999 Dec 31, 2024
0de159f
Refactor: Uri remember로 처리
Guri999 Jan 3, 2025
21a6a33
Refactor: 매직넘버 상수로 관리
Guri999 Jan 3, 2025
308e067
Refactor: page,onPageChange -> page, onPageChange
Guri999 Jan 3, 2025
830538f
Refactor: 빈 프리뷰 제거
Guri999 Jan 3, 2025
b7e491a
Refactor: TopBar 관리 캡슐화
Guri999 Jan 6, 2025
1a1ed20
Refactor: Permission 관리 변경
Guri999 Jan 6, 2025
641f6de
Chore: onTopBarVisibleChange -> onPdfBodyPressed 이름 변경
Guri999 Jan 6, 2025
6020dd8
Refactor: PdfToBitmap class 생성하여 pdf 렌더링 관리
Guri999 Jan 6, 2025
3bd4b0d
Chore: if문 괄호
Guri999 Jan 6, 2025
91e5fa5
Feat: Koin 설정
Guri999 Jan 7, 2025
003c38d
Refactor: PDF화면 MVI refactor
Guri999 Jan 7, 2025
a7f951d
Revert "Refactor: PDF화면 MVI refactor"
Guri999 Jan 7, 2025
39ab182
Revert "Feat: Koin 설정"
Guri999 Jan 7, 2025
ea25198
Refactor: TopBarState currentScope -> currentJob
Guri999 Jan 7, 2025
514b612
Refactor: TopBarState onBodyPress -> show
Guri999 Jan 7, 2025
1b8822a
Refactor: TopBarState 생성자 제한
Guri999 Jan 7, 2025
04c1ab7
Chore: bitmap 줄내림 수정
Guri999 Jan 7, 2025
6345800
Chore: if문 중괄호 표시
Guri999 Jan 7, 2025
9a39999
Chore: line 제거
Guri999 Jan 7, 2025
7afa071
Chore: ignore .idea 추가
Guri999 Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion feature/pdf/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ plugins {
alias(libs.plugins.seedocs.library.compose)
}

setNamespace("feature.pdf")
setNamespace("feature.pdf")

dependencies {
implementation("net.engawapg.lib:zoomable:1.6.2")
}
49 changes: 42 additions & 7 deletions feature/pdf/src/main/java/kr/co/pdf/PdfScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@ import android.graphics.pdf.PdfRenderer
import android.net.Uri
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.painter.ColorPainter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kr.co.ui.theme.SeeDocsTheme
import kr.co.ui.theme.Theme
import net.engawapg.lib.zoomable.rememberZoomState
import net.engawapg.lib.zoomable.zoomable
import java.io.File

@Composable
Expand Down Expand Up @@ -55,6 +64,8 @@ private fun PdfScreen(
modifier = Modifier
.fillMaxSize()
.background(Theme.colors.bg)
.zoomable(rememberZoomState()),
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
items(renderer.pageCount) { page ->
PdfImage(
Expand All @@ -73,22 +84,46 @@ private fun PdfImage(
var bitmap by remember {
mutableStateOf<Bitmap?>(null)
}
var isLoading by remember { mutableStateOf(true) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

의견)
PdfRenderer를 내부적으로 사용하는 Pdf to Bitmap 클래스를 만들어서 로직을 캡슐화하고, 렌더링 상태(ex. 로딩, 렌더링 완료)를 StateFlow로 구독할 수 있게 하는 방법은 어떠신가요?


LaunchedEffect(Unit) {
isLoading = true
val page = renderer.openPage(pageIndex)
Bitmap.createBitmap(page.width, page.height, Bitmap.Config.ARGB_8888).also {
page.render(it, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY)
page.render(it, null, null, PdfRenderer.Page.RENDER_MODE_FOR_PRINT)
bitmap = it
page.close()
isLoading = false
}
}

bitmap?.let {
Image(
bitmap = it.asImageBitmap(),
contentDescription = null,
modifier = Modifier.fillMaxWidth()
)
if (isLoading) {
Box(
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f),
contentAlignment = Alignment.Center
) {
Image(
painter = ColorPainter(Theme.colors.grayText),
contentDescription = null,
modifier = Modifier.fillMaxSize()
)

CircularProgressIndicator(
color = Theme.colors.highlight
)
}
} else {
bitmap?.let {
Image(
bitmap = it.asImageBitmap(),
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
.aspectRatio(it.width.toFloat() / it.height.toFloat())
)
}
}
}

Expand Down