Skip to content

Commit

Permalink
Set HDR Mode exclusively on HDR images
Browse files Browse the repository at this point in the history
Signed-off-by: IacobIonut01 <[email protected]>
  • Loading branch information
IacobIonut01 committed Nov 2, 2024
1 parent d7f7902 commit 0a8bdcb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
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 = 30123
versionCode = 30124
versionName = "3.0.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,13 +74,4 @@ class StandaloneActivity : ComponentActivity() {
}
}

override fun onResume() {
super.onResume()
setHdrMode(true)
}

override fun onPause() {
super.onPause()
setHdrMode(false)
}
}

0 comments on commit 0a8bdcb

Please sign in to comment.