Skip to content

Commit

Permalink
Feature: Add hold to rotate photo
Browse files Browse the repository at this point in the history
Now you can long press to rotate the photo 90 degrees to the right. The change is only visiual and no orientation changes occurs directly on the photo file

Signed-off-by: IacobIonut01 <[email protected]>
  • Loading branch information
IacobIonut01 committed Sep 28, 2024
1 parent bdbb16b commit 251e88e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 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 = 30104
versionCode = 30109
versionName = "3.0.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@ 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.LaunchedEffect
import androidx.compose.runtime.NonRestartableComposable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
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.LocalConfiguration
import androidx.compose.ui.unit.dp
import com.dot.gallery.core.Constants.DEFAULT_TOP_BAR_ANIMATION_DURATION
import com.dot.gallery.core.Settings
import com.dot.gallery.core.presentation.components.util.LocalBatteryStatus
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.github.panpf.sketch.AsyncImage
import com.github.panpf.sketch.request.ComposableImageRequest
import com.github.panpf.sketch.util.Size
Expand All @@ -48,6 +51,13 @@ fun ZoomablePagerImage(
onItemClick: () -> Unit,
onSwipeDown: () -> Unit
) {
val feedbackManager = rememberFeedbackManager()
var isRotating by rememberSaveable { mutableStateOf(false) }
var currentRotation by rememberSaveable { mutableStateOf(0) }
val rotationAnimation by animateFloatAsState(
targetValue = if (isRotating) 90f else 0f,
label = "rotationAnimation"
)
ProvideBatteryStatus {
val allowBlur by Settings.Misc.rememberAllowBlur()
val isPowerSavingMode = LocalBatteryStatus.current.isPowerSavingMode
Expand All @@ -73,21 +83,33 @@ fun ZoomablePagerImage(
}
val zoomState = rememberSketchZoomState()
val scope = rememberCoroutineScope()
LaunchedEffect(LocalConfiguration.current) {
/* LaunchedEffect(LocalConfiguration.current) {
scope.launch {
delay(100)
zoomState.zoomable.reset("alignmentChanged")
}
}

}*/
SketchZoomAsyncImage(
zoomState = zoomState,
modifier = modifier
.fillMaxSize()
.swipe(
onSwipeDown = onSwipeDown
),
)
.graphicsLayer {
rotationZ = if (isRotating) rotationAnimation else 0f
},
onTap = { onItemClick() },
onLongPress = {
scope.launch {
isRotating = true
feedbackManager.vibrate()
currentRotation += 90
delay(350)
zoomState.zoomable.rotate(currentRotation)
isRotating = false
}
},
alignment = Alignment.Center,
uri = media.uri.toString(),
contentDescription = media.label
Expand Down

0 comments on commit 251e88e

Please sign in to comment.