Skip to content

Commit 6c815df

Browse files
committed
lets actually use a different toolbar at the pdf viewer
1 parent 8aa0536 commit 6c815df

File tree

2 files changed

+46
-47
lines changed

2 files changed

+46
-47
lines changed

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ package com.simplemobiletools.filemanager.pro.activities
22

33
import android.content.Context
44
import android.graphics.Color
5-
import android.graphics.drawable.ColorDrawable
65
import android.os.Bundle
76
import android.print.PrintAttributes
87
import android.print.PrintManager
98
import android.view.WindowInsetsController
109
import android.view.WindowManager
10+
import android.widget.RelativeLayout
1111
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
1212
import com.simplemobiletools.commons.extensions.*
13-
import com.simplemobiletools.commons.helpers.NavigationIcon
1413
import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
1514
import com.simplemobiletools.commons.helpers.isPiePlus
1615
import com.simplemobiletools.commons.helpers.isRPlus
@@ -26,24 +25,23 @@ class PDFViewerActivity : SimpleActivity() {
2625

2726
override fun onCreate(savedInstanceState: Bundle?) {
2827
useDynamicTheme = false
28+
2929
super.onCreate(savedInstanceState)
3030
setContentView(R.layout.activity_pdf_viewer)
31-
setupOptionsMenu()
32-
refreshMenuItems()
3331

3432
if (checkAppSideloading()) {
3533
return
3634
}
3735

3836
window.decorView.setBackgroundColor(getProperBackgroundColor())
39-
top_shadow.layoutParams.height = statusBarHeight + actionBarHeight
4037
checkNotchSupport()
4138

4239
if (intent.extras?.containsKey(REAL_FILE_PATH) == true) {
4340
realFilePath = intent.extras?.get(REAL_FILE_PATH)?.toString() ?: ""
4441
pdf_viewer_toolbar.title = realFilePath.getFilenameFromPath()
4542
}
4643

44+
setupMenu()
4745
checkIntent()
4846
if (isRPlus()) {
4947
window.insetsController?.setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS)
@@ -52,26 +50,22 @@ class PDFViewerActivity : SimpleActivity() {
5250

5351
override fun onResume() {
5452
super.onResume()
55-
supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
5653
window.statusBarColor = Color.TRANSPARENT
5754
setTranslucentNavigation()
58-
setupToolbar(pdf_viewer_toolbar, NavigationIcon.Arrow)
5955
}
6056

61-
private fun setupOptionsMenu() {
62-
pdf_viewer_toolbar.setOnMenuItemClickListener { menuItem ->
63-
when (menuItem.itemId) {
64-
R.id.menu_print -> printText()
65-
else -> return@setOnMenuItemClickListener false
57+
private fun setupMenu() {
58+
(pdf_viewer_appbar.layoutParams as RelativeLayout.LayoutParams).topMargin = statusBarHeight
59+
pdf_viewer_toolbar.menu.apply {
60+
findItem(R.id.menu_print).isVisible = realFilePath.isNotEmpty()
61+
findItem(R.id.menu_print).setOnMenuItemClickListener {
62+
printText()
63+
true
6664
}
67-
return@setOnMenuItemClickListener true
6865
}
69-
}
70-
7166

72-
private fun refreshMenuItems() {
73-
pdf_viewer_toolbar.menu.apply {
74-
findItem(R.id.menu_print).isVisible = realFilePath.isNotEmpty()
67+
pdf_viewer_toolbar.setNavigationOnClickListener {
68+
finish()
7569
}
7670
}
7771

@@ -122,6 +116,15 @@ class PDFViewerActivity : SimpleActivity() {
122116
}
123117

124118
top_shadow.animate().alpha(newAlpha).start()
119+
pdf_viewer_appbar.animate().alpha(newAlpha).withStartAction {
120+
if (newAlpha == 1f) {
121+
pdf_viewer_appbar.beVisible()
122+
}
123+
}.withEndAction {
124+
if (newAlpha == 0f) {
125+
pdf_viewer_appbar.beGone()
126+
}
127+
}.start()
125128

126129
// return false to also toggle scroll handle
127130
return true
Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.coordinatorlayout.widget.CoordinatorLayout 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-
android:id="@+id/pdf_viewer_coordinator"
4+
android:id="@+id/pdf_viewer_wrapper"
55
android:layout_width="match_parent"
6-
android:layout_height="match_parent">
6+
android:layout_height="wrap_content"
7+
app:layout_behavior="@string/appbar_scrolling_view_behavior">
8+
9+
<com.github.barteksc.pdfviewer.PDFView
10+
android:id="@+id/pdf_viewer"
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent" />
13+
14+
<ImageView
15+
android:id="@+id/top_shadow"
16+
android:layout_width="match_parent"
17+
android:layout_height="@dimen/top_shadow_height"
18+
android:layout_alignParentTop="true"
19+
android:background="@drawable/gradient_background_flipped"
20+
android:contentDescription="@null" />
721

822
<com.google.android.material.appbar.AppBarLayout
9-
android:id="@+id/pdf_viewer_app_bar_layout"
23+
android:id="@+id/pdf_viewer_appbar"
1024
android:layout_width="match_parent"
11-
android:layout_height="wrap_content">
25+
android:layout_height="wrap_content"
26+
android:layout_alignParentTop="true"
27+
android:background="@android:color/transparent"
28+
android:elevation="0dp"
29+
app:elevation="0dp">
1230

1331
<com.google.android.material.appbar.MaterialToolbar
1432
android:id="@+id/pdf_viewer_toolbar"
1533
android:layout_width="match_parent"
1634
android:layout_height="?attr/actionBarSize"
17-
android:background="@color/color_primary"
1835
app:menu="@menu/menu_pdf_viewer"
19-
app:title="@string/pdf_viewer"
20-
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
36+
app:navigationIcon="@drawable/ic_arrow_left_vector" />
2137

2238
</com.google.android.material.appbar.AppBarLayout>
23-
24-
<RelativeLayout
25-
android:id="@+id/pdf_viewer_wrapper"
26-
android:layout_width="match_parent"
27-
android:layout_height="wrap_content"
28-
app:layout_behavior="@string/appbar_scrolling_view_behavior">
29-
30-
<com.github.barteksc.pdfviewer.PDFView
31-
android:id="@+id/pdf_viewer"
32-
android:layout_width="match_parent"
33-
android:layout_height="match_parent" />
34-
35-
<ImageView
36-
android:id="@+id/top_shadow"
37-
android:layout_width="match_parent"
38-
android:layout_height="@dimen/default_status_action_height"
39-
android:background="@drawable/gradient_background_flipped"
40-
android:contentDescription="@null" />
41-
42-
</RelativeLayout>
43-
</androidx.coordinatorlayout.widget.CoordinatorLayout>
39+
</RelativeLayout>

0 commit comments

Comments
 (0)