Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ object PreferenceDataStore {
}

fun getUserId(): Flow<Int> = summaryStore.data.map {
it[USER_ID_KEY] ?: 0
it[USER_ID_KEY] ?: 41
}

fun getUserName(): Flow<String> = summaryStore.data.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ data class WalkReviewRecordEntity(
title = title,
description = description,
isPublic = isPublic,
isMine = isMine,
selectedCategories = categories.map { category ->
SelectedCategoryDto(
categoryId = category.categoryId,
selectedOptionIds = category.selectedOptionIds
)
},
isMine = isMine,
routeId = routeId,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ fun TapMapScreen(
contentAlignment = Alignment.BottomCenter
) {
Text(
text = "산책 기록 시작하기",
text = "산책 기록하기",
color = PawKeyTheme.colors.white1,
fontSize = 16.sp,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ fun SharedWalkCourseScreen(
color = PawKeyTheme.colors.green500,
shape = RoundedCornerShape(8.dp)
)
.padding(horizontal = 28.dp, vertical = 16.dp),
.padding(horizontal = 24.dp, vertical = 16.dp),
color = PawKeyTheme.colors.green500,
style = PawKeyTheme.typography.body16Sb
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,28 @@ fun sharedWalkCourseMapView(
}
}

LaunchedEffect(centerLabel, trackingManager) {
LaunchedEffect(isTrackingEnabled) {
kakaoMapState?.moveCamera(
CameraUpdateFactory.newCenterPosition(
currentUserLocation, 19
)
)
}

/*LaunchedEffect(centerLabel, trackingManager) {
if (centerLabel != null && trackingManager != null) {
trackingManager?.startTracking(centerLabel)
}
}
}*/

LaunchedEffect(isPauseTracking) {
if (!isPauseTracking) {
trackingManager?.stopTracking()
//trackingManager?.stopTracking()
mapView.isClickable = false
dimScreenLayer?.setColor(Color.Black.copy(alpha = 0.5f).toArgb())
dimScreenLayer?.setVisible(true)
} else {
trackingManager?.stopTracking()
//trackingManager?.stopTracking()
mapView.isClickable = true
dimScreenLayer?.setVisible(false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SharedWalkCourseViewModel @Inject constructor(
_state.update { state ->
state.copy(
poiPoints = it.geometry.coordinates.map { coord ->
LatLng.from(coord[0], coord[1])
LatLng.from(coord[1], coord[0])
}.toPersistentList()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.opengl.GLException
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.view.PixelCopy
import androidx.annotation.RequiresApi
import androidx.compose.foundation.background
import androidx.compose.foundation.border
Expand Down Expand Up @@ -308,7 +310,6 @@ fun WalkCourseRoute(
onLabelClick = { _, _ -> },
currentUserLocation = state.currentLocation,
poiPoints = if (isSharedWalk) {
//Todo : 여기 공유용 루트 좌표값용
listOf()
} else {
state.poiPoints
Expand Down Expand Up @@ -475,12 +476,11 @@ fun WalkCourseScreen(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
// Todo : 텍스트 스타일 24b로 변경 예쩡
if (!isSharedWalk) {
Text(
text = "산책이 중단되었어요!",
textAlign = TextAlign.Center,
style = PawKeyTheme.typography.head22B,
style = PawKeyTheme.typography.head24B,
color = PawKeyTheme.colors.white1,
modifier = Modifier.fillMaxWidth()
)
Expand All @@ -492,6 +492,7 @@ fun WalkCourseScreen(
style = PawKeyTheme.typography.body16M,
color = PawKeyTheme.colors.white2,
modifier = Modifier.fillMaxWidth()
.padding(top = 12.dp)
)
} else {
Text(
Expand Down Expand Up @@ -572,6 +573,7 @@ fun WalkCourseScreen(
},
modifier = Modifier
.padding(top = 16.dp)
.padding(bottom = 44.dp)
)
} else {
Row (
Expand Down Expand Up @@ -613,7 +615,7 @@ fun WalkCourseScreen(
.noRippleClickable {
onStopTracking()
}
.padding(horizontal = 24.dp, vertical = 16.dp),
.padding(horizontal = 28.dp, vertical = 16.dp),
color = PawKeyTheme.colors.white1,
style = PawKeyTheme.typography.body16Sb
)
Expand All @@ -626,20 +628,95 @@ fun WalkCourseScreen(
}

fun captureMapToBitmap(surfaceView: GLSurfaceView, onCaptured: (Bitmap?) -> Unit) {
surfaceView.queueEvent {
val egl = EGLContext.getEGL() as EGL10
val gl = egl.eglGetCurrentContext().gl as GL10

// 원하는 최종 크기를 먼저 계산
val screenWidth = surfaceView.context.resources.displayMetrics.widthPixels
val contentWidth = (screenWidth - 32)
val targetHeight = (156 * surfaceView.context.resources.displayMetrics.density).toInt()

val bitmap = createBitmapFromGLSurface(0, 0, surfaceView.width, surfaceView.height, gl)
onCaptured(bitmap)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
captureUsingPixelCopy(surfaceView, onCaptured)
} else {
surfaceView.queueEvent {
val egl = EGLContext.getEGL() as EGL10
val gl = egl.eglGetCurrentContext().gl as GL10

val context = surfaceView.context
val density = context.resources.displayMetrics.density
val screenWidth = context.resources.displayMetrics.widthPixels

val contentWidth = (screenWidth - 32)
val targetHeight = (156 * density).toInt()

// OpenGL로 전체 비트맵 캡처
val fullBitmap = createBitmapFromGLSurface(0, 0, surfaceView.width, surfaceView.height, gl)

val croppedBitmap = fullBitmap?.let { bitmap ->
val centerX = bitmap.width / 2
val centerY = bitmap.height / 2

val cropStartX = (centerX - contentWidth / 2).coerceAtLeast(0)
val cropStartY = (centerY - targetHeight / 2).coerceAtLeast(0)

val safeWidth = minOf(contentWidth, bitmap.width - cropStartX)
val safeHeight = minOf(targetHeight, bitmap.height - cropStartY)

Bitmap.createBitmap(bitmap, cropStartX, cropStartY, safeWidth, safeHeight)
}

onCaptured(croppedBitmap)
}
}
}

@RequiresApi(Build.VERSION_CODES.O)
fun captureUsingPixelCopy(
surfaceView: GLSurfaceView,
onCaptured: (Bitmap?) -> Unit
) {
val rawBitmap = Bitmap.createBitmap(surfaceView.width, surfaceView.height, Bitmap.Config.ARGB_8888)

try {
PixelCopy.request(surfaceView, rawBitmap, { copyResult ->
if (copyResult == PixelCopy.SUCCESS) {
val croppedBitmap = cropCenterWithAspectRatio(rawBitmap, 16f / 11f)
onCaptured(croppedBitmap)
} else {
Log.e("PixelCopy", "PixelCopy 실패: $copyResult")
onCaptured(null)
}
}, Handler(Looper.getMainLooper()))
} catch (e: IllegalArgumentException) {
e.printStackTrace()
onCaptured(null)
}
}

fun cropCenterWithAspectRatio(
bitmap: Bitmap,
targetAspectRatio: Float
): Bitmap {
val width = bitmap.width
val height = bitmap.height
val currentAspectRatio = width.toFloat() / height.toFloat()

val cropWidth: Int
val cropHeight: Int

if (currentAspectRatio > targetAspectRatio) {
// 현재 이미지가 더 넓음 → 좌우 잘라야 함
cropHeight = height
cropWidth = (height * targetAspectRatio).toInt()
} else {
// 현재 이미지가 더 높음 → 위아래 잘라야 함
cropWidth = width
cropHeight = (width / targetAspectRatio).toInt()
}

val startX = ((width - cropWidth) / 2).coerceAtLeast(0)
val startY = ((height - cropHeight) / 2).coerceAtLeast(0)

val safeWidth = minOf(cropWidth, width - startX)
val safeHeight = minOf(cropHeight, height - startY)

return Bitmap.createBitmap(bitmap, startX, startY, safeWidth, safeHeight)
}


fun createBitmapFromGLSurface(x: Int, y: Int, w: Int, h: Int, gl: GL10): Bitmap? {
val bitmapBuffer = IntArray(w * h)
val bitmapSource = IntArray(w * h)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.Manifest
import android.net.Uri
import android.os.Build
import android.util.Log
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
Expand All @@ -29,6 +30,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
Expand Down Expand Up @@ -64,6 +66,7 @@ fun WalkReviewRoute(
) {
val state by viewModel.state.collectAsStateWithLifecycle()
val isValid = state.isValidForm
val context = LocalContext.current

val lifecycleOwner = LocalLifecycleOwner.current

Expand Down Expand Up @@ -111,6 +114,10 @@ fun WalkReviewRoute(
sideEffect.message
)

is WalkReviewContract.WalkReviewSideEffect.SHowToastMessage -> {
Toast.makeText(context, sideEffect.message, Toast.LENGTH_SHORT).show()
}

is WalkReviewContract.WalkReviewSideEffect.NavigateNext -> {
Log.d("WalkReviewRoute", "navigateNext")
navigateShared(sideEffect.routeId, sideEffect.pageId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class WalkReviewContract {

sealed class WalkReviewSideEffect {
data class ShowSnackBar(val message: String) : WalkReviewSideEffect()
data class SHowToastMessage(val message: String) : WalkReviewSideEffect()
data object NavigateUp: WalkReviewSideEffect()
data class NavigateNext(val routeId : Int, val pageId : Int): WalkReviewSideEffect()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ class WalkReviewViewModel @Inject constructor(
_sideEffect.emit(WalkReviewSideEffect.NavigateNext(response.routeId, response.postId))
Log.d("WalkReviewViewModel", "리뷰 전송 성공!")
Log.d("WalkReviewViewModel", "routeId : ${response.routeId}, postId : ${response.postId}")
}.onFailure {
}.onFailure { respon ->
_sideEffect.emit(WalkReviewSideEffect.SHowToastMessage("${respon.message}"))
_sideEffect.emit(WalkReviewSideEffect.ShowSnackBar("리뷰 전송 실패!"))


Log.e("WalkReviewViewModel", "리뷰 전송 실패!")
}
}
Expand Down
Loading