Skip to content

Commit

Permalink
Maker Faire Set up
Browse files Browse the repository at this point in the history
  • Loading branch information
ing03201 authored and DokySp committed Oct 11, 2024
1 parent 929ca60 commit df20c5e
Show file tree
Hide file tree
Showing 23 changed files with 380 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.graphics.Bitmap
import android.net.Uri
import com.foke.together.domain.interactor.entity.CutFrameType
import com.foke.together.domain.output.ImageRepositoryInterface
import com.foke.together.util.AppPolicy
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
Expand All @@ -20,4 +21,20 @@ class GeneratePhotoFrameUseCase @Inject constructor(
suspend fun clearCapturedImageList() = imageRepositoryInterface.clearCacheDir()
suspend fun saveGraphicsLayerImage(image: Bitmap, fileName: String) = imageRepositoryInterface.cachingImage(image, fileName)
suspend fun saveFinalImage(image: Bitmap, fileName: String) = imageRepositoryInterface.saveToStorage(image, fileName)

fun getFinalSingleImageUri(): Uri {
var finalSingleImageUri: Uri = Uri.EMPTY
context.cacheDir.listFiles().forEach {
file -> if (file.name.contains("${AppPolicy.SINGLE_ROW_FINAL_IMAGE_NAME}")) { finalSingleImageUri = Uri.fromFile(file) }
}
return finalSingleImageUri
}

fun getFinalTwoImageUri(): Uri {
var finalTwoImageUri: Uri = Uri.EMPTY
context.cacheDir.listFiles().forEach {
file -> if (file.name.contains("${AppPolicy.TWO_ROW_FINAL_IMAGE_NAME}")) { finalTwoImageUri = Uri.fromFile(file) }
}
return finalTwoImageUri
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.foke.together.domain.interactor.entity

enum class FramePosition {
LEFT,
RIGHT;
fun findBy(ordinal: Int): FramePosition {
return when (ordinal) {
LEFT.ordinal -> LEFT
RIGHT.ordinal -> RIGHT
else -> throw IllegalArgumentException("Unknown value: $ordinal")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.foke.together.domain.interactor.web

import com.foke.together.util.AppPolicy
import javax.inject.Inject

// Download url
// https://4cuts.store/download/{user_name}/{key}
class GetDownloadUrlUseCase @Inject constructor(
private val getCurrentUserInformationUseCase: GetCurrentUserInformationUseCase
) {
suspend operator fun invoke(key: String): Result<String> {
getCurrentUserInformationUseCase()
.onSuccess {
"${AppPolicy.WEB_SERVER_URL}download/${it.name}/$key"
}
return Result.failure(Exception("Unknown error"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.foke.together.domain.interactor.web

import com.foke.together.domain.output.SessionRepositoryInterface
import javax.inject.Inject

class SessionKeyUseCase @Inject constructor(
private val sessionRepository: SessionRepositoryInterface
) {
suspend fun setSessionKey() {
sessionRepository.setSessionKey()
}

fun getSessionKey(): String {
return sessionRepository.getSessionKey()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.foke.together.domain.output

interface SessionRepositoryInterface {
suspend fun setSessionKey()
fun getSessionKey(): String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.foke.together.external.repository

import com.foke.together.domain.output.SessionRepositoryInterface
import com.foke.together.util.TimeUtil
import javax.inject.Inject

class SessionRepository @Inject constructor(): SessionRepositoryInterface {
private var sessionKey: String = ""
override suspend fun setSessionKey() {
sessionKey = TimeUtil.getCurrentTimeSec()
}

override fun getSessionKey(): String {
return sessionKey
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.foke.together.external.repository.di
import com.foke.together.domain.output.ExternalCameraRepositoryInterface
import com.foke.together.domain.output.ImageRepositoryInterface
import com.foke.together.domain.output.QRCodeRepositoryInterface
import com.foke.together.domain.output.SessionRepositoryInterface
import com.foke.together.external.repository.ExternalCameraRepository
import com.foke.together.external.repository.ImageRepository
import com.foke.together.external.repository.QRCodeRepository
import com.foke.together.external.repository.SessionRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -32,4 +34,10 @@ abstract class RepositoryModule {
abstract fun bindQRCodeRepository(
qrCodeRepository: QRCodeRepository
): QRCodeRepositoryInterface

@Singleton
@Binds
abstract fun bindSessionRepository(
sessionRepository: SessionRepository
): SessionRepositoryInterface
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
Expand All @@ -26,6 +27,8 @@ import androidx.compose.ui.graphics.rememberGraphicsLayer
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -35,6 +38,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleEventEffect
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.foke.together.domain.interactor.entity.FramePosition
import com.foke.together.presenter.R
import com.foke.together.presenter.theme.FourCutTogetherTheme
import com.foke.together.presenter.theme.highContrastDarkColorScheme
Expand All @@ -48,13 +52,31 @@ import kotlinx.coroutines.launch
fun FourCutFrame(
// TODO: Need to refactoring. separate frame design with application theme
designColorScheme: ColorScheme = mediumContrastLightColorScheme,
cameraImageUrlList : List<Uri>? = null
cameraImageUrlList : List<Uri>? = null,
position: FramePosition? = null
) {
ConstraintLayout(
modifier = Modifier
.aspectRatio(ratio = 0.3333f)
.background(color = designColorScheme.surface)
.border(1.dp, designColorScheme.inverseSurface)
.padding(
start = position.let {
when(it){
FramePosition.LEFT -> 20.dp
FramePosition.RIGHT -> 0.dp
null -> 10.dp
}
},
end = position.let {
when(it){
FramePosition.LEFT -> 0.dp
FramePosition.RIGHT -> 20.dp
null -> 10.dp
}
},
top = 40.dp
)
) {
val (cameraColumn, decorateRow) = createRefs()
LazyColumn(
Expand All @@ -67,9 +89,8 @@ fun FourCutFrame(
bottom.linkTo(decorateRow.top)
start.linkTo(parent.start)
end.linkTo(parent.end)
width = Dimension.fillToConstraints
height = Dimension.wrapContent
}
.wrapContentSize()
) {
items(AppPolicy.CAPTURE_COUNT){
//TODO: add camera image
Expand Down Expand Up @@ -114,7 +135,9 @@ fun FourCutFrame(
text = TimeUtil.getCurrentDisplayTime(),
modifier = Modifier.weight(1f),
color = designColorScheme.inverseSurface,
fontSize = 12.sp
fontSize = 15.sp,
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.padding
Expand All @@ -15,6 +16,7 @@ import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.graphics.Color
Expand All @@ -24,6 +26,8 @@ import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.graphics.rememberGraphicsLayer
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -33,6 +37,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LifecycleEventEffect
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.foke.together.domain.interactor.entity.FramePosition
import com.foke.together.presenter.R
import com.foke.together.presenter.theme.FourCutTogetherTheme
import com.foke.together.util.AppPolicy
Expand All @@ -44,25 +49,40 @@ import kotlinx.coroutines.launch
fun MakerFaireFrame(
cameraImageUrlList : List<Uri>? = null,
backgroundColor : Color = Color(0xFFF5B934),
decorateImageUrl: String? = null
position: FramePosition? = null
) {
ConstraintLayout(
modifier = Modifier
.aspectRatio(ratio = 0.3333f)
.background(backgroundColor)
.border(1.dp, Color.White)
.padding(
start = position.let {
when(it){
FramePosition.LEFT -> 20.dp
FramePosition.RIGHT -> 0.dp
null -> 10.dp
}
},
end = position.let {
when(it){
FramePosition.LEFT -> 0.dp
FramePosition.RIGHT -> 20.dp
null -> 10.dp
}
},
top = 40.dp
)
) {
val (cameraColumn,decorateImage, curTime) = createRefs()
val logoImageGuideLineStart = createGuidelineFromStart(0.15f)
val logoImageGuideLineEnd = createGuidelineFromEnd(0.15f)
val (cameraColumn,decorateRow) = createRefs()
LazyColumn(
state = rememberLazyListState(),
verticalArrangement = Arrangement.spacedBy(10.dp),
contentPadding = PaddingValues(horizontal = 10.dp, vertical = 10.dp),
contentPadding = PaddingValues(horizontal = 15.dp, vertical = 15.dp),
modifier = Modifier
.constrainAs(cameraColumn) {
top.linkTo(parent.top, margin = 15.dp)
bottom.linkTo(decorateImage.top)
top.linkTo(parent.top)
bottom.linkTo(decorateRow.top)
start.linkTo(parent.start)
end.linkTo(parent.end)
}
Expand All @@ -84,33 +104,34 @@ fun MakerFaireFrame(
}
}
}

Image(
painter = painterResource(
id = R.drawable.maker_faire_logo
),
contentDescription = "for decorate",
modifier = Modifier.constrainAs(decorateImage){
top.linkTo(cameraColumn.bottom)
bottom.linkTo(curTime.top)
start.linkTo(logoImageGuideLineStart)
end.linkTo(logoImageGuideLineEnd)
width = Dimension.fillToConstraints
height = Dimension.wrapContent
}
)

Text(
text = TimeUtil.getCurrentDisplayTime(),
modifier = Modifier.constrainAs(curTime){
top.linkTo(decorateImage.bottom)
bottom.linkTo(parent.bottom, margin = 15.dp)
start.linkTo(parent.start)
end.linkTo(parent.end)
},
color = Color.White,
fontSize = 12.sp
)
Column(
modifier = Modifier
.constrainAs(decorateRow){
top.linkTo(cameraColumn.bottom)
bottom.linkTo(parent.bottom)
start.linkTo(parent.start)
end.linkTo(parent.end)
height = Dimension.fillToConstraints
width = Dimension.fillToConstraints
},
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(
id = R.drawable.maker_faire_logo
),
contentDescription = "for decorate",
modifier = Modifier.weight(1f)
)
Text(
modifier = Modifier.weight(1f),
text = TimeUtil.getCurrentDisplayTime(),
color = Color.White,
fontSize = 15.sp,
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fun CameraScreen(
end.linkTo(parent.end, margin = 24.dp)
bottom.linkTo(title.top)
width = Dimension.fillToConstraints
height = Dimension.wrapContent
},
)
Text(
Expand Down
Loading

0 comments on commit df20c5e

Please sign in to comment.