use ViewPager2 at pdf viewer

This commit is contained in:
tibbi 2022-12-10 20:03:34 +01:00
parent ab47bcadbe
commit 12aae27ccd
3 changed files with 12 additions and 19 deletions

View File

@ -65,7 +65,7 @@ android {
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:b452494768'
implementation 'com.github.tibbi:PdfViewPager:1bc22f031a'
implementation 'com.github.tibbi:PdfViewPager:6f9641fd2c'
implementation 'com.github.Stericson:RootTools:df729dcb13'
implementation 'com.github.Stericson:RootShell:1.6'
implementation 'com.alexvasilkov:gesture-views:2.5.2'

View File

@ -6,8 +6,10 @@ import android.graphics.Color
import android.os.Bundle
import android.print.PrintAttributes
import android.print.PrintManager
import android.view.View
import android.view.WindowManager
import android.widget.RelativeLayout
import androidx.viewpager2.widget.ViewPager2
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
import com.simplemobiletools.commons.helpers.isPiePlus
@ -15,14 +17,13 @@ import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.extensions.hideSystemUI
import com.simplemobiletools.filemanager.pro.extensions.showSystemUI
import com.simplemobiletools.filemanager.pro.helpers.PdfDocumentAdapter
import es.voghdev.pdfviewpager.library.adapter.BasePDFPagerAdapter
import es.voghdev.pdfviewpager.library.adapter.PDFPagerAdapter
import es.voghdev.pdfviewpager.library.adapter.PdfErrorHandler
import kotlinx.android.synthetic.main.activity_pdf_viewer.*
class PDFViewerActivity : SimpleActivity() {
private var realFilePath = ""
private var isFullScreen = false
private var adapter: BasePDFPagerAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
showTransparentTop = true
@ -56,11 +57,6 @@ class PDFViewerActivity : SimpleActivity() {
window.navigationBarColor = Color.TRANSPARENT
}
override fun onDestroy() {
super.onDestroy()
adapter?.close()
}
private fun setupMenu() {
(pdf_viewer_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
pdf_viewer_toolbar.menu.apply {
@ -99,19 +95,16 @@ class PDFViewerActivity : SimpleActivity() {
return
}
pdf_viewer.orientation = ViewPager2.ORIENTATION_VERTICAL
pdf_viewer.setBackgroundColor(getProperBackgroundColor())
adapter = PDFPagerAdapter.Builder(this)
.setPdfPath(uri.toString())
.setOnPageClickListener {
toggleFullScreen()
}
.setErrorHandler { throwable ->
showErrorToast(throwable.toString())
}
.create()
val clickListener = View.OnClickListener {
toggleFullScreen()
}
pdf_viewer.adapter = adapter
val errorHandler = PdfErrorHandler { throwable -> showErrorToast(throwable.toString()) }
pdf_viewer.adapter = PDFPagerAdapter(this, clickListener, errorHandler, uri.toString())
showSystemUI(true)

View File

@ -6,7 +6,7 @@
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<es.voghdev.pdfviewpager.library.PDFViewPager
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pdf_viewer"
android:layout_width="match_parent"
android:layout_height="match_parent" />