From 755c83a6cbc017dd8014c3d2b2546fa6a6842f7f Mon Sep 17 00:00:00 2001 From: tzugen Date: Fri, 29 Jul 2022 20:12:04 +0200 Subject: [PATCH] Take care of deprecation --- .../ultrasonic/fragment/PlayerFragment.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/PlayerFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/PlayerFragment.kt index af62e9bb..598d46e2 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/PlayerFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/PlayerFragment.kt @@ -10,6 +10,7 @@ package org.moire.ultrasonic.fragment import android.annotation.SuppressLint import android.app.AlertDialog import android.graphics.Point +import android.os.Build import android.os.Bundle import android.os.Handler import android.os.Looper @@ -209,12 +210,23 @@ class PlayerFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { cancellationToken = CancellationToken() setTitle(this, R.string.common_appname) + val windowManager = requireActivity().windowManager - val display = windowManager.defaultDisplay - val size = Point() - display.getSize(size) - val width = size.x - val height = size.y + val width: Int + val height: Int + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + val bounds = windowManager.currentWindowMetrics.bounds + width = bounds.width() + height = bounds.height() + } else { + val display = windowManager.defaultDisplay + val size = Point() + display.getSize(size) + width = size.x + height = size.y + } + setHasOptionsMenu(true) useFiveStarRating = Settings.useFiveStarRating swipeDistance = (width + height) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100