Skip to content

Commit 2ac5648

Browse files
authored
Merge pull request #716 from esensar/feature/bring-back-pdfium
Return `AndroidPdfViewer` based on `PDFium`
2 parents bda0325 + a83ebe8 commit 2ac5648

File tree

4 files changed

+30
-72
lines changed

4 files changed

+30
-72
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ android {
6464
}
6565

6666
dependencies {
67-
implementation 'com.github.SimpleMobileTools:Simple-Commons:30e6321592'
68-
implementation 'com.github.tibbi:PdfViewPager:d2af24208d'
67+
implementation 'com.github.SimpleMobileTools:Simple-Commons:84c71fdcc1'
68+
implementation 'com.github.tibbi:AndroidPdfViewer:e6a533125b'
6969
implementation 'com.github.Stericson:RootTools:df729dcb13'
7070
implementation 'com.github.Stericson:RootShell:1.6'
7171
implementation 'com.alexvasilkov:gesture-views:2.5.2'

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ class MainActivity : SimpleActivity() {
632632
}
633633

634634
private fun launchAbout() {
635-
val licenses = LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GESTURE_VIEWS or LICENSE_PDF_VIEW_PAGER or LICENSE_AUTOFITTEXTVIEW
635+
val licenses = LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GESTURE_VIEWS or LICENSE_PDF_VIEWER or LICENSE_AUTOFITTEXTVIEW
636636

637637
val faqItems = arrayListOf(
638638
FAQItem(R.string.faq_3_title_commons, R.string.faq_3_text_commons),

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/PDFViewerActivity.kt

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,16 @@ import android.graphics.Color
66
import android.os.Bundle
77
import android.print.PrintAttributes
88
import android.print.PrintManager
9-
import android.view.View
109
import android.view.WindowManager
11-
import androidx.constraintlayout.widget.ConstraintLayout
12-
import androidx.viewpager2.widget.MarginPageTransformer
13-
import androidx.viewpager2.widget.ViewPager2
14-
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
10+
import android.widget.RelativeLayout
11+
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
1512
import com.simplemobiletools.commons.extensions.*
1613
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
1714
import com.simplemobiletools.commons.helpers.isPiePlus
1815
import com.simplemobiletools.filemanager.pro.R
1916
import com.simplemobiletools.filemanager.pro.extensions.hideSystemUI
2017
import com.simplemobiletools.filemanager.pro.extensions.showSystemUI
2118
import com.simplemobiletools.filemanager.pro.helpers.PdfDocumentAdapter
22-
import es.voghdev.pdfviewpager.library.adapter.PDFPagerAdapter
23-
import es.voghdev.pdfviewpager.library.adapter.PdfErrorHandler
2419
import kotlinx.android.synthetic.main.activity_pdf_viewer.*
2520

2621
class PDFViewerActivity : SimpleActivity() {
@@ -59,6 +54,7 @@ class PDFViewerActivity : SimpleActivity() {
5954
}
6055

6156
private fun setupMenu() {
57+
(pdf_viewer_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
6258
pdf_viewer_toolbar.menu.apply {
6359
findItem(R.id.menu_print).isVisible = realFilePath.isNotEmpty()
6460
findItem(R.id.menu_print).setOnMenuItemClickListener {
@@ -71,30 +67,21 @@ class PDFViewerActivity : SimpleActivity() {
7167
finish()
7268
}
7369

74-
setupViewOffsets()
75-
val primaryColor = getProperPrimaryColor()
76-
page_counter.background?.applyColorFilter(primaryColor)
77-
page_counter.setTextColor(primaryColor.getContrastColor())
70+
if (!portrait && navigationBarOnSide && navigationBarWidth > 0) {
71+
pdf_viewer_appbar.setPadding(0, 0, navigationBarWidth, 0)
72+
} else {
73+
pdf_viewer_appbar.setPadding(0, 0, 0, 0)
74+
}
7875
}
7976

8077
override fun onConfigurationChanged(newConfig: Configuration) {
8178
super.onConfigurationChanged(newConfig)
82-
setupViewOffsets()
83-
}
84-
85-
private fun setupViewOffsets() {
86-
val pageCounterMargin = resources.getDimension(R.dimen.normal_margin).toInt()
87-
(pdf_viewer_appbar.layoutParams as ConstraintLayout.LayoutParams).topMargin = statusBarHeight
79+
(pdf_viewer_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
8880
if (!portrait && navigationBarOnSide && navigationBarWidth > 0) {
8981
pdf_viewer_appbar.setPadding(0, 0, navigationBarWidth, 0)
9082
} else {
9183
pdf_viewer_appbar.setPadding(0, 0, 0, 0)
9284
}
93-
94-
(page_counter.layoutParams as ConstraintLayout.LayoutParams).apply {
95-
rightMargin = navigationBarWidth + pageCounterMargin
96-
bottomMargin = navigationBarHeight + pageCounterMargin
97-
}
9885
}
9986

10087
private fun checkIntent() {
@@ -104,30 +91,17 @@ class PDFViewerActivity : SimpleActivity() {
10491
return
10592
}
10693

107-
val clickListener = View.OnClickListener {
108-
toggleFullScreen()
109-
}
110-
111-
val errorHandler = PdfErrorHandler { throwable -> showErrorToast(throwable.toString()) }
112-
113-
pdf_viewer.setPageTransformer(MarginPageTransformer(resources.getDimension(R.dimen.activity_margin).toInt()))
114-
pdf_viewer.orientation = ViewPager2.ORIENTATION_VERTICAL
115-
try {
116-
pdf_viewer.adapter = PDFPagerAdapter(this, clickListener, errorHandler, uri.toString(), getProperBackgroundColor())
117-
} catch (e: Exception) {
118-
showErrorToast(e)
119-
finish()
120-
return
121-
}
122-
123-
pdf_viewer.registerOnPageChangeCallback(object : OnPageChangeCallback() {
124-
override fun onPageSelected(position: Int) {
125-
updatePageCounter(position)
94+
val primaryColor = getProperPrimaryColor()
95+
pdf_viewer.setBackgroundColor(getProperBackgroundColor())
96+
pdf_viewer.fromUri(uri)
97+
.scrollHandle(DefaultScrollHandle(this, primaryColor.getContrastColor(), primaryColor))
98+
.spacing(15)
99+
.onTap { toggleFullScreen() }
100+
.onError {
101+
showErrorToast(it.localizedMessage?.toString() ?: getString(R.string.unknown_error_occurred))
102+
finish()
126103
}
127-
})
128-
129-
updatePageCounter(0)
130-
page_counter.beVisible()
104+
.load()
131105

132106
showSystemUI(true)
133107

@@ -137,10 +111,6 @@ class PDFViewerActivity : SimpleActivity() {
137111
}
138112
}
139113

140-
private fun updatePageCounter(position: Int) {
141-
page_counter.text = "${position + 1} / ${pdf_viewer.adapter?.itemCount}"
142-
}
143-
144114
private fun printText() {
145115
val adapter = PdfDocumentAdapter(this, realFilePath)
146116

@@ -160,7 +130,6 @@ class PDFViewerActivity : SimpleActivity() {
160130
showSystemUI(true)
161131
}
162132

163-
page_counter.animate().alpha(newAlpha).start()
164133
top_shadow.animate().alpha(newAlpha).start()
165134
pdf_viewer_appbar.animate().alpha(newAlpha).withStartAction {
166135
if (newAlpha == 1f) {
Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
xmlns:tools="http://schemas.android.com/tools"
54
android:id="@+id/pdf_viewer_wrapper"
65
android:layout_width="match_parent"
7-
android:layout_height="match_parent"
6+
android:layout_height="wrap_content"
87
app:layout_behavior="@string/appbar_scrolling_view_behavior">
98

10-
<androidx.viewpager2.widget.ViewPager2
9+
<com.github.barteksc.pdfviewer.PDFView
1110
android:id="@+id/pdf_viewer"
1211
android:layout_width="match_parent"
1312
android:layout_height="match_parent" />
@@ -16,28 +15,18 @@
1615
android:id="@+id/top_shadow"
1716
android:layout_width="match_parent"
1817
android:layout_height="@dimen/top_shadow_height"
18+
android:layout_alignParentTop="true"
1919
android:background="@drawable/gradient_background_flipped"
20-
android:contentDescription="@null"
21-
app:layout_constraintTop_toTopOf="parent" />
22-
23-
<TextView
24-
android:id="@+id/page_counter"
25-
style="@style/ColoredButtonStyle"
26-
android:layout_width="wrap_content"
27-
android:layout_height="wrap_content"
28-
android:visibility="gone"
29-
app:layout_constraintBottom_toBottomOf="parent"
30-
app:layout_constraintEnd_toEndOf="parent"
31-
tools:text="1/3" />
20+
android:contentDescription="@null" />
3221

3322
<com.google.android.material.appbar.AppBarLayout
3423
android:id="@+id/pdf_viewer_appbar"
3524
android:layout_width="match_parent"
3625
android:layout_height="wrap_content"
26+
android:layout_alignParentTop="true"
3727
android:background="@android:color/transparent"
3828
android:elevation="0dp"
39-
app:elevation="0dp"
40-
app:layout_constraintTop_toTopOf="parent">
29+
app:elevation="0dp">
4130

4231
<com.google.android.material.appbar.MaterialToolbar
4332
android:id="@+id/pdf_viewer_toolbar"
@@ -47,4 +36,4 @@
4736
app:navigationIcon="@drawable/ic_arrow_left_vector" />
4837

4938
</com.google.android.material.appbar.AppBarLayout>
50-
</androidx.constraintlayout.widget.ConstraintLayout>
39+
</RelativeLayout>

0 commit comments

Comments
 (0)