From ab47bcadbe2807b3aec7c11ce11bb989c58ba35c Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 9 Dec 2022 20:47:18 +0100 Subject: [PATCH] fix #619, use a different pdf viewer --- app/build.gradle | 4 +-- .../pro/activities/MainActivity.kt | 2 +- .../pro/activities/PDFViewerActivity.kt | 29 ++++++++++++------- .../main/res/layout/activity_pdf_viewer.xml | 2 +- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8067d14c..261373de 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -64,8 +64,8 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:f538687d6e' - implementation 'com.github.tibbi:AndroidPdfViewer:da57ff410e' + implementation 'com.github.SimpleMobileTools:Simple-Commons:b452494768' + implementation 'com.github.tibbi:PdfViewPager:1bc22f031a' implementation 'com.github.Stericson:RootTools:df729dcb13' implementation 'com.github.Stericson:RootShell:1.6' implementation 'com.alexvasilkov:gesture-views:2.5.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt index f93596f8..a8b3c794 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt @@ -640,7 +640,7 @@ class MainActivity : SimpleActivity() { private fun launchAbout() { closeSearch() - val licenses = LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GESTURE_VIEWS or LICENSE_PDF_VIEWER or LICENSE_AUTOFITTEXTVIEW + val licenses = LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GESTURE_VIEWS or LICENSE_PDF_VIEW_PAGER or LICENSE_AUTOFITTEXTVIEW val faqItems = arrayListOf( FAQItem(R.string.faq_3_title_commons, R.string.faq_3_text_commons), diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt index e55d4e25..16a2b1de 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt @@ -8,7 +8,6 @@ import android.print.PrintAttributes import android.print.PrintManager import android.view.WindowManager import android.widget.RelativeLayout -import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.REAL_FILE_PATH import com.simplemobiletools.commons.helpers.isPiePlus @@ -16,11 +15,14 @@ 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 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 @@ -54,6 +56,11 @@ 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 { @@ -92,17 +99,19 @@ class PDFViewerActivity : SimpleActivity() { return } - val primaryColor = getProperPrimaryColor() pdf_viewer.setBackgroundColor(getProperBackgroundColor()) - pdf_viewer.fromUri(uri) - .scrollHandle(DefaultScrollHandle(this, primaryColor.getContrastColor(), primaryColor)) - .spacing(15) - .onTap { toggleFullScreen() } - .onError { - showErrorToast(it.localizedMessage?.toString() ?: getString(R.string.unknown_error_occurred)) - finish() + + adapter = PDFPagerAdapter.Builder(this) + .setPdfPath(uri.toString()) + .setOnPageClickListener { + toggleFullScreen() } - .load() + .setErrorHandler { throwable -> + showErrorToast(throwable.toString()) + } + .create() + + pdf_viewer.adapter = adapter showSystemUI(true) diff --git a/app/src/main/res/layout/activity_pdf_viewer.xml b/app/src/main/res/layout/activity_pdf_viewer.xml index ba3412c6..a8b95e51 100644 --- a/app/src/main/res/layout/activity_pdf_viewer.xml +++ b/app/src/main/res/layout/activity_pdf_viewer.xml @@ -6,7 +6,7 @@ android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior"> -