Skip to content

Commit

Permalink
Using androidx.window for getting screen size
Browse files Browse the repository at this point in the history
  • Loading branch information
Javernaut committed Nov 20, 2023
1 parent 48272cd commit 240f2a4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ dependencies {
implementation libs.savedstate
implementation libs.viewpager2
implementation libs.browser
implementation libs.window

// TODO replace with own implementation
implementation libs.liveevent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.javernaut.whatthecodec.presentation.video

import android.app.Activity
import android.graphics.Point
import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
Expand All @@ -23,6 +22,7 @@ import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.window.layout.WindowMetricsCalculator
import com.javernaut.whatthecodec.R
import com.javernaut.whatthecodec.presentation.compose.common.GridLayout
import com.javernaut.whatthecodec.presentation.root.viewmodel.model.ActualPreview
Expand All @@ -44,15 +44,16 @@ fun getDesiredFrameWidth(activity: Activity): Int {
}

fun getPreviewViewWidth(activity: Activity): Int {
val point = Point()
activity.windowManager.defaultDisplay.getSize(point)
return min(point.x, point.y)
val metrics = WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(activity)
return with(metrics.bounds) {
min(width(), height())
}
}

@Composable
fun FramesHeader(preview: Preview, dstFrameWidth: Int) {
when (preview) {
is NotYetEvaluated -> { }
is NotYetEvaluated -> {}
is ActualPreview -> {
val backgroundColor by animateColorAsState(Color(preview.backgroundColor))
Box(
Expand All @@ -70,6 +71,7 @@ fun FramesHeader(preview: Preview, dstFrameWidth: Int) {
)
}
}

NoPreviewAvailable -> {
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
Text(
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ detektplugin = "1.23.3"
kotlin = "1.9.20"
coroutines = "1.7.3"
lifecycle = "2.6.2"
window = "1.2.0"
compose-animation = "1.5.4"
compose-compiler = "1.5.4"
compose-foundation = "1.5.4"
Expand All @@ -23,6 +24,8 @@ lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx
lifecycle-livedata-ktx = { module = "androidx.lifecycle:lifecycle-livedata-ktx", version.ref = "lifecycle" }
lifecycle-viewmodel-savedstate = { module = "androidx.lifecycle:lifecycle-viewmodel-savedstate", version.ref = "lifecycle" }

window = { module = "androidx.window:window", version.ref = "window" }

liveevent = "com.github.hadilq.liveevent:liveevent:1.2.0"
palette = "androidx.palette:palette-ktx:1.0.0"
savedstate = "androidx.savedstate:savedstate:1.2.1"
Expand Down

0 comments on commit 240f2a4

Please sign in to comment.