replace deprecated api uses

This commit is contained in:
Pratyush 2022-05-12 16:53:55 +05:30 committed by Daniel Micay
parent 43f971c028
commit 18761b3e4a
2 changed files with 23 additions and 13 deletions

View File

@ -44,6 +44,7 @@ import app.grapheneos.pdfviewer.databinding.PdfviewerBinding;
import app.grapheneos.pdfviewer.fragment.DocumentPropertiesFragment; import app.grapheneos.pdfviewer.fragment.DocumentPropertiesFragment;
import app.grapheneos.pdfviewer.fragment.PasswordPromptFragment; import app.grapheneos.pdfviewer.fragment.PasswordPromptFragment;
import app.grapheneos.pdfviewer.fragment.JumpToPageFragment; import app.grapheneos.pdfviewer.fragment.JumpToPageFragment;
import app.grapheneos.pdfviewer.ktx.ViewKt;
import app.grapheneos.pdfviewer.loader.DocumentPropertiesLoader; import app.grapheneos.pdfviewer.loader.DocumentPropertiesLoader;
import app.grapheneos.pdfviewer.viewModel.PasswordStatus; import app.grapheneos.pdfviewer.viewModel.PasswordStatus;
@ -331,8 +332,7 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
if (mUri != null) { if (mUri != null) {
binding.webview.evaluateJavascript("isTextSelected()", selection -> { binding.webview.evaluateJavascript("isTextSelected()", selection -> {
if (!Boolean.parseBoolean(selection)) { if (!Boolean.parseBoolean(selection)) {
if ((getWindow().getDecorView().getSystemUiVisibility() & if (getSupportActionBar().isShowing()) {
View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
hideSystemUi(); hideSystemUi();
} else { } else {
showSystemUi(); showSystemUi();
@ -569,21 +569,12 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader
} }
private void showSystemUi() { private void showSystemUi() {
getWindow().getDecorView().setSystemUiVisibility( ViewKt.showSystemUi(binding.getRoot());
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getSupportActionBar().show(); getSupportActionBar().show();
} }
private void hideSystemUi() { private void hideSystemUi() {
getWindow().getDecorView().setSystemUiVisibility( ViewKt.hideSystemUi(binding.getRoot());
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_IMMERSIVE);
getSupportActionBar().hide(); getSupportActionBar().hide();
} }

View File

@ -0,0 +1,19 @@
package app.grapheneos.pdfviewer.ktx
import android.view.View
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
private val systemBars = WindowInsetsCompat.Type.statusBars()
fun View.hideSystemUi() {
val controller = ViewCompat.getWindowInsetsController(this) ?: return
controller.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
controller.hide(systemBars)
}
fun View.showSystemUi() {
ViewCompat.getWindowInsetsController(this)?.show(systemBars)
}