Skip to content

Commit

Permalink
Dismiss UI automatically when playing videos
Browse files Browse the repository at this point in the history
Added option in settings (enabled by default)

Fixes [Enhancement] Video UI that doesn't get in your way #416

Signed-off-by: IacobIonut01 <[email protected]>
  • Loading branch information
IacobIonut01 committed Oct 11, 2024
1 parent 7323335 commit 8ed96e3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
applicationId = "com.dot.gallery"
minSdk = 30
targetSdk = 35
versionCode = 30117
versionCode = 30120
versionName = "3.0.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/kotlin/com/dot/gallery/core/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ object Settings {
@Composable
fun rememberFullBrightnessView() =
rememberPreference(key = FULL_BRIGHTNESS_VIEW, defaultValue = false)

private val AUTO_HIDE_ON_VIDEO_PLAY = booleanPreferencesKey("auto_hide_on_video_play")

@Composable
fun rememberAutoHideOnVideoPlay() =
rememberPreference(key = AUTO_HIDE_ON_VIDEO_PLAY, defaultValue = true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import com.dot.gallery.core.Constants.DEFAULT_LOW_VELOCITY_SWIPE_DURATION
import com.dot.gallery.core.Constants.DEFAULT_TOP_BAR_ANIMATION_DURATION
import com.dot.gallery.core.Constants.HEADER_DATE_FORMAT
import com.dot.gallery.core.Constants.Target.TARGET_TRASH
import com.dot.gallery.core.Settings.Misc.rememberAutoHideOnVideoPlay
import com.dot.gallery.feature_node.domain.model.AlbumState
import com.dot.gallery.feature_node.domain.model.Media
import com.dot.gallery.feature_node.domain.model.MediaState
Expand All @@ -87,6 +88,7 @@ import com.dot.gallery.ui.theme.BlackScrim
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import kotlin.time.Duration.Companion.seconds

@Stable
@OptIn(ExperimentalFoundationApi::class)
Expand Down Expand Up @@ -262,6 +264,15 @@ fun MediaViewScreen(
Box(
modifier = Modifier.fillMaxSize()
) {
val hideUiOnPlay by rememberAutoHideOnVideoPlay()
LaunchedEffect(isPlaying.value, hideUiOnPlay) {
if (isPlaying.value && showUI.value && hideUiOnPlay) {
delay(2.seconds)
showUI.value = false
windowInsetsController.toggleSystemBars(false)
}
}

val context = LocalContext.current
val width =
remember(context) { context.resources.displayMetrics.widthPixels }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import com.dot.gallery.core.Position
import com.dot.gallery.core.Settings
import com.dot.gallery.core.Settings.Misc.rememberAudioFocus
import com.dot.gallery.core.Settings.Misc.rememberAutoHideNavBar
import com.dot.gallery.core.Settings.Misc.rememberAutoHideOnVideoPlay
import com.dot.gallery.core.Settings.Misc.rememberAutoHideSearchBar
import com.dot.gallery.core.Settings.Misc.rememberForcedLastScreen
import com.dot.gallery.core.Settings.Misc.rememberFullBrightnessView
Expand Down Expand Up @@ -434,6 +435,17 @@ fun rememberSettingsList(
summary = context.getString(R.string.full_brightness_view_summary),
isChecked = fullBrightnessView,
onCheck = { fullBrightnessView = it },
screenPosition = Position.Middle
)
}

var autoHideOnVideoPlay by rememberAutoHideOnVideoPlay()
val autoHideOnVideoPlayPref = remember(autoHideOnVideoPlay) {
SettingsEntity.SwitchPreference(
title = context.getString(R.string.auto_hide_on_video_play),
summary = context.getString(R.string.auto_hide_on_video_play_summary),
isChecked = autoHideOnVideoPlay,
onCheck = { autoHideOnVideoPlay = it },
screenPosition = Position.Bottom
)
}
Expand Down Expand Up @@ -476,6 +488,7 @@ fun rememberSettingsList(
add(forcedLastScreenPref)
add(audioFocusPref)
add(fullBrightnessViewPref)
add(autoHideOnVideoPlayPref)
/** ********************* **/
/** ********************* **/
/** Navigation Section Start **/
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@
<string name="take_audio_focus_summary">Enabling this will take audio focus when playing media. Any media playing in background will pause while the video is playing. (Restart app required)</string>
<string name="full_brightness_view_title">Full Brightness when viewing</string>
<string name="full_brightness_view_summary">Increase the screen brightness to maximum when viewing images and videos</string>
<string name="auto_hide_on_video_play">Hide UI on Video Play</string>
<string name="auto_hide_on_video_play_summary">Hides the UI after 2 seconds when playing videos</string>
<plurals name="item_count">
<item quantity="one">%s item</item>
<item quantity="other">%s items</item>
Expand Down

0 comments on commit 8ed96e3

Please sign in to comment.