Skip to content

Commit

Permalink
Merge pull request #22 from develop-playground/feature/remove-feed-item
Browse files Browse the repository at this point in the history
피드에서 추억 제거
  • Loading branch information
hongbeomi authored Dec 21, 2022
2 parents 72d5f08 + ac59306 commit 1fce526
Show file tree
Hide file tree
Showing 16 changed files with 243 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ interface MemoryService {
@POST("memory")
suspend fun postMemory(@Body memoryInput: MemoryInput): MemoryData

@DELETE("memory/{id}")
suspend fun deleteMemory(@Path("id") params: Int)

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ class MemoryRepositoryImpl(private val service: MemoryService) : MemoryRepositor

override suspend fun postMemory(params: MemoryInput): Memory = service.postMemory(params).toDomain()

override suspend fun deleteMemory(params: Int) = service.deleteMemory(params)

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.dev.playground.domain.usecase.login.GetTokenUseCase
import com.dev.playground.domain.usecase.login.RemoveKakaoTokenUseCase
import com.dev.playground.domain.usecase.login.RequestLoginUseCase
import com.dev.playground.domain.usecase.login.SetTokenUseCase
import com.dev.playground.domain.usecase.memory.DeleteMemoryUseCase
import com.dev.playground.domain.usecase.memory.GetMemoryListUseCase
import com.dev.playground.domain.usecase.memory.PostMemoryUseCase
import com.dev.playground.domain.usecase.photo.DeletePhotoUseCase
Expand All @@ -15,11 +16,16 @@ import org.koin.dsl.module
val useCaseModule = module {
factory { GetTokenUseCase(get(), get(named(IO))) }
factory { SetTokenUseCase(get(), get(named(IO))) }

factory { RemoveKakaoTokenUseCase(get(), get(named(IO))) }
factory { RequestLoginUseCase(get(), get(named(IO))) }

factory { GetMemoryListUseCase(get(), get(named(IO))) }
factory { PostMemoryUseCase(get(), get(named(IO))) }
factory { DeleteMemoryUseCase(get(), get(named(IO))) }

factory { UploadPhotoUseCase(get(), get(named(IO))) }
factory { DeletePhotoUseCase(get(), get(named(IO))) }

factory { GetAddressUseCase(get(), get(named(IO))) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ interface MemoryRepository {

suspend fun postMemory(params: MemoryInput): Memory

suspend fun deleteMemory(params: Int)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.dev.playground.domain.usecase.memory

import com.dev.playground.domain.repository.MemoryRepository
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext

class DeleteMemoryUseCase(
private val repository: MemoryRepository,
private val dispatcher: CoroutineDispatcher
) {

suspend operator fun invoke(id: Int) = withContext(dispatcher) {
runCatching {
repository.deleteMemory(id)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ val viewModelModule = module {
getAddressUseCase = get()
)
}
viewModel { FeedViewModel(getMemoryListUseCase = get()) }
viewModel {
FeedViewModel(
getMemoryListUseCase = get(),
deleteMemoryUseCase = get()
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.dev.playground.presentation.ui.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import androidx.databinding.DataBindingUtil
import com.dev.playground.presentation.R
import com.dev.playground.presentation.databinding.DialogDropBinding

class DropDialog(context: Context) : Dialog(context) {

companion object {
private const val EMPTY = ""
}

private lateinit var binding: DialogDropBinding

var contentText: String = EMPTY
var leftText: String = EMPTY
var rightText: String = EMPTY

var onLeftClick: (() -> Unit)? = null
var onRightClick: (() -> Unit)? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.inflate(
LayoutInflater.from(context),
R.layout.dialog_drop,
null,
false
)
setContentView(binding.root)
initViews()
}

private fun initViews() = with(binding) {
tvContent.text = contentText
tvLeft.text = leftText
tvRight.text = rightText

tvLeft.setOnClickListener {
onLeftClick?.invoke()
}
tvRight.setOnClickListener {
onRightClick?.invoke()
}
}

}

fun DropDialog.show(action: DropDialog.() -> Unit) = DropDialog(context).apply(action).show()
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ class FeedContract {
}
}

sealed interface Event : UiEvent {
data class OnClickEdit(val id: Int) : Event
data class OnClickRemove(val id: Int) : Event
sealed class Event(open val id: Int) : UiEvent {
data class OnClickEdit(override val id: Int) : Event(id)
data class OnClickRemove(override val id: Int) : Event(id)
data class OnClickDeleteMemory(override val id: Int) : Event(id)
}

sealed interface Effect: UiEffect {
data class ShowEditPage(val id: Int): Effect
data class ShowRemoveDialog(val id: Int): Effect
sealed interface Effect : UiEffect {
data class ShowEditPage(val id: Int) : Effect
data class ShowRemoveDialog(val id: Int) : Effect
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import com.dev.playground.presentation.base.BaseFragment
import com.dev.playground.presentation.base.ScrollableScreen
import com.dev.playground.presentation.base.SimpleBindingAdapter
import com.dev.playground.presentation.databinding.FragmentFeedBinding
import com.dev.playground.presentation.ui.dialog.DropDialog
import com.dev.playground.presentation.ui.dialog.show
import com.dev.playground.presentation.ui.feed.FeedContract.Effect.ShowEditPage
import com.dev.playground.presentation.ui.feed.FeedContract.Effect.ShowRemoveDialog
import com.dev.playground.presentation.ui.feed.FeedContract.Event.OnClickDeleteMemory
import com.dev.playground.presentation.ui.feed.FeedContract.State.Success
import com.dev.playground.presentation.util.repeatOnLifecycleState
import kotlinx.coroutines.flow.collectLatest
Expand Down Expand Up @@ -53,7 +56,19 @@ class FeedFragment : BaseFragment<FragmentFeedBinding>(R.layout.fragment_feed),
is ShowEditPage -> {

}
is ShowRemoveDialog -> {
is ShowRemoveDialog -> context?.let { c ->
DropDialog(c).show {
contentText = getString(R.string.drop_dialog_content_remove_memory)
leftText = getString(R.string.drop_dialog_cancel)
rightText = getString(R.string.drop_dialog_delete)
onLeftClick = {
dismiss()
}
onRightClick = {
setEvent(OnClickDeleteMemory(it.id))
dismiss()
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dev.playground.presentation.ui.feed

import androidx.lifecycle.viewModelScope
import com.dev.playground.domain.usecase.memory.DeleteMemoryUseCase
import com.dev.playground.domain.usecase.memory.GetMemoryListUseCase
import com.dev.playground.presentation.base.BaseViewModel
import com.dev.playground.presentation.model.toPresentation
Expand All @@ -14,6 +15,7 @@ import kotlinx.coroutines.launch

class FeedViewModel(
private val getMemoryListUseCase: GetMemoryListUseCase,
private val deleteMemoryUseCase: DeleteMemoryUseCase,
) : BaseViewModel<State, Event, Effect>(Loading) {

init {
Expand Down Expand Up @@ -43,12 +45,22 @@ class FeedViewModel(
}
}

private fun deleteMemory(id: Int) {
viewModelScope.launch {
deleteMemoryUseCase.invoke(id)
fetch()
}
}

override fun handleEvent(event: Event) {
setEffect {
when (event) {
is OnClickEdit -> ShowEditPage(event.id)
is OnClickRemove -> ShowRemoveDialog(event.id)
when (event) {
is OnClickEdit -> setEffect {
ShowEditPage(event.id)
}
is OnClickRemove -> setEffect {
ShowRemoveDialog(event.id)
}
is Event.OnClickDeleteMemory -> deleteMemory(event.id)
}
}

Expand Down
16 changes: 16 additions & 0 deletions presentation/src/main/res/drawable/ic_warning_lime.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="17.6dp"
android:height="16dp"
android:viewportWidth="17.6"
android:viewportHeight="16">
<group>
<clip-path
android:pathData="M0,0h17.6v16h-17.6z"/>
<path
android:pathData="M17.464,14.435 L9.674,0.49a1.025,1.025 0,0 0,-1.749 0L0.137,14.435a1.062,1.062 0,0 0,0 1.043A0.993,0.993 0,0 0,1.01 16H16.589a1,1 0,0 0,0.875 -0.521,1.068 1.068,0 0,0 0,-1.043M8.634,0.912A0.187,0.187 0,0 1,8.8 0.813a0.185,0.185 0,0 1,0.165 0.1l7.789,13.945a0.2,0.2 0,0 1,0 0.2,0.185 0.185,0 0,1 -0.165,0.1H1.01a0.185,0.185 0,0 1,-0.165 -0.1,0.2 0.2,0 0,1 0,-0.2Z"
android:fillColor="#c8d94d"/>
<path
android:pathData="M8.795,11.962a0.694,0.694 0,0 1,0.684 0.707,0.685 0.685,0 1,1 -1.368,0 0.694,0.694 0,0 1,0.684 -0.707m0.4,-0.894h-0.81a0.046,0.046 0,0 1,-0.046 -0.045l-0.276,-5.356a0.319,0.319 0,0 1,0.313 -0.341h0.829a0.319,0.319 0,0 1,0.313 0.341l-0.276,5.356a0.047,0.047 0,0 1,-0.046 0.045"
android:fillColor="#c8d94d"/>
</group>
</vector>
81 changes: 81 additions & 0 deletions presentation/src/main/res/layout/dialog_drop.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">

<ImageView
android:id="@+id/ivWarning"
android:layout_width="0dp"
android:layout_height="@dimen/drop_dialog_warning_icon_height"
android:background="@color/black"
android:scaleType="centerInside"
android:src="@drawable/ic_warning_lime"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tvContent"
style="@style/Pretendard.Light.14"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingVertical="@dimen/spacing_20"
android:textColor="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ivWarning"
tools:text="안내 안내 안내 안내" />

<View
android:id="@+id/vHorizontalDivider"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/gray_light"
app:layout_constraintTop_toBottomOf="@id/tvContent" />

<TextView
android:id="@+id/tvLeft"
style="@style/Pretendard.Light.14"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:paddingVertical="@dimen/spacing_12"
android:textColor="@color/black"
app:layout_constraintEnd_toStartOf="@id/vVerticalDivider"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vHorizontalDivider"
tools:text="취소" />

<View
android:id="@+id/vVerticalDivider"
android:layout_width="0.5dp"
android:layout_height="0dp"
android:background="@color/gray_light"
app:layout_constraintBottom_toBottomOf="@id/tvLeft"
app:layout_constraintEnd_toStartOf="@id/tvRight"
app:layout_constraintStart_toEndOf="@id/tvLeft"
app:layout_constraintTop_toTopOf="@id/tvLeft" />

<TextView
android:id="@+id/tvRight"
style="@style/Pretendard.Light.14"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:paddingVertical="@dimen/spacing_12"
android:textColor="@color/red"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/vVerticalDivider"
app:layout_constraintTop_toBottomOf="@id/vHorizontalDivider"
tools:text="삭제" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
8 changes: 5 additions & 3 deletions presentation/src/main/res/layout/item_memory.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="item"
type="com.dev.playground.presentation.model.MemoryUIModel" />
Expand Down Expand Up @@ -66,6 +67,7 @@
android:id="@+id/llMemoryEdit"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:orientation="horizontal"
android:paddingHorizontal="@dimen/spacing_16"
Expand Down Expand Up @@ -107,10 +109,10 @@
android:layout_marginHorizontal="@dimen/spacing_16"
android:text="@{item.content}"
android:textColor="@color/black"
app:readMoreTextAppearance="@style/Pretendard.Light.14"
app:readMoreTextColor="@color/gray_medium"
app:readMoreMaxLines="2"
app:readMoreText="@string/memory_content_more"
app:readMoreMaxLines="2" />
app:readMoreTextAppearance="@style/Pretendard.Light.14"
app:readMoreTextColor="@color/gray_medium" />

</LinearLayout>
</layout>
4 changes: 2 additions & 2 deletions presentation/src/main/res/layout/item_photo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
app:imageFile="@{item.file}" />

<ImageButton
android:layout_width="@dimen/photo_remove_size"
android:layout_height="@dimen/photo_remove_size"
android:layout_width="@dimen/photo_remove_button_size"
android:layout_height="@dimen/photo_remove_button_size"
android:background="@drawable/ic_remove_x"
android:layout_gravity="top|end"
android:onClick="@{() -> item.onClickRemove.invoke(item.index)}" />
Expand Down
7 changes: 6 additions & 1 deletion presentation/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@
<dimen name="add_memory_drop_button_radius">5dp</dimen>
<dimen name="add_memory_drop_button_height">44dp</dimen>

<dimen name="photo_remove_button_size">36dp</dimen>

<!-- image pager -->
<dimen name="image_pager_tab_indicator_thickness">2dp</dimen>
<dimen name="image_pager_tab_height">4dp</dimen>

<!-- custom login button -->
<dimen name="round_rect_outline_provider_button_radius">5dp</dimen>
<dimen name="photo_remove_size">36dp</dimen>

<!-- drop dialog -->
<dimen name="drop_dialog_warning_icon_height">32dp</dimen>
<dimen name="drop_dialog_radius">5dp</dimen>

</resources>
Loading

0 comments on commit 1fce526

Please sign in to comment.