11package com.simplemobiletools.filemanager.pro.activities
22
33import android.content.Context
4- import android.content.res.Configuration.UI_MODE_NIGHT_NO
4+ import android.graphics.Color
5+ import android.graphics.drawable.ColorDrawable
56import android.os.Bundle
7+ import android.os.Handler
68import android.print.PrintAttributes
79import android.print.PrintManager
810import android.view.Menu
911import android.view.MenuItem
10- import android.view.View
12+ import android.view.WindowInsetsController
1113import android.view.WindowManager
12- import android.widget.RelativeLayout
13- import androidx.core.view.updateLayoutParams
1414import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle
1515import com.simplemobiletools.commons.extensions.*
1616import com.simplemobiletools.commons.helpers.REAL_FILE_PATH
1717import com.simplemobiletools.commons.helpers.isPiePlus
18- import com.simplemobiletools.commons.helpers.isSPlus
18+ import com.simplemobiletools.commons.helpers.isRPlus
1919import com.simplemobiletools.filemanager.pro.R
20- import com.simplemobiletools.filemanager.pro.extensions.config
21- import com.simplemobiletools.filemanager.pro.extensions.getUiMode
2220import com.simplemobiletools.filemanager.pro.extensions.hideSystemUI
2321import com.simplemobiletools.filemanager.pro.extensions.showSystemUI
22+ import com.simplemobiletools.filemanager.pro.helpers.HIDE_SYSTEM_UI_DELAY
2423import com.simplemobiletools.filemanager.pro.helpers.PdfDocumentAdapter
2524import kotlinx.android.synthetic.main.activity_pdf_viewer.*
2625
2726
2827class PDFViewerActivity : SimpleActivity () {
2928 private var realFilePath = " "
30-
3129 private var isFullScreen = false
32- private var pdfViewerHeight = - 1
33- private var positionOffset = 0f
3430
3531 override fun onCreate (savedInstanceState : Bundle ? ) {
32+ useDynamicTheme = false
33+
3634 super .onCreate(savedInstanceState)
3735 setContentView(R .layout.activity_pdf_viewer)
3836
3937 if (checkAppSideloading()) {
4038 return
4139 }
4240
41+ window.decorView.setBackgroundColor(getProperBackgroundColor())
42+ top_shadow.layoutParams.height = statusBarHeight + actionBarHeight
43+ checkNotchSupport()
44+
4345 if (intent.extras?.containsKey(REAL_FILE_PATH ) == true ) {
4446 realFilePath = intent.extras?.get(REAL_FILE_PATH )?.toString() ? : " "
4547 }
4648
4749 checkIntent()
48- setupNotch()
50+ if (isRPlus()) {
51+ window.insetsController?.setSystemBarsAppearance(0 , WindowInsetsController .APPEARANCE_LIGHT_STATUS_BARS )
52+ }
53+ }
54+
55+ override fun onResume () {
56+ super .onResume()
57+ supportActionBar?.setBackgroundDrawable(ColorDrawable (Color .TRANSPARENT ))
58+ window.statusBarColor = Color .TRANSPARENT
59+ setTranslucentNavigation()
4960 }
5061
5162 override fun onCreateOptionsMenu (menu : Menu ): Boolean {
@@ -54,7 +65,7 @@ class PDFViewerActivity : SimpleActivity() {
5465 findItem(R .id.menu_print).isVisible = realFilePath.isNotEmpty()
5566 }
5667
57- updateMenuItemColors(menu)
68+ updateMenuItemColors(menu, forceWhiteIcons = true )
5869 return true
5970 }
6071
@@ -73,18 +84,26 @@ class PDFViewerActivity : SimpleActivity() {
7384 return
7485 }
7586
76- val filename = getFilenameFromUri(uri)
77- if (filename.isNotEmpty()) {
78- title = filename
79- }
80-
8187 val primaryColor = getProperPrimaryColor()
8288 pdf_viewer.setBackgroundColor(getProperBackgroundColor())
8389 pdf_viewer.fromUri(uri)
8490 .scrollHandle(DefaultScrollHandle (this , primaryColor.getContrastColor(), primaryColor))
8591 .spacing(15 )
8692 .onTap { toggleFullScreen() }
8793 .load()
94+
95+ showSystemUI(true )
96+
97+ pdf_viewer_wrapper.onGlobalLayout {
98+ Handler (mainLooper).postDelayed({
99+ toggleFullScreen()
100+ }, HIDE_SYSTEM_UI_DELAY )
101+
102+ val filename = getFilenameFromUri(uri)
103+ if (filename.isNotEmpty()) {
104+ supportActionBar?.title = filename
105+ }
106+ }
88107 }
89108
90109 private fun printText () {
@@ -96,43 +115,23 @@ class PDFViewerActivity : SimpleActivity() {
96115 }
97116
98117 private fun toggleFullScreen (): Boolean {
99- if (isFullScreen) exitFullScreen() else enterFullScreen()
100118 isFullScreen = ! isFullScreen
101- return true
102- }
103-
104- private fun enterFullScreen () {
105- if (pdfViewerHeight == - 1 ) {
106- pdfViewerHeight = pdf_viewer.height
119+ val newAlpha: Float
120+ if (isFullScreen) {
121+ newAlpha = 0f
122+ hideSystemUI(true )
123+ } else {
124+ newAlpha = 1f
125+ showSystemUI(true )
107126 }
108- positionOffset = pdf_viewer.positionOffset
109- hideSystemUI(true )
110-
111- pdf_viewer.updateLayoutParams<RelativeLayout .LayoutParams > {
112- // hack to workaround pdf viewer height glitch
113- this .height = pdf_viewer_wrapper.height + statusBarHeight + actionBarHeight
114- }
115- }
116127
117- private fun exitFullScreen () {
118- positionOffset = pdf_viewer.positionOffset
128+ top_shadow.animate().alpha(newAlpha).start()
119129
120- showSystemUI(true )
121- pdf_viewer.updateLayoutParams<RelativeLayout .LayoutParams > {
122- this .height = pdfViewerHeight
123- }
124- pdf_viewer.post { pdf_viewer.positionOffset = positionOffset }
125-
126- @Suppress(" DEPRECATION" )
127- // use light status bar on material you
128- if (isSPlus() && config.isUsingSystemTheme && getUiMode() == UI_MODE_NIGHT_NO ) {
129- val flags = window.decorView.systemUiVisibility
130- window.decorView.systemUiVisibility = flags or View .SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
131- }
130+ // return false to also toggle scroll handle
131+ return true
132132 }
133133
134-
135- private fun setupNotch () {
134+ private fun checkNotchSupport () {
136135 if (isPiePlus()) {
137136 window.attributes.layoutInDisplayCutoutMode = WindowManager .LayoutParams .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
138137 window.addFlags(WindowManager .LayoutParams .FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS )
0 commit comments