Skip to content

Commit

Permalink
preview fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrollzzzz committed Apr 6, 2024
1 parent 8def0d3 commit bb4d255
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FillViewModel @Inject constructor(
private fun createTempFiles() {
viewModelScope.launch {
clearCache()
val names = listOf("Фото 1", "Фото 2", "Фото 3", "Фото 4")
val names = listOf("photo1", "photo2", "photo3", "photo4")
_state.value.photos.addAll(createTempFiles(names))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ import android.content.res.Configuration
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.widthIn
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
import com.scrollz.emailphotolab.presentation.photo.components.CameraPreview
import com.scrollz.emailphotolab.theme.PhotoTheme
Expand All @@ -25,18 +21,10 @@ class PhotoActivity : ComponentActivity() {
val uri = intent.data ?: throw Exception("bad uri")
setContent {
PhotoTheme {
// PhotoScreen(
// modifier = Modifier.fillMaxSize(),
// uri = uri,
// onResult = { result ->
// if (result) setResult(Activity.RESULT_OK)
// else setResult(Activity.RESULT_CANCELED)
// }
// )
val isLandscape = LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE
CameraPreview(
modifier = Modifier.fillMaxSize(),
isLandscape = !isLandscape,
isLandscape = isLandscape,
uri = uri,
close = { result ->
if (result) setResult(Activity.RESULT_OK)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
package com.scrollz.emailphotolab.presentation.photo.components

import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.graphics.Matrix
import android.net.Uri
import android.util.Log
import android.util.Size
import android.view.Surface
import androidx.annotation.OptIn
import androidx.camera.camera2.interop.Camera2CameraInfo
import androidx.camera.camera2.interop.ExperimentalCamera2Interop
import androidx.camera.core.Camera
import androidx.camera.core.CameraSelector
import androidx.camera.core.ExperimentalGetImage
import androidx.camera.core.ImageAnalysis
import androidx.camera.core.ImageCapture
import androidx.camera.core.ImageCaptureException
import androidx.camera.core.ImageProxy
import androidx.camera.core.Preview
import androidx.camera.core.resolutionselector.ResolutionSelector
Expand All @@ -26,8 +21,6 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -40,7 +33,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.content.ContextCompat
import java.util.concurrent.Executors

@OptIn(ExperimentalCamera2Interop::class)
@Composable
Expand Down Expand Up @@ -89,7 +81,7 @@ internal fun CameraPreview(
val resolutionSelector = ResolutionSelector.Builder()
.setResolutionStrategy(ResolutionStrategy.HIGHEST_AVAILABLE_STRATEGY)
.setResolutionFilter { a, _ ->
Log.i("sizes", a.toString());
Log.i("sizes", a.toString())
listOf(Size(1920, 1080))
}.build()

Expand All @@ -108,8 +100,9 @@ internal fun CameraPreview(
if (imageTaken) {
saveImage(imageProxy)
close(true)
} else {
imageProxy.close()
}
imageProxy.close()
}
}

Expand Down Expand Up @@ -141,37 +134,16 @@ internal fun CameraPreview(
) {
AndroidView(
modifier = Modifier.aspectRatio(
ratio = if (isLandscape) 9/16f else 9/16f,
ratio = 9/16f,
matchHeightConstraintsFirst = isLandscape
),
factory = { previewView }
)
CameraUI(
modifier = modifier,
isLandscape = isLandscape,
isButtonEnabled = isButtonEnabled,
takePhoto = takePhoto,
close = { close(false) }
)
}

// Surface(
// modifier = Modifier,
// color = Color.Black
// ) {
// AndroidView(
// modifier = Modifier.aspectRatio(
// ratio = if (isLandscape) 9/16f else 9/16f,
// matchHeightConstraintsFirst = isLandscape
// ),
// factory = { previewView }
// )
// CameraUI(
// modifier = modifier,
// isLandscape = isLandscape,
// isButtonEnabled = isButtonEnabled,
// takePhoto = takePhoto,
// close = { close(false) }
// )
// }
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
package com.scrollz.emailphotolab.presentation.photo.components

import android.content.res.Configuration
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.scrollz.emailphotolab.R

@Composable
fun CameraUI(
modifier: Modifier = Modifier,
isLandscape: Boolean,
isButtonEnabled: Boolean,
takePhoto: () -> Unit,
close: () -> Unit
Expand Down

0 comments on commit bb4d255

Please sign in to comment.