mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
Removes unneeded code in BottomSheetDialog.kt
This commit is contained in:
parent
85f16e8dfa
commit
e0f327e8f6
1 changed files with 3 additions and 24 deletions
|
@ -16,32 +16,11 @@
|
|||
|
||||
package im.vector.app.core.extensions
|
||||
|
||||
import android.os.Build
|
||||
import android.util.DisplayMetrics
|
||||
import androidx.annotation.FloatRange
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import io.github.hyuwah.draggableviewlib.Utils.getScreenHeight
|
||||
|
||||
fun BottomSheetDialog.setPeekHeightAsScreenPercentage(@FloatRange(from = 0.0, to = 1.0) percentage: Float) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
setPeekHeightPostApi30(percentage)
|
||||
} else {
|
||||
setPeekHeightPreApi30(percentage)
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
private fun BottomSheetDialog.setPeekHeightPostApi30(percentage: Float) {
|
||||
window?.windowManager?.currentWindowMetrics?.let { windowMetrics ->
|
||||
val height = windowMetrics.bounds.height()
|
||||
behavior.setPeekHeight((height * percentage).toInt(), true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun BottomSheetDialog.setPeekHeightPreApi30(percentage: Float) {
|
||||
val displayMetrics = DisplayMetrics()
|
||||
@Suppress("DEPRECATION")
|
||||
window?.windowManager?.defaultDisplay?.getMetrics(displayMetrics)
|
||||
val height = displayMetrics.heightPixels
|
||||
behavior.setPeekHeight((height * percentage).toInt(), true)
|
||||
val screenHeight = getScreenHeight(context)
|
||||
behavior.setPeekHeight((screenHeight * percentage).toInt(), true)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue