Skip to content

Commit

Permalink
fix(gestures): get the system's brightness
Browse files Browse the repository at this point in the history
the brightness curves in android aren't linear and i differ from phone to phone so i can't make an accurate representation that satisfies.
this should be enough, i think
  • Loading branch information
abdallahmehiz committed Jun 25, 2024
1 parent 19d5ae6 commit 180af77
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package live.mehiz.mpvkt.ui.player

import android.media.AudioManager
import android.net.Uri
import android.provider.Settings
import android.util.DisplayMetrics
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.ViewModel
Expand Down Expand Up @@ -63,7 +64,10 @@ class PlayerViewModel(
val playerUpdate = MutableStateFlow(PlayerUpdates.None)
val isBrightnessSliderShown = MutableStateFlow(false)
val isVolumeSliderShown = MutableStateFlow(false)
val currentBrightness = MutableStateFlow(activity.window.attributes.screenBrightness)
val currentBrightness = MutableStateFlow(
Settings.System.getFloat(activity.contentResolver, Settings.System.SCREEN_BRIGHTNESS)
.normalize(0f, 255f, 0f, 1f)
)
val currentVolume = MutableStateFlow(activity.audioManager.getStreamVolume(AudioManager.STREAM_MUSIC))

val sheetShown = MutableStateFlow(Sheets.None)
Expand Down Expand Up @@ -340,3 +344,7 @@ data class Track(
val name: String,
val language: String?,
)

fun Float.normalize(inMin: Float, inMax: Float, outMin: Float, outMax: Float): Float {
return (this - inMin) * (outMax - outMin) / (inMax - inMin) + outMin
}

0 comments on commit 180af77

Please sign in to comment.