Skip to content

Commit

Permalink
🐛 conflict solve
Browse files Browse the repository at this point in the history
  • Loading branch information
ii2001 committed Oct 24, 2024
2 parents 9313286 + 431c1d3 commit 70eb76a
Show file tree
Hide file tree
Showing 93 changed files with 2,187 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class DefaultRecipeStepMakingLocalDataSource
return recipeStepDao.insertCreatedRecipeStep(recipeStep)
}

override suspend fun fetchRecipeStepsByRecipeId(recipeId: Long): List<RecipeStepEntity>? {
return recipeStepDao.fetchRecipeStepsByRecipeId(recipeId)
override suspend fun fetchRecipeSteps(): List<RecipeStepEntity>? {
return recipeStepDao.fetchRecipeStepsByRecipeId()
}

override suspend fun fetchRecipeStepByStepNumber(
Expand All @@ -29,4 +29,20 @@ class DefaultRecipeStepMakingLocalDataSource
override suspend fun deleteRecipeStepsByRecipeId(recipeId: Long) {
recipeStepDao.deleteRecipeStepsByRecipeId(recipeId)
}

override suspend fun deleteRecipeStepByStepNumber(
recipeId: Long,
stepNumber: Int,
) {
recipeStepDao.deleteRecipeStepByStepNumber(recipeId, stepNumber)
}

override suspend fun updateRecipeStepImage(
id: Long,
imageUri: String?,
imageTitle: String?,
imageUploaded: Boolean,
) {
recipeStepDao.updateRecipeStepImage(id, imageUri, imageTitle, imageUploaded)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@ import net.pengcook.android.data.model.step.RecipeStepEntity
interface RecipeStepMakingLocalDataSource {
suspend fun insertCreatedRecipeStep(recipeStep: RecipeStepEntity): Long

suspend fun fetchRecipeStepsByRecipeId(recipeId: Long): List<RecipeStepEntity>?
suspend fun fetchRecipeSteps(): List<RecipeStepEntity>?

suspend fun fetchRecipeStepByStepNumber(
recipeId: Long,
stepNumber: Int,
): RecipeStepEntity?

suspend fun deleteRecipeStepsByRecipeId(recipeId: Long)

suspend fun deleteRecipeStepByStepNumber(
recipeId: Long,
stepNumber: Int,
)

suspend fun updateRecipeStepImage(
id: Long,
imageUri: String?,
imageTitle: String?,
imageUploaded: Boolean,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class DefaultMakingRecipeLocalDataSource
return database.withTransaction {
recipeDescriptionDao.insertCreatedRecipeDescription(recipeDescription)
ingredientDao.saveIngredients(ingredients)
categoryDao.deleteAllCategories()
categoryDao.saveSingleCategory(category)
recipeDescription.id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import net.pengcook.android.data.model.step.RecipeStepEntity

@Database(
entities = [RecipeDescriptionEntity::class, RecipeStepEntity::class, CategoryEntity::class, IngredientEntity::class],
version = 6,
version = 7,
)
abstract class RecipeDatabase : RoomDatabase() {
abstract fun recipeDescriptionDao(): RecipeDescriptionDao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ object RecipeStepContract {
const val COLUMN_STEP_NUMBER = "step_number"
const val COLUMN_COOKING_TIME = "cooking_time"
const val COLUMN_DESCRIPTION = "description"
const val COLUMN_IMAGE_UPLOADED = "image_uploaded"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ interface RecipeStepDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertCreatedRecipeStep(recipeStep: RecipeStepEntity): Long

@Query("SELECT * FROM recipe_step WHERE recipe_description_id = :recipeId")
suspend fun fetchRecipeStepsByRecipeId(recipeId: Long): List<RecipeStepEntity>?
@Query("SELECT * FROM recipe_step ORDER BY step_number ASC")
suspend fun fetchRecipeStepsByRecipeId(): List<RecipeStepEntity>?

@Query("SELECT * FROM recipe_step WHERE recipe_description_id = :recipeId AND step_number = :stepNumber")
suspend fun fetchRecipeStepByStepNumber(
Expand All @@ -22,4 +22,19 @@ interface RecipeStepDao {

@Query("DELETE FROM recipe_step WHERE recipe_description_id = :recipeId")
suspend fun deleteRecipeStepsByRecipeId(recipeId: Long)

@Query("DELETE FROM recipe_step WHERE recipe_description_id = :recipeId AND step_number = :stepNumber")
suspend fun deleteRecipeStepByStepNumber(
recipeId: Long,
stepNumber: Int,
)

// change image content
@Query("UPDATE recipe_step SET image_uri = :imageUri, image_title = :imageTitle, image_uploaded = :imageUploaded WHERE id = :id")
suspend fun updateRecipeStepImage(
id: Long,
imageUri: String?,
imageTitle: String?,
imageUploaded: Boolean,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ import net.pengcook.android.data.model.makingrecipe.entity.RecipeDescriptionEnti
],
)
data class RecipeStepEntity(
@ColumnInfo(RecipeStepContract.COLUMN_ID) val id: Long = System.currentTimeMillis(),
@ColumnInfo(RecipeStepContract.COLUMN_STEP_NUMBER) val stepNumber: Int,
@ColumnInfo(RecipeStepContract.COLUMN_ID) val id: Long = (System.currentTimeMillis().toString() + stepNumber.toString()).toLong(),
@ColumnInfo(RecipeStepContract.COLUMN_RECIPE_DESCRIPTION_ID) val recipeDescriptionId: Long,
@ColumnInfo(RecipeStepContract.COLUMN_IMAGE_URI) val imageUri: String?,
@ColumnInfo(RecipeStepContract.COLUMN_IMAGE_TITLE) val imageTitle: String?,
@ColumnInfo(RecipeStepContract.COLUMN_COOKING_TIME) val cookingTime: String?,
@ColumnInfo(RecipeStepContract.COLUMN_STEP_NUMBER) val stepNumber: Int,
@ColumnInfo(RecipeStepContract.COLUMN_DESCRIPTION) val description: String?,
@ColumnInfo(RecipeStepContract.COLUMN_IMAGE_UPLOADED) val imageUploaded: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class DefaultRecipeStepMakingRepository
private val recipeStepMakingCacheDataSource: RecipeStepMakingCacheDataSource,
) : NetworkResponseHandler(),
RecipeStepMakingRepository {
override suspend fun fetchRecipeSteps(): Result<List<RecipeStepMaking>?> {
return runCatching {
recipeStepMakingLocalDataSource.fetchRecipeSteps()?.map {
it.toRecipeStepMaking()
}
}
}

override suspend fun fetchRecipeStep(
recipeId: Long,
sequence: Int,
Expand Down Expand Up @@ -52,6 +60,31 @@ class DefaultRecipeStepMakingRepository
}
}

override suspend fun deleteRecipeStepsNonAsync(recipeId: Long) {
recipeStepMakingLocalDataSource.deleteRecipeStepsByRecipeId(recipeId)
}

override suspend fun updateRecipeStepImage(
id: Long,
imageUri: String?,
imageTitle: String?,
imageUploaded: Boolean,
) {
recipeStepMakingLocalDataSource.updateRecipeStepImage(
id,
imageUri,
imageTitle,
imageUploaded,
)
}

override suspend fun deleteRecipeStepByStepNumber(
recipeId: Long,
stepNumber: Int,
) {
recipeStepMakingLocalDataSource.deleteRecipeStepByStepNumber(recipeId, stepNumber)
}

private fun RecipeStepMaking.toRecipeStepEntity(): RecipeStepEntity =
RecipeStepEntity(
recipeDescriptionId = recipeId,
Expand All @@ -60,6 +93,7 @@ class DefaultRecipeStepMakingRepository
description = description.ifEmpty { null },
imageUri = imageUri.ifEmpty { null },
imageTitle = image.ifEmpty { null },
imageUploaded = imageUploaded,
)

private fun RecipeStepEntity.toRecipeStepMaking(): RecipeStepMaking =
Expand All @@ -71,5 +105,6 @@ class DefaultRecipeStepMakingRepository
imageUri = imageUri ?: "",
image = imageTitle ?: "",
cookingTime = cookingTime ?: "00:00:00",
imageUploaded = imageUploaded,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package net.pengcook.android.data.repository.making.step
import net.pengcook.android.presentation.core.model.RecipeStepMaking

interface RecipeStepMakingRepository {
suspend fun fetchRecipeSteps(): Result<List<RecipeStepMaking>?>

suspend fun fetchRecipeStep(
recipeId: Long,
sequence: Int,
Expand All @@ -14,4 +16,18 @@ interface RecipeStepMakingRepository {
): Result<Unit>

fun deleteRecipeSteps(recipeId: Long)

suspend fun deleteRecipeStepsNonAsync(recipeId: Long)

suspend fun updateRecipeStepImage(
id: Long,
imageUri: String?,
imageTitle: String?,
imageUploaded: Boolean,
)

suspend fun deleteRecipeStepByStepNumber(
recipeId: Long,
stepNumber: Int,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class DefaultMakingRecipeRepository

override suspend fun fetchTotalRecipeData(): Result<RecipeCreation?> =
runCatching {
val recipeCreation = makingRecipeLocalDataSource.fetchTotalRecipeData()?.toRecipeCreation()
val recipeCreation =
makingRecipeLocalDataSource.fetchTotalRecipeData()?.toRecipeCreation()
println(recipeCreation)
recipeCreation
}
Expand All @@ -54,8 +55,11 @@ class DefaultMakingRecipeRepository
runCatching {
val id = recipeDescription.recipeDescriptionId
val recipeDescriptionEntity = recipeDescription.toRecipeDescriptionEntity(id)
// val categoryEntities = recipeDescription.categories.toCategoryEntities(id)
val categoryEntity = CategoryEntity(recipeId = id, categoryName = recipeDescription.categories.joinToString())
val categoryEntity =
CategoryEntity(
recipeId = id,
categoryName = recipeDescription.categories.joinToString(",") { it.trim() },
)
val ingredientEntities = recipeDescription.ingredients.toIngredientEntities(id)
makingRecipeLocalDataSource.saveRecipeDescription(
recipeDescription = recipeDescriptionEntity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ fun RecipeStepEntity.toRecipeStepMaking(): RecipeStepMaking =
imageUri = imageUri ?: "",
stepId = id,
cookingTime = cookingTime ?: "00:00:00",
imageUploaded = imageUploaded,
)

fun IngredientEntity.toIngredient(): Ingredient =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fun loadImage(
view: ImageView,
uri: Uri?,
) {
println("uri: $uri")
Glide
.with(view.context)
.load(uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,28 @@ data class RecipeStepMaking(
val sequence: Int,
val imageUri: String,
val cookingTime: String,
val imageUploaded: Boolean,
) {
init {
require(cookingTime.matches(Regex("\\d{2}:\\d{2}:\\d{2}"))) {
"cookingTime must be in the format of HH:MM:SS"
}
}

val minute: String = if (cookingTime.split(":")[1] == "00") "" else cookingTime.split(":")[1]
val second: String = if (cookingTime.split(":")[2] == "00") "" else cookingTime.split(":")[2]

companion object {
val EMPTY =
RecipeStepMaking(
stepId = 0,
recipeId = 0,
description = "",
image = "",
sequence = 0,
imageUri = "",
cookingTime = "00:00:00",
imageUploaded = false,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.pengcook.android.presentation.making

import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import net.pengcook.android.presentation.making.listener.ItemMoveListener

class ItemMoveCallback(private val listener: ItemMoveListener) : ItemTouchHelper.SimpleCallback(
ItemTouchHelper.UP or ItemTouchHelper.DOWN or ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT,
0,
) {
override fun onMove(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder,
): Boolean {
listener.onItemMove(viewHolder.absoluteAdapterPosition, target.absoluteAdapterPosition)
return true
}

override fun onSwiped(
viewHolder: RecyclerView.ViewHolder,
direction: Int,
) {
// Not To Implement
}

override fun onSelectedChanged(
viewHolder: RecyclerView.ViewHolder?,
actionState: Int,
) {
super.onSelectedChanged(viewHolder, actionState)
if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) {
viewHolder?.itemView?.apply {
alpha = 0.7f
scaleX = 1.1f
scaleY = 1.1f
}
}
}

override fun clearView(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
) {
super.clearView(recyclerView, viewHolder)
viewHolder.itemView.apply {
alpha = 1.0f
scaleX = 1.0f
scaleY = 1.0f
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ sealed interface RecipeMakingEvent {

data object AddImage : RecipeMakingEvent

data object AddStepImages : RecipeMakingEvent

data class PresignedUrlRequestSuccessful(val presignedUrl: String) : RecipeMakingEvent

data class StepImagesPresignedUrlRequestSuccessful(val presignedUrls: List<String>) : RecipeMakingEvent

data object PostImageSuccessful : RecipeMakingEvent

data object PostImageFailure : RecipeMakingEvent
Expand All @@ -16,4 +20,40 @@ sealed interface RecipeMakingEvent {
data object PostRecipeFailure : RecipeMakingEvent

data object MakingCancellation : RecipeMakingEvent

data object PostStepImageCompleted : RecipeMakingEvent
}

sealed interface RecipeMakingEvent2 {
data class ChangeImage(val id: Int) : RecipeMakingEvent2

data class ImageDeletionSuccessful(val id: Int) : RecipeMakingEvent2

data object UnexpectedError : RecipeMakingEvent2

data object NullPhotoPath : RecipeMakingEvent2

data object PostImageSuccessful : RecipeMakingEvent2

data object PostImageFailure : RecipeMakingEvent2

data object RecipeSavingSuccessful : RecipeMakingEvent2

data object RecipeSavingFailure : RecipeMakingEvent2

data object MakingCancellation : RecipeMakingEvent2

data object AddThumbnailImage : RecipeMakingEvent2

data object AddStepImages : RecipeMakingEvent2

data object StepImageSelectionFailure : RecipeMakingEvent2

data object DescriptionFormNotCompleted : RecipeMakingEvent2

data object RecipePostFailure : RecipeMakingEvent2

data object RecipePostSuccessful : RecipeMakingEvent2

data class NavigateToMakingStep(val sequence: Int) : RecipeMakingEvent2
}
Loading

0 comments on commit 70eb76a

Please sign in to comment.