From 0a8bdcbbc4cb72c41746b803d2960331138ffaad Mon Sep 17 00:00:00 2001 From: IacobIonut01 Date: Sat, 2 Nov 2024 20:45:55 +0200 Subject: [PATCH] Set HDR Mode exclusively on HDR images Signed-off-by: IacobIonut01 --- app/build.gradle.kts | 2 +- .../presentation/main/MainActivity.kt | 11 ---------- .../components/media/ZoomablePagerImage.kt | 20 +++++++++++++++++++ .../standalone/StandaloneActivity.kt | 10 ---------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 42628f559..fa214051c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -22,7 +22,7 @@ android { applicationId = "com.dot.gallery" minSdk = 30 targetSdk = 35 - versionCode = 30123 + versionCode = 30124 versionName = "3.0.1" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/main/MainActivity.kt b/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/main/MainActivity.kt index 9d8c1825e..bdf409ea2 100644 --- a/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/main/MainActivity.kt +++ b/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/main/MainActivity.kt @@ -30,7 +30,6 @@ import com.dot.gallery.core.Settings.Misc.rememberForceTheme import com.dot.gallery.core.Settings.Misc.rememberIsDarkMode import com.dot.gallery.core.presentation.components.AppBarContainer import com.dot.gallery.core.presentation.components.NavigationComp -import com.dot.gallery.feature_node.presentation.util.setHdrMode import com.dot.gallery.feature_node.presentation.util.toggleOrientation import com.dot.gallery.ui.theme.GalleryTheme import dagger.hilt.android.AndroidEntryPoint @@ -94,16 +93,6 @@ class MainActivity : AppCompatActivity() { } } - override fun onResume() { - super.onResume() - setHdrMode(true) - } - - override fun onPause() { - super.onPause() - setHdrMode(false) - } - private fun enforceSecureFlag() { lifecycleScope.launch { getSecureMode(this@MainActivity).collectLatest { enabled -> diff --git a/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/mediaview/components/media/ZoomablePagerImage.kt b/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/mediaview/components/media/ZoomablePagerImage.kt index 853d11286..524b66ed0 100644 --- a/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/mediaview/components/media/ZoomablePagerImage.kt +++ b/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/mediaview/components/media/ZoomablePagerImage.kt @@ -11,6 +11,7 @@ import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.NonRestartableComposable import androidx.compose.runtime.Stable import androidx.compose.runtime.getValue @@ -26,6 +27,7 @@ import androidx.compose.ui.draw.blur import androidx.compose.ui.graphics.FilterQuality import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp import com.dot.gallery.core.Constants.DEFAULT_TOP_BAR_ANIMATION_DURATION import com.dot.gallery.core.Settings @@ -34,7 +36,9 @@ import com.dot.gallery.core.presentation.components.util.ProvideBatteryStatus import com.dot.gallery.core.presentation.components.util.swipe import com.dot.gallery.feature_node.domain.model.Media import com.dot.gallery.feature_node.presentation.util.rememberFeedbackManager +import com.dot.gallery.feature_node.presentation.util.setHdrMode import com.github.panpf.sketch.AsyncImage +import com.github.panpf.sketch.getBitmapOrNull import com.github.panpf.sketch.rememberAsyncImageState import com.github.panpf.sketch.request.ComposableImageRequest import com.github.panpf.sketch.request.ImageOptions @@ -98,6 +102,22 @@ fun ZoomablePagerImage( ) } ) + + val context = LocalContext.current + + DisposableEffect(media, asyncState.result) { + scope.launch { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + asyncState.result?.image?.getBitmapOrNull()?.let { + context.setHdrMode(it.hasGainmap()) + } + } + } + onDispose { + context.setHdrMode(false) + } + } + SketchZoomAsyncImage( zoomState = zoomState, state = asyncState, diff --git a/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/standalone/StandaloneActivity.kt b/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/standalone/StandaloneActivity.kt index 78650609a..e300dc8b5 100644 --- a/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/standalone/StandaloneActivity.kt +++ b/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/standalone/StandaloneActivity.kt @@ -20,7 +20,6 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.dot.gallery.feature_node.domain.model.AlbumState import com.dot.gallery.feature_node.presentation.mediaview.MediaViewScreen -import com.dot.gallery.feature_node.presentation.util.setHdrMode import com.dot.gallery.feature_node.presentation.util.toggleOrientation import com.dot.gallery.ui.theme.GalleryTheme import dagger.hilt.android.AndroidEntryPoint @@ -75,13 +74,4 @@ class StandaloneActivity : ComponentActivity() { } } - override fun onResume() { - super.onResume() - setHdrMode(true) - } - - override fun onPause() { - super.onPause() - setHdrMode(false) - } } \ No newline at end of file