mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
use ViewPager2 at pdf viewer
This commit is contained in:
@ -65,7 +65,7 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:b452494768'
|
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:RootTools:df729dcb13'
|
||||||
implementation 'com.github.Stericson:RootShell:1.6'
|
implementation 'com.github.Stericson:RootShell:1.6'
|
||||||
implementation 'com.alexvasilkov:gesture-views:2.5.2'
|
implementation 'com.alexvasilkov:gesture-views:2.5.2'
|
||||||
|
@ -6,8 +6,10 @@ import android.graphics.Color
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.print.PrintAttributes
|
import android.print.PrintAttributes
|
||||||
import android.print.PrintManager
|
import android.print.PrintManager
|
||||||
|
import android.view.View
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
|
||||||
import com.simplemobiletools.commons.helpers.isPiePlus
|
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.hideSystemUI
|
||||||
import com.simplemobiletools.filemanager.pro.extensions.showSystemUI
|
import com.simplemobiletools.filemanager.pro.extensions.showSystemUI
|
||||||
import com.simplemobiletools.filemanager.pro.helpers.PdfDocumentAdapter
|
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.PDFPagerAdapter
|
||||||
|
import es.voghdev.pdfviewpager.library.adapter.PdfErrorHandler
|
||||||
import kotlinx.android.synthetic.main.activity_pdf_viewer.*
|
import kotlinx.android.synthetic.main.activity_pdf_viewer.*
|
||||||
|
|
||||||
class PDFViewerActivity : SimpleActivity() {
|
class PDFViewerActivity : SimpleActivity() {
|
||||||
private var realFilePath = ""
|
private var realFilePath = ""
|
||||||
private var isFullScreen = false
|
private var isFullScreen = false
|
||||||
private var adapter: BasePDFPagerAdapter? = null
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
showTransparentTop = true
|
showTransparentTop = true
|
||||||
@ -56,11 +57,6 @@ class PDFViewerActivity : SimpleActivity() {
|
|||||||
window.navigationBarColor = Color.TRANSPARENT
|
window.navigationBarColor = Color.TRANSPARENT
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
|
||||||
super.onDestroy()
|
|
||||||
adapter?.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupMenu() {
|
private fun setupMenu() {
|
||||||
(pdf_viewer_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
|
(pdf_viewer_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
|
||||||
pdf_viewer_toolbar.menu.apply {
|
pdf_viewer_toolbar.menu.apply {
|
||||||
@ -99,19 +95,16 @@ class PDFViewerActivity : SimpleActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pdf_viewer.orientation = ViewPager2.ORIENTATION_VERTICAL
|
||||||
pdf_viewer.setBackgroundColor(getProperBackgroundColor())
|
pdf_viewer.setBackgroundColor(getProperBackgroundColor())
|
||||||
|
|
||||||
adapter = PDFPagerAdapter.Builder(this)
|
val clickListener = View.OnClickListener {
|
||||||
.setPdfPath(uri.toString())
|
toggleFullScreen()
|
||||||
.setOnPageClickListener {
|
}
|
||||||
toggleFullScreen()
|
|
||||||
}
|
|
||||||
.setErrorHandler { throwable ->
|
|
||||||
showErrorToast(throwable.toString())
|
|
||||||
}
|
|
||||||
.create()
|
|
||||||
|
|
||||||
pdf_viewer.adapter = adapter
|
val errorHandler = PdfErrorHandler { throwable -> showErrorToast(throwable.toString()) }
|
||||||
|
|
||||||
|
pdf_viewer.adapter = PDFPagerAdapter(this, clickListener, errorHandler, uri.toString())
|
||||||
|
|
||||||
showSystemUI(true)
|
showSystemUI(true)
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
<es.voghdev.pdfviewpager.library.PDFViewPager
|
<androidx.viewpager2.widget.ViewPager2
|
||||||
android:id="@+id/pdf_viewer"
|
android:id="@+id/pdf_viewer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
Reference in New Issue
Block a user